Refactoring.

This commit is contained in:
Martin Rotter 2016-01-15 09:39:06 +01:00
parent b91d7b926d
commit ef33988ca6
17 changed files with 35 additions and 35 deletions

View File

@ -51,7 +51,7 @@ QList<QAction*> RootItem::contextMenu() {
return QList<QAction*>();
}
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<Category*>(this);
Category *RootItem::toCategory() const {
return static_cast<Category*>(const_cast<RootItem*>(this));
}
Feed *RootItem::toFeed() {
return static_cast<Feed*>(this);
Feed *RootItem::toFeed() const {
return static_cast<Feed*>(const_cast<RootItem*>(this));
}
ServiceRoot *RootItem::toServiceRoot() const {

View File

@ -82,14 +82,14 @@ class RootItem : public QObject {
virtual QList<QAction*> 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:

View File

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

View File

@ -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<Message> ServiceRoot::undeletedMessages() const {
QList<Message> messages;
int account_id = accountId();
const int account_id = accountId();
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
QSqlQuery query(database);

View File

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

View File

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

View File

@ -63,11 +63,11 @@ class StandardFeed : public Feed {
QList<QAction*> contextMenu();
bool canBeEdited() {
bool canBeEdited() const {
return true;
}
bool canBeDeleted() {
bool canBeDeleted() const {
return true;
}

View File

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

View File

@ -34,7 +34,7 @@ class StandardServiceEntryPoint : public ServiceEntryPoint {
QIcon icon() const;
QString code() const;
ServiceRoot *createNewRoot();
ServiceRoot *createNewRoot() const;
QList<ServiceRoot*> initializeSubtree() const;
};

View File

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

View File

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

View File

@ -138,7 +138,7 @@ void TtRssFeed::updateCounts(bool including_total_count) {
}
}
bool TtRssFeed::canBeEdited() {
bool TtRssFeed::canBeEdited() const {
return true;
}

View File

@ -41,7 +41,7 @@ class TtRssFeed : public Feed {
void updateCounts(bool including_total_count);
bool canBeEdited();
bool canBeEdited() const;
bool editViaGui();
int countOfAllMessages() const;

View File

@ -71,7 +71,7 @@ QString TtRssServiceEntryPoint::code() const {
return SERVICE_CODE_TT_RSS;
}
ServiceRoot *TtRssServiceEntryPoint::createNewRoot() {
ServiceRoot *TtRssServiceEntryPoint::createNewRoot() const {
QPointer<FormEditAccount> form_acc = new FormEditAccount(qApp->mainForm());
TtRssServiceRoot *new_root = form_acc.data()->execForCreate();
delete form_acc.data();

View File

@ -35,7 +35,7 @@ class TtRssServiceEntryPoint : public ServiceEntryPoint {
QIcon icon() const;
QString code() const;
ServiceRoot *createNewRoot();
ServiceRoot *createNewRoot() const;
QList<ServiceRoot*> initializeSubtree() const;
};

View File

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

View File

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