diff --git a/resources/graphics/icons/mini-kfaenza/application-wiki.png b/resources/graphics/icons/mini-kfaenza/application-wiki.png new file mode 100644 index 000000000..17e2abcaf Binary files /dev/null and b/resources/graphics/icons/mini-kfaenza/application-wiki.png differ diff --git a/src/core/messagesmodel.cpp b/src/core/messagesmodel.cpp index ca6cf4f11..db4d5cff7 100755 --- a/src/core/messagesmodel.cpp +++ b/src/core/messagesmodel.cpp @@ -29,9 +29,7 @@ MessagesModel::MessagesModel(QObject *parent) - : QSqlTableModel(parent, - qApp->database()->connection("MessagesModel", - DatabaseFactory::FromSettings)) { + : QSqlTableModel(parent, qApp->database()->connection("MessagesModel", DatabaseFactory::FromSettings)) { setObjectName("MessagesModel"); setupFonts(); setupIcons(); @@ -102,7 +100,7 @@ QStringList MessagesModel::textualFeeds() const { } int MessagesModel::messageId(int row_index) const { - return data(row_index, MSG_DB_ID_INDEX).toInt(); + return data(row_index, MSG_DB_ID_INDEX, Qt::EditRole).toInt(); } Message MessagesModel::messageAt(int row_index) const { @@ -164,6 +162,11 @@ QVariant MessagesModel::data(const QModelIndex &idx, int role) const { return author_name.isEmpty() ? "-" : author_name; } + /* + else if (index_column == MSG_DB_ID_INDEX) { + return QSqlTableModel::data(index(idx.row(), MSG_DB_TITLE_INDEX, idx.parent())); + } + */ else if (index_column != MSG_DB_IMPORTANT_INDEX && index_column != MSG_DB_READ_INDEX) { return QSqlTableModel::data(idx, role); diff --git a/src/core/messagesproxymodel.cpp b/src/core/messagesproxymodel.cpp index a7558eb6d..89df4c6ac 100644 --- a/src/core/messagesproxymodel.cpp +++ b/src/core/messagesproxymodel.cpp @@ -64,6 +64,75 @@ QModelIndexList MessagesProxyModel::mapListFromSource(const QModelIndexList &ind return mapped_indexes; } +QModelIndexList MessagesProxyModel::match(const QModelIndex &start, int role, + const QVariant &value, int hits, Qt::MatchFlags flags) const { + QModelIndexList result; + uint matchType = flags & 0x0F; + Qt::CaseSensitivity cs = Qt::CaseInsensitive; + bool wrap = flags & Qt::MatchWrap; + bool allHits = (hits == -1); + QString text; + int from = start.row(); + int to = rowCount(); + + for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) { + for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) { + QModelIndex idx = index(r, start.column()); + if (!idx.isValid()) + continue; + QVariant v; + + if (start.column() == MSG_DB_ID_INDEX) { + v = m_sourceModel->data(mapToSource(idx).row(), MSG_DB_TITLE_INDEX); + } + else { + v = data(idx, role); + } + + // QVariant based matching. + if (matchType == Qt::MatchExactly) { + if (value == v) + result.append(idx); + } else { // QString based matching. + if (text.isEmpty()) // Lazy conversion. + text = value.toString(); + QString t = v.toString(); + switch (matchType) { + case Qt::MatchRegExp: + if (QRegExp(text, cs).exactMatch(t)) + result.append(idx); + break; + case Qt::MatchWildcard: + if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t)) + result.append(idx); + break; + case Qt::MatchStartsWith: + if (t.startsWith(text, cs)) + result.append(idx); + break; + case Qt::MatchEndsWith: + if (t.endsWith(text, cs)) + result.append(idx); + break; + case Qt::MatchFixedString: + if (t.compare(text, cs) == 0) + result.append(idx); + break; + case Qt::MatchContains: + default: + if (t.contains(text, cs)) + result.append(idx); + } + } + } + + // Prepare for the next iteration. + from = 0; + to = start.row(); + } + return result; +} + QModelIndexList MessagesProxyModel::mapListToSource(const QModelIndexList &indexes) { QModelIndexList source_indexes; diff --git a/src/core/messagesproxymodel.h b/src/core/messagesproxymodel.h index 2eae7710b..5733f1cfb 100644 --- a/src/core/messagesproxymodel.h +++ b/src/core/messagesproxymodel.h @@ -40,6 +40,8 @@ class MessagesProxyModel : public QSortFilterProxyModel { QModelIndexList mapListToSource(const QModelIndexList &indexes); QModelIndexList mapListFromSource(const QModelIndexList &indexes, bool deep = false); + QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const; + protected: // Compares two rows of data. bool lessThan(const QModelIndex &left, const QModelIndex &right) const; diff --git a/src/gui/messagesview.cpp b/src/gui/messagesview.cpp index 36ed11828..dcc51b7ab 100755 --- a/src/gui/messagesview.cpp +++ b/src/gui/messagesview.cpp @@ -216,9 +216,7 @@ void MessagesView::currentChanged(const QModelIndex ¤t, void MessagesView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { - if (qApp->settings()->value(APP_CFG_MESSAGES, - "keep_cursor_center", - false).toBool()) { + if (qApp->settings()->value(APP_CFG_MESSAGES, "keep_cursor_center", false).toBool()) { scrollTo(currentIndex(), QAbstractItemView::PositionAtCenter); }