#pragma once #include #include #include class SelectionManager { public: explicit SelectionManager() : _multiselection_enabled(false) {} void discard() { _selected_ids.clear(); } void fetch(int note_id, int element_id) { if (!isSelected(note_id, element_id)) _selected_ids[note_id].emplace_back(element_id); } void remove(int note_id, int element_id) { if (_selected_ids.count(note_id) == 0) return; auto& elements_ids = _selected_ids[note_id]; for (std::size_t i = 0; i < elements_ids.size(); ++i) { if (element_id == elements_ids.at(i)) { elements_ids[i] = std::move(elements_ids.back()); elements_ids.pop_back(); break; } } } bool isSelected(int note_id, int element_id) const { if (_selected_ids.count(note_id) == 0) return false; const std::vector& selected_elements = _selected_ids.at(note_id); for (const auto& selected_element : selected_elements) if (selected_element == element_id) return true; return false; } void enableMultiselection(bool enable = true) { _multiselection_enabled = enable; } bool isMultiselectionEnabled() const { return _multiselection_enabled; } private: std::map> _selected_ids; bool _multiselection_enabled; };