Skip to content

Commit bdc00d5

Browse files
author
Martin Rotter
committed
raw fixes for #546
1 parent fd1355e commit bdc00d5

File tree

4 files changed

+145
-76
lines changed

4 files changed

+145
-76
lines changed

src/librssguard/core/feedsproxymodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FeedsProxyModel : public QSortFilterProxyModel {
3636
void invalidateReadFeedsFilter(bool set_new_value = false, bool show_unread_only = false);
3737

3838
signals:
39-
void expandAfterFilterIn(QModelIndex idx) const;
39+
void expandAfterFilterIn(QModelIndex source_idx) const;
4040

4141
private:
4242

src/librssguard/gui/feedmessageviewer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ FeedsToolBar* FeedMessageViewer::feedsToolBar() const {
8686
void FeedMessageViewer::saveSize() {
8787
Settings* settings = qApp->settings();
8888

89-
m_feedsView->saveAllExpandStates();
89+
//m_feedsView->saveAllExpandStates();
9090

9191
// Store offsets of splitters.
9292
settings->setValue(GROUP(GUI), GUI::SplitterFeeds, toVariant(m_feedSplitter->sizes()));
@@ -357,10 +357,11 @@ void FeedMessageViewer::refreshVisualProperties() {
357357

358358
if (icon_size > 0) {
359359
m_toolBarFeeds->setIconSize({ icon_size, icon_size });
360-
m_toolBarMessages->setIconSize({ icon_size, icon_size });
361360
}
362361
else {
363362
m_toolBarFeeds->setIconSize({ qApp->style()->pixelMetric(QStyle::PM_ToolBarIconSize),
364363
qApp->style()->pixelMetric(QStyle::PM_ToolBarIconSize) });
365364
}
365+
366+
m_toolBarMessages->setIconSize(m_toolBarFeeds->iconSize());
366367
}

src/librssguard/gui/feedsview.cpp

Lines changed: 133 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
FeedsView::FeedsView(QWidget* parent)
3131
: BaseTreeView(parent), m_contextMenuService(nullptr), m_contextMenuBin(nullptr), m_contextMenuCategories(nullptr),
3232
m_contextMenuFeeds(nullptr), m_contextMenuImportant(nullptr), m_contextMenuEmptySpace(nullptr), m_contextMenuOtherItems(nullptr),
33-
m_contextMenuLabel(nullptr) {
33+
m_contextMenuLabel(nullptr), m_isFiltering(false) {
3434
setObjectName(QSL("FeedsView"));
3535

3636
// Allocate models.
@@ -44,8 +44,12 @@ FeedsView::FeedsView(QWidget* parent)
4444
connect(m_sourceModel, &FeedsModel::itemExpandRequested, this, &FeedsView::onItemExpandRequested);
4545
connect(m_sourceModel, &FeedsModel::itemExpandStateSaveRequested, this, &FeedsView::onItemExpandStateSaveRequested);
4646
connect(header(), &QHeaderView::sortIndicatorChanged, this, &FeedsView::saveSortState);
47+
4748
connect(m_proxyModel, &FeedsProxyModel::expandAfterFilterIn, this, &FeedsView::expandItemDelayed);
4849

50+
connect(this, &FeedsView::expanded, this, &FeedsView::onIndexExpanded);
51+
connect(this, &FeedsView::collapsed, this, &FeedsView::onIndexCollapsed);
52+
4953
setModel(m_proxyModel);
5054
setupAppearance();
5155
}
@@ -88,60 +92,6 @@ RootItem* FeedsView::selectedItem() const {
8892
}
8993
}
9094

91-
void FeedsView::onItemExpandStateSaveRequested(RootItem* item) {
92-
saveExpandStates(item);
93-
}
94-
95-
void FeedsView::saveAllExpandStates() {
96-
saveExpandStates(sourceModel()->rootItem());
97-
}
98-
99-
void FeedsView::saveExpandStates(RootItem* item) {
100-
Settings* settings = qApp->settings();
101-
QList<RootItem*> items = item->getSubTree(RootItem::Kind::Category |
102-
RootItem::Kind::ServiceRoot |
103-
RootItem::Kind::Labels);
104-
105-
// Iterate all categories and save their expand statuses.
106-
for (const RootItem* it : items) {
107-
const QString setting_name = it->hashCode();
108-
QModelIndex source_index = sourceModel()->indexForItem(it);
109-
QModelIndex visible_index = model()->mapFromSource(source_index);
110-
111-
// TODO: Think.
112-
113-
/*
114-
if (isRowHidden(visible_index.row(), visible_index.parent())) {
115-
continue;
116-
}
117-
*/
118-
119-
settings->setValue(GROUP(CategoriesExpandStates),
120-
setting_name,
121-
isExpanded(visible_index));
122-
}
123-
}
124-
125-
void FeedsView::loadAllExpandStates() {
126-
const Settings* settings = qApp->settings();
127-
QList<RootItem*> expandable_items;
128-
129-
expandable_items.append(sourceModel()->rootItem()->getSubTree(RootItem::Kind::Category |
130-
RootItem::Kind::ServiceRoot |
131-
RootItem::Kind::Labels));
132-
133-
// Iterate all categories and save their expand statuses.
134-
for (const RootItem* item : expandable_items) {
135-
const QString setting_name = item->hashCode();
136-
137-
setExpanded(model()->mapFromSource(sourceModel()->indexForItem(item)),
138-
settings->value(GROUP(CategoriesExpandStates), setting_name, item->childCount() > 0).toBool());
139-
}
140-
141-
sortByColumn(qApp->settings()->value(GROUP(GUI), SETTING(GUI::DefaultSortColumnFeeds)).toInt(),
142-
static_cast<Qt::SortOrder>(qApp->settings()->value(GROUP(GUI), SETTING(GUI::DefaultSortOrderFeeds)).toInt()));
143-
}
144-
14595
void FeedsView::copyUrlOfSelectedFeeds() const {
14696
auto feeds = selectedFeeds();
14797
QStringList urls;
@@ -525,18 +475,6 @@ void FeedsView::switchVisibility() {
525475
setVisible(!isVisible());
526476
}
527477

528-
void FeedsView::filterItems(const QString& pattern) {
529-
#if QT_VERSION < 0x050C00 // Qt < 5.12.0
530-
m_proxyModel->setFilterRegExp(pattern.toLower());
531-
#else
532-
m_proxyModel->setFilterRegularExpression(pattern.toLower());
533-
#endif
534-
535-
if (!pattern.simplified().isEmpty()) {
536-
expandAll();
537-
}
538-
}
539-
540478
void FeedsView::drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const {
541479
if (!rootIsDecorated()) {
542480
painter->save();
@@ -558,12 +496,135 @@ void FeedsView::focusInEvent(QFocusEvent* event) {
558496
}
559497
}
560498

561-
void FeedsView::expandItemDelayed(const QModelIndex& idx) {
562-
QTimer::singleShot(100, this, [=] {
563-
QModelIndex pidx = m_proxyModel->mapFromSource(idx);
499+
void FeedsView::filterItems(const QString& pattern) {
500+
m_isFiltering = !pattern.isEmpty();
501+
502+
#if QT_VERSION < 0x050C00 // Qt < 5.12.0
503+
m_proxyModel->setFilterRegExp(pattern.toLower());
504+
#else
505+
m_proxyModel->setFilterRegularExpression(pattern.toLower());
506+
#endif
507+
508+
if (pattern.isEmpty()) {
509+
loadAllExpandStates();
510+
}
511+
else {
512+
expandAll();
513+
}
514+
}
515+
516+
void FeedsView::onIndexExpanded(const QModelIndex& idx) {
517+
qDebugNN << LOGSEC_GUI << "Feed list item expanded - " << m_proxyModel->data(idx).toString();
518+
519+
if (m_isFiltering) {
520+
return;
521+
}
522+
523+
const RootItem* it = m_sourceModel->itemForIndex(m_proxyModel->mapToSource(idx));
524+
525+
if (it != nullptr && (int(it->kind()) & int(RootItem::Kind::Category |
526+
RootItem::Kind::ServiceRoot |
527+
RootItem::Kind::Labels)) > 0) {
528+
const QString setting_name = it->hashCode();
529+
530+
qApp->settings()->setValue(GROUP(CategoriesExpandStates),
531+
setting_name,
532+
true);
533+
}
534+
}
535+
536+
void FeedsView::onIndexCollapsed(const QModelIndex& idx) {
537+
qDebugNN << LOGSEC_GUI << "Feed list item collapsed - " << m_proxyModel->data(idx).toString();
538+
539+
if (m_isFiltering) {
540+
return;
541+
}
542+
543+
RootItem* it = m_sourceModel->itemForIndex(m_proxyModel->mapToSource(idx));
544+
545+
if (it != nullptr && (int(it->kind()) & int(RootItem::Kind::Category |
546+
RootItem::Kind::ServiceRoot |
547+
RootItem::Kind::Labels)) > 0) {
548+
const QString setting_name = it->hashCode();
549+
550+
qApp->settings()->setValue(GROUP(CategoriesExpandStates),
551+
setting_name,
552+
false);
553+
}
554+
}
555+
556+
void FeedsView::onItemExpandStateSaveRequested(RootItem* item) {
557+
saveExpandStates(item);
558+
}
559+
560+
void FeedsView::saveAllExpandStates() {
561+
saveExpandStates(sourceModel()->rootItem());
562+
}
563+
564+
void FeedsView::saveExpandStates(RootItem* item) {
565+
Settings* settings = qApp->settings();
566+
QList<RootItem*> items = item->getSubTree(RootItem::Kind::Category |
567+
RootItem::Kind::ServiceRoot |
568+
RootItem::Kind::Labels);
569+
570+
// Iterate all categories and save their expand statuses.
571+
for (const RootItem* it : items) {
572+
const QString setting_name = it->hashCode();
573+
QModelIndex source_index = sourceModel()->indexForItem(it);
574+
QModelIndex visible_index = model()->mapFromSource(source_index);
575+
576+
// TODO: Think.
577+
578+
/*
579+
if (isRowHidden(visible_index.row(), visible_index.parent())) {
580+
continue;
581+
}
582+
*/
583+
584+
settings->setValue(GROUP(CategoriesExpandStates),
585+
setting_name,
586+
isExpanded(visible_index));
587+
}
588+
}
589+
590+
bool FeedsView::isFiltering() const
591+
{
592+
return m_isFiltering;
593+
}
594+
595+
void FeedsView::setIsFiltering(bool newIsFiltering)
596+
{
597+
m_isFiltering = newIsFiltering;
598+
}
599+
600+
void FeedsView::loadAllExpandStates() {
601+
const Settings* settings = qApp->settings();
602+
QList<RootItem*> expandable_items;
603+
604+
expandable_items.append(sourceModel()->rootItem()->getSubTree(RootItem::Kind::Category |
605+
RootItem::Kind::ServiceRoot |
606+
RootItem::Kind::Labels));
607+
608+
// Iterate all categories and save their expand statuses.
609+
for (const RootItem* item : expandable_items) {
610+
const QString setting_name = item->hashCode();
611+
612+
setExpanded(model()->mapFromSource(sourceModel()->indexForItem(item)),
613+
settings->value(GROUP(CategoriesExpandStates), setting_name, item->childCount() > 0).toBool());
614+
}
615+
616+
sortByColumn(qApp->settings()->value(GROUP(GUI), SETTING(GUI::DefaultSortColumnFeeds)).toInt(),
617+
static_cast<Qt::SortOrder>(qApp->settings()->value(GROUP(GUI), SETTING(GUI::DefaultSortOrderFeeds)).toInt()));
618+
}
619+
620+
void FeedsView::expandItemDelayed(const QModelIndex& source_idx) {
621+
if (m_isFiltering) {
622+
QTimer::singleShot(100, this, [=] {
623+
QModelIndex pidx = m_proxyModel->mapFromSource(source_idx);
564624

565-
setExpanded(pidx, true);
566-
});
625+
setExpanded(pidx, true);
626+
});
627+
}
567628
}
568629

569630
QMenu* FeedsView::initializeContextMenuCategories(RootItem* clicked_item) {

src/librssguard/gui/feedsview.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class RSSGUARD_DLLSPEC FeedsView : public BaseTreeView {
3939
void saveAllExpandStates();
4040
void loadAllExpandStates();
4141

42+
bool isFiltering() const;
43+
void setIsFiltering(bool newIsFiltering);
44+
4245
public slots:
4346
void copyUrlOfSelectedFeeds() const;
4447
void sortByColumn(int column, Qt::SortOrder order);
@@ -91,7 +94,10 @@ class RSSGUARD_DLLSPEC FeedsView : public BaseTreeView {
9194
void mouseDoubleClickEvent(QMouseEvent* event);
9295

9396
private slots:
94-
void expandItemDelayed(const QModelIndex& idx);
97+
void onIndexExpanded(const QModelIndex& idx);
98+
void onIndexCollapsed(const QModelIndex& idx);
99+
100+
void expandItemDelayed(const QModelIndex& source_idx);
95101
void markSelectedItemReadStatus(RootItem::ReadStatus read);
96102
void markAllItemsReadStatus(RootItem::ReadStatus read);
97103

@@ -127,6 +133,7 @@ class RSSGUARD_DLLSPEC FeedsView : public BaseTreeView {
127133
QMenu* m_contextMenuLabel;
128134
FeedsModel* m_sourceModel;
129135
FeedsProxyModel* m_proxyModel;
136+
bool m_isFiltering;
130137
};
131138

132139
inline FeedsProxyModel* FeedsView::model() const {

0 commit comments

Comments
 (0)