From ef33988ca6946d75fa505fcdd2316fd820c4fa89 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 15 Jan 2016 09:39:06 +0100 Subject: [PATCH] Refactoring. --- src/services/abstract/rootitem.cpp | 12 ++++++------ src/services/abstract/rootitem.h | 8 ++++---- src/services/abstract/serviceentrypoint.h | 2 +- src/services/abstract/serviceroot.cpp | 4 ++-- src/services/abstract/serviceroot.h | 8 ++++---- src/services/standard/standardcategory.h | 4 ++-- src/services/standard/standardfeed.h | 4 ++-- src/services/standard/standardserviceentrypoint.cpp | 2 +- src/services/standard/standardserviceentrypoint.h | 2 +- src/services/standard/standardserviceroot.cpp | 4 ++-- src/services/standard/standardserviceroot.h | 4 ++-- src/services/tt-rss/ttrssfeed.cpp | 2 +- src/services/tt-rss/ttrssfeed.h | 2 +- src/services/tt-rss/ttrssserviceentrypoint.cpp | 2 +- src/services/tt-rss/ttrssserviceentrypoint.h | 2 +- src/services/tt-rss/ttrssserviceroot.cpp | 4 ++-- src/services/tt-rss/ttrssserviceroot.h | 4 ++-- 17 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/services/abstract/rootitem.cpp b/src/services/abstract/rootitem.cpp index 7f2fa156b..5b7afe33d 100755 --- a/src/services/abstract/rootitem.cpp +++ b/src/services/abstract/rootitem.cpp @@ -51,7 +51,7 @@ QList RootItem::contextMenu() { return QList(); } -bool RootItem::canBeEdited() { +bool RootItem::canBeEdited() const { return false; } @@ -59,7 +59,7 @@ bool RootItem::editViaGui() { return false; } -bool RootItem::canBeDeleted() { +bool RootItem::canBeDeleted() const { return false; } @@ -359,12 +359,12 @@ bool RootItem::removeChild(RootItem *child) { return m_childItems.removeOne(child); } -Category *RootItem::toCategory() { - return static_cast(this); +Category *RootItem::toCategory() const { + return static_cast(const_cast(this)); } -Feed *RootItem::toFeed() { - return static_cast(this); +Feed *RootItem::toFeed() const { + return static_cast(const_cast(this)); } ServiceRoot *RootItem::toServiceRoot() const { diff --git a/src/services/abstract/rootitem.h b/src/services/abstract/rootitem.h index 8e9a5c4ad..2a551a064 100755 --- a/src/services/abstract/rootitem.h +++ b/src/services/abstract/rootitem.h @@ -82,14 +82,14 @@ class RootItem : public QObject { virtual QList contextMenu(); // Can properties of this item be edited? - virtual bool canBeEdited(); + virtual bool canBeEdited() const; // Performs editing of properties of this item (probably via dialog) // and returns result status. virtual bool editViaGui(); // Can the item be deleted? - virtual bool canBeDeleted(); + virtual bool canBeDeleted() const; // Performs deletion of the item, this // method should NOT display any additional dialogs. @@ -255,8 +255,8 @@ class RootItem : public QObject { } // Converters - Category *toCategory(); - Feed *toFeed(); + Category *toCategory() const; + Feed *toFeed() const; ServiceRoot *toServiceRoot() const; private: diff --git a/src/services/abstract/serviceentrypoint.h b/src/services/abstract/serviceentrypoint.h index 716280dda..d9c99ec7a 100755 --- a/src/services/abstract/serviceentrypoint.h +++ b/src/services/abstract/serviceentrypoint.h @@ -41,7 +41,7 @@ class ServiceEntryPoint { // some kind of first-time configuration dialog inside itself // before returning the root item. // Returns NULL if initialization of new root cannot be done. - virtual ServiceRoot *createNewRoot() = 0; + virtual ServiceRoot *createNewRoot() const = 0; // Performs initialization of all service accounts created using this entry // point from persistent DB. diff --git a/src/services/abstract/serviceroot.cpp b/src/services/abstract/serviceroot.cpp index 279c814db..46a0f59c0 100755 --- a/src/services/abstract/serviceroot.cpp +++ b/src/services/abstract/serviceroot.cpp @@ -36,7 +36,7 @@ ServiceRoot::~ServiceRoot() { bool ServiceRoot::deleteViaGui() { QSqlDatabase connection = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlQuery query(connection); - int account_id = accountId(); + const int account_id = accountId(); query.setForwardOnly(true); QStringList queries; @@ -84,7 +84,7 @@ bool ServiceRoot::markAsReadUnread(RootItem::ReadStatus status) { QList ServiceRoot::undeletedMessages() const { QList messages; - int account_id = accountId(); + const int account_id = accountId(); QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlQuery query(database); diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index d2fcb9cd9..b4e7e387d 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -82,6 +82,10 @@ class ServiceRoot : public RootItem { virtual void start(bool freshly_activated) = 0; virtual void stop() = 0; + // Account ID corresponds with DB attribute Accounts (id). + int accountId() const; + void setAccountId(int account_id); + // Returns the UNIQUE code of the given service. // NOTE: Keep in sync with ServiceEntryRoot::code(). virtual QString code() const = 0; @@ -156,10 +160,6 @@ class ServiceRoot : public RootItem { void requestItemReassignment(RootItem *item, RootItem *new_parent); void requestItemRemoval(RootItem *item); - // Account ID corresponds with DB attribute Accounts (id). - int accountId() const; - void setAccountId(int account_id); - public slots: virtual void addNewFeed(const QString &url = QString()) = 0; virtual void addNewCategory() = 0; diff --git a/src/services/standard/standardcategory.h b/src/services/standard/standardcategory.h index f5213be1f..91cdc4b86 100755 --- a/src/services/standard/standardcategory.h +++ b/src/services/standard/standardcategory.h @@ -47,11 +47,11 @@ class StandardCategory : public Category { Qt::ItemFlags additionalFlags() const; bool performDragDropChange(RootItem *target_item); - bool canBeEdited() { + bool canBeEdited() const { return true; } - bool canBeDeleted() { + bool canBeDeleted() const { return true; } diff --git a/src/services/standard/standardfeed.h b/src/services/standard/standardfeed.h index 7e62e07f3..570f663b4 100755 --- a/src/services/standard/standardfeed.h +++ b/src/services/standard/standardfeed.h @@ -63,11 +63,11 @@ class StandardFeed : public Feed { QList contextMenu(); - bool canBeEdited() { + bool canBeEdited() const { return true; } - bool canBeDeleted() { + bool canBeDeleted() const { return true; } diff --git a/src/services/standard/standardserviceentrypoint.cpp b/src/services/standard/standardserviceentrypoint.cpp index 219da2c2f..18181c2f4 100755 --- a/src/services/standard/standardserviceentrypoint.cpp +++ b/src/services/standard/standardserviceentrypoint.cpp @@ -59,7 +59,7 @@ QString StandardServiceEntryPoint::code() const { return SERVICE_CODE_STD_RSS; } -ServiceRoot *StandardServiceEntryPoint::createNewRoot() { +ServiceRoot *StandardServiceEntryPoint::createNewRoot() const { // Switch DB. QSqlDatabase database = qApp->database()->connection(QSL("StandardServiceEntryPoint"), DatabaseFactory::FromSettings); QSqlQuery query(database); diff --git a/src/services/standard/standardserviceentrypoint.h b/src/services/standard/standardserviceentrypoint.h index df8b00770..65e5ee60a 100755 --- a/src/services/standard/standardserviceentrypoint.h +++ b/src/services/standard/standardserviceentrypoint.h @@ -34,7 +34,7 @@ class StandardServiceEntryPoint : public ServiceEntryPoint { QIcon icon() const; QString code() const; - ServiceRoot *createNewRoot(); + ServiceRoot *createNewRoot() const; QList initializeSubtree() const; }; diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index 8c34bcb3a..6bb9a11b9 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -108,11 +108,11 @@ QString StandardServiceRoot::code() const { return SERVICE_CODE_STD_RSS; } -bool StandardServiceRoot::canBeEdited() { +bool StandardServiceRoot::canBeEdited() const { return false; } -bool StandardServiceRoot::canBeDeleted() { +bool StandardServiceRoot::canBeDeleted() const { return true; } diff --git a/src/services/standard/standardserviceroot.h b/src/services/standard/standardserviceroot.h index 4f1692481..2e485dd2c 100755 --- a/src/services/standard/standardserviceroot.h +++ b/src/services/standard/standardserviceroot.h @@ -43,8 +43,8 @@ class StandardServiceRoot : public ServiceRoot { QString code() const; - bool canBeEdited(); - bool canBeDeleted(); + bool canBeEdited() const; + bool canBeDeleted() const; bool deleteViaGui(); bool markAsReadUnread(ReadStatus status); diff --git a/src/services/tt-rss/ttrssfeed.cpp b/src/services/tt-rss/ttrssfeed.cpp index fb4075e9e..3d8e1f830 100755 --- a/src/services/tt-rss/ttrssfeed.cpp +++ b/src/services/tt-rss/ttrssfeed.cpp @@ -138,7 +138,7 @@ void TtRssFeed::updateCounts(bool including_total_count) { } } -bool TtRssFeed::canBeEdited() { +bool TtRssFeed::canBeEdited() const { return true; } diff --git a/src/services/tt-rss/ttrssfeed.h b/src/services/tt-rss/ttrssfeed.h index a28d964a8..edcfd52d6 100755 --- a/src/services/tt-rss/ttrssfeed.h +++ b/src/services/tt-rss/ttrssfeed.h @@ -41,7 +41,7 @@ class TtRssFeed : public Feed { void updateCounts(bool including_total_count); - bool canBeEdited(); + bool canBeEdited() const; bool editViaGui(); int countOfAllMessages() const; diff --git a/src/services/tt-rss/ttrssserviceentrypoint.cpp b/src/services/tt-rss/ttrssserviceentrypoint.cpp index 29e03754c..02f3e7684 100755 --- a/src/services/tt-rss/ttrssserviceentrypoint.cpp +++ b/src/services/tt-rss/ttrssserviceentrypoint.cpp @@ -71,7 +71,7 @@ QString TtRssServiceEntryPoint::code() const { return SERVICE_CODE_TT_RSS; } -ServiceRoot *TtRssServiceEntryPoint::createNewRoot() { +ServiceRoot *TtRssServiceEntryPoint::createNewRoot() const { QPointer form_acc = new FormEditAccount(qApp->mainForm()); TtRssServiceRoot *new_root = form_acc.data()->execForCreate(); delete form_acc.data(); diff --git a/src/services/tt-rss/ttrssserviceentrypoint.h b/src/services/tt-rss/ttrssserviceentrypoint.h index c14839651..d62d78de0 100755 --- a/src/services/tt-rss/ttrssserviceentrypoint.h +++ b/src/services/tt-rss/ttrssserviceentrypoint.h @@ -35,7 +35,7 @@ class TtRssServiceEntryPoint : public ServiceEntryPoint { QIcon icon() const; QString code() const; - ServiceRoot *createNewRoot(); + ServiceRoot *createNewRoot() const; QList initializeSubtree() const; }; diff --git a/src/services/tt-rss/ttrssserviceroot.cpp b/src/services/tt-rss/ttrssserviceroot.cpp index e412dc85c..9dd105766 100755 --- a/src/services/tt-rss/ttrssserviceroot.cpp +++ b/src/services/tt-rss/ttrssserviceroot.cpp @@ -129,11 +129,11 @@ void TtRssServiceRoot::addNewCategory() { // Do nothing. } -bool TtRssServiceRoot::canBeEdited() { +bool TtRssServiceRoot::canBeEdited() const { return true; } -bool TtRssServiceRoot::canBeDeleted() { +bool TtRssServiceRoot::canBeDeleted() const { return true; } diff --git a/src/services/tt-rss/ttrssserviceroot.h b/src/services/tt-rss/ttrssserviceroot.h index 82d5564f8..d25589f94 100755 --- a/src/services/tt-rss/ttrssserviceroot.h +++ b/src/services/tt-rss/ttrssserviceroot.h @@ -40,8 +40,8 @@ class TtRssServiceRoot : public ServiceRoot { QString code() const; - bool canBeEdited(); - bool canBeDeleted(); + bool canBeEdited() const; + bool canBeDeleted() const; bool editViaGui(); bool deleteViaGui();