Added wiki icon + fixed keyboard search for message list.

This commit is contained in:
Martin Rotter 2014-09-17 20:42:32 +02:00
parent d24166c325
commit 37873e16b1
5 changed files with 79 additions and 7 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -216,9 +216,7 @@ void MessagesView::currentChanged(const QModelIndex &current,
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);
}