Fully dynamic sorting.

This commit is contained in:
Martin Rotter 2016-01-21 10:53:15 +01:00
parent 36d3f2120a
commit 12c0d3d463
9 changed files with 31 additions and 24 deletions

View File

@ -13,6 +13,7 @@ Fixed:
Changed:
▪ Sorting of both views (feeds/messages) is now fully dynamic.
▪ Tweaked "remove duplicates" policy.
▪ TT-RSS plugin can now restore messages from local recycle bin.

View File

@ -177,7 +177,6 @@ void FeedsModel::onFeedUpdatesFinished(const FeedDownloadResults &results) {
}
emit feedsUpdateFinished();
//emit sortingRequired();
}
void FeedsModel::updateAllFeeds() {

View File

@ -211,9 +211,6 @@ class FeedsModel : public QAbstractItemModel {
// NOTE: View will probably expand dropped index.
void requireItemValidationAfterDragDrop(const QModelIndex &source_index);
// When emitted, view (re)sorts items.
void sortingRequired();
private:
RootItem *m_rootItem;
QList<QString> m_headerData;

View File

@ -179,6 +179,10 @@ QModelIndexList MessagesProxyModel::match(const QModelIndex &start, int role,
return result;
}
void MessagesProxyModel::sort(int column, Qt::SortOrder order) {
QSortFilterProxyModel::sort(column, order);
}
QModelIndexList MessagesProxyModel::mapListToSource(const QModelIndexList &indexes) const {
QModelIndexList source_indexes;

View File

@ -45,6 +45,8 @@ class MessagesProxyModel : public QSortFilterProxyModel {
// Fix for matching indexes with respect to specifics of the message model.
QModelIndexList match(const QModelIndex &start, int role, const QVariant &entered_value, int hits, Qt::MatchFlags flags) const;
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
private:
QModelIndex getNextUnreadItemIndex(int default_row, int max_row) const;

View File

@ -58,7 +58,6 @@ FeedsView::FeedsView(QWidget *parent)
connect(m_sourceModel, SIGNAL(requireItemValidationAfterDragDrop(QModelIndex)), this, SLOT(validateItemAfterDragDrop(QModelIndex)));
connect(m_sourceModel, SIGNAL(itemExpandRequested(QList<RootItem*>,bool)), this, SLOT(onItemExpandRequested(QList<RootItem*>,bool)));
connect(m_sourceModel, SIGNAL(itemExpandStateSaveRequested(RootItem*)), this, SLOT(onItemExpandStateSaveRequested(RootItem*)));
connect(m_sourceModel, SIGNAL(sortingRequired()), this, SLOT(reSort()));
connect(header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(saveSortState(int,Qt::SortOrder)));
setModel(m_proxyModel);
@ -134,27 +133,20 @@ void FeedsView::loadAllExpandStates() {
settings->value(GROUP(CategoriesExpandStates), setting_name, item->childCount() > 0).toBool());
}
sort(true);
sortByColumn(qApp->settings()->value(GROUP(GUI), SETTING(GUI::DefaultSortColumnFeeds)).toInt(),
static_cast<Qt::SortOrder>(qApp->settings()->value(GROUP(GUI), SETTING(GUI::DefaultSortOrderFeeds)).toInt()));
}
void FeedsView::sort(bool from_settings) {
int column;
Qt::SortOrder order;
void FeedsView::sortByColumn(int column, Qt::SortOrder order) {
const int old_column = header()->sortIndicatorSection();
const Qt::SortOrder old_order = header()->sortIndicatorOrder();
if (from_settings) {
column = qApp->settings()->value(GROUP(GUI), SETTING(GUI::DefaultSortColumnFeeds)).toInt();
order = static_cast<Qt::SortOrder>(qApp->settings()->value(GROUP(GUI), SETTING(GUI::DefaultSortOrderFeeds)).toInt());
if (column == old_column && order == old_order) {
m_proxyModel->sort(column, order);
}
else {
column = header()->sortIndicatorSection();
order = header()->sortIndicatorOrder();
QTreeView::sortByColumn(column, order);
}
sortByColumn(column, order);
}
void FeedsView::reSort() {
m_proxyModel->sort(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
}
void FeedsView::addFeedIntoSelectedAccount() {

View File

@ -60,10 +60,8 @@ class FeedsView : public QTreeView {
void saveAllExpandStates();
void loadAllExpandStates();
public slots:
// Sorts according to column/order taken from settings.
void sort(bool from_settings);
void reSort();
public slots:
void sortByColumn(int column, Qt::SortOrder order);
void addFeedIntoSelectedAccount();
void addCategoryIntoSelectedAccount();

View File

@ -245,6 +245,18 @@ void MessagesView::loadItem(RootItem *item) {
#endif
}
void MessagesView::sortByColumn(int column, Qt::SortOrder order) {
const int old_column = header()->sortIndicatorSection();
const Qt::SortOrder old_order = header()->sortIndicatorOrder();
if (column == old_column && order == old_order) {
m_proxyModel->sort(column, order);
}
else {
QTreeView::sortByColumn(column, order);
}
}
void MessagesView::openSelectedSourceMessagesExternally() {
foreach (const QModelIndex &index, selectionModel()->selectedRows()) {
const QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()).m_url;

View File

@ -59,6 +59,8 @@ class MessagesView : public QTreeView {
// Loads un-deleted messages from selected feeds.
void loadItem(RootItem *item);
void sortByColumn(int column, Qt::SortOrder order);
// Message manipulators.
void openSelectedSourceMessagesExternally();
void openSelectedSourceMessagesInternally();