From b0f42ee67299d7bd6ea24214042a3c2c304d1265 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 7 Sep 2019 19:33:58 +0200 Subject: [PATCH] GModelSelection: Add contains_row(int) and toggle(GModelIndex) --- Libraries/LibGUI/GModelSelection.cpp | 10 ++++++++++ Libraries/LibGUI/GModelSelection.h | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/Libraries/LibGUI/GModelSelection.cpp b/Libraries/LibGUI/GModelSelection.cpp index 6eee4570f9..bf3a6fb37e 100644 --- a/Libraries/LibGUI/GModelSelection.cpp +++ b/Libraries/LibGUI/GModelSelection.cpp @@ -20,6 +20,16 @@ void GModelSelection::add(const GModelIndex& index) m_view.notify_selection_changed({}); } +void GModelSelection::toggle(const GModelIndex& index) +{ + ASSERT(index.is_valid()); + if (m_indexes.contains(index)) + m_indexes.remove(index); + else + m_indexes.set(index); + m_view.notify_selection_changed({}); +} + bool GModelSelection::remove(const GModelIndex& index) { ASSERT(index.is_valid()); diff --git a/Libraries/LibGUI/GModelSelection.h b/Libraries/LibGUI/GModelSelection.h index d1c7ba9172..33430508ef 100644 --- a/Libraries/LibGUI/GModelSelection.h +++ b/Libraries/LibGUI/GModelSelection.h @@ -14,9 +14,18 @@ public: bool is_empty() const { return m_indexes.is_empty(); } bool contains(const GModelIndex& index) const { return m_indexes.contains(index); } + bool contains_row(int row) const + { + for (auto& index : m_indexes) { + if (index.row() == row) + return true; + } + return false; + } void set(const GModelIndex&); void add(const GModelIndex&); + void toggle(const GModelIndex&); bool remove(const GModelIndex&); void clear();