Many refactoring stuff. Recycle bin now displays count of deleted items.

This commit is contained in:
Martin Rotter 2014-09-17 12:21:19 +02:00
parent 202d26cea5
commit 5581a5a92f
11 changed files with 56 additions and 45 deletions

View File

@ -3,16 +3,20 @@
Fixed:
<ul>
<li>Overall code cleanups and refactoring primarily in area of feed/message models and recycle bin functionality.</li>
<li>Fixed bug #66, #67.</li>
<li>Blau skin now has colored webkit scrollbars, fixed some button widths and enhanced menu popup tool buttons.</li>
</ul>
Added:
<ul>
<li>Top-level recycle bin which displays count of deleted items properly.</li>
<li>MySQL backend now alows to defragment/optimize RSS Guard database.</li>
</ul>
Changed:
<ul>
<li>Target message is now selected instead of highlighted when searching with keyboard.</li>
</ul>
<hr/>

View File

@ -66,13 +66,7 @@ FeedsModel::~FeedsModel() {
delete m_rootItem;
}
QModelIndexList FeedsModel::persistentIndexList() const {
return QAbstractItemModel::persistentIndexList();
}
QVariant FeedsModel::headerData(int section,
Qt::Orientation orientation,
int role) const {
QVariant FeedsModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (orientation != Qt::Horizontal) {
return QVariant();
}
@ -900,6 +894,10 @@ void FeedsModel::assembleFeeds(FeedAssignment feeds) {
}
}
FeedsModelRecycleBin *FeedsModel::recycleBin() const {
return m_recycleBin;
}
void FeedsModel::assembleCategories(CategoryAssignment categories) {
QHash<int, FeedsModelRootItem*> assignments;
assignments.insert(NO_PARENT_CATEGORY, m_rootItem);

View File

@ -45,10 +45,6 @@ class FeedsModel : public QAbstractItemModel {
explicit FeedsModel(QObject *parent = 0);
virtual ~FeedsModel();
// Returns list of all indexes available in the model.
// NOTE: Overriden because original method is protected.
QModelIndexList persistentIndexList() const;
// Model implementation.
inline QVariant data(const QModelIndex &index, int role) const {
// Return data according to item.
@ -142,6 +138,9 @@ class FeedsModel : public QAbstractItemModel {
// it to active structure.
bool mergeModel(FeedsImportExportModel *model, QString &output_message);
// Access to recycle bin.
FeedsModelRecycleBin *recycleBin() const;
public slots:
// Feeds operations.
bool markFeedsRead(const QList<FeedsModelFeed*> &feeds, int read);

View File

@ -94,6 +94,9 @@ QVariant FeedsModelRecycleBin::data(int column, int role) const {
return QVariant();
}
case Qt::ToolTipRole:
return tr("Recycle bin\n%1").arg(tr("%n deleted message(s).", 0, countOfUnreadMessages()));
case Qt::TextAlignmentRole:
if (column == FDS_MODEL_COUNTS_INDEX) {
return Qt::AlignCenter;

View File

@ -68,7 +68,9 @@ int FeedsModelRootItem::countOfAllMessages() const {
int total_count = 0;
foreach (FeedsModelRootItem *child_item, m_childItems) {
total_count += child_item->countOfAllMessages();
if (child_item->kind() != FeedsModelRootItem::RecycleBin) {
total_count += child_item->countOfAllMessages();
}
}
return total_count;
@ -95,7 +97,9 @@ int FeedsModelRootItem::countOfUnreadMessages() const {
int total_count = 0;
foreach (FeedsModelRootItem *child_item, m_childItems) {
total_count += child_item->countOfUnreadMessages();
if (child_item->kind() != FeedsModelRootItem::RecycleBin) {
total_count += child_item->countOfUnreadMessages();
}
}
return total_count;

View File

@ -274,7 +274,7 @@ bool MessagesModel::setMessageRead(int row_index, int read) {
// can reflect.
emit dataChanged(index(row_index, 0),
index(row_index, columnCount() - 1));
emit feedCountsChanged();
emit feedCountsChanged(false);
return true;
}
else {
@ -354,7 +354,7 @@ bool MessagesModel::switchBatchMessageImportance(const QModelIndexList &messages
select();
fetchAll();
emit feedCountsChanged();
//emit feedCountsChanged(false);
return true;
}
else {
@ -381,7 +381,7 @@ bool MessagesModel::setBatchMessagesDeleted(const QModelIndexList &messages,
select();
fetchAll();
emit feedCountsChanged();
emit feedCountsChanged(true);
return true;
}
else {
@ -407,7 +407,7 @@ bool MessagesModel::setBatchMessagesRead(const QModelIndexList &messages, int re
select();
fetchAll();
emit feedCountsChanged();
emit feedCountsChanged(true);
return true;
}
else {

View File

@ -109,7 +109,7 @@ class MessagesModel : public QSqlTableModel {
signals:
// Emitted if some persistent change is made which affects
// count of "unread/all" messages.
void feedCountsChanged();
void feedCountsChanged(bool total_message_number_changed = true);
protected:
// Returns selected feed ids in concatenated textual form,

View File

@ -206,7 +206,7 @@ void FeedMessageViewer::createConnections() {
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(bool)), m_feedsView, SLOT(updateCountsOfSelectedFeeds()));
// State of many messages is changed, then we need
// to reload selections.

View File

@ -23,6 +23,7 @@
#include "core/feedsproxymodel.h"
#include "core/feedsmodelrootitem.h"
#include "core/feedsmodelcategory.h"
#include "core/feedsmodelrecyclebin.h"
#include "core/feedsmodelfeed.h"
#include "miscellaneous/systemfactory.h"
#include "gui/formmain.h"
@ -407,18 +408,24 @@ void FeedsView::openSelectedFeedsInNewspaperMode() {
}
}
void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) {
QList<FeedsModelFeed*> selected_feeds = selectedFeeds();
if (!selected_feeds.isEmpty()) {
foreach (FeedsModelFeed *feed, selected_feeds) {
feed->updateCounts(update_total_too);
}
// Make sure that selected view reloads changed indexes.
m_sourceModel->reloadChangedLayout(m_proxyModel->mapListToSource(selectionModel()->selectedRows()));
notifyWithCounts();
void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) {
foreach (FeedsModelFeed *feed, selectedFeeds()) {
feed->updateCounts(update_total_too);
}
QModelIndexList selected_indexes = m_proxyModel->mapListToSource(selectionModel()->selectedRows());
if (update_total_too) {
// Number of items in recycle bin has changed.
m_sourceModel->recycleBin()->updateCounts();
// We need to refresh data for recycle bin too.
selected_indexes.append(m_sourceModel->indexForItem(m_sourceModel->recycleBin()));
}
// Make sure that selected view reloads changed indexes.
m_sourceModel->reloadChangedLayout(selected_indexes);
notifyWithCounts();
}
void FeedsView::updateCountsOfAllFeeds(bool update_total_too) {
@ -426,9 +433,13 @@ void FeedsView::updateCountsOfAllFeeds(bool update_total_too) {
feed->updateCounts(update_total_too);
}
if (update_total_too) {
// Number of items in recycle bin has changed.
m_sourceModel->recycleBin()->updateCounts();
}
// Make sure that all views reloads its data.
m_sourceModel->reloadWholeLayout();
notifyWithCounts();
}

View File

@ -50,17 +50,14 @@ MessagesView::~MessagesView() {
void MessagesView::createConnections() {
// Forward feed counts changes.
connect(m_sourceModel, SIGNAL(feedCountsChanged()),
this, SIGNAL(feedCountsChanged()));
connect(m_sourceModel, SIGNAL(feedCountsChanged(bool)), this, SIGNAL(feedCountsChanged(bool)));
// Make sure that source message is opened
// in new tab on double click.
connect(this, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(openSelectedSourceMessagesInternally()));
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openSelectedSourceMessagesInternally()));
// Adjust columns when layout gets changed.
connect(header(), SIGNAL(geometriesChanged()),
this, SLOT(adjustColumns()));
connect(header(), SIGNAL(geometriesChanged()), this, SLOT(adjustColumns()));
}
void MessagesView::keyboardSearch(const QString &search) {
@ -137,8 +134,7 @@ void MessagesView::contextMenuEvent(QContextMenuEvent *event) {
QModelIndex clicked_index = indexAt(event->pos());
if (!clicked_index.isValid()) {
qDebug("Context menu for MessagesView will not be shown because "
"user clicked on invalid item.");
qDebug("Context menu for MessagesView will not be shown because user clicked on invalid item.");
return;
}

View File

@ -52,11 +52,7 @@ class MessagesView : public QTreeView {
void createConnections();
public slots:
void keyboardSearch(const QString &search) {
setSelectionMode(QAbstractItemView::SingleSelection);
QTreeView::keyboardSearch(search);
setSelectionMode(QAbstractItemView::ExtendedSelection);
}
void keyboardSearch(const QString &search);
// Called after data got changed externally
// and it needs to be reloaded to the view.
@ -118,7 +114,7 @@ class MessagesView : public QTreeView {
// Emitted if counts of unread/total messages has changed
// because of user interaction with list of messages.
void feedCountsChanged();
void feedCountsChanged(bool total_message_number_changed = true);
private:
QMenu *m_contextMenu;