void PropertyEditor::slotAddDynamicProperty(QAction *action) { if (!m_propertySheet) return; const QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(m_core->extensionManager(), m_object); if (!dynamicSheet) return; QString newName; QVariant newValue; { // Make sure the dialog is closed before the signal is emitted. const QVariant::Type type = static_cast<QVariant::Type>(action->data().toInt()); NewDynamicPropertyDialog dlg(core()->dialogGui(), m_currentBrowser); if (type != QVariant::Invalid) dlg.setPropertyType(type); QStringList reservedNames; const int propertyCount = m_propertySheet->count(); for (int i = 0; i < propertyCount; i++) { if (!dynamicSheet->isDynamicProperty(i) || m_propertySheet->isVisible(i)) reservedNames.append(m_propertySheet->propertyName(i)); } dlg.setReservedNames(reservedNames); if (dlg.exec() == QDialog::Rejected) return; newName = dlg.propertyName(); newValue = dlg.propertyValue(); } m_recentlyAddedDynamicProperty = newName; emit addDynamicProperty(newName, newValue); }
bool QAbstractDiagramGraphicsItem::setProperty(const QString & name, const QVariant & value) { if (diagram() && diagram()->layers()->isLocked(this)){ return false; } QDiagramMetaProperty metaProperty = m_metadata->property(m_metadata->indexOfProperty(name)); // Check if property is dynamic if (!metaProperty.isValid()){ QVariant currentValue = m_dynamicProperties.value(name); QVariant newValue = itemPropertyChange(name, value); addDynamicProperty(name, newValue); if (currentValue != newValue){ QAbstractDiagram* d = diagram(); if (d && !m_blockUndoCommands){ d->undoStack()->push(new QDiagramChangePropertyCommand(d, (QDiagramShape*)this, name, currentValue, newValue)); } } return false; } if (metaProperty.isReadOnly()){ // Property is read only return false; } QVariant currentValue = m_properties.value(name); QVariant newValue = itemPropertyChange(name, QDiagramProperty::fromVariant(metaProperty.type(), value)); if (currentValue != newValue){ QAbstractDiagram* d = diagram(); if (d && !m_blockUndoCommands){ d->undoStack()->push(new QDiagramChangePropertyCommand(d, (QDiagramShape*)this, name, currentValue, newValue)); return true; } } return false; }
void IObject::sendAddDynamicProperty( const QString &name, const QVariant &value, const QString& propertyGroup, const bool bulkUpdate /*= false*/ ) { if(this->thread() == QThread::currentThread()) { addPropertyGroup(name, propertyGroup); emit addDynamicProperty(name, value, propertyGroup, bulkUpdate); } else { QMetaObject::invokeMethod(this, "sendAddDynamicProperty", Qt::AutoConnection, Q_ARG(const QString&, name), Q_ARG(const QVariant&, value), Q_ARG(const QString&, propertyGroup), Q_ARG(const bool, bulkUpdate)); } }
void QAbstractDiagramGraphicsItem::restoreProperties(const QVariantMap & p) { blockUndoCommands(true); QMapIterator<QString,QVariant> it(p); int index; while(it.hasNext()){ it.next(); index = metaData()->indexOfProperty(it.key()); if (index > -1){ if (metaData()->property(index).type() == QDiagramToolkit::Rect){ if (it.value().canConvert(QVariant::Map)){ if (it.key() == "geometry"){ QVariantMap m = m_properties.value("geometry").toMap(); m["width"] = it.value().toMap().value("width", m.value("width")); m["height"] = it.value().toMap().value("height", m.value("height")); m["x"] = it.value().toMap().value("x").toDouble(); m["y"] = it.value().toMap().value("y").toDouble(); setPos(m.value("x").toDouble(), m.value("y").toDouble()); m_properties[it.key()] = m; } else { m_properties[it.key()] = it.value().toMap(); } } } else if (metaData()->property(index).type() == QDiagramToolkit::String){ m_properties[it.key()] = QString::fromUtf8(it.value().toByteArray()); } else { m_properties[it.key()] = it.value(); } if (it.key() == "zlevel"){ setZValue(it.value().toDouble()); } } else { addDynamicProperty(it.key(), it.value()); m_properties[it.key()] = it.value(); } } blockUndoCommands(false); }