Refactorings...

This commit is contained in:
Martin Rotter 2014-01-14 14:42:20 +01:00
parent 406cc9cde5
commit 101140d6ed
23 changed files with 165 additions and 198 deletions

View File

@ -298,6 +298,12 @@ QSqlDatabase DatabaseFactory::connection(const QString &connection_name,
}
}
void DatabaseFactory::removeConnection(const QString &connection_name) {
qDebug("Removing database connection '%s'.", qPrintable(connection_name));
QSqlDatabase::removeDatabase(connection_name);
}
void DatabaseFactory::saveMemoryDatabase() {
QSqlDatabase database = connection();
QSqlDatabase file_database = connection(objectName(), false);

View File

@ -25,11 +25,7 @@ class DatabaseFactory : public QObject {
bool in_memory = true);
// Removes connection.
inline void removeConnection(const QString &connection_name = QString()) {
qDebug("Removing database connection '%s'.", qPrintable(connection_name));
QSqlDatabase::removeDatabase(connection_name);
}
void removeConnection(const QString &connection_name = QString());
// Performs saving of items from in-memory database
// to file-based database.

View File

@ -317,7 +317,7 @@ void FeedsModel::reloadWholeLayout() {
void FeedsModel::loadFromDatabase() {
// Delete all childs of the root node and clear them from the memory.
qDeleteAll(m_rootItem->childItems());
m_rootItem->clearChilds();
m_rootItem->clearChildren();
QSqlDatabase database = DatabaseFactory::instance()->connection();
CategoryAssignment categories;

View File

@ -16,23 +16,7 @@ FeedsModelRootItem::~FeedsModelRootItem() {
qDeleteAll(m_childItems);
}
FeedsModelRootItem::Kind FeedsModelRootItem::kind() const {
return m_kind;
}
QIcon FeedsModelRootItem::icon() const {
return m_icon;
}
void FeedsModelRootItem::appendChild(FeedsModelRootItem *child) {
m_childItems.append(child);
child->setParent(this);
}
int FeedsModelRootItem::columnCount() const {
// FeedsModel offers exactly two columns.
return 2;
}
int FeedsModelRootItem::row() const {
if (m_parentItem) {
@ -44,10 +28,6 @@ int FeedsModelRootItem::row() const {
}
}
int FeedsModelRootItem::childCount() const {
return m_childItems.size();
}
QVariant FeedsModelRootItem::data(int column, int role) const {
Q_UNUSED(column)
Q_UNUSED(role)
@ -76,34 +56,6 @@ int FeedsModelRootItem::countOfUnreadMessages() const {
return total_count;
}
void FeedsModelRootItem::setIcon(const QIcon &icon) {
m_icon = icon;
}
int FeedsModelRootItem::id() const {
return m_id;
}
void FeedsModelRootItem::setId(int id) {
m_id = id;
}
QString FeedsModelRootItem::title() const {
return m_title;
}
void FeedsModelRootItem::setTitle(const QString &title) {
m_title = title;
}
QList<FeedsModelRootItem *> FeedsModelRootItem::childItems() const {
return m_childItems;
}
void FeedsModelRootItem::clearChilds() {
m_childItems.clear();
}
bool FeedsModelRootItem::removeChild(int index) {
if (index >= 0 && index < m_childItems.size()) {
m_childItems.removeAt(index);
@ -114,25 +66,6 @@ bool FeedsModelRootItem::removeChild(int index) {
}
}
QDateTime FeedsModelRootItem::creationDate() const {
return m_creationDate;
}
void FeedsModelRootItem::setCreationDate(const QDateTime &creation_date) {
m_creationDate = creation_date;
}
QString FeedsModelRootItem::description() const {
return m_description;
}
void FeedsModelRootItem::setDescription(const QString &description) {
m_description = description;
}
bool FeedsModelRootItem::isEqual(FeedsModelRootItem *lhs,
FeedsModelRootItem *rhs) {
return (lhs->kind() == rhs->kind()) && (lhs->id() == rhs->id());

View File

@ -35,9 +35,20 @@ class FeedsModelRootItem {
return m_childItems.value(row);
}
virtual void appendChild(FeedsModelRootItem *child);
virtual int childCount() const;
virtual int columnCount() const;
inline virtual int childCount() const {
return m_childItems.size();
}
inline virtual int columnCount() const {
// FeedsModel offers exactly two columns.
return 2;
}
inline virtual void appendChild(FeedsModelRootItem *child) {
m_childItems.append(child);
child->setParent(this);
}
virtual int row() const;
virtual QVariant data(int column, int role) const;
@ -46,38 +57,69 @@ class FeedsModelRootItem {
virtual int countOfUnreadMessages() const;
virtual int countOfAllMessages() const;
virtual Kind kind() const;
// Each item has icon.
QIcon icon() const;
void setIcon(const QIcon &icon);
// Each item has some kind of id.
int id() const;
void setId(int id);
// Each item has its title.
// NOTE: This is note entirely true for the root item.
QString title() const;
void setTitle(const QString &title);
QDateTime creationDate() const;
void setCreationDate(const QDateTime &creation_date);
QString description() const;
void setDescription(const QString &description);
// Access to children.
QList<FeedsModelRootItem *> childItems() const;
inline QList<FeedsModelRootItem*> childItems() const {
return m_childItems;
}
// Removes all children from this item.
// NOTE: Children are NOT freed from the memory.
void clearChilds();
inline void clearChildren() {
m_childItems.clear();
}
// Removes particular child at given index.
// NOTE: Child is NOT freed from the memory.
bool removeChild(int index);
inline Kind kind() const {
return m_kind;
}
// Each item has icon.
inline QIcon icon() const {
return m_icon;
}
inline void setIcon(const QIcon &icon) {
m_icon = icon;
}
// Each item has some kind of id.
inline int id() const {
return m_id;
}
inline void setId(int id) {
m_id = id;
}
// Each item has its title.
// NOTE: This is note entirely true for the root item.
inline QString title() const {
return m_title;
}
inline void setTitle(const QString &title) {
m_title = title;
}
inline QDateTime creationDate() const {
return m_creationDate;
}
inline void setCreationDate(const QDateTime &creation_date) {
m_creationDate = creation_date;
}
inline QString description() const {
return m_description;
}
inline void setDescription(const QString &description) {
m_description = description;
}
// Compares two model items.
static bool isEqual(FeedsModelRootItem *lhs, FeedsModelRootItem *rhs);
static bool lessThan(FeedsModelRootItem *lhs, FeedsModelRootItem *rhs);

View File

@ -38,30 +38,6 @@ FeedsModelStandardFeed *FeedsModelStandardFeed::loadFromRecord(const QSqlRecord
return feed;
}
QString FeedsModelStandardFeed::encoding() const {
return m_encoding;
}
void FeedsModelStandardFeed::setEncoding(const QString &encoding) {
m_encoding = encoding;
}
QString FeedsModelStandardFeed::url() const {
return m_url;
}
void FeedsModelStandardFeed::setUrl(const QString &url) {
m_url = url;
}
QString FeedsModelStandardFeed::language() const {
return m_language;
}
void FeedsModelStandardFeed::setLanguage(const QString &language) {
m_language = language;
}
QVariant FeedsModelStandardFeed::data(int column, int role) const {
switch (role) {
case Qt::DisplayRole:

View File

@ -25,14 +25,29 @@ class FeedsModelStandardFeed : public FeedsModelFeed {
void update();
// Various getters/setters.
QString encoding() const;
void setEncoding(const QString &encoding);
inline QString encoding() const {
return m_encoding;
}
QString url() const;
void setUrl(const QString &url);
inline void setEncoding(const QString &encoding) {
m_encoding = encoding;
}
QString language() const;
void setLanguage(const QString &language);
inline QString url() const {
return m_url;
}
inline void setUrl(const QString &url) {
m_url = url;
}
inline QString language() const {
return m_language;
}
inline void setLanguage(const QString &language) {
m_language = language;
}
// Loads standard feed object from given SQL record.
static FeedsModelStandardFeed *loadFromRecord(const QSqlRecord &record);

View File

@ -25,9 +25,7 @@ FeedsProxyModel::~FeedsProxyModel() {
qDebug("Destroying FeedsProxyModel instance");
}
FeedsModel *FeedsProxyModel::sourceModel() {
return m_sourceModel;
}
bool FeedsProxyModel::lessThan(const QModelIndex &left,
const QModelIndex &right) const {

View File

@ -15,7 +15,9 @@ class FeedsProxyModel : public QSortFilterProxyModel {
virtual ~FeedsProxyModel();
// Access to the source model.
FeedsModel *sourceModel();
inline FeedsModel *sourceModel() {
return m_sourceModel;
}
// Maps list of indexes.
QModelIndexList mapListToSource(const QModelIndexList &indexes);

View File

@ -32,10 +32,7 @@ MessagesModel::~MessagesModel() {
qDebug("Destroying MessagesModel instance.");
}
bool MessagesModel::submitAll() {
qFatal("Submitting changes via model is not allowed.");
return false;
}
void MessagesModel::setupIcons() {
m_favoriteIcon = IconThemeFactory::instance()->fromTheme("favorites");
@ -55,9 +52,7 @@ void MessagesModel::setupFonts() {
m_boldFont.setBold(true);
}
QList<int> MessagesModel::currentFeeds() const {
return m_currentFeeds;
}
void MessagesModel::loadMessages(const QList<int> feed_ids) {
m_currentFeeds = feed_ids;

View File

@ -44,11 +44,17 @@ class MessagesModel : public QSqlTableModel {
int messageId(int row_index) const;
// Access to list of currently loaded feed IDs.
QList<int> currentFeeds() const;
inline QList<int> currentFeeds() const {
return m_currentFeeds;
}
public slots:
// To disable persistent changes submissions.
bool submitAll();
inline bool submitAll() {
qFatal("Submitting changes via model is not allowed.");
return false;
}
// CORE messages manipulators.
// NOTE: These are used to change properties of one message.

View File

@ -21,9 +21,7 @@ MessagesProxyModel::~MessagesProxyModel() {
qDebug("Destroying MessagesProxyModel instance.");
}
MessagesModel *MessagesProxyModel::sourceModel() {
return m_sourceModel;
}
bool MessagesProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const {
// TODO: Maybe use QString::localeAwareCompare() here for

View File

@ -15,7 +15,9 @@ class MessagesProxyModel : public QSortFilterProxyModel {
virtual ~MessagesProxyModel();
// Source model getter.
MessagesModel *sourceModel();
inline MessagesModel *sourceModel() {
return m_sourceModel;
}
// Maps list of indexes.
QModelIndexList mapListToSource(const QModelIndexList &indexes);

View File

@ -21,13 +21,12 @@ Settings::~Settings() {
qDebug("Deleting Settings instance.");
}
Settings::Type Settings::type() const {
return m_initializationStatus;
}
QSettings::Status Settings::checkSettings() {
qDebug("Syncing settings.");
sync();
return status();
}
@ -40,17 +39,9 @@ Settings *Settings::instance() {
return s_instance;
}
QVariant Settings::value(const QString &section,
const QString &key,
const QVariant &default_value) {
return QSettings::value(QString("%1/%2").arg(section, key), default_value);
}
void Settings::setValue(const QString &section,
const QString &key,
const QVariant &value) {
QSettings::setValue(QString("%1/%2").arg(section, key), value);
}
QSettings::Status Settings::setupSettings() {
// If settings file exists in executable file working directory

View File

@ -22,16 +22,22 @@ class Settings : public QSettings {
virtual ~Settings();
// Type of used settings.
Type type() const;
inline Type type() const {
return m_initializationStatus;
}
// Getter/setter for settings values.
QVariant value(const QString &section,
inline QVariant value(const QString &section,
const QString &key,
const QVariant &default_value = QVariant());
const QVariant &default_value = QVariant()) {
return QSettings::value(QString("%1/%2").arg(section, key), default_value);
}
void setValue(const QString &section,
inline void setValue(const QString &section,
const QString &key,
const QVariant &value);
const QVariant &value) {
QSettings::setValue(QString("%1/%2").arg(section, key), value);
}
// Synchronizes settings.
QSettings::Status checkSettings();

View File

@ -102,9 +102,7 @@ SystemFactory *SystemFactory::getInstance() {
return s_instance;
}
QReadWriteLock *SystemFactory::applicationCloseLock() const {
return m_applicationCloseLock;
}
bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) {
SystemFactory::AutoStartStatus current_status = SystemFactory::getAutoStartStatus();

View File

@ -40,11 +40,14 @@ class SystemFactory : public QObject {
QString getAutostartDesktopFileLocation();
#endif
// Singleton getter.
static SystemFactory *getInstance();
// Access to application-wide close lock.
QReadWriteLock *applicationCloseLock() const;
inline QReadWriteLock *applicationCloseLock() const {
return m_applicationCloseLock;
}
// Singleton getter.
static SystemFactory *getInstance();
private:
// This read-write lock is used by application on its close.

View File

@ -185,6 +185,8 @@ void FeedMessageViewer::createConnections() {
m_feedDownloader, SLOT(updateFeeds(QList<FeedsModelFeed*>)));
connect(m_feedDownloader, SIGNAL(finished()),
this, SLOT(onFeedUpdatesFinished()));
connect(m_feedDownloader, SIGNAL(started()),
this, SLOT(onFeedUpdatesStarted()));
connect(m_feedDownloader, SIGNAL(progress(FeedsModelFeed*,int,int)),
this, SLOT(onFeedUpdatesProgress(FeedsModelFeed*,int,int)));

View File

@ -32,13 +32,9 @@ FeedsView::~FeedsView() {
qDebug("Destroying FeedsView instance.");
}
FeedsProxyModel *FeedsView::model() {
return m_proxyModel;
}
FeedsModel *FeedsView::sourceModel() {
return m_sourceModel;
}
void FeedsView::setSortingEnabled(bool enable) {
QTreeView::setSortingEnabled(enable);

View File

@ -31,8 +31,13 @@ class FeedsView : public QTreeView {
explicit FeedsView(QWidget *parent = 0);
virtual ~FeedsView();
FeedsProxyModel *model();
FeedsModel *sourceModel();
inline FeedsProxyModel *model() {
return m_proxyModel;
}
inline FeedsModel *sourceModel() {
return m_sourceModel;
}
// Enables or disables sorting.
void setSortingEnabled(bool enable);
@ -77,9 +82,6 @@ class FeedsView : public QTreeView {
// Reloads counts for particular feed.
void updateCountsOfParticularFeed(FeedsModelFeed *feed, bool update_total_too = true);
// TODO: pouzit metodu dole pro uvodni zobrazeni
// poctu v trayi
// Notifies other components about messages
// counts.
inline void notifyWithCounts() {

View File

@ -38,7 +38,7 @@ class FormCategoryDetails : public QDialog {
// and parent_item contains parent item of newly
// created or edited category.
// NOTE: Newly ADDED category is NOT added to the model NOR
// in the database.
// to the database.
// NOTE: Newly EDITED category IS COPY of its original.
// SO NO ORIGINAL MODEL DATA ARE EDITED OR CHANGED.
FormCategoryDetailsAnswer exec(FeedsModelCategory *input_category,

View File

@ -56,13 +56,9 @@ FormMain *FormMain::instance() {
return s_instance;
}
QMenu *FormMain::trayMenu() {
return m_trayMenu;
}
TabWidget *FormMain::tabWidget() {
return m_ui->m_tabWidget;
}
QList<QAction*> FormMain::allActions() {
QList<QAction*> actions;
@ -95,9 +91,7 @@ QList<QAction*> FormMain::allActions() {
return actions;
}
StatusBar *FormMain::statusBar() {
return m_statusBar;
}
void FormMain::prepareMenus() {
// Setup menu for tray icon.

View File

@ -23,19 +23,25 @@ class FormMain : public QMainWindow {
virtual ~FormMain();
// Returns menu for the tray icon.
QMenu *trayMenu();
inline QMenu *trayMenu() {
return m_trayMenu;
}
// Returns global tab widget.
TabWidget *tabWidget();
inline TabWidget *tabWidget() {
return m_ui->m_tabWidget;
}
// Access to statusbar.
inline StatusBar *statusBar() {
return m_statusBar;
}
// Returns list of all globally available actions.
// NOTE: This is used for setting dynamic shortcuts
// for given actions.
QList<QAction*> allActions();
// Access to statusbar.
StatusBar *statusBar();
// Singleton accessor.
static FormMain *instance();