From c37eadea07a28837b9bafcf69118942515e745ee Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 5 Sep 2023 10:24:37 +0200 Subject: [PATCH] make displaying of huge article lists faster due to optimizations in how article list filtering is handled --- src/librssguard/core/messageobject.cpp | 16 ++-- src/librssguard/core/messageobject.h | 8 -- src/librssguard/core/messagesmodel.cpp | 4 +- .../core/messagesmodelsqllayer.cpp | 5 +- src/librssguard/core/messagesproxymodel.cpp | 77 ++++++++++++------- src/librssguard/core/messagesproxymodel.h | 4 +- src/librssguard/database/databasequeries.cpp | 6 +- src/librssguard/definitions/globals.h | 8 +- src/librssguard/gui/dialogs/formmain.cpp | 5 +- .../styleditemdelegatewithoutfocus.cpp | 5 +- src/librssguard/gui/tabbar.cpp | 5 +- .../gui/toolbars/toolbareditor.cpp | 7 +- src/librssguard/gui/webbrowser.cpp | 3 +- .../qtextbrowser/textbrowserviewer.cpp | 5 +- src/librssguard/miscellaneous/skinfactory.cpp | 2 +- src/librssguard/services/abstract/label.cpp | 7 +- .../services/abstract/labelsnode.cpp | 4 +- .../services/abstract/serviceroot.cpp | 4 +- 18 files changed, 98 insertions(+), 77 deletions(-) diff --git a/src/librssguard/core/messageobject.cpp b/src/librssguard/core/messageobject.cpp index d3ce80a61..0e96fb1b0 100644 --- a/src/librssguard/core/messageobject.cpp +++ b/src/librssguard/core/messageobject.cpp @@ -6,6 +6,7 @@ #include "database/databasefactory.h" #include "database/databasequeries.h" #include "definitions/definitions.h" +#include "definitions/globals.h" #include "services/abstract/labelsnode.h" #include @@ -41,27 +42,27 @@ bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicateCheck attri QVector> bind_values; // Now we construct the query according to parameter. - if ((attribute_check & DuplicateCheck::SameTitle) == DuplicateCheck::SameTitle) { + if (Globals::hasFlag(attribute_check, DuplicateCheck::SameTitle)) { where_clauses.append(QSL("title = :title")); bind_values.append({QSL(":title"), title()}); } - if ((attribute_check & DuplicateCheck::SameUrl) == DuplicateCheck::SameUrl) { + if (Globals::hasFlag(attribute_check, DuplicateCheck::SameUrl)) { where_clauses.append(QSL("url = :url")); bind_values.append({QSL(":url"), url()}); } - if ((attribute_check & DuplicateCheck::SameAuthor) == DuplicateCheck::SameAuthor) { + if (Globals::hasFlag(attribute_check, DuplicateCheck::SameAuthor)) { where_clauses.append(QSL("author = :author")); bind_values.append({QSL(":author"), author()}); } - if ((attribute_check & DuplicateCheck::SameDateCreated) == DuplicateCheck::SameDateCreated) { + if (Globals::hasFlag(attribute_check, DuplicateCheck::SameDateCreated)) { where_clauses.append(QSL("date_created = :date_created")); bind_values.append({QSL(":date_created"), created().toMSecsSinceEpoch()}); } - if ((attribute_check & DuplicateCheck::SameCustomId) == DuplicateCheck::SameCustomId) { + if (Globals::hasFlag(attribute_check, DuplicateCheck::SameCustomId)) { where_clauses.append(QSL("custom_id = :custom_id")); bind_values.append({QSL(":custom_id"), customId()}); } @@ -76,7 +77,7 @@ bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicateCheck attri bind_values.append({QSL(":id"), QString::number(m_message->m_id)}); } - if ((attribute_check & DuplicateCheck::AllFeedsSameAccount) != DuplicateCheck::AllFeedsSameAccount) { + if (!Globals::hasFlag(attribute_check, DuplicateCheck::AllFeedsSameAccount)) { // Limit to current feed. where_clauses.append(QSL("feed = :feed")); bind_values.append({QSL(":feed"), feedCustomId()}); @@ -177,8 +178,7 @@ QString MessageObject::createLabelId(const QString& title, const QString& hex_co return lbl_id; } - if ((m_account->supportedLabelOperations() & ServiceRoot::LabelOperation::Adding) != - ServiceRoot::LabelOperation::Adding) { + if (!Globals::hasFlag(m_account->supportedLabelOperations(), ServiceRoot::LabelOperation::Adding)) { qWarningNN << LOGSEC_CORE << "This account does not support creating labels."; return nullptr; } diff --git a/src/librssguard/core/messageobject.h b/src/librssguard/core/messageobject.h index 25f85ae10..0fc5efe6e 100644 --- a/src/librssguard/core/messageobject.h +++ b/src/librssguard/core/messageobject.h @@ -163,12 +163,4 @@ class MessageObject : public QObject { bool m_runningAfterFetching; }; -inline MessageObject::DuplicateCheck operator|(MessageObject::DuplicateCheck lhs, MessageObject::DuplicateCheck rhs) { - return static_cast(int(lhs) | int(rhs)); -} - -inline MessageObject::DuplicateCheck operator&(MessageObject::DuplicateCheck lhs, MessageObject::DuplicateCheck rhs) { - return static_cast(int(lhs) & int(rhs)); -} - #endif // MESSAGEOBJECT_H diff --git a/src/librssguard/core/messagesmodel.cpp b/src/librssguard/core/messagesmodel.cpp index 77f45149c..86faca92d 100644 --- a/src/librssguard/core/messagesmodel.cpp +++ b/src/librssguard/core/messagesmodel.cpp @@ -579,8 +579,8 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const { return dta.toInt() == 1 ? m_favoriteIcon : QVariant(); } else if (index_column == MSG_DB_HAS_ENCLOSURES) { - QModelIndex idx_important = index(idx.row(), MSG_DB_HAS_ENCLOSURES); - QVariant dta = QSqlQueryModel::data(idx_important); + QModelIndex idx_enc = index(idx.row(), MSG_DB_HAS_ENCLOSURES); + QVariant dta = QSqlQueryModel::data(idx_enc); return dta.toBool() ? m_enclosuresIcon : QVariant(); } diff --git a/src/librssguard/core/messagesmodelsqllayer.cpp b/src/librssguard/core/messagesmodelsqllayer.cpp index baf0715fe..a3cbe2ae0 100644 --- a/src/librssguard/core/messagesmodelsqllayer.cpp +++ b/src/librssguard/core/messagesmodelsqllayer.cpp @@ -4,6 +4,7 @@ #include "database/databasequeries.h" #include "definitions/definitions.h" +#include "definitions/globals.h" #include "miscellaneous/application.h" MessagesModelSqlLayer::MessagesModelSqlLayer() @@ -44,8 +45,8 @@ MessagesModelSqlLayer::MessagesModelSqlLayer() void MessagesModelSqlLayer::addSortState(int column, Qt::SortOrder order, bool ignore_multicolumn_sorting) { int existing = m_sortColumns.indexOf(column); - bool is_ctrl_pressed = (QApplication::queryKeyboardModifiers() & Qt::KeyboardModifier::ControlModifier) == - Qt::KeyboardModifier::ControlModifier; + bool is_ctrl_pressed = + Globals::hasFlag(QApplication::queryKeyboardModifiers(), Qt::KeyboardModifier::ControlModifier); if (existing >= 0) { m_sortColumns.removeAt(existing); diff --git a/src/librssguard/core/messagesproxymodel.cpp b/src/librssguard/core/messagesproxymodel.cpp index fb4c16a37..74d7a37cd 100644 --- a/src/librssguard/core/messagesproxymodel.cpp +++ b/src/librssguard/core/messagesproxymodel.cpp @@ -6,6 +6,7 @@ #include "core/messagesmodelcache.h" #include "definitions/globals.h" #include "miscellaneous/regexfactory.h" +#include "miscellaneous/textfactory.h" #include @@ -30,74 +31,96 @@ MessagesProxyModel::~MessagesProxyModel() { } void MessagesProxyModel::initializeFilters() { - m_filters[MessageListFilter::ShowUnread] = [](const Message& msg) { - return !msg.m_isRead; + m_filters[MessageListFilter::ShowUnread] = [this](int msg_row_index) { + return !m_sourceModel->data(msg_row_index, MSG_DB_READ_INDEX, Qt::ItemDataRole::EditRole).toBool(); }; - m_filters[MessageListFilter::ShowImportant] = [](const Message& msg) { - return msg.m_isImportant; + m_filters[MessageListFilter::ShowImportant] = [this](int msg_row_index) { + return m_sourceModel->data(msg_row_index, MSG_DB_IMPORTANT_INDEX, Qt::ItemDataRole::EditRole).toBool(); }; - m_filters[MessageListFilter::ShowToday] = [](const Message& msg) { + m_filters[MessageListFilter::ShowToday] = [this](int msg_row_index) { const QDateTime current_dt = QDateTime::currentDateTime(); const QDate current_d = current_dt.date(); + const QDateTime msg_created = + TextFactory::parseDateTime(m_sourceModel->data(msg_row_index, MSG_DB_DCREATED_INDEX, Qt::ItemDataRole::EditRole) + .value()); - return current_d.startOfDay() <= msg.m_created && msg.m_created <= current_d.endOfDay(); + return current_d.startOfDay() <= msg_created && msg_created <= current_d.endOfDay(); }; - m_filters[MessageListFilter::ShowYesterday] = [](const Message& msg) { + m_filters[MessageListFilter::ShowYesterday] = [this](int msg_row_index) { const QDateTime current_dt = QDateTime::currentDateTime(); const QDate current_d = current_dt.date(); + const QDateTime msg_created = + TextFactory::parseDateTime(m_sourceModel->data(msg_row_index, MSG_DB_DCREATED_INDEX, Qt::ItemDataRole::EditRole) + .value()); - return current_d.addDays(-1).startOfDay() <= msg.m_created && msg.m_created <= current_d.addDays(-1).endOfDay(); + return current_d.addDays(-1).startOfDay() <= msg_created && msg_created <= current_d.addDays(-1).endOfDay(); }; - m_filters[MessageListFilter::ShowLast24Hours] = [](const Message& msg) { + m_filters[MessageListFilter::ShowLast24Hours] = [this](int msg_row_index) { const QDateTime current_dt = QDateTime::currentDateTime(); + const QDateTime msg_created = + TextFactory::parseDateTime(m_sourceModel->data(msg_row_index, MSG_DB_DCREATED_INDEX, Qt::ItemDataRole::EditRole) + .value()); - return current_dt.addSecs(-24 * 60 * 60) <= msg.m_created && msg.m_created <= current_dt; + return current_dt.addSecs(-24 * 60 * 60) <= msg_created && msg_created <= current_dt; }; - m_filters[MessageListFilter::ShowLast48Hours] = [](const Message& msg) { + m_filters[MessageListFilter::ShowLast48Hours] = [this](int msg_row_index) { const QDateTime current_dt = QDateTime::currentDateTime(); + const QDateTime msg_created = + TextFactory::parseDateTime(m_sourceModel->data(msg_row_index, MSG_DB_DCREATED_INDEX, Qt::ItemDataRole::EditRole) + .value()); - return current_dt.addSecs(-48 * 60 * 60) <= msg.m_created && msg.m_created <= current_dt; + return current_dt.addSecs(-48 * 60 * 60) <= msg_created && msg_created <= current_dt; }; - m_filters[MessageListFilter::ShowThisWeek] = [](const Message& msg) { + m_filters[MessageListFilter::ShowThisWeek] = [this](int msg_row_index) { const QDateTime current_dt = QDateTime::currentDateTime(); const QDate current_d = current_dt.date(); + const QDateTime msg_created = + TextFactory::parseDateTime(m_sourceModel->data(msg_row_index, MSG_DB_DCREATED_INDEX, Qt::ItemDataRole::EditRole) + .value()); - return current_d.year() == msg.m_created.date().year() && - current_d.weekNumber() == msg.m_created.date().weekNumber(); + return current_d.year() == msg_created.date().year() && current_d.weekNumber() == msg_created.date().weekNumber(); }; - m_filters[MessageListFilter::ShowLastWeek] = [](const Message& msg) { + m_filters[MessageListFilter::ShowLastWeek] = [this](int msg_row_index) { const QDateTime current_dt = QDateTime::currentDateTime(); const QDate current_d = current_dt.date(); + const QDateTime msg_created = + TextFactory::parseDateTime(m_sourceModel->data(msg_row_index, MSG_DB_DCREATED_INDEX, Qt::ItemDataRole::EditRole) + .value()); - return current_d.addDays(-7).year() == msg.m_created.date().year() && - current_d.addDays(-7).weekNumber() == msg.m_created.date().weekNumber(); + return current_d.addDays(-7).year() == msg_created.date().year() && + current_d.addDays(-7).weekNumber() == msg_created.date().weekNumber(); }; - m_filters[MessageListFilter::ShowOnlyWithAttachments] = [](const Message& msg) { - return msg.m_enclosures.size() > 0; + m_filters[MessageListFilter::ShowOnlyWithAttachments] = [this](int msg_row_index) { + const bool msg_has_enclosures = + m_sourceModel->data(msg_row_index, MSG_DB_HAS_ENCLOSURES, Qt::ItemDataRole::EditRole).toBool(); + + return msg_has_enclosures; }; - m_filters[MessageListFilter::ShowOnlyWithScore] = [](const Message& msg) { - return msg.m_score > MSG_SCORE_MIN; + m_filters[MessageListFilter::ShowOnlyWithScore] = [this](int msg_row_index) { + const int msg_score = m_sourceModel->data(msg_row_index, MSG_DB_SCORE_INDEX, Qt::ItemDataRole::EditRole).toDouble(); + + return msg_score > MSG_SCORE_MIN; }; m_filterKeys = m_filters.keys(); } -bool MessagesProxyModel::filterAcceptsMessage(const Message& msg) const { +bool MessagesProxyModel::filterAcceptsMessage(int msg_row_index) const { if (m_filter == MessageListFilter::NoFiltering) { return true; } for (MessageListFilter val : m_filterKeys) { - if (Globals::hasFlag(m_filter, val) && m_filters[val](msg)) { + if (Globals::hasFlag(m_filter, val) && m_filters[val](msg_row_index)) { return true; } } @@ -184,8 +207,7 @@ bool MessagesProxyModel::filterAcceptsRow(int source_row, const QModelIndex& sou // otherwise they would just disappear from the list for example when batch marked as read // which is distracting. return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent) && - (m_sourceModel->cache()->containsData(source_row) || - filterAcceptsMessage(m_sourceModel->messageAt(source_row))); + (m_sourceModel->cache()->containsData(source_row) || filterAcceptsMessage(source_row)); } void MessagesProxyModel::setMessageListFilter(MessageListFilter filter) { @@ -216,7 +238,8 @@ QModelIndexList MessagesProxyModel::match(const QModelIndex& start, QModelIndexList result; const int match_type = flags & 0x0F; const Qt::CaseSensitivity case_sensitivity = Qt::CaseSensitivity::CaseInsensitive; - const bool wrap = (flags & Qt::MatchFlag::MatchWrap) > 0; + const bool wrap = Globals::hasFlag(flags, Qt::MatchFlag::MatchWrap); + ; const bool all_hits = (hits == -1); QString entered_text; int from = start.row(); diff --git a/src/librssguard/core/messagesproxymodel.h b/src/librssguard/core/messagesproxymodel.h index 27ec55104..0747a4445 100644 --- a/src/librssguard/core/messagesproxymodel.h +++ b/src/librssguard/core/messagesproxymodel.h @@ -56,7 +56,7 @@ class MessagesProxyModel : public QSortFilterProxyModel { QModelIndex getNextImportantItemIndex(int default_row, int max_row) const; QModelIndex getNextUnreadItemIndex(int default_row, int max_row) const; - bool filterAcceptsMessage(const Message& msg) const; + bool filterAcceptsMessage(int msg_row_index) const; virtual bool lessThan(const QModelIndex& left, const QModelIndex& right) const; virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; @@ -64,7 +64,7 @@ class MessagesProxyModel : public QSortFilterProxyModel { // Source model pointer. MessagesModel* m_sourceModel; MessageListFilter m_filter; - QMap> m_filters; + QMap> m_filters; QList m_filterKeys; }; diff --git a/src/librssguard/database/databasequeries.cpp b/src/librssguard/database/databasequeries.cpp index 7e9b514fa..9dfd0112d 100644 --- a/src/librssguard/database/databasequeries.cpp +++ b/src/librssguard/database/databasequeries.cpp @@ -3,6 +3,7 @@ #include "database/databasequeries.h" #include "3rd-party/boolinq/boolinq.h" +#include "definitions/globals.h" #include "exceptions/applicationexception.h" #include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" @@ -1710,9 +1711,8 @@ QPair DatabaseQueries::updateMessages(const QSqlDatabase& db, } } - const bool uses_online_labels = - (feed->getParentServiceRoot()->supportedLabelOperations() & ServiceRoot::LabelOperation::Synchronised) == - ServiceRoot::LabelOperation::Synchronised; + const bool uses_online_labels = Globals::hasFlag(feed->getParentServiceRoot()->supportedLabelOperations(), + ServiceRoot::LabelOperation::Synchronised); for (Message& message : messages) { if (!message.m_customId.isEmpty() || message.m_id > 0) { diff --git a/src/librssguard/definitions/globals.h b/src/librssguard/definitions/globals.h index 130a0b78e..83f4c8419 100644 --- a/src/librssguard/definitions/globals.h +++ b/src/librssguard/definitions/globals.h @@ -5,14 +5,16 @@ class Globals { public: - template static bool hasFlag(T lhs, U rhs); + template + static bool hasFlag(T value, U flag); private: Globals(); }; -template inline bool Globals::hasFlag(T lhs, U rhs) { - return (int(lhs) & int(rhs)) == int(rhs); +template +inline bool Globals::hasFlag(T value, U flag) { + return (int(value) & int(flag)) == int(flag); } #endif // GLOBALS_H diff --git a/src/librssguard/gui/dialogs/formmain.cpp b/src/librssguard/gui/dialogs/formmain.cpp index 3c94fd2b2..4a80e473b 100644 --- a/src/librssguard/gui/dialogs/formmain.cpp +++ b/src/librssguard/gui/dialogs/formmain.cpp @@ -3,6 +3,7 @@ #include "gui/dialogs/formmain.h" #include "definitions/definitions.h" +#include "definitions/globals.h" #include "gui/dialogs/formabout.h" #include "gui/dialogs/formaddaccount.h" #include "gui/dialogs/formbackupdatabasesettings.h" @@ -1042,8 +1043,8 @@ void FormMain::restoreDatabaseSettings() { void FormMain::changeEvent(QEvent* event) { switch (event->type()) { case QEvent::Type::WindowStateChange: { - if ((windowState() & Qt::WindowState::WindowMinimized) == Qt::WindowState::WindowMinimized && - SystemTrayIcon::isSystemTrayDesired() && SystemTrayIcon::isSystemTrayAreaAvailable() && + if (Globals::hasFlag(windowState(), Qt::WindowState::WindowMinimized) && SystemTrayIcon::isSystemTrayDesired() && + SystemTrayIcon::isSystemTrayAreaAvailable() && qApp->settings()->value(GROUP(GUI), SETTING(GUI::HideMainWindowWhenMinimized)).toBool()) { event->ignore(); diff --git a/src/librssguard/gui/reusable/styleditemdelegatewithoutfocus.cpp b/src/librssguard/gui/reusable/styleditemdelegatewithoutfocus.cpp index c61c92273..9a4662e48 100644 --- a/src/librssguard/gui/reusable/styleditemdelegatewithoutfocus.cpp +++ b/src/librssguard/gui/reusable/styleditemdelegatewithoutfocus.cpp @@ -3,6 +3,7 @@ #include "gui/reusable/styleditemdelegatewithoutfocus.h" #include "definitions/definitions.h" +#include "definitions/globals.h" StyledItemDelegateWithoutFocus::StyledItemDelegateWithoutFocus(int height_row, int padding_row, QObject* parent) : QStyledItemDelegate(parent), m_rowHeight(height_row), m_rowPadding(padding_row) {} @@ -12,7 +13,7 @@ void StyledItemDelegateWithoutFocus::paint(QPainter* painter, const QModelIndex& index) const { QStyleOptionViewItem item_option(option); - if ((item_option.state & QStyle::StateFlag::State_HasFocus) == QStyle::StateFlag::State_HasFocus) { + if (Globals::hasFlag(item_option.state, QStyle::StateFlag::State_HasFocus)) { item_option.state = item_option.state ^ QStyle::StateFlag::State_HasFocus; } @@ -22,7 +23,7 @@ void StyledItemDelegateWithoutFocus::paint(QPainter* painter, item_option.direction = Qt::LayoutDirection::RightToLeft; } - if ((item_option.state & QStyle::StateFlag::State_Selected) == QStyle::StateFlag::State_Selected && + if (Globals::hasFlag(item_option.state, QStyle::StateFlag::State_Selected) && index.data(Qt::ItemDataRole::ForegroundRole).isValid()) { item_option.palette.setColor(QPalette::ColorRole::HighlightedText, index.data(HIGHLIGHTED_FOREGROUND_TITLE_ROLE).value()); diff --git a/src/librssguard/gui/tabbar.cpp b/src/librssguard/gui/tabbar.cpp index 68d232e2f..a8e273882 100644 --- a/src/librssguard/gui/tabbar.cpp +++ b/src/librssguard/gui/tabbar.cpp @@ -3,6 +3,7 @@ #include "gui/tabbar.h" #include "definitions/definitions.h" +#include "definitions/globals.h" #include "gui/reusable/plaintoolbutton.h" #include "miscellaneous/settings.h" @@ -91,7 +92,7 @@ void TabBar::mousePressEvent(QMouseEvent* event) { // Check if user clicked tab with middle button. // NOTE: This needs to be done here because // destination does not know the original event. - if ((event->button() & Qt::MiddleButton) == Qt::MiddleButton && + if (Globals::hasFlag(event->button(), Qt::MouseButton::MiddleButton) && qApp->settings()->value(GROUP(GUI), SETTING(GUI::TabCloseMiddleClick)).toBool()) { if (tabType(tab_index) == TabBar::TabType::Closable || tabType(tab_index) == TabBar::TabType::DownloadManager) { // This tab is closable, so we can close it. @@ -110,7 +111,7 @@ void TabBar::mouseDoubleClickEvent(QMouseEvent* event) { // Check if user clicked tab with middle button. // NOTE: This needs to be done here because // destination does not know the original event. - if ((event->button() & Qt::LeftButton) == Qt::LeftButton && + if (Globals::hasFlag(event->button(), Qt::MouseButton::LeftButton) && qApp->settings()->value(GROUP(GUI), SETTING(GUI::TabCloseDoubleClick)).toBool()) { if (int(tabType(tab_index) & (TabBar::TabType::Closable | TabBar::TabType::DownloadManager)) > 0) { // This tab is closable, so we can close it. diff --git a/src/librssguard/gui/toolbars/toolbareditor.cpp b/src/librssguard/gui/toolbars/toolbareditor.cpp index f2130bc72..24278269e 100644 --- a/src/librssguard/gui/toolbars/toolbareditor.cpp +++ b/src/librssguard/gui/toolbars/toolbareditor.cpp @@ -2,6 +2,7 @@ #include "gui/toolbars/toolbareditor.h" +#include "definitions/globals.h" #include "gui/toolbars/basetoolbar.h" #include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" @@ -144,14 +145,12 @@ bool ToolBarEditor::eventFilter(QObject* object, QEvent* event) { return true; } else if (key_event->key() == Qt::Key::Key_Down && - (key_event->modifiers() & Qt::KeyboardModifier::ControlModifier) == - Qt::KeyboardModifier::ControlModifier) { + Globals::hasFlag(key_event->modifiers(), Qt::KeyboardModifier::ControlModifier)) { moveActionDown(); return true; } else if (key_event->key() == Qt::Key::Key_Up && - (key_event->modifiers() & Qt::KeyboardModifier::ControlModifier) == - Qt::KeyboardModifier::ControlModifier) { + Globals::hasFlag(key_event->modifiers(), Qt::KeyboardModifier::ControlModifier)) { moveActionUp(); return true; } diff --git a/src/librssguard/gui/webbrowser.cpp b/src/librssguard/gui/webbrowser.cpp index af478371f..fc186211d 100644 --- a/src/librssguard/gui/webbrowser.cpp +++ b/src/librssguard/gui/webbrowser.cpp @@ -2,6 +2,7 @@ #include "gui/webbrowser.h" +#include "definitions/globals.h" #include "gui/dialogs/formmain.h" #include "gui/messagebox.h" #include "gui/reusable/discoverfeedsbutton.h" @@ -173,7 +174,7 @@ bool WebBrowser::eventFilter(QObject* watched, QEvent* event) { QWheelEvent* wh_event = static_cast(event); // Zoom with mouse. - if ((wh_event->modifiers() & Qt::KeyboardModifier::ControlModifier) > 0) { + if (Globals::hasFlag(wh_event->modifiers(), Qt::KeyboardModifier::ControlModifier)) { if (wh_event->angleDelta().y() > 0 && m_webView->canZoomIn()) { m_webView->zoomIn(); onZoomFactorChanged(); diff --git a/src/librssguard/gui/webviewers/qtextbrowser/textbrowserviewer.cpp b/src/librssguard/gui/webviewers/qtextbrowser/textbrowserviewer.cpp index b6a18c2bb..81b2baf5c 100644 --- a/src/librssguard/gui/webviewers/qtextbrowser/textbrowserviewer.cpp +++ b/src/librssguard/gui/webviewers/qtextbrowser/textbrowserviewer.cpp @@ -3,6 +3,7 @@ #include "gui/webviewers/qtextbrowser/textbrowserviewer.h" #include "3rd-party/boolinq/boolinq.h" +#include "definitions/globals.h" #include "gui/dialogs/formmain.h" #include "gui/webbrowser.h" #include "miscellaneous/application.h" @@ -472,8 +473,8 @@ void TextBrowserViewer::downloadLink() { void TextBrowserViewer::onAnchorClicked(const QUrl& url) { if (!url.isEmpty()) { const QUrl resolved_url = (m_currentUrl.isValid() && url.isRelative()) ? m_currentUrl.resolved(url) : url; - const bool ctrl_pressed = (QGuiApplication::keyboardModifiers() & Qt::KeyboardModifier::ControlModifier) == - Qt::KeyboardModifier::ControlModifier; + const bool ctrl_pressed = + Globals::hasFlag(QGuiApplication::keyboardModifiers(), Qt::KeyboardModifier::ControlModifier); if (ctrl_pressed) { // Open in new tab. diff --git a/src/librssguard/miscellaneous/skinfactory.cpp b/src/librssguard/miscellaneous/skinfactory.cpp index e3e50e1bc..b66f96d3d 100644 --- a/src/librssguard/miscellaneous/skinfactory.cpp +++ b/src/librssguard/miscellaneous/skinfactory.cpp @@ -562,7 +562,7 @@ QVariant Skin::colorForModel(SkinEnums::PaletteColors type, bool use_skin_colors } } - return (use_skin_colors & m_colorPalette.contains(type)) ? m_colorPalette[type] : QVariant(); + return (use_skin_colors && m_colorPalette.contains(type)) ? m_colorPalette[type] : QVariant(); } QPalette Skin::extractPalette() const { diff --git a/src/librssguard/services/abstract/label.cpp b/src/librssguard/services/abstract/label.cpp index daab0dbb9..8791a4845 100644 --- a/src/librssguard/services/abstract/label.cpp +++ b/src/librssguard/services/abstract/label.cpp @@ -4,6 +4,7 @@ #include "database/databasefactory.h" #include "database/databasequeries.h" +#include "definitions/globals.h" #include "miscellaneous/application.h" #include "services/abstract/cacheforserviceroot.h" #include "services/abstract/gui/formaddeditlabel.h" @@ -39,8 +40,7 @@ int Label::countOfAllMessages() const { } bool Label::canBeEdited() const { - return (getParentServiceRoot()->supportedLabelOperations() & ServiceRoot::LabelOperation::Editing) == - ServiceRoot::LabelOperation::Editing; + return Globals::hasFlag(getParentServiceRoot()->supportedLabelOperations(), ServiceRoot::LabelOperation::Editing); } bool Label::editViaGui() { @@ -57,8 +57,7 @@ bool Label::editViaGui() { } bool Label::canBeDeleted() const { - return (getParentServiceRoot()->supportedLabelOperations() & ServiceRoot::LabelOperation::Deleting) == - ServiceRoot::LabelOperation::Deleting; + return Globals::hasFlag(getParentServiceRoot()->supportedLabelOperations(), ServiceRoot::LabelOperation::Deleting); } bool Label::deleteViaGui() { diff --git a/src/librssguard/services/abstract/labelsnode.cpp b/src/librssguard/services/abstract/labelsnode.cpp index 9a42e00be..62989657c 100644 --- a/src/librssguard/services/abstract/labelsnode.cpp +++ b/src/librssguard/services/abstract/labelsnode.cpp @@ -4,6 +4,7 @@ #include "database/databasefactory.h" #include "database/databasequeries.h" +#include "definitions/globals.h" #include "exceptions/applicationexception.h" #include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" @@ -92,8 +93,7 @@ QList LabelsNode::contextMenuFeedsList() { } void LabelsNode::createLabel() { - if ((getParentServiceRoot()->supportedLabelOperations() & ServiceRoot::LabelOperation::Adding) == - ServiceRoot::LabelOperation::Adding) { + if (Globals::hasFlag(getParentServiceRoot()->supportedLabelOperations(), ServiceRoot::LabelOperation::Adding)) { FormAddEditLabel frm(qApp->mainFormWidget()); Label* new_lbl = frm.execForAdd(); diff --git a/src/librssguard/services/abstract/serviceroot.cpp b/src/librssguard/services/abstract/serviceroot.cpp index 28905164a..d316fba4a 100644 --- a/src/librssguard/services/abstract/serviceroot.cpp +++ b/src/librssguard/services/abstract/serviceroot.cpp @@ -5,6 +5,7 @@ #include "3rd-party/boolinq/boolinq.h" #include "core/messagesmodel.h" #include "database/databasequeries.h" +#include "definitions/globals.h" #include "exceptions/applicationexception.h" #include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" @@ -495,8 +496,7 @@ void ServiceRoot::syncIn() { auto categories_custom_data = storeCustomCategoriesData(); // Remove from feeds model, then from SQL but leave messages intact. - bool uses_remote_labels = - (supportedLabelOperations() & LabelOperation::Synchronised) == LabelOperation::Synchronised; + bool uses_remote_labels = Globals::hasFlag(supportedLabelOperations(), LabelOperation::Synchronised); // Remove stuff. cleanAllItemsFromModel(uses_remote_labels);