mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-16 19:03:25 +01:00
Added wiki icon + fixed keyboard search for message list.
This commit is contained in:
parent
d24166c325
commit
37873e16b1
BIN
resources/graphics/icons/mini-kfaenza/application-wiki.png
Normal file
BIN
resources/graphics/icons/mini-kfaenza/application-wiki.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user