You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project-kyoku/src/modes/classicmode/editor/selectionmanager.h

70 lines
1.5 KiB
C++

#pragma once
#include <map>
#include <vector>
#include <algorithm>
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<int>& 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<int, std::vector<int>> _selected_ids;
bool _multiselection_enabled;
};