feat(qt): persist filter preferences in masternode list#7148
feat(qt): persist filter preferences in masternode list#7148PastaPastaPasta merged 2 commits intodashpay:developfrom
Conversation
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
WalkthroughThe changes add persistent storage of MasternodeList UI filter preferences using QSettings. The MasternodeList constructor loads saved settings (HideBanned, TypeFilter, FilterText, OwnedOnly) and applies them to the UI and proxy model on startup. Handlers for filter text, type filter, hide-banned, and owned-only now save updates to QSettings. The default m_hide_banned value (and the "Hide banned" checkbox default) is changed from true to false. Sequence Diagram(s)sequenceDiagram
participant User
participant UI as MasternodeList UI
participant Model as MasternodeListSortFilterProxyModel
participant Settings as QSettings
participant Wallet as WalletModel
User->>UI: Open Masternode list
UI->>Settings: read(HideBanned, TypeFilter, FilterText, OwnedOnly)
Settings-->>UI: return saved values
UI->>Model: apply filters (HideBanned, TypeFilter, FilterText, OwnedOnly)
UI->>UI: update checkbox/text controls
alt WalletModel present
Wallet->>UI: setWalletModel()
UI->>Settings: read(OwnedOnly)
Settings-->>UI: return OwnedOnly
UI->>Model: apply OwnedOnly
end
User->>UI: change filter controls
UI->>Model: update filter
UI->>Settings: write(updated filter values)
Settings-->>UI: confirm write
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/qt/masternodelist.cpp (1)
336-338: Consider debouncing the QSettings write for filter text.
on_filterText_textChangedfires on every keystroke, creating aQSettingsinstance and writing each time. While Qt typically batches filesystem writes, this is still unnecessary churn. The other filters (checkbox/combobox) change infrequently, so they're fine — but text input can generate rapid-fire calls.A lightweight alternative: save the filter text in the destructor or on a short timer, rather than on every character.
There was a problem hiding this comment.
🧹 Nitpick comments (3)
src/qt/masternodelist.cpp (3)
143-148: Consider defining settings key names as constants to avoid duplication.The same string literals (
"mnListHideBanned","mnListTypeFilter","mnListFilterText","mnListOwnedOnly") appear in both the load (here) and save (in each handler) paths. Extracting them toconstexpr/constvariables in the anonymous namespace would prevent silent typo-induced bugs.Example
namespace { constexpr int MASTERNODELIST_UPDATE_SECONDS{3}; const QString SETTINGS_KEY_HIDE_BANNED{"mnListHideBanned"}; const QString SETTINGS_KEY_TYPE_FILTER{"mnListTypeFilter"}; const QString SETTINGS_KEY_FILTER_TEXT{"mnListFilterText"}; const QString SETTINGS_KEY_OWNED_ONLY{"mnListOwnedOnly"}; } // anonymous namespace
147-147: Clamp the persisted type-filter index before applying.
QComboBox::setCurrentIndexsilently accepts out-of-range values (sets selection to -1). While the downstream slot guards against negative/overflow indices, loading a corrupted setting would leave the combo box with no visible selection. A quick clamp at load time is more defensive.Proposed fix
- ui->comboBoxType->setCurrentIndex(settings.value("mnListTypeFilter", 0).toInt()); + const int type_filter = settings.value("mnListTypeFilter", 0).toInt(); + if (type_filter >= 0 && type_filter < static_cast<int>(MasternodeListSortFilterProxyModel::TypeFilter::COUNT)) { + ui->comboBoxType->setCurrentIndex(type_filter); + }
336-338: Filter text is saved on every keystroke.
on_filterText_textChangedfires per character. This is fine forQSettings(writes are cheap and batched on most platforms), but if this ever becomes a concern, debouncing the save — or saving only on focus-out / window close — would be an option.
Additional Information
In response to community feedback to the UI changes done in dash#7116, the following changes have been implemented
Breaking Changes
None expected.
Checklist