Shinya Kitaoka 810553
#pragma once
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>
Shinya Kitaoka 120a6e
class MultipleSelection : public TSelection {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef T object_type;
Shinya Kitaoka 120a6e
  typedef std::vector<t> objects_container;</t>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  MultipleSelection() {}
Shinya Kitaoka 120a6e
  MultipleSelection(const T &t) : m_objects(1, t) {}
Shinya Kitaoka 120a6e
  MultipleSelection(const std::vector<t> &objects) : m_objects(objects) {</t>
Shinya Kitaoka 120a6e
    std::sort(m_objects.begin(), m_objects.end());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool isEmpty() const override { return m_objects.empty(); }
Shinya Kitaoka 473e70
  void selectNone() override {
Shinya Kitaoka 120a6e
    m_objects.clear();
Shinya Kitaoka 120a6e
    notifyView();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool contains(int v) const {
Shinya Kitaoka 120a6e
    return std::binary_search(m_objects.begin(), m_objects.end(), v);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool contains(const MultipleSelection &other) const {
Shinya Kitaoka 120a6e
    return std::includes(m_objects.begin(), m_objects.end(),
Shinya Kitaoka 120a6e
                         other.m_objects.begin(), other.m_objects.end());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const objects_container &objects() const { return m_objects; }
Shinya Kitaoka 120a6e
  void setObjects(const objects_container &objects) {
Shinya Kitaoka 120a6e
    m_objects = objects;
Shinya Kitaoka 120a6e
    std::sort(m_objects.begin(), m_objects.end());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool hasSingleObject() const { return (m_objects.size() == 1); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  objects_container m_objects;  //!< Selected objects
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // MULTIPLESELECTION_H