From 52d1975664038f373abb337719f88d53c67e2247 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 16 Sep 2014 21:20:47 +0200 Subject: [PATCH] Refactorings. --- src/definitions/definitions.h.in | 1 + src/gui/feedmessageviewer.cpp | 45 +++++++++++--------------------- src/gui/feedsview.cpp | 39 +++++++++++++-------------- src/gui/feedsview.h | 10 +++---- 4 files changed, 37 insertions(+), 58 deletions(-) diff --git a/src/definitions/definitions.h.in b/src/definitions/definitions.h.in index b0b5b19f0..2790d51e9 100755 --- a/src/definitions/definitions.h.in +++ b/src/definitions/definitions.h.in @@ -69,6 +69,7 @@ #define SEPARATOR_ACTION_NAME "separator" #define FILTER_WIDTH 150 #define FILTER_RIGHT_MARGIN 5 +#define FEEDS_VIEW_INDENTATION 10 #define APP_DB_MYSQL_DRIVER "QMYSQL" #define APP_DB_MYSQL_INIT "db_init_mysql.sql" diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 520c1d84b..8ba8f5f3f 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -195,55 +195,40 @@ void FeedMessageViewer::createConnections() { m_messagesView, SLOT(filterMessages(MessagesModel::DisplayFilter))); // Message changers. - connect(m_messagesView, SIGNAL(currentMessagesRemoved()), - m_messagesBrowser, SLOT(clear())); - connect(m_messagesView, SIGNAL(currentMessagesChanged(QList)), - m_messagesBrowser, SLOT(navigateToMessages(QList))); + connect(m_messagesView, SIGNAL(currentMessagesRemoved()), m_messagesBrowser, SLOT(clear())); + connect(m_messagesView, SIGNAL(currentMessagesChanged(QList)), m_messagesBrowser, SLOT(navigateToMessages(QList))); // Import & export of feeds. - connect(form_main->m_ui->m_actionExportFeeds, SIGNAL(triggered()), - this, SLOT(exportFeeds())); - connect(form_main->m_ui->m_actionImportFeeds, SIGNAL(triggered()), - this, SLOT(importFeeds())); + connect(form_main->m_ui->m_actionExportFeeds, SIGNAL(triggered()), this, SLOT(exportFeeds())); + connect(form_main->m_ui->m_actionImportFeeds, SIGNAL(triggered()), this, SLOT(importFeeds())); // If user selects feeds, load their messages. - connect(m_feedsView, SIGNAL(feedsSelected(QList)), - m_messagesView, SLOT(loadFeeds(QList))); + connect(m_feedsView, SIGNAL(feedsSelected(QList)), m_messagesView, SLOT(loadFeeds(QList))); // If user changes status of some messages, recalculate message counts. - connect(m_messagesView, SIGNAL(feedCountsChanged()), - m_feedsView, SLOT(updateCountsOfSelectedFeeds())); + connect(m_messagesView, SIGNAL(feedCountsChanged()), m_feedsView, SLOT(updateCountsOfSelectedFeeds())); // State of many messages is changed, then we need // to reload selections. connect(m_feedsView, SIGNAL(feedsNeedToBeReloaded(int)), m_messagesView, SLOT(reloadSelections(int))); // If counts of unread/all messages change, update the tray icon. - connect(m_feedsView, SIGNAL(feedCountsChanged(int,int)), - this, SLOT(updateTrayIconStatus(int,int))); + connect(m_feedsView, SIGNAL(feedCountsChanged(int,int)), this, SLOT(updateTrayIconStatus(int,int))); // Message openers. connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(QList)), - form_main->m_ui->m_tabWidget, - SLOT(addBrowserWithMessages(QList))); + form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList))); connect(m_messagesView, SIGNAL(openLinkNewTab(QString)), - form_main->m_ui->m_tabWidget, - SLOT(addLinkedBrowser(QString))); + form_main->m_ui->m_tabWidget, SLOT(addLinkedBrowser(QString))); connect(m_feedsView, SIGNAL(openMessagesInNewspaperView(QList)), - form_main->m_ui->m_tabWidget, - SLOT(addBrowserWithMessages(QList))); + form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList))); // Downloader connections. - connect(m_feedDownloaderThread, SIGNAL(finished()), - m_feedDownloaderThread, SLOT(deleteLater())); - connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList)), - m_feedDownloader, SLOT(updateFeeds(QList))); - 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))); + connect(m_feedDownloaderThread, SIGNAL(finished()), m_feedDownloaderThread, SLOT(deleteLater())); + connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList)), m_feedDownloader, SLOT(updateFeeds(QList))); + 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))); // Toolbar forwardings. connect(form_main->m_ui->m_actionSwitchImportanceOfSelectedMessages, diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index f86fc8dc5..1007909b3 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -90,28 +90,27 @@ void FeedsView::updateAutoUpdateStatus() { } } -void FeedsView::setSortingEnabled(bool enable) { - QTreeView::setSortingEnabled(enable); - header()->setSortIndicatorShown(false); -} - QList FeedsView::selectedFeeds() const { - QModelIndexList selection = selectionModel()->selectedRows(); - QModelIndexList mapped_selection = m_proxyModel->mapListToSource(selection); + QModelIndex current_index = currentIndex(); - return m_sourceModel->feedsForIndexes(mapped_selection); + if (current_index.isValid()) { + return m_sourceModel->feedsForIndex(m_proxyModel->mapToSource(current_index)); + } + else { + return QList(); + } } QList FeedsView::allFeeds() const { return m_sourceModel->allFeeds(); } -FeedsModelCategory *FeedsView::isCurrentIndexCategory() const { +FeedsModelCategory *FeedsView::selectedCategory() const { QModelIndex current_mapped = m_proxyModel->mapToSource(currentIndex()); return m_sourceModel->categoryForIndex(current_mapped); } -FeedsModelFeed *FeedsView::isCurrentIndexFeed() const { +FeedsModelFeed *FeedsView::selectedFeed() const { QModelIndex current_mapped = m_proxyModel->mapToSource(currentIndex()); return m_sourceModel->feedForIndex(current_mapped); } @@ -301,10 +300,10 @@ void FeedsView::editSelectedItem() { FeedsModelCategory *category; FeedsModelFeed *feed; - if ((category = isCurrentIndexCategory()) != NULL) { + if ((category = selectedCategory()) != NULL) { editCategory(static_cast(category)); } - else if ((feed = isCurrentIndexFeed()) != NULL) { + else if ((feed = selectedFeed()) != NULL) { // Feed is selected. switch (feed->type()) { case FeedsModelFeed::Atom10: @@ -407,7 +406,7 @@ void FeedsView::openSelectedFeedsInNewspaperMode() { if (!messages.isEmpty()) { emit openMessagesInNewspaperView(messages); - markSelectedFeedsRead(); + QTimer::singleShot(0, this, SLOT(markSelectedFeedsRead())); } } @@ -421,7 +420,6 @@ void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) { // Make sure that selected view reloads changed indexes. m_sourceModel->reloadChangedLayout(m_proxyModel->mapListToSource(selectionModel()->selectedRows())); - notifyWithCounts(); } } @@ -489,7 +487,7 @@ void FeedsView::initializeContextMenuCategoriesFeeds() { } void FeedsView::initializeContextMenuEmptySpace() { - m_contextMenuEmptySpace = new QMenu(tr("Context menu for feeds"), this); + m_contextMenuEmptySpace = new QMenu(tr("Context menu"), this); m_contextMenuEmptySpace->addActions(QList() << qApp->mainForm()->m_ui->m_actionUpdateAllFeeds << qApp->mainForm()->m_ui->m_actionAddCategory << @@ -508,13 +506,14 @@ void FeedsView::setupAppearance() { #endif header()->setStretchLastSection(false); + header()->setSortIndicatorShown(false); setUniformRowHeights(true); setAnimated(true); setSortingEnabled(true); setItemsExpandable(true); setExpandsOnDoubleClick(true); setEditTriggers(QAbstractItemView::NoEditTriggers); - setIndentation(10); + setIndentation(FEEDS_VIEW_INDENTATION); setAcceptDrops(false); setDragEnabled(false); setDropIndicatorShown(false); @@ -525,11 +524,10 @@ void FeedsView::setupAppearance() { // Sort in ascending order, that is categories are // "bigger" than feeds. - sortByColumn(0, Qt::AscendingOrder); + sortByColumn(FDS_MODEL_TITLE_INDEX, Qt::AscendingOrder); } -void FeedsView::selectionChanged(const QItemSelection &selected, - const QItemSelection &deselected) { +void FeedsView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { QTreeView::selectionChanged(selected, deselected); m_selectedFeeds.clear(); @@ -538,8 +536,7 @@ void FeedsView::selectionChanged(const QItemSelection &selected, #if defined(DEBUG) QModelIndex index_for_feed = m_sourceModel->indexForItem(feed); - qDebug("Selecting feed '%s' (source index [%d, %d]).", - qPrintable(feed->title()), index_for_feed.row(), index_for_feed.column()); + qDebug("Selecting feed '%s' (source index [%d, %d]).", qPrintable(feed->title()), index_for_feed.row(), index_for_feed.column()); #endif m_selectedFeeds << feed->id(); diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index e0c15ed50..35255c598 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -53,9 +53,6 @@ class FeedsView : public QTreeView { // Resets global auto-update intervals according to settings // and starts/stop the timer as needed. void updateAutoUpdateStatus(); - - // Enables or disables sorting. - void setSortingEnabled(bool enable); // Returns list of selected/all feeds. QList selectedFeeds() const; @@ -64,8 +61,8 @@ class FeedsView : public QTreeView { // Return true if current index contains category/feed and // stores category/feed in the parameter pointer, // otherwise false. - FeedsModelCategory *isCurrentIndexCategory() const; - FeedsModelFeed *isCurrentIndexFeed() const; + FeedsModelCategory *selectedCategory() const; + FeedsModelFeed *selectedFeed() const; // Saves/loads expand states of all nodes (feeds/categories) of the list // to/from settings. @@ -144,8 +141,7 @@ class FeedsView : public QTreeView { void setupAppearance(); // Handle selections. - void selectionChanged(const QItemSelection &selected, - const QItemSelection &deselected); + void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void keyPressEvent(QKeyEvent *event);