Refactorings.

This commit is contained in:
Martin Rotter 2014-09-16 21:20:47 +02:00
parent d15d2460bb
commit 52d1975664
4 changed files with 37 additions and 58 deletions

View File

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

View File

@ -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<Message>)),
m_messagesBrowser, SLOT(navigateToMessages(QList<Message>)));
connect(m_messagesView, SIGNAL(currentMessagesRemoved()), m_messagesBrowser, SLOT(clear()));
connect(m_messagesView, SIGNAL(currentMessagesChanged(QList<Message>)), m_messagesBrowser, SLOT(navigateToMessages(QList<Message>)));
// 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<int>)),
m_messagesView, SLOT(loadFeeds(QList<int>)));
connect(m_feedsView, SIGNAL(feedsSelected(QList<int>)), m_messagesView, SLOT(loadFeeds(QList<int>)));
// 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<Message>)),
form_main->m_ui->m_tabWidget,
SLOT(addBrowserWithMessages(QList<Message>)));
form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList<Message>)));
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<Message>)),
form_main->m_ui->m_tabWidget,
SLOT(addBrowserWithMessages(QList<Message>)));
form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList<Message>)));
// Downloader connections.
connect(m_feedDownloaderThread, SIGNAL(finished()),
m_feedDownloaderThread, SLOT(deleteLater()));
connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList<FeedsModelFeed*>)),
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)));
connect(m_feedDownloaderThread, SIGNAL(finished()), m_feedDownloaderThread, SLOT(deleteLater()));
connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList<FeedsModelFeed*>)), 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)));
// Toolbar forwardings.
connect(form_main->m_ui->m_actionSwitchImportanceOfSelectedMessages,

View File

@ -90,28 +90,27 @@ void FeedsView::updateAutoUpdateStatus() {
}
}
void FeedsView::setSortingEnabled(bool enable) {
QTreeView::setSortingEnabled(enable);
header()->setSortIndicatorShown(false);
}
QList<FeedsModelFeed*> 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<FeedsModelFeed*>();
}
}
QList<FeedsModelFeed*> 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<FeedsModelCategory*>(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<QAction*>() <<
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();

View File

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