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 /examples | |
| 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 'examples')
| -rw-r--r-- | examples/triage/entry.cpp | 11 | ||||
| -rw-r--r-- | examples/triage/entry.h | 4 | ||||
| -rw-r--r-- | examples/triage/exports.cpp | 11 | ||||
| -rw-r--r-- | examples/triage/exports.h | 4 | ||||
| -rw-r--r-- | examples/triage/imports.cpp | 11 | ||||
| -rw-r--r-- | examples/triage/imports.h | 4 | ||||
| -rw-r--r-- | examples/triage/strings.cpp | 11 | ||||
| -rw-r--r-- | examples/triage/strings.h | 4 |
8 files changed, 36 insertions, 24 deletions
diff --git a/examples/triage/entry.cpp b/examples/triage/entry.cpp index c62b9c36..98e5cff9 100644 --- a/examples/triage/entry.cpp +++ b/examples/triage/entry.cpp @@ -271,15 +271,18 @@ void EntryTreeView::scrollToCurrentItem() } -void EntryTreeView::selectFirstItem() +void EntryTreeView::ensureSelection() { - setCurrentIndex(m_model->index(0, 0, QModelIndex())); + if (auto current = currentIndex(); !current.isValid()) + setCurrentIndex(m_model->index(0, 0, QModelIndex())); } -void EntryTreeView::activateFirstItem() +void EntryTreeView::activateSelection() { - entryDoubleClicked(m_model->index(0, 0, QModelIndex())); + ensureSelection(); + if (auto current = currentIndex(); current.isValid()) + entryDoubleClicked(current); } diff --git a/examples/triage/entry.h b/examples/triage/entry.h index 66943d1d..a1396741 100644 --- a/examples/triage/entry.h +++ b/examples/triage/entry.h @@ -49,8 +49,8 @@ class EntryTreeView : public QTreeView, public FilterTarget virtual void setFilter(const std::string& filterText) override; virtual void scrollToFirstItem() override; virtual void scrollToCurrentItem() override; - virtual void selectFirstItem() override; - virtual void activateFirstItem() override; + virtual void ensureSelection() override; + virtual void activateSelection() override; virtual void closeFilter() override; protected: diff --git a/examples/triage/exports.cpp b/examples/triage/exports.cpp index ad315384..c9f0e42d 100644 --- a/examples/triage/exports.cpp +++ b/examples/triage/exports.cpp @@ -438,15 +438,18 @@ void ExportsTreeView::scrollToCurrentItem() } -void ExportsTreeView::selectFirstItem() +void ExportsTreeView::ensureSelection() { - setCurrentIndex(m_model->index(0, 0, QModelIndex())); + if (auto current = currentIndex(); !current.isValid()) + setCurrentIndex(m_model->index(0, 0, QModelIndex())); } -void ExportsTreeView::activateFirstItem() +void ExportsTreeView::activateSelection() { - exportDoubleClicked(m_model->index(0, 0, QModelIndex())); + ensureSelection(); + if (auto current = currentIndex(); current.isValid()) + exportDoubleClicked(current); } diff --git a/examples/triage/exports.h b/examples/triage/exports.h index e47b775e..aeca67e0 100644 --- a/examples/triage/exports.h +++ b/examples/triage/exports.h @@ -80,8 +80,8 @@ class ExportsTreeView : public QTreeView, public FilterTarget virtual void setFilter(const std::string& filterText) override; virtual void scrollToFirstItem() override; virtual void scrollToCurrentItem() override; - virtual void selectFirstItem() override; - virtual void activateFirstItem() override; + virtual void ensureSelection() override; + virtual void activateSelection() override; virtual void closeFilter() override; protected: diff --git a/examples/triage/imports.cpp b/examples/triage/imports.cpp index ea4fe5d3..19c6a62b 100644 --- a/examples/triage/imports.cpp +++ b/examples/triage/imports.cpp @@ -343,15 +343,18 @@ void ImportsTreeView::scrollToCurrentItem() } -void ImportsTreeView::selectFirstItem() +void ImportsTreeView::ensureSelection() { - setCurrentIndex(m_model->index(0, 0, QModelIndex())); + if (auto current = currentIndex(); !current.isValid()) + setCurrentIndex(m_model->index(0, 0, QModelIndex())); } -void ImportsTreeView::activateFirstItem() +void ImportsTreeView::activateSelection() { - importDoubleClicked(m_model->index(0, 0, QModelIndex())); + ensureSelection(); + if (auto current = currentIndex(); current.isValid()) + importDoubleClicked(current); } diff --git a/examples/triage/imports.h b/examples/triage/imports.h index 9d490c01..8a2441f7 100644 --- a/examples/triage/imports.h +++ b/examples/triage/imports.h @@ -58,8 +58,8 @@ class ImportsTreeView : public QTreeView, public FilterTarget virtual void setFilter(const std::string& filterText) override; virtual void scrollToFirstItem() override; virtual void scrollToCurrentItem() override; - virtual void selectFirstItem() override; - virtual void activateFirstItem() override; + virtual void ensureSelection() override; + virtual void activateSelection() override; virtual void closeFilter() override; protected: diff --git a/examples/triage/strings.cpp b/examples/triage/strings.cpp index b84f6b62..269f747a 100644 --- a/examples/triage/strings.cpp +++ b/examples/triage/strings.cpp @@ -288,15 +288,18 @@ void StringsTreeView::scrollToCurrentItem() } -void StringsTreeView::selectFirstItem() +void StringsTreeView::ensureSelection() { - setCurrentIndex(m_model->index(0, 0, QModelIndex())); + if (auto current = currentIndex(); !current.isValid()) + setCurrentIndex(m_model->index(0, 0, QModelIndex())); } -void StringsTreeView::activateFirstItem() +void StringsTreeView::activateSelection() { - stringDoubleClicked(m_model->index(0, 0, QModelIndex())); + ensureSelection(); + if (auto current = currentIndex(); current.isValid()) + stringDoubleClicked(current); } diff --git a/examples/triage/strings.h b/examples/triage/strings.h index a7de2912..25de66cd 100644 --- a/examples/triage/strings.h +++ b/examples/triage/strings.h @@ -50,8 +50,8 @@ class StringsTreeView : public QTreeView, public FilterTarget virtual void setFilter(const std::string& filterText) override; virtual void scrollToFirstItem() override; virtual void scrollToCurrentItem() override; - virtual void selectFirstItem() override; - virtual void activateFirstItem() override; + virtual void ensureSelection() override; + virtual void activateSelection() override; virtual void closeFilter() override; protected: |
