From bfef688f5da31b4dae5ad4ba30843bda92a37cd6 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: May 01 2023 08:50:43 +0000 Subject: #assistants: TStringId as TProperty::name, add non-transtaled UI name --- diff --git a/toonz/sources/common/tproperty.cpp b/toonz/sources/common/tproperty.cpp index ea5e4f5..3bd89f4 100644 --- a/toonz/sources/common/tproperty.cpp +++ b/toonz/sources/common/tproperty.cpp @@ -51,20 +51,20 @@ TPropertyGroup *TPropertyGroup::clone() const { } void TPropertyGroup::add(TProperty *p) { - std::string name = p->getName(); + const TStringId &name = p->getNameId(); assert(m_table.find(name) == m_table.end()); m_properties.push_back(std::make_pair(p, true)); m_table[name] = p; } void TPropertyGroup::bind(TProperty &p) { - std::string name = p.getName(); + const TStringId &name = p.getNameId(); assert(m_table.find(name) == m_table.end()); m_properties.push_back(std::make_pair(&p, false)); m_table[name] = &p; } -TProperty *TPropertyGroup::getProperty(std::string name) { +TProperty *TPropertyGroup::getProperty(const TStringId &name) { PropertyTable::iterator i = m_table.find(name); if (i == m_table.end()) return 0; diff --git a/toonz/sources/include/tproperty.h b/toonz/sources/include/tproperty.h index 0229761..502165c 100644 --- a/toonz/sources/include/tproperty.h +++ b/toonz/sources/include/tproperty.h @@ -4,6 +4,7 @@ #define TPROPERTY_INCLUDED #include "tconvert.h" +#include "tstringid.h" #include @@ -68,20 +69,28 @@ public: class TypeError {}; class RangeError {}; - TProperty(std::string name) : m_name(name), m_visible(true) { - m_qstringName = QString::fromStdString(name); - } + TProperty(std::string name): + m_name(name), + m_uiNameOrig(name), + m_visible(true), + m_qstringName(QString::fromStdString(name)) + { } virtual ~TProperty() {} virtual TProperty *clone() const = 0; + // Used only for translation in Qt. Original not translated name. + const std::string& getUINameOrig() const { return m_uiNameOrig; } + void setUINameOrig(const std::string &str) { m_uiNameOrig = str; } + // Used only for translation in Qt QString getQStringName() const { return m_qstringName; } void setQStringName(const QString &str) { m_qstringName = str; } virtual void assignUIName(TProperty *refP); - std::string getName() const { return m_name; } + std::string getName() const { return m_name.str(); } + TStringId getNameId() const { return m_name; } virtual std::string getValueAsString() = 0; virtual void accept(Visitor &v) = 0; @@ -90,6 +99,7 @@ public: void removeListener(Listener *listener); void notifyListeners() const; + // Used to pass action name std::string getId() const { return m_id; } void setId(std::string id) { m_id = id; } @@ -97,7 +107,8 @@ public: void setVisible(bool state) { m_visible = state; } private: - std::string m_name; + TStringId m_name; + std::string m_uiNameOrig; QString m_qstringName; std::string m_id; std::vector m_listeners; @@ -370,12 +381,15 @@ public: return ret; } - void addValue(std::wstring value, const QString &iconName = QString()) { + void addValueWithUIName(std::wstring value, const QString &name, const QString &iconName = QString()) { if (m_index == -1) m_index = 0; m_range.push_back(value); - m_items.push_back(Item(QString::fromStdWString(value), iconName)); + m_items.push_back(Item(name, iconName)); } + void addValue(std::wstring value, const QString &iconName = QString()) + { addValueWithUIName(value, 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(); @@ -434,7 +448,7 @@ private: class DVAPI TPropertyGroup { public: typedef std::vector> PropertyVector; - typedef std::map PropertyTable; + typedef std::map PropertyTable; // exception class PropertyNotFoundError {}; @@ -451,10 +465,11 @@ public: void bind(TProperty &p); //! 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; - } + TProperty *getProperty(const TStringId &name); + TProperty *getProperty(const std::string &name) + { return getProperty(TStringId::find(name)); } + TProperty *getProperty(int i) + { return (i >= (int)m_properties.size()) ? 0 : m_properties[i].first; } void setProperties(TPropertyGroup *g);