Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef MULTIPLESELECTION_H
Toshihiro Shimizu 890ddd
#define MULTIPLESELECTION_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/selection.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// STD includes
Toshihiro Shimizu 890ddd
#include <algorithm></algorithm>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
//    MultipleSelection  definition
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  \brief      Represents a selection of multiple objects.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \details    This template class implements a TSelection storing
Toshihiro Shimizu 890ddd
              multiple objects.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \remark     The stored objects must support operator<().
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Toshihiro Shimizu 890ddd
class MultipleSelection : public TSelection
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef T object_type;
Toshihiro Shimizu 890ddd
	typedef std::vector<t> objects_container;</t>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	MultipleSelection() {}
Toshihiro Shimizu 890ddd
	MultipleSelection(const T &t) : m_objects(1, t) {}
Toshihiro Shimizu 890ddd
	MultipleSelection(const std::vector<t> &objects)</t>
Toshihiro Shimizu 890ddd
		: m_objects(objects)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::sort(m_objects.begin(), m_objects.end());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isEmpty() const { return m_objects.empty(); }
Toshihiro Shimizu 890ddd
	void selectNone()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_objects.clear();
Toshihiro Shimizu 890ddd
		notifyView();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool contains(int v) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return std::binary_search(m_objects.begin(), m_objects.end(), v);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool contains(const MultipleSelection &other) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return std::includes(m_objects.begin(), m_objects.end(),
Toshihiro Shimizu 890ddd
							 other.m_objects.begin(), other.m_objects.end());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const objects_container &objects() const { return m_objects; }
Toshihiro Shimizu 890ddd
	void setObjects(const objects_container &objects)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_objects = objects;
Toshihiro Shimizu 890ddd
		std::sort(m_objects.begin(), m_objects.end());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool hasSingleObject() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (m_objects.size() == 1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	objects_container m_objects; //!< Selected objects
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // MULTIPLESELECTION_H