| #pragma once |
| |
| #ifndef MULTIPLESELECTION_H |
| #define MULTIPLESELECTION_H |
| |
| |
| #include "toonzqt/selection.h" |
| |
| |
| #include <algorithm> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename T> |
| class MultipleSelection : public TSelection { |
| public: |
| typedef T object_type; |
| typedef std::vector<T> objects_container; |
| |
| public: |
| MultipleSelection() {} |
| MultipleSelection(const T &t) : m_objects(1, t) {} |
| MultipleSelection(const std::vector<T> &objects) : m_objects(objects) { |
| std::sort(m_objects.begin(), m_objects.end()); |
| } |
| |
| bool isEmpty() const override { return m_objects.empty(); } |
| void selectNone() override { |
| m_objects.clear(); |
| notifyView(); |
| } |
| |
| bool contains(int v) const { |
| return std::binary_search(m_objects.begin(), m_objects.end(), v); |
| } |
| |
| bool contains(const MultipleSelection &other) const { |
| return std::includes(m_objects.begin(), m_objects.end(), |
| other.m_objects.begin(), other.m_objects.end()); |
| } |
| |
| const objects_container &objects() const { return m_objects; } |
| void setObjects(const objects_container &objects) { |
| m_objects = objects; |
| std::sort(m_objects.begin(), m_objects.end()); |
| } |
| |
| bool hasSingleObject() const { return (m_objects.size() == 1); } |
| |
| protected: |
| objects_container m_objects; |
| }; |
| |
| #endif |