123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
-
- #include "variantmanager.h"
- // 获取DataLink的TypeID
- int VariantManager::tagDataLinkTypeId()
- {
- return qMetaTypeId<DataLink>();
- }
- // 获取TableExInfo的TypeID
- int VariantManager::tagTableExInfoTypeId()
- {
- return qMetaTypeId<CONTROL_PROPERTY_EX>();
- }
- VariantManager::VariantManager(QObject *parent)
- : QtVariantPropertyManager(parent),
- propertyEditor_(Q_NULLPTR)
- {
- }
- VariantManager::~VariantManager()
- {
- }
- bool VariantManager::isPropertyTypeSupported(int propertyType) const
- {
- if (
- propertyType == tagDataLinkTypeId() ||
- propertyType == tagTableExInfoTypeId()
- // propertyType == functionTypeId() ||
-
-
-
-
- // ||
- //propertyType == TagTextListTypeId() ||
- //propertyType == filePathTypeId() ||
- //propertyType == scriptTypeId()
- )
- return true;
- return QtVariantPropertyManager::isPropertyTypeSupported(propertyType);
- }
- int VariantManager::valueType(int propertyType) const
- {
- if (propertyType == tagDataLinkTypeId())
- return QVariant::String;
- return QtVariantPropertyManager::valueType(propertyType);
- }
- QVariant VariantManager::value(const QtProperty *property) const
- {
- if (theValues.contains(property))
- return theValues[property].value;
- return QtVariantPropertyManager::value(property);
- }
- QStringList VariantManager::attributes(int propertyType) const
- {
- //if (propertyType == functionTypeId())
- //{
- // QStringList attr;
- // attr << QLatin1String("supportevents");
- // return attr;
- //} else
- if (propertyType == tagDataLinkTypeId())
- {
- return QtVariantPropertyManager::attributes(propertyType);
- }
- else if (propertyType == tagTableExInfoTypeId())
- {
- return QtVariantPropertyManager::attributes(propertyType);
- //QStringList attr;
- // attr << QLatin1String("TableExInfoTest");
- // return attr;
- }
-
-
- // else if (propertyType == TagTextListTypeId()) {
- // return QtVariantPropertyManager::attributes(propertyType);
- //} else if (propertyType == filePathTypeId()) {
- // QStringList attr;
- // attr << QLatin1String("filter");
- // return attr;
- //} else if (propertyType == scriptTypeId()) {
- // QStringList attr;
- // attr << QLatin1String("supportevents");
- // return attr;
- //}
- return QtVariantPropertyManager::attributes(propertyType);
- }
- int VariantManager::attributeType(int propertyType, const QString &attribute) const
- {
- if (propertyType == tagDataLinkTypeId())
- {
- return QtVariantPropertyManager::attributeType(propertyType, attribute);
- }
- else if (propertyType == tagTableExInfoTypeId())
- {
- return QtVariantPropertyManager::attributeType(propertyType, attribute);
- }
-
- //if (propertyType == functionTypeId()) {
- // if (attribute == QLatin1String("supportevents"))
- // return QVariant::String;
- // return 0;
- //} else if (propertyType == tagColorListTypeId()) {
- // return QtVariantPropertyManager::attributeType(propertyType, attribute);
- //} else if (propertyType == TagTextListTypeId()) {
- // return QtVariantPropertyManager::attributeType(propertyType, attribute);
- //} else if (propertyType == filePathTypeId()) {
- // if (attribute == QLatin1String("filter"))
- // return QVariant::String;
- // return 0;
- //} else if (propertyType == scriptTypeId()) {
- // if (attribute == QLatin1String("supportevents"))
- // return QVariant::String;
- // return 0;
- //}
- return QtVariantPropertyManager::attributeType(propertyType, attribute);
- }
- QVariant VariantManager::attributeValue(const QtProperty *property,
- const QString &attribute) const
- {
- if (theValues.contains(property)) {
- if (attribute == QLatin1String("supportevents"))
- return theValues[property].attribute;
- else if (attribute == QLatin1String("filter"))
- return theValues[property].attribute;
- return QVariant();
- }
- return QtVariantPropertyManager::attributeValue(property, attribute);
- }
- QString VariantManager::valueText(const QtProperty *property) const
- {
- if (theValues.contains(property))
- return theValues[property].value;
- return QtVariantPropertyManager::valueText(property);
- }
- /// <summary>
- /// 为控件赋值
- /// </summary>
- /// <param name="property"></param>
- /// <param name="val"></param>
- void VariantManager::setValue(QtProperty *property, const QVariant &val)
- {
- // qDebug() << "VariantManager::setValue - " << val.toString();
- // 为自定义类型控件属性赋值
- if (theValues.contains(property)) {
- if (val.type() != QVariant::String && !val.canConvert(QVariant::String))
- return;
- QString str = val.value<QString>();
- Data d = theValues[property];
- if (d.value == str)
- return;
- d.value = str;
- theValues[property] = d;
- emit propertyChanged(property);
- emit valueChanged(property, str);
- return;
- }
- // 为通用类型控件属性赋值
- QtVariantPropertyManager::setValue(property, val);
- }
- void VariantManager::setAttribute(QtProperty *property,
- const QString &attribute,
- const QVariant &val)
- {
- if (theValues.contains(property)) {
- if (attribute == QLatin1String("supportevents") ||
- attribute == QLatin1String("filter")) {
- if (val.type() != QVariant::String && !val.canConvert(QVariant::String))
- return;
- QString str = val.value<QString>();
- Data d = theValues[property];
- if (d.attribute == str)
- return;
- d.attribute = str;
- theValues[property] = d;
- emit attributeChanged(property, attribute, str);
- }
- return;
- }
- QtVariantPropertyManager::setAttribute(property, attribute, val);
- }
- void VariantManager::initializeProperty(QtProperty *property)
- {
- //if (propertyType(property) == functionTypeId() ||
- // propertyType(property) == tagColorListTypeId() ||
- // propertyType(property) == TagTextListTypeId() ||
- // propertyType(property) == filePathTypeId() ||
- // propertyType(property) == scriptTypeId()) {
- // theValues[property] = Data();
- //}
- // 初始化自定义类型
- if (propertyType(property) == tagDataLinkTypeId() ||
- propertyType(property) == tagTableExInfoTypeId())
- {
- theValues[property] = Data();
- }
- // 初始化属性列表
- QtVariantPropertyManager::initializeProperty(property);
- }
- void VariantManager::uninitializeProperty(QtProperty *property)
- {
- theValues.remove(property);
- QtVariantPropertyManager::uninitializeProperty(property);
- }
- void VariantManager::setPropertyEditor(QtTreePropertyBrowser *editor)
- {
- if(propertyEditor_ != editor) {
- propertyEditor_ = editor;
- }
- }
- QtTreePropertyBrowser *VariantManager::getPropertyEditor()
- {
- return propertyEditor_;
- }
|