2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef TPROPERTY_INCLUDED
|
|
|
|
#define TPROPERTY_INCLUDED
|
|
|
|
|
|
|
|
#include "tconvert.h"
|
2021-11-04 03:05:17 +13:00
|
|
|
#include "tpixel.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-07 19:06:00 +12:00
|
|
|
#include <cstdint>
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
#undef DVAPI
|
|
|
|
#undef DVVAR
|
|
|
|
|
|
|
|
#ifdef TNZCORE_EXPORTS
|
|
|
|
#define DVAPI DV_EXPORT_API
|
|
|
|
#define DVVAR DV_EXPORT_VAR
|
|
|
|
#else
|
|
|
|
#define DVAPI DV_IMPORT_API
|
|
|
|
#define DVVAR DV_IMPORT_VAR
|
|
|
|
#endif
|
|
|
|
|
2017-05-09 00:13:29 +12:00
|
|
|
#ifdef _MSC_VER
|
2016-03-19 06:57:51 +13:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4251)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class TRangeProperty;
|
|
|
|
|
|
|
|
typedef TRangeProperty<int> TIntProperty;
|
|
|
|
typedef TRangeProperty<double> TDoubleProperty;
|
|
|
|
|
|
|
|
class DVAPI TBoolProperty;
|
|
|
|
class DVAPI TStringProperty;
|
|
|
|
class DVAPI TEnumProperty;
|
|
|
|
class DVAPI TDoublePairProperty;
|
|
|
|
class DVAPI TIntPairProperty;
|
|
|
|
class DVAPI TStyleIndexProperty;
|
|
|
|
class DVAPI TPointerProperty;
|
2021-11-04 03:05:17 +13:00
|
|
|
class DVAPI TColorChipProperty;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
class TIStream;
|
|
|
|
class TOStream;
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class DVAPI TProperty {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
class Visitor {
|
|
|
|
public:
|
|
|
|
virtual void visit(TDoubleProperty *p) = 0;
|
|
|
|
virtual void visit(TIntProperty *p) = 0;
|
|
|
|
virtual void visit(TBoolProperty *p) = 0;
|
|
|
|
virtual void visit(TStringProperty *p) = 0;
|
|
|
|
virtual void visit(TEnumProperty *p) = 0;
|
|
|
|
virtual void visit(TDoublePairProperty *p) = 0;
|
|
|
|
virtual void visit(TIntPairProperty *p) = 0;
|
|
|
|
virtual void visit(TStyleIndexProperty *p) = 0;
|
|
|
|
virtual void visit(TPointerProperty *p) = 0;
|
2021-11-04 03:05:17 +13:00
|
|
|
virtual void visit(TColorChipProperty *p) = 0;
|
2016-06-15 18:43:10 +12:00
|
|
|
virtual ~Visitor() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Listener {
|
|
|
|
public:
|
|
|
|
virtual void onPropertyChanged() = 0;
|
|
|
|
virtual ~Listener() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// eccezioni
|
|
|
|
class TypeError {};
|
|
|
|
class RangeError {};
|
|
|
|
|
|
|
|
TProperty(std::string name) : m_name(name) {
|
|
|
|
m_qstringName = QString::fromStdString(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~TProperty() {}
|
|
|
|
|
|
|
|
virtual TProperty *clone() const = 0;
|
|
|
|
|
|
|
|
// Used only for translation in Qt
|
|
|
|
QString getQStringName() const { return m_qstringName; }
|
|
|
|
void setQStringName(const QString &str) { m_qstringName = str; }
|
2018-06-04 15:18:43 +12:00
|
|
|
virtual void assignUIName(TProperty *refP);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
std::string getName() const { return m_name; }
|
|
|
|
virtual std::string getValueAsString() = 0;
|
|
|
|
|
|
|
|
virtual void accept(Visitor &v) = 0;
|
|
|
|
|
|
|
|
void addListener(Listener *listener);
|
|
|
|
void removeListener(Listener *listener);
|
|
|
|
void notifyListeners() const;
|
|
|
|
|
|
|
|
std::string getId() const { return m_id; }
|
|
|
|
void setId(std::string id) { m_id = id; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2022-02-22 07:07:34 +13:00
|
|
|
bool getVisible() const { return m_visible; }
|
|
|
|
void setVisible(bool state) { m_visible = state; }
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
std::string m_name;
|
|
|
|
QString m_qstringName;
|
|
|
|
std::string m_id;
|
|
|
|
std::vector<Listener *> m_listeners;
|
2022-02-22 07:07:34 +13:00
|
|
|
bool m_visible;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
template <class T>
|
2016-06-29 18:17:12 +12:00
|
|
|
class TRangeProperty final : public TProperty {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
typedef std::pair<T, T> Range;
|
|
|
|
|
|
|
|
TRangeProperty(std::string name, T minValue, T maxValue, T value,
|
|
|
|
bool isMaxRangeLimited = true)
|
|
|
|
: TProperty(name)
|
|
|
|
, m_range(minValue, maxValue)
|
|
|
|
, m_value(minValue)
|
2019-10-11 16:13:41 +13:00
|
|
|
, m_isMaxRangeLimited(isMaxRangeLimited)
|
|
|
|
, m_isLinearSlider(true) {
|
2016-06-15 18:43:10 +12:00
|
|
|
setValue(value);
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TProperty *clone() const override { return new TRangeProperty<T>(*this); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
Range getRange() const { return m_range; }
|
|
|
|
|
|
|
|
void setValue(T v, bool cropEnabled = false) {
|
|
|
|
if (cropEnabled && m_isMaxRangeLimited)
|
|
|
|
v = tcrop(v, m_range.first, m_range.second);
|
|
|
|
if (cropEnabled && !m_isMaxRangeLimited)
|
|
|
|
v = v < m_range.first ? m_range.first : v;
|
|
|
|
if (v < m_range.first || (v > m_range.second && m_isMaxRangeLimited))
|
|
|
|
throw RangeError();
|
|
|
|
m_value = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
T getValue() const { return m_value; }
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
std::string getValueAsString() override { return std::to_string(m_value); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void accept(Visitor &v) override { v.visit(this); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
bool isMaxRangeLimited() const { return m_isMaxRangeLimited; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2019-10-11 16:13:41 +13:00
|
|
|
void setNonLinearSlider() { m_isLinearSlider = false; }
|
|
|
|
bool isLinearSlider() { return m_isLinearSlider; }
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
Range m_range;
|
|
|
|
T m_value;
|
|
|
|
bool m_isMaxRangeLimited;
|
2019-10-11 16:13:41 +13:00
|
|
|
bool m_isLinearSlider;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2016-04-15 17:11:23 +12:00
|
|
|
#ifdef _WIN32
|
2016-03-19 06:57:51 +13:00
|
|
|
template class DVAPI TRangeProperty<int>;
|
|
|
|
template class DVAPI TRangeProperty<double>;
|
|
|
|
#endif
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class TDoublePairProperty final : public TProperty {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
typedef std::pair<double, double> Range;
|
|
|
|
typedef std::pair<double, double> Value;
|
|
|
|
|
|
|
|
TDoublePairProperty(std::string name, double minValue, double maxValue,
|
|
|
|
double v0, double v1, bool isMaxRangeLimited = true)
|
|
|
|
: TProperty(name)
|
|
|
|
, m_range(Range(minValue, maxValue))
|
2019-10-11 16:13:41 +13:00
|
|
|
, m_isMaxRangeLimited(isMaxRangeLimited)
|
|
|
|
, m_isLinearSlider(true) {
|
2016-06-15 18:43:10 +12:00
|
|
|
setValue(Value(v0, v1));
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TProperty *clone() const override { return new TDoublePairProperty(*this); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
Range getRange() const { return m_range; }
|
|
|
|
|
|
|
|
bool isMaxRangeLimited() const { return m_isMaxRangeLimited; }
|
|
|
|
|
|
|
|
void setValue(const Value &value) {
|
|
|
|
if (value.first < m_range.first ||
|
|
|
|
(m_isMaxRangeLimited && value.first > m_range.second) ||
|
|
|
|
value.second < m_range.first ||
|
|
|
|
(m_isMaxRangeLimited && value.second > m_range.second))
|
|
|
|
throw RangeError();
|
|
|
|
m_value = value;
|
|
|
|
}
|
|
|
|
Value getValue() const { return m_value; }
|
2016-06-19 20:06:29 +12:00
|
|
|
std::string getValueAsString() override {
|
2016-06-15 18:43:10 +12:00
|
|
|
return std::to_string(m_value.first) + "," + std::to_string(m_value.second);
|
|
|
|
}
|
2016-06-19 20:06:29 +12:00
|
|
|
void accept(Visitor &v) override { v.visit(this); };
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2019-10-11 16:13:41 +13:00
|
|
|
void setNonLinearSlider() { m_isLinearSlider = false; }
|
|
|
|
bool isLinearSlider() { return m_isLinearSlider; }
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
Range m_range;
|
|
|
|
Value m_value;
|
|
|
|
bool m_isMaxRangeLimited;
|
2019-10-11 16:13:41 +13:00
|
|
|
bool m_isLinearSlider;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class TIntPairProperty final : public TProperty {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
typedef std::pair<int, int> Range;
|
|
|
|
typedef std::pair<int, int> Value;
|
|
|
|
|
|
|
|
TIntPairProperty(std::string name, int minValue, int maxValue, int v0, int v1,
|
|
|
|
bool isMaxRangeLimited = true)
|
|
|
|
: TProperty(name)
|
|
|
|
, m_range(minValue, maxValue)
|
2019-10-11 16:13:41 +13:00
|
|
|
, m_isMaxRangeLimited(isMaxRangeLimited)
|
|
|
|
, m_isLinearSlider(true) {
|
2016-06-15 18:43:10 +12:00
|
|
|
setValue(Value(v0, v1));
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TProperty *clone() const override { return new TIntPairProperty(*this); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
Range getRange() const { return m_range; }
|
|
|
|
|
|
|
|
bool isMaxRangeLimited() const { return m_isMaxRangeLimited; }
|
|
|
|
|
|
|
|
void setValue(const Value &value) {
|
|
|
|
if (value.first < m_range.first ||
|
|
|
|
(m_isMaxRangeLimited && value.first > m_range.second) ||
|
|
|
|
value.second < m_range.first ||
|
|
|
|
(m_isMaxRangeLimited && value.second > m_range.second))
|
|
|
|
throw RangeError();
|
|
|
|
m_value = value;
|
|
|
|
}
|
|
|
|
Value getValue() const { return m_value; }
|
2016-06-19 20:06:29 +12:00
|
|
|
std::string getValueAsString() override {
|
2016-06-15 18:43:10 +12:00
|
|
|
return std::to_string(m_value.first) + "," + std::to_string(m_value.second);
|
|
|
|
}
|
2016-06-19 20:06:29 +12:00
|
|
|
void accept(Visitor &v) override { v.visit(this); };
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2019-10-11 16:13:41 +13:00
|
|
|
void setNonLinearSlider() { m_isLinearSlider = false; }
|
|
|
|
bool isLinearSlider() { return m_isLinearSlider; }
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
Range m_range;
|
|
|
|
Value m_value;
|
|
|
|
bool m_isMaxRangeLimited;
|
2019-10-11 16:13:41 +13:00
|
|
|
bool m_isLinearSlider;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI TBoolProperty final : public TProperty {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
TBoolProperty(std::string name, bool value)
|
|
|
|
: TProperty(name), m_value(value) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TProperty *clone() const override { return new TBoolProperty(*this); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void setValue(bool v) { m_value = v; }
|
|
|
|
bool getValue() const { return m_value; }
|
2016-06-19 20:06:29 +12:00
|
|
|
std::string getValueAsString() override { return std::to_string(m_value); }
|
|
|
|
void accept(Visitor &v) override { v.visit(this); };
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
bool m_value;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI TStringProperty final : public TProperty {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
TStringProperty(std::string name, std::wstring value)
|
|
|
|
: TProperty(name), m_value(value) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TProperty *clone() const override { return new TStringProperty(*this); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void setValue(std::wstring v) { m_value = v; }
|
|
|
|
std::wstring getValue() const { return m_value; }
|
2016-06-19 20:06:29 +12:00
|
|
|
std::string getValueAsString() override { return ::to_string(m_value); }
|
|
|
|
void accept(Visitor &v) override { v.visit(this); };
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
std::wstring m_value;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI TStyleIndexProperty final : public TProperty {
|
2020-11-12 16:36:21 +13:00
|
|
|
int m_styleIndex = -1;
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
TStyleIndexProperty(std::string name, std::wstring value)
|
|
|
|
: TProperty(name), m_value(value) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TProperty *clone() const override { return new TStyleIndexProperty(*this); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void setValue(std::wstring v) { m_value = v; }
|
2020-11-12 16:36:21 +13:00
|
|
|
void setStyleIndex(int index) { m_styleIndex = index; }
|
|
|
|
int getStyleIndex() { return m_styleIndex; }
|
2016-06-15 18:43:10 +12:00
|
|
|
std::wstring getValue() const { return m_value; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
std::string getValueAsString() override { return ::to_string(m_value); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void accept(Visitor &v) override { v.visit(this); };
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
std::wstring m_value;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI TPointerProperty final : public TProperty {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
TPointerProperty(std::string name, void *value)
|
|
|
|
: TProperty(name), m_value(value) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TProperty *clone() const override { return new TPointerProperty(*this); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void setValue(void *v) { m_value = v; }
|
|
|
|
void *getValue() const { return m_value; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
std::string getValueAsString() override { return ::to_string(m_value); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void accept(Visitor &v) override { v.visit(this); };
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
void *m_value;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI TEnumProperty final : public TProperty {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
typedef std::vector<std::wstring> Range;
|
2018-04-26 21:24:25 +12:00
|
|
|
// Used only for translation and styling in Qt
|
|
|
|
struct Item {
|
|
|
|
QString UIName;
|
|
|
|
QString iconName;
|
|
|
|
|
|
|
|
Item(const QString &name = QString(), const QString &icon = QString())
|
|
|
|
: UIName(name), iconName(icon) {}
|
|
|
|
};
|
|
|
|
typedef std::vector<Item> Items;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
TEnumProperty(const std::string &name) : TProperty(name), m_index(-1) {}
|
|
|
|
|
|
|
|
TEnumProperty(const std::string &name, const Range &range,
|
|
|
|
const std::wstring &v)
|
|
|
|
: TProperty(name), m_range(range), m_index(indexOf(v)) {
|
|
|
|
if (m_index < 0) throw RangeError();
|
2018-04-26 21:24:25 +12:00
|
|
|
m_items.resize(m_range.size());
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
TEnumProperty(const std::string &name, Range::const_iterator i0,
|
|
|
|
Range::const_iterator i1, const std::wstring &v)
|
|
|
|
: TProperty(name), m_range(i0, i1), m_index(indexOf(v)) {
|
|
|
|
if (m_index < 0) throw RangeError();
|
2018-04-26 21:24:25 +12:00
|
|
|
m_items.resize(m_range.size());
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TProperty *clone() const override { return new TEnumProperty(*this); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
int indexOf(const std::wstring &value) {
|
|
|
|
Range::const_iterator it = std::find(m_range.begin(), m_range.end(), value);
|
|
|
|
return (it == m_range.end()) ? -1 : it - m_range.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValue(const std::wstring &value) {
|
|
|
|
bool ret =
|
|
|
|
std::find(m_range.begin(), m_range.end(), value) != m_range.end();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-04-26 21:24:25 +12:00
|
|
|
void addValue(std::wstring value, const QString &iconName = QString()) {
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_index == -1) m_index = 0;
|
|
|
|
m_range.push_back(value);
|
2018-04-26 21:24:25 +12:00
|
|
|
m_items.push_back(Item(QString::fromStdWString(value), iconName));
|
|
|
|
}
|
|
|
|
|
|
|
|
void setItemUIName(std::wstring value, const QString &name) {
|
|
|
|
int index = indexOf(value);
|
|
|
|
if (index < 0 || index >= (int)m_items.size()) throw RangeError();
|
|
|
|
m_items[index].UIName = name;
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
void deleteAllValues() {
|
|
|
|
m_range.clear();
|
2018-04-26 21:24:25 +12:00
|
|
|
m_items.clear();
|
2016-06-15 18:43:10 +12:00
|
|
|
m_index = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIndex(int index) {
|
|
|
|
if (index < 0 || index >= (int)m_range.size()) throw RangeError();
|
|
|
|
m_index = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setValue(const std::wstring &value) {
|
|
|
|
int idx = indexOf(value);
|
2022-01-04 12:37:07 +13:00
|
|
|
// if (idx < 0) throw RangeError();
|
|
|
|
if (idx < 0)
|
|
|
|
idx = 0; // Avoid exception if program's item list doesn't contain
|
|
|
|
// the selected item in scene file
|
2016-06-15 18:43:10 +12:00
|
|
|
m_index = idx;
|
|
|
|
}
|
|
|
|
|
2018-04-26 21:24:25 +12:00
|
|
|
int getCount() const { return (int)m_items.size(); }
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
const Range &getRange() const { return m_range; }
|
2018-04-26 21:24:25 +12:00
|
|
|
const Items &getItems() const { return m_items; }
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::wstring getValue() const {
|
|
|
|
return (m_index < 0) ? L"" : m_range[m_index];
|
|
|
|
}
|
2016-06-20 14:23:05 +12:00
|
|
|
std::string getValueAsString() override {
|
|
|
|
return ::to_string(m_range[m_index]);
|
|
|
|
}
|
2018-04-26 21:24:25 +12:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int getIndex() const { return m_index; }
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void accept(Visitor &v) override { v.visit(this); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
static void enableRangeSaving(bool on);
|
|
|
|
static bool isRangeSavingEnabled();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2018-06-04 15:18:43 +12:00
|
|
|
void assignUIName(TProperty *refP) override;
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
Range m_range;
|
2018-04-26 21:24:25 +12:00
|
|
|
Items m_items;
|
2016-06-15 18:43:10 +12:00
|
|
|
int m_index;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2021-11-04 03:05:17 +13:00
|
|
|
class DVAPI TColorChipProperty final : public TProperty {
|
|
|
|
public:
|
|
|
|
struct ColorChip {
|
|
|
|
QString UIName;
|
|
|
|
TPixel32 pixelColor;
|
|
|
|
|
|
|
|
ColorChip(const QString &name = QString(),
|
|
|
|
const TPixel32 &color = TPixel32(0, 0, 0))
|
|
|
|
: UIName(name), pixelColor(color) {}
|
|
|
|
};
|
|
|
|
typedef std::vector<ColorChip> ColorChips;
|
|
|
|
|
|
|
|
TColorChipProperty(const std::string &name) : TProperty(name), m_index(-1) {}
|
|
|
|
|
|
|
|
TProperty *clone() const override { return new TColorChipProperty(*this); }
|
|
|
|
|
|
|
|
int indexOf(const std::wstring &value) {
|
|
|
|
ColorChips::const_iterator it;
|
|
|
|
for (it = m_chips.begin(); it != m_chips.end(); it++) {
|
|
|
|
ColorChip chip = *it;
|
|
|
|
if (chip.UIName == QString::fromStdWString(value)) break;
|
|
|
|
}
|
|
|
|
return (it == m_chips.end()) ? -1 : it - m_chips.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
int indexOf(TPixel32 color) {
|
|
|
|
ColorChips::const_iterator it;
|
|
|
|
for (it = m_chips.begin(); it != m_chips.end(); it++) {
|
|
|
|
ColorChip chip = *it;
|
|
|
|
if (chip.pixelColor == color) break;
|
|
|
|
}
|
|
|
|
return (it == m_chips.end()) ? -1 : it - m_chips.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValue(const std::wstring &value) { return (indexOf(value) != -1); }
|
|
|
|
|
|
|
|
void addValue(std::wstring value, const TPixel32 &color) {
|
|
|
|
if (m_index == -1) m_index = 0;
|
|
|
|
m_chips.push_back(ColorChip(QString::fromStdWString(value), color));
|
|
|
|
}
|
|
|
|
|
|
|
|
void setItemUIName(std::wstring value, const QString &name) {
|
|
|
|
int index = indexOf(value);
|
|
|
|
if (index < 0 || index >= (int)m_chips.size()) throw RangeError();
|
|
|
|
m_chips[index].UIName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteAllValues() {
|
|
|
|
m_chips.clear();
|
|
|
|
m_index = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIndex(int index) {
|
|
|
|
if (index < 0 || index >= (int)m_chips.size()) throw RangeError();
|
|
|
|
m_index = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setValue(const std::wstring &value) {
|
|
|
|
int idx = indexOf(value);
|
|
|
|
if (idx < 0) throw RangeError();
|
|
|
|
m_index = idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setColor(TPixel32 color) {
|
|
|
|
int idx = indexOf(color);
|
|
|
|
if (idx < 0) throw RangeError();
|
|
|
|
m_index = idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getCount() const { return (int)m_chips.size(); }
|
|
|
|
|
|
|
|
const ColorChips &getColorChips() const { return m_chips; }
|
|
|
|
|
|
|
|
std::wstring getValue() const {
|
|
|
|
return (m_index < 0) ? L"" : m_chips[m_index].UIName.toStdWString();
|
|
|
|
}
|
|
|
|
std::string getValueAsString() override {
|
|
|
|
return (m_index < 0) ? "" : m_chips[m_index].UIName.toStdString();
|
|
|
|
}
|
|
|
|
TPixel32 getColorValue() const {
|
|
|
|
return (m_index < 0) ? TPixel32(0, 0, 0) : m_chips[m_index].pixelColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getIndex() const { return m_index; }
|
|
|
|
|
|
|
|
void accept(Visitor &v) override { v.visit(this); }
|
|
|
|
|
|
|
|
void assignUIName(TProperty *refP) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ColorChips m_chips;
|
|
|
|
int m_index;
|
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class DVAPI TPropertyGroup {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
typedef std::vector<std::pair<TProperty *, bool>> PropertyVector;
|
|
|
|
typedef std::map<std::string, TProperty *> PropertyTable;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// exception
|
|
|
|
class PropertyNotFoundError {};
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPropertyGroup();
|
|
|
|
virtual ~TPropertyGroup();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
virtual TPropertyGroup *clone() const;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
//! get ownership
|
|
|
|
void add(TProperty *p);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
//! don't get ownership
|
|
|
|
void bind(TProperty &p);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
//! returns 0 if the property doesn't exist
|
|
|
|
TProperty *getProperty(std::string name);
|
|
|
|
TProperty *getProperty(int i) {
|
|
|
|
return (i >= (int)m_properties.size()) ? 0 : m_properties[i].first;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void setProperties(TPropertyGroup *g);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void accept(TProperty::Visitor &v);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int getPropertyCount() const { return (int)m_properties.size(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void loadData(TIStream &is);
|
|
|
|
void saveData(TOStream &os) const;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void clear();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2018-06-04 15:18:43 +12:00
|
|
|
// for adding translation to file writers properties
|
|
|
|
virtual void updateTranslation(){};
|
|
|
|
|
|
|
|
void assignUINames(TPropertyGroup *refPg);
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
PropertyTable m_table;
|
|
|
|
PropertyVector m_properties;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
// not implemented
|
|
|
|
TPropertyGroup(const TPropertyGroup &);
|
|
|
|
TPropertyGroup &operator=(const TPropertyGroup &);
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2017-05-09 00:13:29 +12:00
|
|
|
#ifdef _MSC_VER
|
2016-03-19 06:57:51 +13:00
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|