123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #include "variantfactory.h"
- #include "variantmanager.h"
- #include "PropertyDataLinkEdit.h"
- #include "../vpControls/VControlObject.h"
- VariantFactory::~VariantFactory()
- {
- QList<QWidget *> editors = theEditorToProperty.keys();
- QListIterator<QWidget *> it(editors);
- while (it.hasNext())
- delete it.next();
- }
- /// <summary>
- /// 关联属性管理器
- /// </summary>
- /// <param name="manager"></param>
- void VariantFactory::connectPropertyManager(QtVariantPropertyManager *manager)
- {
- // 将数值和属性变化的信号进行绑定
- connect(manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)),
- this, SLOT(slotPropertyChanged(QtProperty *, const QVariant &)));
- connect(manager, SIGNAL(attributeChanged(QtProperty *, const QString &, const QVariant &)),
- this, SLOT(slotPropertyAttributeChanged(QtProperty *, const QString &, const QVariant &)));
- QtVariantEditorFactory::connectPropertyManager(manager);
- }
- /// <summary>
- /// 通过实现 createEditor 虚函数来为每种不同的类型增加对话框
- /// </summary>
- /// <param name="manager"></param>
- /// <param name="property"></param>
- /// <param name="parent"></param>
- /// <returns></returns>
- #include "objectcontroller.h"
- //#include "VButton.h"
- QWidget *VariantFactory::createEditor(QtVariantPropertyManager *manager,
- QtProperty *property,
- QWidget *parent)
- {
- // 为DataLink类型的属性增加自定义对话框
- if (manager->propertyType(property) == VariantManager::tagDataLinkTypeId())
- {
- // 当前属性控件里的数值
- // QString strValue = manager->value(property).toString();
- // 设置对话框的初始化数据
- //editor->setValue(manager->value(property).toString());
- // 2021-9-14增加,此处保存关联控件的类型名称,用于根据不同类型的控件显示不同的对话框界面
- QObject* pObject = ((ObjectController*)manager->parent())->object();
- VControlObject* pControl = VControlObject::controlPtr(pObject);
- //// 对象类名称(之前是需要通过类名称区分控件类型,现在不需要了)
- //QString strClassname = pObject->metaObject()->className();
- // 变动的属性项的名字,在扩展属性多Link的时候需要用来区分是哪个数据链接有了变动
- QString strPropertyName = property->propertyName();
- // TODO: 此处需要绑定本属性对应的索引号,这样关联的时候才知道这个Edit中的内容该关联到控件的哪个DataLink中
- //editor->setControlClass(strClassname);
- //editor->setControlPtr(pControl);
- // 针对tagDataLinkTypeId 新建对应的自定义属性Edit
- PropertyDataLinkEdit* editor = new PropertyDataLinkEdit(
- parent,
- pControl,
- strPropertyName
- );
- // 保存Edit和Property的对应关系
- theCreatedEditors[property].append(editor);
- theEditorToProperty[editor] = property;
- // 将数值改变消息和对话框销毁消息绑定
- connect(editor, SIGNAL(dataLinkChanged(const QString &)),
- this, SLOT(slotSetValue(const QString &)));
- connect(editor, SIGNAL(destroyed(QObject *)),
- this, SLOT(slotEditorDestroyed(QObject *)));
- qDebug() << "VariantFactory::createEditor - New DesignerPropertyDataLinkEdit with ClassName: " << pObject->metaObject()->className();;
- return editor;
- }
- return QtVariantEditorFactory::createEditor(manager, property, parent);
- }
- void VariantFactory::disconnectPropertyManager(QtVariantPropertyManager *manager)
- {
- disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)),
- this, SLOT(slotPropertyChanged(QtProperty *, const QVariant &)));
- disconnect(manager, SIGNAL(attributeChanged(QtProperty *, const QString &, const QVariant &)),
- this, SLOT(slotPropertyAttributeChanged(QtProperty *, const QString &, const QVariant &)));
- QtVariantEditorFactory::disconnectPropertyManager(manager);
- }
- void VariantFactory::slotPropertyChanged(QtProperty *property, const QVariant &value)
- {
- if (!theCreatedEditors.contains(property))
- return;
- QtVariantPropertyManager *manager = propertyManager(property);
- QList<QWidget *> editors = theCreatedEditors[property];
- QListIterator<QWidget *> itEditor(editors);
- while (itEditor.hasNext())
- {
- if (manager->propertyType(property) == VariantManager::tagDataLinkTypeId())
- {
- // 在属性值变更时,接收到对应的数据类型变更通知,则调用Edit中对应的方法为控件赋值
- PropertyDataLinkEdit*pDataLinkEdit = dynamic_cast<PropertyDataLinkEdit*>(itEditor.next());
- // pTagColorListEdit->setValueColorList(value.toString().split('|'));
- pDataLinkEdit->setValue(value.toString());
- }
- }
- }
- void VariantFactory::slotPropertyAttributeChanged(QtProperty *property,
- const QString &attribute, const QVariant &value)
- {
- Q_UNUSED(attribute);
- Q_UNUSED(value);
- if (!theCreatedEditors.contains(property))
- return;
- QtVariantPropertyManager *manager = propertyManager(property);
- if (manager->propertyType(property) == VariantManager::tagDataLinkTypeId())
- {
- }
- }
- void VariantFactory::slotSetValue(const QString &value)
- {
- QObject *object = sender();
- QMap<QWidget *, QtProperty *>::ConstIterator itEditor = theEditorToProperty.constBegin();
- while (itEditor != theEditorToProperty.constEnd())
- {
- if (itEditor.key() == object)
- {
- QtProperty *property = itEditor.value();
- QtVariantPropertyManager *manager = propertyManager(property);
- if (!manager)
- return;
- // 通过属性设计器给属性赋值
- manager->setValue(property, value);
- qDebug() << "VariantFactory::slotSetValue - " << value;
- return;
- }
- itEditor++;
- }
- }
- void VariantFactory::slotEditorDestroyed(QObject *object)
- {
- QMap<QWidget *, QtProperty *>::ConstIterator itEditor = theEditorToProperty.constBegin();
- while (itEditor != theEditorToProperty.constEnd()) {
- if (itEditor.key() == object) {
- QWidget *editor = itEditor.key();
- QtProperty *property = itEditor.value();
- theEditorToProperty.remove(editor);
- theCreatedEditors[property].removeAll(editor);
- if (theCreatedEditors[property].isEmpty())
- theCreatedEditors.remove(property);
- return;
- }
- itEditor++;
- }
- }
|