Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TPROPERTY_INCLUDED
Toshihiro Shimizu 890ddd
#define TPROPERTY_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tconvert.h"
bfef68
#include "tstringid.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9eb50d
#include <cstdint></cstdint>
Shinya Kitaoka 9eb50d
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef TNZCORE_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
e280ae
#ifdef _MSC_VER
Toshihiro Shimizu 890ddd
#pragma warning(push)
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4251)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TRangeProperty;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TRangeProperty<int> TIntProperty;</int>
Toshihiro Shimizu 890ddd
typedef TRangeProperty<double> TDoubleProperty;</double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TBoolProperty;
Toshihiro Shimizu 890ddd
class DVAPI TStringProperty;
Toshihiro Shimizu 890ddd
class DVAPI TEnumProperty;
Toshihiro Shimizu 890ddd
class DVAPI TDoublePairProperty;
Toshihiro Shimizu 890ddd
class DVAPI TIntPairProperty;
Toshihiro Shimizu 890ddd
class DVAPI TStyleIndexProperty;
Toshihiro Shimizu 890ddd
class DVAPI TPointerProperty;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TIStream;
Toshihiro Shimizu 890ddd
class TOStream;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TProperty {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  class Visitor {
Shinya Kitaoka 120a6e
  public:
Shinya Kitaoka 120a6e
    virtual void visit(TDoubleProperty *p)     = 0;
Shinya Kitaoka 120a6e
    virtual void visit(TIntProperty *p)        = 0;
Shinya Kitaoka 120a6e
    virtual void visit(TBoolProperty *p)       = 0;
Shinya Kitaoka 120a6e
    virtual void visit(TStringProperty *p)     = 0;
Shinya Kitaoka 120a6e
    virtual void visit(TEnumProperty *p)       = 0;
Shinya Kitaoka 120a6e
    virtual void visit(TDoublePairProperty *p) = 0;
Shinya Kitaoka 120a6e
    virtual void visit(TIntPairProperty *p)    = 0;
Shinya Kitaoka 120a6e
    virtual void visit(TStyleIndexProperty *p) = 0;
Shinya Kitaoka 120a6e
    virtual void visit(TPointerProperty *p)    = 0;
Shinya Kitaoka 120a6e
    virtual ~Visitor() {}
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  class Listener {
Shinya Kitaoka 120a6e
  public:
Shinya Kitaoka 120a6e
    virtual void onPropertyChanged() = 0;
Shinya Kitaoka 120a6e
    virtual ~Listener() {}
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // eccezioni
Shinya Kitaoka 120a6e
  class TypeError {};
Shinya Kitaoka 120a6e
  class RangeError {};
Shinya Kitaoka 120a6e
bfef68
  TProperty(std::string name):
bfef68
    m_name(name),
bfef68
    m_visible(true),
bfef68
    m_qstringName(QString::fromStdString(name))
bfef68
    { }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual ~TProperty() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual TProperty *clone() const = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Used only for translation in Qt
Shinya Kitaoka 120a6e
  QString getQStringName() const { return m_qstringName; }
Shinya Kitaoka 120a6e
  void setQStringName(const QString &str) { m_qstringName = str; }
shun-iwasawa e87e08
  virtual void assignUIName(TProperty *refP);
Shinya Kitaoka 120a6e
bfef68
  std::string getName() const { return m_name.str(); }
bfef68
  TStringId getNameId() const { return m_name; }
Shinya Kitaoka 120a6e
  virtual std::string getValueAsString() = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual void accept(Visitor &v) = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void addListener(Listener *listener);
Shinya Kitaoka 120a6e
  void removeListener(Listener *listener);
Shinya Kitaoka 120a6e
  void notifyListeners() const;
Shinya Kitaoka 120a6e
bfef68
  // Used to pass action name
Shinya Kitaoka 120a6e
  std::string getId() const { return m_id; }
Shinya Kitaoka 120a6e
  void setId(std::string id) { m_id = id; }
Toshihiro Shimizu 890ddd
justburner 8ca956
  bool getVisible() const { return m_visible; }
justburner 8ca956
  void setVisible(bool state) { m_visible = state; }
justburner 8ca956
Toshihiro Shimizu 890ddd
private:
bfef68
  TStringId m_name;
Shinya Kitaoka 120a6e
  QString m_qstringName;
Shinya Kitaoka 120a6e
  std::string m_id;
Shinya Kitaoka 120a6e
  std::vector<listener *=""> m_listeners;</listener>
justburner 8ca956
  bool m_visible;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka d1f6c4
class TRangeProperty final : public TProperty {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef std::pair<t, t=""> Range;</t,>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRangeProperty(std::string name, T minValue, T maxValue, T value,
Shinya Kitaoka 120a6e
                 bool isMaxRangeLimited = true)
Shinya Kitaoka 120a6e
      : TProperty(name)
Shinya Kitaoka 120a6e
      , m_range(minValue, maxValue)
Shinya Kitaoka 120a6e
      , m_value(minValue)
shun-iwasawa 76d093
      , m_isMaxRangeLimited(isMaxRangeLimited)
da847a
      , m_isLinearSlider(true)
da847a
      , m_isSpinner(false) {
Shinya Kitaoka 120a6e
    setValue(value);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TProperty *clone() const override { return new TRangeProperty<t>(*this); }</t>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  Range getRange() const { return m_range; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setValue(T v, bool cropEnabled = false) {
Shinya Kitaoka 120a6e
    if (cropEnabled && m_isMaxRangeLimited)
Shinya Kitaoka 120a6e
      v = tcrop(v, m_range.first, m_range.second);
Shinya Kitaoka 120a6e
    if (cropEnabled && !m_isMaxRangeLimited)
Shinya Kitaoka 120a6e
      v = v < m_range.first ? m_range.first : v;
Shinya Kitaoka 120a6e
    if (v < m_range.first || (v > m_range.second && m_isMaxRangeLimited))
Shinya Kitaoka 120a6e
      throw RangeError();
Shinya Kitaoka 120a6e
    m_value = v;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  T getValue() const { return m_value; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  std::string getValueAsString() override { return std::to_string(m_value); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void accept(Visitor &v) override { v.visit(this); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isMaxRangeLimited() const { return m_isMaxRangeLimited; }
Toshihiro Shimizu 890ddd
shun-iwasawa 76d093
  void setNonLinearSlider() { m_isLinearSlider = false; }
shun-iwasawa 76d093
  bool isLinearSlider() { return m_isLinearSlider; }
shun-iwasawa 76d093
da847a
  //! has meaning for int properties only
da847a
  void setSpinner() { m_isSpinner = true; }
da847a
  bool isSpinner() { return m_isSpinner; }
da847a
  
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  Range m_range;
Shinya Kitaoka 120a6e
  T m_value;
Shinya Kitaoka 120a6e
  bool m_isMaxRangeLimited;
shun-iwasawa 76d093
  bool m_isLinearSlider;
da847a
  bool m_isSpinner;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TRangeProperty<int>;</int>
Toshihiro Shimizu 890ddd
template class DVAPI TRangeProperty<double>;</double>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TDoublePairProperty final : public TProperty {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef std::pair<double, double=""> Range;</double,>
Shinya Kitaoka 120a6e
  typedef std::pair<double, double=""> Value;</double,>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoublePairProperty(std::string name, double minValue, double maxValue,
Shinya Kitaoka 120a6e
                      double v0, double v1, bool isMaxRangeLimited = true)
Shinya Kitaoka 120a6e
      : TProperty(name)
Shinya Kitaoka 120a6e
      , m_range(Range(minValue, maxValue))
shun-iwasawa 76d093
      , m_isMaxRangeLimited(isMaxRangeLimited)
shun-iwasawa 76d093
      , m_isLinearSlider(true) {
Shinya Kitaoka 120a6e
    setValue(Value(v0, v1));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TProperty *clone() const override { return new TDoublePairProperty(*this); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  Range getRange() const { return m_range; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isMaxRangeLimited() const { return m_isMaxRangeLimited; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setValue(const Value &value) {
Shinya Kitaoka 120a6e
    if (value.first < m_range.first ||
Shinya Kitaoka 120a6e
        (m_isMaxRangeLimited && value.first > m_range.second) ||
Shinya Kitaoka 120a6e
        value.second < m_range.first ||
Shinya Kitaoka 120a6e
        (m_isMaxRangeLimited && value.second > m_range.second))
Shinya Kitaoka 120a6e
      throw RangeError();
Shinya Kitaoka 120a6e
    m_value = value;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  Value getValue() const { return m_value; }
Shinya Kitaoka 473e70
  std::string getValueAsString() override {
Shinya Kitaoka 120a6e
    return std::to_string(m_value.first) + "," + std::to_string(m_value.second);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void accept(Visitor &v) override { v.visit(this); };
Toshihiro Shimizu 890ddd
shun-iwasawa 76d093
  void setNonLinearSlider() { m_isLinearSlider = false; }
shun-iwasawa 76d093
  bool isLinearSlider() { return m_isLinearSlider; }
shun-iwasawa 76d093
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  Range m_range;
Shinya Kitaoka 120a6e
  Value m_value;
Shinya Kitaoka 120a6e
  bool m_isMaxRangeLimited;
shun-iwasawa 76d093
  bool m_isLinearSlider;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TIntPairProperty final : public TProperty {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef std::pair<int, int=""> Range;</int,>
Shinya Kitaoka 120a6e
  typedef std::pair<int, int=""> Value;</int,>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TIntPairProperty(std::string name, int minValue, int maxValue, int v0, int v1,
Shinya Kitaoka 120a6e
                   bool isMaxRangeLimited = true)
Shinya Kitaoka 120a6e
      : TProperty(name)
Shinya Kitaoka 120a6e
      , m_range(minValue, maxValue)
shun-iwasawa 76d093
      , m_isMaxRangeLimited(isMaxRangeLimited)
shun-iwasawa 76d093
      , m_isLinearSlider(true) {
Shinya Kitaoka 120a6e
    setValue(Value(v0, v1));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TProperty *clone() const override { return new TIntPairProperty(*this); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  Range getRange() const { return m_range; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isMaxRangeLimited() const { return m_isMaxRangeLimited; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setValue(const Value &value) {
Shinya Kitaoka 120a6e
    if (value.first < m_range.first ||
Shinya Kitaoka 120a6e
        (m_isMaxRangeLimited && value.first > m_range.second) ||
Shinya Kitaoka 120a6e
        value.second < m_range.first ||
Shinya Kitaoka 120a6e
        (m_isMaxRangeLimited && value.second > m_range.second))
Shinya Kitaoka 120a6e
      throw RangeError();
Shinya Kitaoka 120a6e
    m_value = value;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  Value getValue() const { return m_value; }
Shinya Kitaoka 473e70
  std::string getValueAsString() override {
Shinya Kitaoka 120a6e
    return std::to_string(m_value.first) + "," + std::to_string(m_value.second);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void accept(Visitor &v) override { v.visit(this); };
Toshihiro Shimizu 890ddd
shun-iwasawa 76d093
  void setNonLinearSlider() { m_isLinearSlider = false; }
shun-iwasawa 76d093
  bool isLinearSlider() { return m_isLinearSlider; }
shun-iwasawa 76d093
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  Range m_range;
Shinya Kitaoka 120a6e
  Value m_value;
Shinya Kitaoka 120a6e
  bool m_isMaxRangeLimited;
shun-iwasawa 76d093
  bool m_isLinearSlider;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TBoolProperty final : public TProperty {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TBoolProperty(std::string name, bool value)
Shinya Kitaoka 120a6e
      : TProperty(name), m_value(value) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TProperty *clone() const override { return new TBoolProperty(*this); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setValue(bool v) { m_value = v; }
Shinya Kitaoka 120a6e
  bool getValue() const { return m_value; }
Shinya Kitaoka 473e70
  std::string getValueAsString() override { return std::to_string(m_value); }
Shinya Kitaoka 473e70
  void accept(Visitor &v) override { v.visit(this); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  bool m_value;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TStringProperty final : public TProperty {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TStringProperty(std::string name, std::wstring value)
Shinya Kitaoka 120a6e
      : TProperty(name), m_value(value) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TProperty *clone() const override { return new TStringProperty(*this); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setValue(std::wstring v) { m_value = v; }
Shinya Kitaoka 120a6e
  std::wstring getValue() const { return m_value; }
Shinya Kitaoka 473e70
  std::string getValueAsString() override { return ::to_string(m_value); }
Shinya Kitaoka 473e70
  void accept(Visitor &v) override { v.visit(this); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  std::wstring m_value;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TStyleIndexProperty final : public TProperty {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TStyleIndexProperty(std::string name, std::wstring value)
Shinya Kitaoka 120a6e
      : TProperty(name), m_value(value) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TProperty *clone() const override { return new TStyleIndexProperty(*this); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setValue(std::wstring v) { m_value = v; }
Shinya Kitaoka 120a6e
  std::wstring getValue() const { return m_value; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  std::string getValueAsString() override { return ::to_string(m_value); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void accept(Visitor &v) override { v.visit(this); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  std::wstring m_value;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TPointerProperty final : public TProperty {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TPointerProperty(std::string name, void *value)
Shinya Kitaoka 120a6e
      : TProperty(name), m_value(value) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TProperty *clone() const override { return new TPointerProperty(*this); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setValue(void *v) { m_value = v; }
Shinya Kitaoka 120a6e
  void *getValue() const { return m_value; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  std::string getValueAsString() override { return ::to_string(m_value); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void accept(Visitor &v) override { v.visit(this); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  void *m_value;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TEnumProperty final : public TProperty {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef std::vector<std::wstring> Range;</std::wstring>
shun-iwasawa df7bb0
  // Used only for translation and styling in Qt
shun-iwasawa df7bb0
  struct Item {
shun-iwasawa df7bb0
    QString UIName;
shun-iwasawa df7bb0
    QString iconName;
shun-iwasawa df7bb0
shun-iwasawa df7bb0
    Item(const QString &name = QString(), const QString &icon = QString())
shun-iwasawa df7bb0
        : UIName(name), iconName(icon) {}
shun-iwasawa df7bb0
  };
shun-iwasawa df7bb0
  typedef std::vector<item> Items;</item>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TEnumProperty(const std::string &name) : TProperty(name), m_index(-1) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TEnumProperty(const std::string &name, const Range &range,
Shinya Kitaoka 120a6e
                const std::wstring &v)
Shinya Kitaoka 120a6e
      : TProperty(name), m_range(range), m_index(indexOf(v)) {
Shinya Kitaoka 120a6e
    if (m_index < 0) throw RangeError();
shun-iwasawa df7bb0
    m_items.resize(m_range.size());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TEnumProperty(const std::string &name, Range::const_iterator i0,
Shinya Kitaoka 120a6e
                Range::const_iterator i1, const std::wstring &v)
Shinya Kitaoka 120a6e
      : TProperty(name), m_range(i0, i1), m_index(indexOf(v)) {
Shinya Kitaoka 120a6e
    if (m_index < 0) throw RangeError();
shun-iwasawa df7bb0
    m_items.resize(m_range.size());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TProperty *clone() const override { return new TEnumProperty(*this); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int indexOf(const std::wstring &value) {
Shinya Kitaoka 120a6e
    Range::const_iterator it = std::find(m_range.begin(), m_range.end(), value);
Shinya Kitaoka 120a6e
    return (it == m_range.end()) ? -1 : it - m_range.begin();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isValue(const std::wstring &value) {
Shinya Kitaoka 120a6e
    bool ret =
Shinya Kitaoka 120a6e
        std::find(m_range.begin(), m_range.end(), value) != m_range.end();
Shinya Kitaoka 120a6e
    return ret;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
bfef68
  void addValueWithUIName(std::wstring value, const QString &name, const QString &iconName = QString()) {
Shinya Kitaoka 120a6e
    if (m_index == -1) m_index = 0;
Shinya Kitaoka 120a6e
    m_range.push_back(value);
bfef68
    m_items.push_back(Item(name, iconName));
shun-iwasawa df7bb0
  }
shun-iwasawa df7bb0
bfef68
  void addValue(std::wstring value, const QString &iconName = QString())
bfef68
    { addValueWithUIName(value, QString::fromStdWString(value), iconName); }
bfef68
shun-iwasawa df7bb0
  void setItemUIName(std::wstring value, const QString &name) {
shun-iwasawa df7bb0
    int index = indexOf(value);
shun-iwasawa df7bb0
    if (index < 0 || index >= (int)m_items.size()) throw RangeError();
shun-iwasawa df7bb0
    m_items[index].UIName = name;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void deleteAllValues() {
Shinya Kitaoka 120a6e
    m_range.clear();
shun-iwasawa df7bb0
    m_items.clear();
Shinya Kitaoka 120a6e
    m_index = -1;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setIndex(int index) {
Shinya Kitaoka 120a6e
    if (index < 0 || index >= (int)m_range.size()) throw RangeError();
Shinya Kitaoka 120a6e
    m_index = index;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setValue(const std::wstring &value) {
Shinya Kitaoka 120a6e
    int idx = indexOf(value);
justburner e7c1a3
    //if (idx < 0) throw RangeError();
justburner e7c1a3
    if (idx < 0)
justburner e7c1a3
      idx = 0;  // Avoid exception if program's item list doesn't contain
justburner e7c1a3
                //  the selected item in scene file
Shinya Kitaoka 120a6e
    m_index = idx;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa df7bb0
  int getCount() const { return (int)m_items.size(); }
shun-iwasawa df7bb0
Shinya Kitaoka 120a6e
  const Range &getRange() const { return m_range; }
shun-iwasawa df7bb0
  const Items &getItems() const { return m_items; }
shun-iwasawa df7bb0
Shinya Kitaoka 120a6e
  std::wstring getValue() const {
Shinya Kitaoka 120a6e
    return (m_index < 0) ? L"" : m_range[m_index];
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 38fd86
  std::string getValueAsString() override {
Shinya Kitaoka 38fd86
    return ::to_string(m_range[m_index]);
Shinya Kitaoka 38fd86
  }
shun-iwasawa df7bb0
Shinya Kitaoka 120a6e
  int getIndex() const { return m_index; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void accept(Visitor &v) override { v.visit(this); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  static void enableRangeSaving(bool on);
Shinya Kitaoka 120a6e
  static bool isRangeSavingEnabled();
Toshihiro Shimizu 890ddd
shun-iwasawa e87e08
  void assignUIName(TProperty *refP) override;
shun-iwasawa e87e08
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  Range m_range;
shun-iwasawa df7bb0
  Items m_items;
Shinya Kitaoka 120a6e
  int m_index;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TPropertyGroup {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef std::vector<std::pair<tproperty *,="" bool="">> PropertyVector;</std::pair<tproperty>
bfef68
  typedef std::map<tstringid, *="" tproperty=""> PropertyTable;</tstringid,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // exception
Shinya Kitaoka 120a6e
  class PropertyNotFoundError {};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPropertyGroup();
Shinya Kitaoka 120a6e
  virtual ~TPropertyGroup();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual TPropertyGroup *clone() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! get ownership
Shinya Kitaoka 120a6e
  void add(TProperty *p);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! don't get ownership
Shinya Kitaoka 120a6e
  void bind(TProperty &p);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! returns 0 if the property doesn't exist
bfef68
  TProperty *getProperty(const TStringId &name);
bfef68
  TProperty *getProperty(const std::string &name)
bfef68
    { return getProperty(TStringId::find(name)); }
bfef68
  TProperty *getProperty(int i)
bfef68
    { return (i >= (int)m_properties.size()) ? 0 : m_properties[i].first; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setProperties(TPropertyGroup *g);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void accept(TProperty::Visitor &v);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getPropertyCount() const { return (int)m_properties.size(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void loadData(TIStream &is);
Shinya Kitaoka 120a6e
  void saveData(TOStream &os) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void clear();
Toshihiro Shimizu 890ddd
shun-iwasawa e87e08
  // for adding translation to file writers properties
shun-iwasawa e87e08
  virtual void updateTranslation(){};
shun-iwasawa e87e08
shun-iwasawa e87e08
  void assignUINames(TPropertyGroup *refPg);
shun-iwasawa e87e08
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  PropertyTable m_table;
Shinya Kitaoka 120a6e
  PropertyVector m_properties;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  TPropertyGroup(const TPropertyGroup &);
Shinya Kitaoka 120a6e
  TPropertyGroup &operator=(const TPropertyGroup &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
e280ae
#ifdef _MSC_VER
Toshihiro Shimizu 890ddd
#pragma warning(pop)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif