30
30
FeedsView::FeedsView (QWidget* parent)
31
31
: BaseTreeView(parent), m_contextMenuService(nullptr ), m_contextMenuBin(nullptr ), m_contextMenuCategories(nullptr ),
32
32
m_contextMenuFeeds(nullptr ), m_contextMenuImportant(nullptr ), m_contextMenuEmptySpace(nullptr ), m_contextMenuOtherItems(nullptr ),
33
- m_contextMenuLabel(nullptr ) {
33
+ m_contextMenuLabel(nullptr ), m_isFiltering( false ) {
34
34
setObjectName (QSL (" FeedsView" ));
35
35
36
36
// Allocate models.
@@ -44,8 +44,12 @@ FeedsView::FeedsView(QWidget* parent)
44
44
connect (m_sourceModel, &FeedsModel::itemExpandRequested, this , &FeedsView::onItemExpandRequested);
45
45
connect (m_sourceModel, &FeedsModel::itemExpandStateSaveRequested, this , &FeedsView::onItemExpandStateSaveRequested);
46
46
connect (header (), &QHeaderView::sortIndicatorChanged, this , &FeedsView::saveSortState);
47
+
47
48
connect (m_proxyModel, &FeedsProxyModel::expandAfterFilterIn, this , &FeedsView::expandItemDelayed);
48
49
50
+ connect (this , &FeedsView::expanded, this , &FeedsView::onIndexExpanded);
51
+ connect (this , &FeedsView::collapsed, this , &FeedsView::onIndexCollapsed);
52
+
49
53
setModel (m_proxyModel);
50
54
setupAppearance ();
51
55
}
@@ -88,60 +92,6 @@ RootItem* FeedsView::selectedItem() const {
88
92
}
89
93
}
90
94
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
-
145
95
void FeedsView::copyUrlOfSelectedFeeds () const {
146
96
auto feeds = selectedFeeds ();
147
97
QStringList urls;
@@ -525,18 +475,6 @@ void FeedsView::switchVisibility() {
525
475
setVisible (!isVisible ());
526
476
}
527
477
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
-
540
478
void FeedsView::drawBranches (QPainter* painter, const QRect& rect, const QModelIndex& index) const {
541
479
if (!rootIsDecorated ()) {
542
480
painter->save ();
@@ -558,12 +496,135 @@ void FeedsView::focusInEvent(QFocusEvent* event) {
558
496
}
559
497
}
560
498
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);
564
624
565
- setExpanded (pidx, true );
566
- });
625
+ setExpanded (pidx, true );
626
+ });
627
+ }
567
628
}
568
629
569
630
QMenu* FeedsView::initializeContextMenuCategories (RootItem* clicked_item) {
0 commit comments