Refactoring, correct selection after keyboard search.
This commit is contained in:
parent
52d1975664
commit
202d26cea5
@ -35,7 +35,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) {
|
FeedsModel::FeedsModel(QObject *parent)
|
||||||
|
: QAbstractItemModel(parent), m_recycleBin(new FeedsModelRecycleBin()) {
|
||||||
setObjectName("FeedsModel");
|
setObjectName("FeedsModel");
|
||||||
|
|
||||||
// Create root item.
|
// Create root item.
|
||||||
@ -692,7 +693,8 @@ void FeedsModel::loadFromDatabase() {
|
|||||||
assembleCategories(categories);
|
assembleCategories(categories);
|
||||||
assembleFeeds(feeds);
|
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) {
|
QList<FeedsModelFeed*> FeedsModel::feedsForIndex(const QModelIndex &index) {
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
class FeedsModelCategory;
|
class FeedsModelCategory;
|
||||||
class FeedsModelFeed;
|
class FeedsModelFeed;
|
||||||
|
class FeedsModelRecycleBin;
|
||||||
class FeedsImportExportModel;
|
class FeedsImportExportModel;
|
||||||
|
|
||||||
typedef QList<QPair<int, FeedsModelCategory*> > CategoryAssignment;
|
typedef QList<QPair<int, FeedsModelCategory*> > CategoryAssignment;
|
||||||
@ -170,6 +171,7 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
FeedsModelRootItem *m_rootItem;
|
FeedsModelRootItem *m_rootItem;
|
||||||
|
FeedsModelRecycleBin *m_recycleBin;
|
||||||
QList<QString> m_headerData;
|
QList<QString> m_headerData;
|
||||||
QList<QString> m_tooltipData;
|
QList<QString> m_tooltipData;
|
||||||
QIcon m_countsIcon;
|
QIcon m_countsIcon;
|
||||||
|
@ -20,20 +20,25 @@
|
|||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "miscellaneous/iconfactory.h"
|
#include "miscellaneous/iconfactory.h"
|
||||||
|
|
||||||
|
#include <QSqlQuery>
|
||||||
|
|
||||||
FeedsModelRecycleBin::FeedsModelRecycleBin(FeedsModelRootItem *parent) : FeedsModelRootItem(parent) {
|
|
||||||
|
FeedsModelRecycleBin::FeedsModelRecycleBin(FeedsModelRootItem *parent)
|
||||||
|
: FeedsModelRootItem(parent) {
|
||||||
m_kind = FeedsModelRootItem::RecycleBin;
|
m_kind = FeedsModelRootItem::RecycleBin;
|
||||||
m_icon = qApp->icons()->fromTheme("folder-recycle-bin");
|
m_icon = qApp->icons()->fromTheme("folder-recycle-bin");
|
||||||
m_id = ID_RECYCLE_BIN;
|
m_id = ID_RECYCLE_BIN;
|
||||||
m_title = tr("Recycle bin");
|
m_title = tr("Recycle bin");
|
||||||
m_description = tr("Recycle bin contains all deleted messages from all feeds.");
|
m_description = tr("Recycle bin contains all deleted messages from all feeds.");
|
||||||
m_creationDate = QDateTime::currentDateTime();
|
m_creationDate = QDateTime::currentDateTime();
|
||||||
|
|
||||||
|
updateCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedsModelRecycleBin::~FeedsModelRecycleBin() {
|
FeedsModelRecycleBin::~FeedsModelRecycleBin() {
|
||||||
|
qDebug("Destroying FeedsModelRecycleBin instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FeedsModelRecycleBin::childCount() const {
|
int FeedsModelRecycleBin::childCount() const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -43,14 +48,13 @@ void FeedsModelRecycleBin::appendChild(FeedsModelRootItem *child) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int FeedsModelRecycleBin::countOfUnreadMessages() const {
|
int FeedsModelRecycleBin::countOfUnreadMessages() const {
|
||||||
return 0;
|
return m_totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FeedsModelRecycleBin::countOfAllMessages() const {
|
int FeedsModelRecycleBin::countOfAllMessages() const {
|
||||||
return 0;
|
return m_totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant FeedsModelRecycleBin::data(int column, int role) const {
|
QVariant FeedsModelRecycleBin::data(int column, int role) const {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
@ -102,3 +106,17 @@ QVariant FeedsModelRecycleBin::data(int column, int role) const {
|
|||||||
return QVariant();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -35,6 +35,12 @@ class FeedsModelRecycleBin : public FeedsModelRootItem {
|
|||||||
int countOfUnreadMessages() const;
|
int countOfUnreadMessages() const;
|
||||||
int countOfAllMessages() const;
|
int countOfAllMessages() const;
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updateCounts();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_totalCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FEEDSMODELRECYCLEBIN_H
|
#endif // FEEDSMODELRECYCLEBIN_H
|
||||||
|
@ -37,7 +37,6 @@ FeedsModelRootItem::FeedsModelRootItem(FeedsModelRootItem *parent_item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FeedsModelRootItem::~FeedsModelRootItem() {
|
FeedsModelRootItem::~FeedsModelRootItem() {
|
||||||
qDebug("Destroying FeedsModelRootItem instance.");
|
|
||||||
qDeleteAll(m_childItems);
|
qDeleteAll(m_childItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +132,7 @@ void FeedsView::loadExpandedStates() {
|
|||||||
// Iterate all categories and save their expand statuses.
|
// Iterate all categories and save their expand statuses.
|
||||||
foreach (FeedsModelCategory *category, sourceModel()->allCategories().values()) {
|
foreach (FeedsModelCategory *category, sourceModel()->allCategories().values()) {
|
||||||
setExpanded(model()->mapFromSource(sourceModel()->indexForItem(category)),
|
setExpanded(model()->mapFromSource(sourceModel()->indexForItem(category)),
|
||||||
settings->value(APP_CFG_CAT_EXP,
|
settings->value(APP_CFG_CAT_EXP, QString::number(category->id()), true).toBool());
|
||||||
QString::number(category->id()),
|
|
||||||
true).toBool());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,8 +167,7 @@ void FeedsView::updateSelectedFeeds() {
|
|||||||
|
|
||||||
void FeedsView::executeNextAutoUpdate() {
|
void FeedsView::executeNextAutoUpdate() {
|
||||||
if (!qApp->closeLock()->tryLock()) {
|
if (!qApp->closeLock()->tryLock()) {
|
||||||
qDebug("Delaying scheduled feed auto-updates for one minute "
|
qDebug("Delaying scheduled feed auto-updates for one minute due to another running update.");
|
||||||
"due to another running update.");
|
|
||||||
|
|
||||||
// Cannot update, quit.
|
// Cannot update, quit.
|
||||||
return;
|
return;
|
||||||
|
@ -55,17 +55,16 @@ class FeedsView : public QTreeView {
|
|||||||
void updateAutoUpdateStatus();
|
void updateAutoUpdateStatus();
|
||||||
|
|
||||||
// Returns list of selected/all feeds.
|
// Returns list of selected/all feeds.
|
||||||
|
// NOTE: This is recursive method which returns all descendants.
|
||||||
QList<FeedsModelFeed*> selectedFeeds() const;
|
QList<FeedsModelFeed*> selectedFeeds() const;
|
||||||
QList<FeedsModelFeed*> allFeeds() const;
|
QList<FeedsModelFeed*> allFeeds() const;
|
||||||
|
|
||||||
// Return true if current index contains category/feed and
|
// Returns pointers to selected feed/category if they are really
|
||||||
// stores category/feed in the parameter pointer,
|
// selected.
|
||||||
// otherwise false.
|
|
||||||
FeedsModelCategory *selectedCategory() const;
|
FeedsModelCategory *selectedCategory() const;
|
||||||
FeedsModelFeed *selectedFeed() const;
|
FeedsModelFeed *selectedFeed() const;
|
||||||
|
|
||||||
// Saves/loads expand states of all nodes (feeds/categories) of the list
|
// Saves/loads expand states of all nodes (feeds/categories) of the list to/from settings.
|
||||||
// to/from settings.
|
|
||||||
void saveExpandedStates();
|
void saveExpandedStates();
|
||||||
void loadExpandedStates();
|
void loadExpandedStates();
|
||||||
|
|
||||||
|
@ -63,6 +63,12 @@ void MessagesView::createConnections() {
|
|||||||
this, SLOT(adjustColumns()));
|
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) {
|
void MessagesView::reloadSelections(int mark_current_index_read) {
|
||||||
QModelIndex current_index = selectionModel()->currentIndex();
|
QModelIndex current_index = selectionModel()->currentIndex();
|
||||||
QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index);
|
QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index);
|
||||||
|
@ -52,6 +52,12 @@ class MessagesView : public QTreeView {
|
|||||||
void createConnections();
|
void createConnections();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void keyboardSearch(const QString &search) {
|
||||||
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
QTreeView::keyboardSearch(search);
|
||||||
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
}
|
||||||
|
|
||||||
// Called after data got changed externally
|
// Called after data got changed externally
|
||||||
// and it needs to be reloaded to the view.
|
// and it needs to be reloaded to the view.
|
||||||
// If "mark_current_index_read" is 0, then message with
|
// If "mark_current_index_read" is 0, then message with
|
||||||
|
Loading…
x
Reference in New Issue
Block a user