#include "variantmanager.h" // 获取DataLink的TypeID int VariantManager::tagDataLinkTypeId() { return qMetaTypeId(); } // 获取TableExInfo的TypeID int VariantManager::tagTableExInfoTypeId() { return qMetaTypeId(); } 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); } /// /// 为控件赋值 /// /// /// 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(); 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(); 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_; }