clazy refactoring, need to finish it later

This commit is contained in:
Martin Rotter 2021-03-17 14:31:22 +01:00
parent 95892001f6
commit aa18d074a3
19 changed files with 80 additions and 63 deletions

View File

@ -226,7 +226,7 @@ void FeedDownloader::updateOneFeed(Feed* feed) {
}
// Process changed labels.
for (Label* lbl : msg_backup.m_assignedLabels) {
for (Label* lbl : qAsConst(msg_backup.m_assignedLabels)) {
if (!msg_orig->m_assignedLabels.contains(lbl)) {
// Label is not there anymore, it was deassigned.
lbl->deassignFromMessage(*msg_orig);
@ -238,7 +238,7 @@ void FeedDownloader::updateOneFeed(Feed* feed) {
}
}
for (Label* lbl : msg_orig->m_assignedLabels) {
for (Label* lbl : qAsConst(msg_orig->m_assignedLabels)) {
if (!msg_backup.m_assignedLabels.contains(lbl)) {
// Label is in new message, but is not in old message, it
// was newly assigned.

View File

@ -3,9 +3,9 @@
#include "core/feedsmodel.h"
#include "3rd-party/boolinq/boolinq.h"
#include "database/databasefactory.h"
#include "definitions/definitions.h"
#include "gui/dialogs/formmain.h"
#include "database/databasefactory.h"
#include "miscellaneous/feedreader.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h"
@ -292,8 +292,9 @@ void FeedsModel::reassignNodeToNewParent(RootItem* original_node, RootItem* new_
QList<ServiceRoot*>FeedsModel::serviceRoots() const {
QList<ServiceRoot*> roots;
auto ch = m_rootItem->childItems();
for (RootItem* root : m_rootItem->childItems()) {
for (RootItem* root : qAsConst(ch)) {
if (root->kind() == RootItem::Kind::ServiceRoot) {
roots.append(root->toServiceRoot());
}
@ -304,8 +305,9 @@ QList<ServiceRoot*>FeedsModel::serviceRoots() const {
QList<Feed*>FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
QList<Feed*>feeds_for_update;
auto stf = m_rootItem->getSubTreeFeeds();
for (Feed* feed : m_rootItem->getSubTreeFeeds()) {
for (Feed* feed : qAsConst(stf)) {
switch (feed->autoUpdateType()) {
case Feed::AutoUpdateType::DontAutoUpdate:
@ -489,8 +491,9 @@ bool FeedsModel::addServiceAccount(ServiceRoot* root, bool freshly_activated) {
bool FeedsModel::restoreAllBins() {
bool result = true;
auto srts = serviceRoots();
for (ServiceRoot* root : serviceRoots()) {
for (ServiceRoot* root : qAsConst(srts)) {
RecycleBin* bin_of_root = root->recycleBin();
if (bin_of_root != nullptr) {
@ -503,8 +506,9 @@ bool FeedsModel::restoreAllBins() {
bool FeedsModel::emptyAllBins() {
bool result = true;
auto srts = serviceRoots();
for (ServiceRoot* root : serviceRoots()) {
for (ServiceRoot* root : qAsConst(srts)) {
RecycleBin* bin_of_root = root->recycleBin();
if (bin_of_root != nullptr) {
@ -516,8 +520,10 @@ bool FeedsModel::emptyAllBins() {
}
void FeedsModel::loadActivatedServiceAccounts() {
auto serv = qApp->feedReader()->feedServices();
// Iterate all globally available feed "service plugins".
for (const ServiceEntryPoint* entry_point : qApp->feedReader()->feedServices()) {
for (const ServiceEntryPoint* entry_point : qAsConst(serv)) {
// Load all stored root nodes from the entry point and add those to the model.
QList<ServiceRoot*> roots = entry_point->initializeSubtree();
@ -534,7 +540,9 @@ void FeedsModel::loadActivatedServiceAccounts() {
}
void FeedsModel::stopServiceAccounts() {
for (ServiceRoot* account : serviceRoots()) {
auto serv = serviceRoots();
for (ServiceRoot* account : qAsConst(serv)) {
account->stop();
}
}

View File

@ -20,13 +20,14 @@ Enclosure::Enclosure(QString url, QString mime) : m_url(std::move(url)), m_mimeT
QList<Enclosure> Enclosures::decodeEnclosuresFromString(const QString& enclosures_data) {
QList<Enclosure> enclosures;
for (const QString& single_enclosure : enclosures_data.split(ENCLOSURES_OUTER_SEPARATOR,
auto enc = enclosures_data.split(ENCLOSURES_OUTER_SEPARATOR,
#if QT_VERSION >= 0x050F00 // Qt >= 5.15.0
Qt::SplitBehaviorFlags::SkipEmptyParts)) {
Qt::SplitBehaviorFlags::SkipEmptyParts);
#else
QString::SplitBehavior::SkipEmptyParts)) {
QString::SplitBehavior::SkipEmptyParts);
#endif
for (const QString& single_enclosure : qAsConst(enc)) {
Enclosure enclosure;
if (single_enclosure.contains(ECNLOSURES_INNER_SEPARATOR)) {

View File

@ -22,7 +22,7 @@ bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicationAttribute
// Check database according to duplication attribute_check.
QSqlQuery q(*m_db);
QStringList where_clauses;
QList<QPair<QString, QVariant>> bind_values;
QVector<QPair<QString, QVariant>> bind_values;
// Now we construct the query according to parameter.
if ((attribute_check& DuplicationAttributeCheck::SameTitle) == DuplicationAttributeCheck::SameTitle) {

View File

@ -70,7 +70,7 @@ class MessageObject : public QObject {
// Check if message is duplicate with another messages in DB.
// Parameter "attribute_check" is DuplicationAttributeCheck enum
// value casted to int.
Q_INVOKABLE bool isDuplicateWithAttribute(DuplicationAttributeCheck attribute_check) const;
Q_INVOKABLE bool isDuplicateWithAttribute(MessageObject::DuplicationAttributeCheck attribute_check) const;
// Adds given label to list of assigned labels to this message.
// Returns true if label was assigned now or if the message already has it assigned.

View File

@ -48,7 +48,7 @@ void DatabaseFactory::determineDriver() {
if (m_dbDriver->driverType() != DatabaseDriver::DriverType::SQLite) {
// Try to setup connection and fallback to SQLite.
try {
m_dbDriver->connection(metaObject()->className());
m_dbDriver->connection(QSL("DatabaseFactory"));
}
catch (const ApplicationException& ex) {
qCriticalNN << LOGSEC_DB

View File

@ -598,8 +598,6 @@ int DatabaseQueries::getMessageCountsForLabel(const QSqlDatabase& db, Label* lab
return q.value(0).toInt();
}
else {
auto aa = q.lastError().text();
if (ok != nullptr) {
*ok = false;
}
@ -877,8 +875,6 @@ QList<Message> DatabaseQueries::getUndeletedMessagesForAccount(const QSqlDatabas
}
}
else {
auto aa = q.lastError().text();
if (ok != nullptr) {
*ok = false;
}
@ -1268,7 +1264,7 @@ bool DatabaseQueries::deleteAccount(const QSqlDatabase& db, int account_id) {
<< QSL("DELETE FROM Labels WHERE account_id = :account_id;")
<< QSL("DELETE FROM Accounts WHERE id = :account_id;");
for (const QString& q : queries) {
for (const QString& q : qAsConst(queries)) {
query.prepare(q);
query.bindValue(QSL(":account_id"), account_id);
@ -1483,8 +1479,6 @@ bool DatabaseQueries::purgeLeftoverLabelAssignments(const QSqlDatabase& db, int
}
if (!succ) {
auto xx = q.lastError().text();
qWarningNN << LOGSEC_DB
<< "Removing of leftover label assignments failed: '"
<< q.lastError().text()
@ -1509,11 +1503,10 @@ bool DatabaseQueries::purgeLabelsAndLabelAssignments(const QSqlDatabase& db, int
}
bool DatabaseQueries::storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id) {
QSqlQuery query_category(db);
QSqlQuery query_feed(db);
// Iterate all children.
for (RootItem* child : tree_root->getSubTree()) {
auto str = tree_root->getSubTree();
for (RootItem* child : qAsConst(str)) {
if (child->kind() == RootItem::Kind::Category) {
createOverwriteCategory(db, child->toCategory(), account_id, child->parent()->id());
}
@ -1522,7 +1515,9 @@ bool DatabaseQueries::storeAccountTree(const QSqlDatabase& db, RootItem* tree_ro
}
else if (child->kind() == RootItem::Kind::Labels) {
// Add all labels.
for (RootItem* lbl : child->childItems()) {
auto ch = child->childItems();
for (RootItem* lbl : qAsConst(ch)) {
Label* label = lbl->toLabel();
if (!createLabel(db, label, account_id)) {
@ -1733,8 +1728,6 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in
q.bindValue(QSL(":custom_data"), serialized_custom_data);
if (!q.exec()) {
auto xx = q.lastError().text();
throw ApplicationException(q.lastError().text());
}
}

View File

@ -41,7 +41,7 @@ bool DynamicShortcutsWidget::areShortcutsUnique() const {
}
void DynamicShortcutsWidget::updateShortcuts() {
for (const ActionBinding& binding : m_actionBindings) {
for (const ActionBinding& binding : qAsConst(m_actionBindings)) {
binding.first->setShortcut(binding.second->shortcut());
}
}

View File

@ -58,7 +58,7 @@ ServiceEntryPoint* FormAddAccount::selectedEntryPoint() const {
}
void FormAddAccount::loadEntryPoints() {
for (const ServiceEntryPoint* entry_point : m_entryPoints) {
for (const ServiceEntryPoint* entry_point : qAsConst(m_entryPoints)) {
QListWidgetItem* item = new QListWidgetItem(entry_point->icon(), entry_point->name(), m_ui->m_listEntryPoints);
item->setToolTip(entry_point->description());

View File

@ -2,6 +2,7 @@
#include "gui/dialogs/formmain.h"
#include "database/databasefactory.h"
#include "definitions/definitions.h"
#include "gui/dialogs/formabout.h"
#include "gui/dialogs/formaddaccount.h"
@ -22,7 +23,6 @@
#include "gui/systemtrayicon.h"
#include "gui/tabbar.h"
#include "miscellaneous/application.h"
#include "database/databasefactory.h"
#include "miscellaneous/feedreader.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/mutex.h"
@ -257,7 +257,9 @@ void FormMain::updateAddItemMenu() {
// NOTE: Clear here deletes items from memory but only those OWNED by the menu.
m_ui->m_menuAddItem->clear();
for (ServiceRoot* activated_root : qApp->feedReader()->feedsModel()->serviceRoots()) {
auto srts = qApp->feedReader()->feedsModel()->serviceRoots();
for (ServiceRoot* activated_root : qAsConst(srts)) {
QMenu* root_menu = new QMenu(activated_root->title(), m_ui->m_menuAddItem);
root_menu->setIcon(activated_root->icon());
@ -312,7 +314,9 @@ void FormMain::updateAddItemMenu() {
void FormMain::updateRecycleBinMenu() {
m_ui->m_menuRecycleBin->clear();
for (const ServiceRoot* activated_root : qApp->feedReader()->feedsModel()->serviceRoots()) {
auto srts = qApp->feedReader()->feedsModel()->serviceRoots();
for (const ServiceRoot* activated_root : qAsConst(srts)) {
QMenu* root_menu = new QMenu(activated_root->title(), m_ui->m_menuRecycleBin);
root_menu->setIcon(activated_root->icon());
@ -354,7 +358,9 @@ void FormMain::updateRecycleBinMenu() {
void FormMain::updateAccountsMenu() {
m_ui->m_menuAccounts->clear();
for (ServiceRoot* activated_root : qApp->feedReader()->feedsModel()->serviceRoots()) {
auto srts = qApp->feedReader()->feedsModel()->serviceRoots();
for (ServiceRoot* activated_root : srts) {
QMenu* root_menu = new QMenu(activated_root->title(), m_ui->m_menuAccounts);
root_menu->setIcon(activated_root->icon());

View File

@ -9,11 +9,11 @@
#include "3rd-party/boolinq/boolinq.h"
#include "core/messagefilter.h"
#include "core/messagesforfiltersmodel.h"
#include "database/databasequeries.h"
#include "exceptions/filteringexception.h"
#include "gui/guiutilities.h"
#include "gui/messagebox.h"
#include "miscellaneous/application.h"
#include "database/databasequeries.h"
#include "miscellaneous/feedreader.h"
#include "miscellaneous/iconfactory.h"
#include "network-web/webfactory.h"
@ -157,7 +157,9 @@ void FormMessageFiltersManager::removeSelectedFilter() {
}
void FormMessageFiltersManager::loadFilters() {
for (auto* fltr : m_reader->messageFilters()) {
auto flt = m_reader->messageFilters();
for (auto* fltr : qAsConst(flt)) {
auto* it = new QListWidgetItem(fltr->name(), m_ui.m_listFilters);
it->setData(Qt::ItemDataRole::UserRole, QVariant::fromValue<MessageFilter*>(fltr));
@ -344,7 +346,7 @@ void FormMessageFiltersManager::processCheckedFeeds() {
}
// Process changed labels.
for (Label* lbl : msg_backup.m_assignedLabels) {
for (Label* lbl : qAsConst(msg_backup.m_assignedLabels)) {
if (!msg->m_assignedLabels.contains(lbl)) {
// Label is not there anymore, it was deassigned.
lbl->deassignFromMessage(*msg);
@ -356,7 +358,7 @@ void FormMessageFiltersManager::processCheckedFeeds() {
}
}
for (Label* lbl : msg->m_assignedLabels) {
for (Label* lbl : qAsConst(msg->m_assignedLabels)) {
if (!msg_backup.m_assignedLabels.contains(lbl)) {
// Label is in new message, but is not in old message, it
// was newly assigned.
@ -428,8 +430,9 @@ void FormMessageFiltersManager::loadFilterFeedAssignments(MessageFilter* filter,
}
m_loadingFilter = true;
auto stf = account->getSubTreeFeeds();
for (auto* feed : account->getSubTreeFeeds()) {
for (auto* feed : qAsConst(stf)) {
if (feed->messageFilters().contains(filter)) {
m_feedsModel->sourceModel()->setItemChecked(feed, Qt::CheckState::Checked);
}
@ -503,10 +506,8 @@ void FormMessageFiltersManager::showFilter(MessageFilter* filter) {
}
void FormMessageFiltersManager::loadAccounts() {
for (auto* acc : m_accounts) {
m_ui.m_cmbAccounts->addItem(acc->icon(),
acc->title(),
QVariant::fromValue(acc));
for (auto* acc : qAsConst(m_accounts)) {
m_ui.m_cmbAccounts->addItem(acc->icon(), acc->title(), QVariant::fromValue(acc));
}
}

View File

@ -56,7 +56,7 @@ void FormSettings::applySettings() {
m_settings.checkSettings();
QStringList panels_for_restart;
for (SettingsPanel* panel : m_panels) {
for (SettingsPanel* panel : qAsConst(m_panels)) {
if (panel->isDirty()) {
panel->saveSettings();
}
@ -94,7 +94,7 @@ void FormSettings::applySettings() {
void FormSettings::cancelSettings() {
QStringList changed_panels;
for (SettingsPanel* panel : m_panels) {
for (SettingsPanel* panel : qAsConst(m_panels)) {
if (panel->isDirty()) {
changed_panels.append(panel->title().toLower());
}

View File

@ -148,7 +148,7 @@ void FormUpdate::saveUpdateFile(const QByteArray& file_contents) {
void FormUpdate::loadAvailableFiles() {
m_ui.m_listFiles->clear();
for (const UpdateUrl& url : m_updateInfo.m_urls) {
for (const UpdateUrl& url : qAsConst(m_updateInfo.m_urls)) {
if (SystemFactory::supportedUpdateFiles().match(url.m_name).hasMatch()) {
QListWidgetItem* item = new QListWidgetItem(url.m_name + tr(" (size ") + url.m_size + QSL(")"));

View File

@ -60,12 +60,13 @@ void DiscoverFeedsButton::linkTriggered(QAction* action) {
void DiscoverFeedsButton::fillMenu() {
menu()->clear();
auto srts = qApp->feedReader()->feedsModel()->serviceRoots();
for (const ServiceRoot* root : qApp->feedReader()->feedsModel()->serviceRoots()) {
for (const ServiceRoot* root : qAsConst(srts)) {
if (root->supportsFeedAdding()) {
QMenu* root_menu = menu()->addMenu(root->icon(), root->title());
for (const QString& url : m_addresses) {
for (const QString& url : qAsConst(m_addresses)) {
QAction* url_action = root_menu->addAction(root->icon(), url);
url_action->setProperty("url", url);

View File

@ -717,7 +717,7 @@ void FeedsView::selectionChanged(const QItemSelection& selected, const QItemSele
if (!selectedIndexes().isEmpty() &&
qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::AutoExpandOnSelection)).toBool()) {
expand(selectedIndexes().first());
expand(selectedIndexes().constFirst());
}
}

View File

@ -3,8 +3,8 @@
#include "gui/labelsmenu.h"
#include "3rd-party/boolinq/boolinq.h"
#include "miscellaneous/application.h"
#include "database/databasequeries.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include <QCheckBox>
@ -22,7 +22,7 @@ LabelsMenu::LabelsMenu(const QList<Message>& messages, const QList<Label*>& labe
addAction(act_not_labels);
}
else {
QSqlDatabase db = qApp->database()->driver()->connection(metaObject()->className());
QSqlDatabase db = qApp->database()->driver()->connection(QSL("LabelsMenu"));
for (Label* label: boolinq::from(labels).orderBy([](const Label* label) {
return label->title().toLower();
@ -73,13 +73,13 @@ void LabelsMenu::changeLabelAssignment(Qt::CheckState state) {
if (origin != nullptr) {
if (state == Qt::CheckState::Checked) {
// Assign this label to selected messages.
for (const auto& msg : m_messages) {
for (const auto& msg : qAsConst(m_messages)) {
origin->label()->assignToMessage(msg);
}
}
else if (state == Qt::CheckState::Unchecked) {
// Remove label from selected messages.
for (const auto& msg : m_messages) {
for (const auto& msg : qAsConst(m_messages)) {
origin->label()->deassignFromMessage(msg);
}
}
@ -140,7 +140,7 @@ void LabelAction::updateActionForState() {
break;
case Qt::CheckState::PartiallyChecked:
highlight = QColor("#ff8c00");
highlight = QColor(100, 50, 0);
break;
case Qt::CheckState::Unchecked:

View File

@ -231,8 +231,9 @@ void MessagePreviewer::updateLabels(bool only_clear) {
if (m_root.data() != nullptr && !m_root.data()->getParentServiceRoot()->labelsNode()->labels().isEmpty()) {
m_separator = m_toolBar->addSeparator();
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
auto lbls = m_root.data()->getParentServiceRoot()->labelsNode()->labels();
for (auto* label : m_root.data()->getParentServiceRoot()->labelsNode()->labels()) {
for (auto* label : lbls) {
LabelButton* btn_label = new LabelButton(this);
btn_label->setLabel(label);

View File

@ -209,10 +209,11 @@ void MessagesView::initializeContextMenu() {
// External tools.
QFileIconProvider icon_provider;
QMenu* menu_ext_tools = new QMenu(tr("Open with external tool"), m_contextMenu);
auto tools = ExternalTool::toolsFromSettings();
menu_ext_tools->setIcon(qApp->icons()->fromTheme(QSL("document-open")));
for (const ExternalTool& tool : ExternalTool::toolsFromSettings()) {
for (const ExternalTool& tool : qAsConst(tools)) {
QAction* act_tool = new QAction(QFileInfo(tool.executable()).fileName(), menu_ext_tools);
act_tool->setIcon(icon_provider.icon(tool.executable()));
@ -375,7 +376,9 @@ void MessagesView::switchShowUnreadOnly(bool set_new_value, bool show_unread_onl
}
void MessagesView::openSelectedSourceMessagesExternally() {
for (const QModelIndex& index : selectionModel()->selectedRows()) {
auto rws = selectionModel()->selectedRows();
for (const QModelIndex& index : qAsConst(rws)) {
QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row())
.m_url
.replace(QRegularExpression("[\\t\\n]"), QString());
@ -397,8 +400,9 @@ void MessagesView::openSelectedSourceMessagesExternally() {
void MessagesView::openSelectedMessagesInternally() {
QList<Message> messages;
auto rws = selectionModel()->selectedRows();
for (const QModelIndex& index : selectionModel()->selectedRows()) {
for (const QModelIndex& index : qAsConst(rws)) {
messages << m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row());
}
@ -591,8 +595,9 @@ void MessagesView::openSelectedMessagesWithExternalTool() {
if (sndr != nullptr) {
auto tool = sndr->data().value<ExternalTool>();
auto rws = selectionModel()->selectedRows();
for (const QModelIndex& index : selectionModel()->selectedRows()) {
for (const QModelIndex& index : qAsConst(rws)) {
const QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row())
.m_url
.replace(QRegularExpression("[\\t\\n]"), QString());

View File

@ -92,8 +92,9 @@ void SettingsFeedsMessages::initializeMessageDateFormats() {
QStringList best_formats;
const QDateTime current_dt = QDateTime::currentDateTime();
const QLocale current_locale = qApp->localization()->loadedLocale();
auto installed_languages = qApp->localization()->installedLanguages();
for (const Language& lang : qApp->localization()->installedLanguages()) {
for (const Language& lang : qAsConst(installed_languages)) {
QLocale locale(lang.m_code);
best_formats << locale.dateTimeFormat(QLocale::LongFormat)
@ -103,7 +104,7 @@ void SettingsFeedsMessages::initializeMessageDateFormats() {
best_formats.removeDuplicates();
for (const QString& format : best_formats) {
for (const QString& format : qAsConst(best_formats)) {
m_ui->m_cmbMessagesDateTimeFormat->addItem(current_locale.toString(current_dt, format), format);
}
}