From 37873e16b131244d1c71fba96d9548d308ebd912 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 17 Sep 2014 20:42:32 +0200 Subject: [PATCH] Added wiki icon + fixed keyboard search for message list. --- .../icons/mini-kfaenza/application-wiki.png | Bin 0 -> 5239 bytes src/core/messagesmodel.cpp | 11 ++- src/core/messagesproxymodel.cpp | 69 ++++++++++++++++++ src/core/messagesproxymodel.h | 2 + src/gui/messagesview.cpp | 4 +- 5 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 resources/graphics/icons/mini-kfaenza/application-wiki.png 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 0000000000000000000000000000000000000000..17e2abcaf06014752d36d8dd3e48b0716ba95b16 GIT binary patch literal 5239 zcmWld2|UyPAIIkiAvu;Sbk0kt%Ge@S}M{YuBv|KGl za*TwAx$pRYdhD@%AA3B$`+h&4_ujAP>-GM|nHcGwW9DauKp^LkdRk`SsP^y8!~i}^ z-7(YPz<|1|s|7jz_sVZCNrgb5l1MFebN`&x?2uSHtM*RSy}|aaqrH{274N6={cBlo zy}r4HPh`1$FB#vBV?tez(ojD>BPSlNr_K)LIMRAoZ0(kYdLs_imPq6G(7HAP-7In^ zlHmQ`e)1FjYb%3;E5}WKYeReZHRX1t=dLM-dA84}EHO%ZKb019s8qp4yZw;;j&o*7 zuA85?9H__FLt963@?+HduBkZ}MYXhTRnbd3(yb=C90)!Y;bAZ{R^IuZY#cbpb;^;1 z_Y;rjJi(W5QR&jrd|9}G<2ApI=SwF?)Kjiu2rISu4MgJAvtP-&C#wnfkLN=4Q{F1R zjG(lfF5Nz@3Wp*4YF|)VesdWkFf%m|@F(=&AzafUq4aM<3m%dxmER04`dO!sqWgB# zXX1tvY~l;6+u9Jf6cqz_d@jACtE}BX(D#I*q%$rqM;{Leo$QGk$-vs1Bc^L469QFK znV~irq1=uKXW7rBq`ND`PSDQkTG>JaxLO^m%fyJ^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j#&HfuAAcfgh z=u}v0rlbGt9ExJs5g>`NXJ5j(qj;moA8p5y71*v^xia36h;s*)2f&q%#w_Og?b`Xt zFI}T?n48B;cicJ-J0A!kVUeP#$GeRk|K=WU)4~k75~90{i;LVu_~YiU6LqecSy?D| zcaTJNK|RA#VwzN|Hw(2U8$fUZU@ROF2bu<wDEoK0-z+^64h2 zxv@+t6?bX=NNOUHJnEUEG(2ZM0(kb$&53{{<$N=)wDjx1K-?eW_vV~2{Gh9O%ci{l zS4A?lNYg3m>g!{&sj{2e}IJuzRFk#IJS< zqq0#H(1x8f9zf;p-Mb){7L-c#JDW9i0&l|XcPUBC^Qmf^f&minsM5amGsr?h4hjO? zy(vP-ojq)xYm<#k^;P!G*b%;Nzmr`JHxjlv_^%=u;l-gKPl~MUD0olGUB7<)9+Ry^ z+IUBZYO&eb$%bVrwPeaW!4Xe)no}#u!n0Z-)_3{mhl|?`n|H(ZCbPeGG|CV*MW?p5 zImVI(o&{v<7suk~=Ts{xh3@>o$~@}990-gBoU$q3=2253&gSR8O@&_zx!+5!(Yk+T=ZRI^IET)KJAM2FgU zN?nwizw)g^V!Zsy(f!Vcomcbem#Qb2{&aFu?%R%q$%i2xZ3&Dhu?ysXQuJm~%RKi> zczj1Y6#i;9#6-qFCanL^_3^{<5S8os8NH@W{Tjdatabase()->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); }