void AudioUnitPropertiesWindow::setAudioUnit(AudioUnit *pAudioUnit) { Q_ASSERT(pAudioUnit != nullptr); QtVariantPropertyManager *pPropertyManager = pAudioUnit->propertyManager(); QtVariantProperty *pRootProperty = pAudioUnit->rootProperty(); QList<QtProperty*> subProperties = pRootProperty->subProperties(); for (QtProperty *pProperty : subProperties) { m_pPropertyBrowser->addProperty(pProperty); } m_pPropertyBrowser->setFactoryForManager(pPropertyManager, m_pPropertyFactory); m_pPropertyBrowser->setPropertiesWithoutValueMarked(true); m_pPropertyBrowser->setRootIsDecorated(false); m_pPropertyBrowser->setAlternatingRowColors(true); m_pPropertyBrowser->setResizeMode(QtTreePropertyBrowser::Interactive); setWindowTitle(tr("Properties of '%1'").arg(pAudioUnit->plugin()->name())); }
void PropertyEditor::setObject(QObject *object) { QDesignerFormWindowInterface *oldFormWindow = QDesignerFormWindowInterface::findFormWindow(m_object); // In the first setObject() call following the addition of a dynamic property, focus and edit it. const bool editNewDynamicProperty = object != 0 && m_object == object && !m_recentlyAddedDynamicProperty.isEmpty(); m_object = object; m_propertyManager->setObject(object); QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object); FormWindowBase *fwb = qobject_cast<FormWindowBase *>(formWindow); m_treeFactory->setFormWindowBase(fwb); m_groupFactory->setFormWindowBase(fwb); storeExpansionState(); UpdateBlocker ub(this); updateToolBarLabel(); QMap<QString, QtVariantProperty *> toRemove = m_nameToProperty; const QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(m_core->extensionManager(), m_object); const QDesignerPropertySheet *sheet = qobject_cast<QDesignerPropertySheet*>(m_core->extensionManager()->extension(m_object, Q_TYPEID(QDesignerPropertySheetExtension))); // Optimizization: Instead of rebuilding the complete list every time, compile a list of properties to remove, // remove them, traverse the sheet, in case property exists just set a value, otherwise - create it. QExtensionManager *m = m_core->extensionManager(); m_propertySheet = qobject_cast<QDesignerPropertySheetExtension*>(m->extension(object, Q_TYPEID(QDesignerPropertySheetExtension))); if (m_propertySheet) { const int propertyCount = m_propertySheet->count(); for (int i = 0; i < propertyCount; ++i) { if (!m_propertySheet->isVisible(i)) continue; const QString propertyName = m_propertySheet->propertyName(i); if (m_propertySheet->indexOf(propertyName) != i) continue; const QString groupName = m_propertySheet->propertyGroup(i); const QMap<QString, QtVariantProperty *>::const_iterator rit = toRemove.constFind(propertyName); if (rit != toRemove.constEnd()) { QtVariantProperty *property = rit.value(); if (m_propertyToGroup.value(property) == groupName && toBrowserType(m_propertySheet->property(i), propertyName) == property->propertyType()) toRemove.remove(propertyName); } } } QMapIterator<QString, QtVariantProperty *> itRemove(toRemove); while (itRemove.hasNext()) { itRemove.next(); QtVariantProperty *property = itRemove.value(); m_nameToProperty.remove(itRemove.key()); m_propertyToGroup.remove(property); delete property; } if (oldFormWindow != formWindow) reloadResourceProperties(); bool isMainContainer = false; if (QWidget *widget = qobject_cast<QWidget*>(object)) { if (QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(widget)) { isMainContainer = (fw->mainContainer() == widget); } } m_groups.clear(); if (m_propertySheet) { QtProperty *lastProperty = 0; QtProperty *lastGroup = 0; const int propertyCount = m_propertySheet->count(); for (int i = 0; i < propertyCount; ++i) { if (!m_propertySheet->isVisible(i)) continue; const QString propertyName = m_propertySheet->propertyName(i); if (m_propertySheet->indexOf(propertyName) != i) continue; const QVariant value = m_propertySheet->property(i); const int type = toBrowserType(value, propertyName); QtVariantProperty *property = m_nameToProperty.value(propertyName, 0); bool newProperty = property == 0; if (newProperty) { property = m_propertyManager->addProperty(type, propertyName); if (property) { newProperty = true; if (type == DesignerPropertyManager::enumTypeId()) { const PropertySheetEnumValue e = qvariant_cast<PropertySheetEnumValue>(value); QStringList names; QStringListIterator it(e.metaEnum.keys()); while (it.hasNext()) names.append(it.next()); m_updatingBrowser = true; property->setAttribute(m_strings.m_enumNamesAttribute, names); m_updatingBrowser = false; } else if (type == DesignerPropertyManager::designerFlagTypeId()) { const PropertySheetFlagValue f = qvariant_cast<PropertySheetFlagValue>(value); QList<QPair<QString, uint> > flags; QStringListIterator it(f.metaFlags.keys()); while (it.hasNext()) { const QString name = it.next(); const uint val = f.metaFlags.keyToValue(name); flags.append(qMakePair(name, val)); } m_updatingBrowser = true; QVariant v; qVariantSetValue(v, flags); property->setAttribute(m_strings.m_flagsAttribute, v); m_updatingBrowser = false; } } } if (property != 0) { const bool dynamicProperty = (dynamicSheet && dynamicSheet->isDynamicProperty(i)) || (sheet && sheet->isDefaultDynamicProperty(i)); switch (type) { case QVariant::Palette: setupPaletteProperty(property); break; case QVariant::KeySequence: //addCommentProperty(property, propertyName); break; default: break; } if (type == QVariant::String || type == qMetaTypeId<PropertySheetStringValue>()) setupStringProperty(property, isMainContainer); property->setAttribute(m_strings.m_resettableAttribute, m_propertySheet->hasReset(i)); const QString groupName = m_propertySheet->propertyGroup(i); QtVariantProperty *groupProperty = 0; if (newProperty) { QMap<QString, QtVariantProperty*>::const_iterator itPrev = m_nameToProperty.insert(propertyName, property); m_propertyToGroup[property] = groupName; if (m_sorting) { QtProperty *previous = 0; if (itPrev != m_nameToProperty.constBegin()) previous = (--itPrev).value(); m_currentBrowser->insertProperty(property, previous); } } const QMap<QString, QtVariantProperty*>::const_iterator gnit = m_nameToGroup.constFind(groupName); if (gnit != m_nameToGroup.constEnd()) { groupProperty = gnit.value(); } else { groupProperty = m_propertyManager->addProperty(QtVariantPropertyManager::groupTypeId(), groupName); QtBrowserItem *item = 0; if (!m_sorting) item = m_currentBrowser->insertProperty(groupProperty, lastGroup); m_nameToGroup[groupName] = groupProperty; m_groups.append(groupProperty); if (dynamicProperty) m_dynamicGroup = groupProperty; if (m_currentBrowser == m_treeBrowser && item) { m_treeBrowser->setBackgroundColor(item, propertyColor(groupProperty)); groupProperty->setModified(true); } } /* Group changed or new group. Append to last subproperty of * that group. Note that there are cases in which a derived * property sheet appends fake properties for the class * which will appear after the layout group properties * (QWizardPage). To make them appear at the end of the * actual class group, goto last element. */ if (lastGroup != groupProperty) { lastGroup = groupProperty; lastProperty = 0; // Append at end const QList<QtProperty*> subProperties = lastGroup->subProperties(); if (!subProperties.empty()) lastProperty = subProperties.back(); lastGroup = groupProperty; } if (!m_groups.contains(groupProperty)) m_groups.append(groupProperty); if (newProperty) groupProperty->insertSubProperty(property, lastProperty); lastProperty = property; updateBrowserValue(property, value); property->setModified(m_propertySheet->isChanged(i)); if (propertyName == QLatin1String("geometry") && type == QVariant::Rect) { QList<QtProperty *> subProperties = property->subProperties(); foreach (QtProperty *subProperty, subProperties) { const QString subPropertyName = subProperty->propertyName(); if (subPropertyName == QLatin1String("X") || subPropertyName == QLatin1String("Y")) subProperty->setEnabled(!isMainContainer); } } } else { qWarning("%s", qPrintable(msgUnsupportedType(propertyName, type))); } }