2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef MULTIPLESELECTION_H
|
|
|
|
#define MULTIPLESELECTION_H
|
|
|
|
|
|
|
|
// TnzQt includes
|
|
|
|
#include "toonzqt/selection.h"
|
|
|
|
|
|
|
|
// STD includes
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
//**********************************************************************
|
|
|
|
// MultipleSelection definition
|
|
|
|
//**********************************************************************
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Represents a selection of multiple objects.
|
|
|
|
|
|
|
|
\details This template class implements a TSelection storing
|
|
|
|
multiple objects.
|
|
|
|
|
|
|
|
\remark The stored objects must support operator<().
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <typename T>
|
2016-06-15 18:43:10 +12:00
|
|
|
class MultipleSelection : public TSelection {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
typedef T object_type;
|
|
|
|
typedef std::vector<T> objects_container;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
bool isEmpty() const override { return m_objects.empty(); }
|
|
|
|
void selectNone() override {
|
2016-06-15 18:43:10 +12:00
|
|
|
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); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
protected:
|
2016-06-15 18:43:10 +12:00
|
|
|
objects_container m_objects; //!< Selected objects
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // MULTIPLESELECTION_H
|