Refactoring, correct selection after keyboard search.

This commit is contained in:
Martin Rotter 2014-09-17 10:00:04 +02:00
parent 52d1975664
commit 202d26cea5
9 changed files with 53 additions and 18 deletions

View File

@ -35,7 +35,8 @@
#include <algorithm>
FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) {
FeedsModel::FeedsModel(QObject *parent)
: QAbstractItemModel(parent), m_recycleBin(new FeedsModelRecycleBin()) {
setObjectName("FeedsModel");
// Create root item.
@ -692,7 +693,8 @@ void FeedsModel::loadFromDatabase() {
assembleCategories(categories);
assembleFeeds(feeds);
m_rootItem->appendChild(new FeedsModelRecycleBin());
// As the last item, add recycle bin, which is needed.
m_rootItem->appendChild(m_recycleBin);
}
QList<FeedsModelFeed*> FeedsModel::feedsForIndex(const QModelIndex &index) {

View File

@ -28,6 +28,7 @@
class FeedsModelCategory;
class FeedsModelFeed;
class FeedsModelRecycleBin;
class FeedsImportExportModel;
typedef QList<QPair<int, FeedsModelCategory*> > CategoryAssignment;
@ -170,6 +171,7 @@ class FeedsModel : public QAbstractItemModel {
private:
FeedsModelRootItem *m_rootItem;
FeedsModelRecycleBin *m_recycleBin;
QList<QString> m_headerData;
QList<QString> m_tooltipData;
QIcon m_countsIcon;

View File

@ -20,20 +20,25 @@
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include <QSqlQuery>
FeedsModelRecycleBin::FeedsModelRecycleBin(FeedsModelRootItem *parent) : FeedsModelRootItem(parent) {
FeedsModelRecycleBin::FeedsModelRecycleBin(FeedsModelRootItem *parent)
: FeedsModelRootItem(parent) {
m_kind = FeedsModelRootItem::RecycleBin;
m_icon = qApp->icons()->fromTheme("folder-recycle-bin");
m_id = ID_RECYCLE_BIN;
m_title = tr("Recycle bin");
m_description = tr("Recycle bin contains all deleted messages from all feeds.");
m_creationDate = QDateTime::currentDateTime();
updateCounts();
}
FeedsModelRecycleBin::~FeedsModelRecycleBin() {
qDebug("Destroying FeedsModelRecycleBin instance.");
}
int FeedsModelRecycleBin::childCount() const {
return 0;
}
@ -43,14 +48,13 @@ void FeedsModelRecycleBin::appendChild(FeedsModelRootItem *child) {
}
int FeedsModelRecycleBin::countOfUnreadMessages() const {
return 0;
return m_totalCount;
}
int FeedsModelRecycleBin::countOfAllMessages() const {
return 0;
return m_totalCount;
}
QVariant FeedsModelRecycleBin::data(int column, int role) const {
switch (role) {
case Qt::DisplayRole:
@ -102,3 +106,17 @@ QVariant FeedsModelRecycleBin::data(int column, int role) const {
return QVariant();
}
}
void FeedsModelRecycleBin::updateCounts() {
QSqlDatabase database = qApp->database()->connection("FeedsModelRecycleBin",
DatabaseFactory::FromSettings);
QSqlQuery query_all(database);
query_all.setForwardOnly(true);
if (query_all.exec("SELECT count(*) FROM Messages WHERE is_deleted = 1;") && query_all.next()) {
m_totalCount = query_all.value(0).toInt();
}
else {
m_totalCount = 0;
}
}

View File

@ -35,6 +35,12 @@ class FeedsModelRecycleBin : public FeedsModelRootItem {
int countOfUnreadMessages() const;
int countOfAllMessages() const;
QVariant data(int column, int role) const;
public slots:
void updateCounts();
private:
int m_totalCount;
};
#endif // FEEDSMODELRECYCLEBIN_H

View File

@ -37,7 +37,6 @@ FeedsModelRootItem::FeedsModelRootItem(FeedsModelRootItem *parent_item)
}
FeedsModelRootItem::~FeedsModelRootItem() {
qDebug("Destroying FeedsModelRootItem instance.");
qDeleteAll(m_childItems);
}

View File

@ -132,9 +132,7 @@ void FeedsView::loadExpandedStates() {
// Iterate all categories and save their expand statuses.
foreach (FeedsModelCategory *category, sourceModel()->allCategories().values()) {
setExpanded(model()->mapFromSource(sourceModel()->indexForItem(category)),
settings->value(APP_CFG_CAT_EXP,
QString::number(category->id()),
true).toBool());
settings->value(APP_CFG_CAT_EXP, QString::number(category->id()), true).toBool());
}
}
@ -169,8 +167,7 @@ void FeedsView::updateSelectedFeeds() {
void FeedsView::executeNextAutoUpdate() {
if (!qApp->closeLock()->tryLock()) {
qDebug("Delaying scheduled feed auto-updates for one minute "
"due to another running update.");
qDebug("Delaying scheduled feed auto-updates for one minute due to another running update.");
// Cannot update, quit.
return;

View File

@ -55,17 +55,16 @@ class FeedsView : public QTreeView {
void updateAutoUpdateStatus();
// Returns list of selected/all feeds.
// NOTE: This is recursive method which returns all descendants.
QList<FeedsModelFeed*> selectedFeeds() const;
QList<FeedsModelFeed*> allFeeds() const;
// Return true if current index contains category/feed and
// stores category/feed in the parameter pointer,
// otherwise false.
// Returns pointers to selected feed/category if they are really
// selected.
FeedsModelCategory *selectedCategory() const;
FeedsModelFeed *selectedFeed() const;
// Saves/loads expand states of all nodes (feeds/categories) of the list
// to/from settings.
// Saves/loads expand states of all nodes (feeds/categories) of the list to/from settings.
void saveExpandedStates();
void loadExpandedStates();

View File

@ -63,6 +63,12 @@ void MessagesView::createConnections() {
this, SLOT(adjustColumns()));
}
void MessagesView::keyboardSearch(const QString &search) {
setSelectionMode(QAbstractItemView::SingleSelection);
QTreeView::keyboardSearch(search);
setSelectionMode(QAbstractItemView::ExtendedSelection);
}
void MessagesView::reloadSelections(int mark_current_index_read) {
QModelIndex current_index = selectionModel()->currentIndex();
QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index);

View File

@ -52,6 +52,12 @@ class MessagesView : public QTreeView {
void createConnections();
public slots:
void keyboardSearch(const QString &search) {
setSelectionMode(QAbstractItemView::SingleSelection);
QTreeView::keyboardSearch(search);
setSelectionMode(QAbstractItemView::ExtendedSelection);
}
// Called after data got changed externally
// and it needs to be reloaded to the view.
// If "mark_current_index_read" is 0, then message with