diff options
| author | Mark Rowe <mark@vector35.com> | 2025-10-24 08:21:26 -0700 |
|---|---|---|
| committer | Mark Rowe <mark@vector35.com> | 2025-11-04 16:04:04 -0800 |
| commit | ade58079a0a3e6b9d1a0793ab4c084d0f9431f4d (patch) | |
| tree | 1970e1e26858163d24d1359908b529f363789034 /view | |
| parent | 63ef49621522efa11e1fcfc709812adb0300d3f6 (diff) | |
Update FilterEdit and FilterTarget to preserve existing selections
The down and enter keys now preserve an existing selection in the
associated list or table views, rather than unconditionally selecting or
activating the first item.
Diffstat (limited to 'view')
| -rw-r--r-- | view/kernelcache/ui/kctriage.h | 29 | ||||
| -rw-r--r-- | view/kernelcache/ui/symboltable.h | 29 | ||||
| -rw-r--r-- | view/sharedcache/ui/dsctriage.h | 29 | ||||
| -rw-r--r-- | view/sharedcache/ui/symboltable.h | 29 |
4 files changed, 56 insertions, 60 deletions
diff --git a/view/kernelcache/ui/kctriage.h b/view/kernelcache/ui/kctriage.h index d4a961e8..c69c6a0a 100644 --- a/view/kernelcache/ui/kctriage.h +++ b/view/kernelcache/ui/kctriage.h @@ -150,24 +150,23 @@ public: } } - void selectFirstItem() override { - if (model()->rowCount() > 0) { - QModelIndex top = indexAt(rect().topLeft()); - if (top.isValid()) { - selectionModel()->select(top, QItemSelectionModel::ClearAndSelect); - setCurrentIndex(top); - } + void ensureSelection() override { + QModelIndex current = selectionModel()->currentIndex(); + if (current.isValid() && !isRowHidden(current.row())) + return; + + if (auto top = indexAt(rect().topLeft()); top.isValid()) + { + selectionModel()->select(top, QItemSelectionModel::ClearAndSelect); + setCurrentIndex(top); } } - void activateFirstItem() override { - if (model()->rowCount() > 0) { - QModelIndex topLeft = indexAt(rect().topLeft()); - if (topLeft.isValid()) { - setCurrentIndex(topLeft); - emit activated(topLeft); - } - } + + void activateSelection() override { + ensureSelection(); + if (auto current = selectionModel()->currentIndex(); current.isValid()) + emit activated(current); } signals: diff --git a/view/kernelcache/ui/symboltable.h b/view/kernelcache/ui/symboltable.h index 866390c7..28d07199 100644 --- a/view/kernelcache/ui/symboltable.h +++ b/view/kernelcache/ui/symboltable.h @@ -68,26 +68,25 @@ public: scrollTo(currentIndex); } - void selectFirstItem() override + void ensureSelection() override { - if (model()->rowCount() > 0) { - QModelIndex top = indexAt(rect().topLeft()); - if (top.isValid()) { - selectionModel()->select(top, QItemSelectionModel::ClearAndSelect); - setCurrentIndex(top); - } + QModelIndex current = selectionModel()->currentIndex(); + if (current.isValid() || model()->rowCount() == 0) + return; + + if (auto top = indexAt(rect().topLeft()); top.isValid()) + { + selectionModel()->select(top, QItemSelectionModel::ClearAndSelect); + setCurrentIndex(top); } } - void activateFirstItem() override + + void activateSelection() override { - if (model()->rowCount() > 0) { - QModelIndex topLeft = indexAt(rect().topLeft()); - if (topLeft.isValid()) { - setCurrentIndex(topLeft); - emit activated(topLeft); - } - } + ensureSelection(); + if (auto current = selectionModel()->currentIndex(); current.isValid()) + emit activated(current); } KernelCacheAPI::CacheSymbol getSymbolAtRow(int row) const diff --git a/view/sharedcache/ui/dsctriage.h b/view/sharedcache/ui/dsctriage.h index 33f45bcf..02a41eab 100644 --- a/view/sharedcache/ui/dsctriage.h +++ b/view/sharedcache/ui/dsctriage.h @@ -150,24 +150,23 @@ public: } } - void selectFirstItem() override { - if (model()->rowCount() > 0) { - QModelIndex top = indexAt(rect().topLeft()); - if (top.isValid()) { - selectionModel()->select(top, QItemSelectionModel::ClearAndSelect); - setCurrentIndex(top); - } + void ensureSelection() override { + QModelIndex current = selectionModel()->currentIndex(); + if (current.isValid() && !isRowHidden(current.row())) + return; + + if (auto top = indexAt(rect().topLeft()); top.isValid()) + { + selectionModel()->select(top, QItemSelectionModel::ClearAndSelect); + setCurrentIndex(top); } } - void activateFirstItem() override { - if (model()->rowCount() > 0) { - QModelIndex topLeft = indexAt(rect().topLeft()); - if (topLeft.isValid()) { - setCurrentIndex(topLeft); - emit activated(topLeft); - } - } + + void activateSelection() override { + ensureSelection(); + if (auto current = selectionModel()->currentIndex(); current.isValid()) + emit activated(current); } signals: diff --git a/view/sharedcache/ui/symboltable.h b/view/sharedcache/ui/symboltable.h index 9c7a1eab..ab0174f9 100644 --- a/view/sharedcache/ui/symboltable.h +++ b/view/sharedcache/ui/symboltable.h @@ -72,26 +72,25 @@ public: scrollTo(currentIndex); } - void selectFirstItem() override + void ensureSelection() override { - if (model()->rowCount() > 0) { - QModelIndex top = indexAt(rect().topLeft()); - if (top.isValid()) { - selectionModel()->select(top, QItemSelectionModel::ClearAndSelect); - setCurrentIndex(top); - } + QModelIndex current = selectionModel()->currentIndex(); + if (current.isValid() || model()->rowCount() == 0) + return; + + if (auto top = indexAt(rect().topLeft()); top.isValid()) + { + selectionModel()->select(top, QItemSelectionModel::ClearAndSelect); + setCurrentIndex(top); } } - void activateFirstItem() override + + void activateSelection() override { - if (model()->rowCount() > 0) { - QModelIndex topLeft = indexAt(rect().topLeft()); - if (topLeft.isValid()) { - setCurrentIndex(topLeft); - emit activated(topLeft); - } - } + ensureSelection(); + if (auto current = selectionModel()->currentIndex(); current.isValid()) + emit activated(current); } SharedCacheAPI::CacheSymbol getSymbolAtRow(int row) const |
