diff --git a/src/plugins/qmldesigner/components/connectioneditor/backendmodel.cpp b/src/plugins/qmldesigner/components/connectioneditor/backendmodel.cpp index 815a3a8c01e..a8bc3376e48 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/backendmodel.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/backendmodel.cpp @@ -11,7 +11,6 @@ #include "nodemetainfo.h" #include "nodeproperty.h" #include "rewriterview.h" -#include "rewritertransaction.h" #include "addnewbackenddialog.h" @@ -20,8 +19,6 @@ namespace QmlDesigner { -namespace Internal { - BackendModel::BackendModel(ConnectionView *parent) : QStandardItemModel(parent) ,m_connectionView(parent) @@ -29,7 +26,7 @@ BackendModel::BackendModel(ConnectionView *parent) : connect(this, &QStandardItemModel::dataChanged, this, &BackendModel::handleDataChanged); } -ConnectionView *QmlDesigner::Internal::BackendModel::connectionView() const +ConnectionView *BackendModel::connectionView() const { return m_connectionView; } @@ -311,6 +308,4 @@ void BackendModel::handleDataChanged(const QModelIndex &topLeft, const QModelInd m_lock = false; } -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/backendmodel.h b/src/plugins/qmldesigner/components/connectioneditor/backendmodel.h index c61a94f2e54..9ba2dbfb0ee 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/backendmodel.h +++ b/src/plugins/qmldesigner/components/connectioneditor/backendmodel.h @@ -8,8 +8,6 @@ namespace QmlDesigner { -namespace Internal { - class ConnectionView; class BackendModel : public QStandardItemModel @@ -47,6 +45,4 @@ private: bool m_lock = false; }; -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/bindingmodel.cpp b/src/plugins/qmldesigner/components/connectioneditor/bindingmodel.cpp index d1acaad0245..c07d6536d60 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/bindingmodel.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/bindingmodel.cpp @@ -18,8 +18,6 @@ namespace QmlDesigner { -namespace Internal { - BindingModel::BindingModel(ConnectionView *parent) : QStandardItemModel(parent) , m_connectionView(parent) @@ -440,6 +438,4 @@ void BindingModel::handleException() resetModel(); } -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/bindingmodel.h b/src/plugins/qmldesigner/components/connectioneditor/bindingmodel.h index 02ab6956c8d..40f0703f267 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/bindingmodel.h +++ b/src/plugins/qmldesigner/components/connectioneditor/bindingmodel.h @@ -11,8 +11,6 @@ namespace QmlDesigner { -namespace Internal { - class ConnectionView; class BindingModel : public QStandardItemModel @@ -65,6 +63,4 @@ private: }; -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp index 5711d696145..075bcf6de12 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp @@ -48,8 +48,6 @@ bool isConnection(const QmlDesigner::ModelNode &modelNode) namespace QmlDesigner { -namespace Internal { - ConnectionModel::ConnectionModel(ConnectionView *parent) : QStandardItemModel(parent) , m_connectionView(parent) @@ -351,7 +349,7 @@ void ConnectionModel::deleteConnectionByRow(int currentRow) { SignalHandlerProperty targetSignal = signalHandlerPropertyForRow(currentRow); QTC_ASSERT(targetSignal.isValid(), return ); - QmlDesigner::ModelNode node = targetSignal.parentModelNode(); + ModelNode node = targetSignal.parentModelNode(); QTC_ASSERT(node.isValid(), return ); QList allSignals = node.signalProperties(); @@ -527,6 +525,4 @@ QStringList ConnectionModel::getPossibleSignalsForConnection(const ModelNode &co return stringList; } -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h index 06a7e1f6e62..a2587bae641 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h @@ -13,8 +13,6 @@ class BindingProperty; class SignalHandlerProperty; class VariantProperty; -namespace Internal { - class ConnectionView; class ConnectionModel : public QStandardItemModel @@ -73,6 +71,4 @@ private: QString m_exceptionError; }; -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionview.cpp b/src/plugins/qmldesigner/components/connectioneditor/connectionview.cpp index a5a790717ea..b837133afd5 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionview.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionview.cpp @@ -22,8 +22,6 @@ namespace QmlDesigner { -namespace Internal { - ConnectionView::ConnectionView(ExternalDependenciesInterface &externalDependencies) : AbstractView{externalDependencies} , m_connectionViewWidget(new ConnectionViewWidget()) @@ -278,6 +276,4 @@ ConnectionView *ConnectionView::instance() return s_instance; } -} // namesapce Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionview.h b/src/plugins/qmldesigner/components/connectioneditor/connectionview.h index a3a0301ebee..f95961653b0 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionview.h +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionview.h @@ -15,8 +15,6 @@ QT_END_NAMESPACE namespace QmlDesigner { -namespace Internal { - class ConnectionViewWidget; class BindingModel; class ConnectionModel; @@ -82,6 +80,4 @@ private: //variables BackendModel *m_backendModel; }; -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.cpp b/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.cpp index 946b31cd530..a071f4e1eb4 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.cpp @@ -34,8 +34,6 @@ namespace QmlDesigner { -namespace Internal { - ConnectionViewWidget::ConnectionViewWidget(QWidget *parent) : QFrame(parent), ui(new Ui::ConnectionViewWidget) @@ -612,6 +610,4 @@ void ConnectionViewWidget::backendTableViewSelectionChanged(const QModelIndex &c } -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.h b/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.h index ed0e9b2f360..c3b63165d84 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.h +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.h @@ -20,8 +20,6 @@ namespace Ui { class ConnectionViewWidget; } class ActionEditor; class BindingEditor; -namespace Internal { - class BindingModel; class ConnectionModel; class DynamicPropertiesModel; @@ -93,6 +91,4 @@ private: QModelIndex m_dynamicIndex; }; -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/delegates.cpp b/src/plugins/qmldesigner/components/connectioneditor/delegates.cpp index ee3981c4965..3ecfea8577a 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/delegates.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/delegates.cpp @@ -20,8 +20,6 @@ namespace QmlDesigner { -namespace Internal { - QStringList prependOnForSignalHandler(const QStringList &signalNames) { QStringList signalHandlerNames; @@ -408,6 +406,4 @@ QWidget *BackendDelegate::createEditor(QWidget *parent, const QStyleOptionViewIt return widget; } -} // namesapce Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/delegates.h b/src/plugins/qmldesigner/components/connectioneditor/delegates.h index 030f56d222c..dcdc55fce9e 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/delegates.h +++ b/src/plugins/qmldesigner/components/connectioneditor/delegates.h @@ -9,8 +9,6 @@ namespace QmlDesigner { -namespace Internal { - class PropertiesComboBox : public QComboBox { Q_OBJECT @@ -77,6 +75,4 @@ public: const QModelIndex &index) const override; }; -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/dynamicpropertiesmodel.cpp b/src/plugins/qmldesigner/components/connectioneditor/dynamicpropertiesmodel.cpp index 40a130e846e..44dd2ad1d2f 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/dynamicpropertiesmodel.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/dynamicpropertiesmodel.cpp @@ -3,32 +3,32 @@ #include "dynamicpropertiesmodel.h" -#include "connectionview.h" - -#include -#include -#include -#include -#include -#include -#include -#include +#include "bindingproperty.h" +#include "nodeabstractproperty.h" +#include "nodemetainfo.h" +#include "qmlchangeset.h" +#include "qmldesignerconstants.h" +#include "qmldesignerplugin.h" +#include "qmlobjectnode.h" +#include "qmltimeline.h" +#include "rewritertransaction.h" +#include "rewritingexception.h" +#include "variantproperty.h" #include -#include #include #include #include -#include namespace { -bool compareVariantProperties(const QmlDesigner::VariantProperty &variantProperty01, const QmlDesigner::VariantProperty &variantProperty02) +bool compareVariantProperties(const QmlDesigner::VariantProperty &variantProp1, + const QmlDesigner::VariantProperty &variantProp2) { - if (variantProperty01.parentModelNode() != variantProperty02.parentModelNode()) + if (variantProp1.parentModelNode() != variantProp2.parentModelNode()) return false; - if (variantProperty01.name() != variantProperty02.name()) + if (variantProp1.name() != variantProp2.name()) return false; return true; } @@ -87,22 +87,19 @@ QVariant convertVariantForTypeName(const QVariant &variant, const QmlDesigner::T return returnValue; } -} //internal namespace +} // namespace namespace QmlDesigner { -namespace Internal { - -QmlDesigner::PropertyName DynamicPropertiesModel::unusedProperty(const QmlDesigner::ModelNode &modelNode) +PropertyName DynamicPropertiesModel::unusedProperty(const ModelNode &modelNode) { - QmlDesigner::PropertyName propertyName = "property"; + PropertyName propertyName = "property"; int i = 0; if (modelNode.isValid() && modelNode.metaInfo().isValid()) { while (true) { - const QmlDesigner::PropertyName currentPropertyName = propertyName + QString::number(i).toLatin1(); + const PropertyName currentPropertyName = propertyName + QString::number(i++).toLatin1(); if (!modelNode.hasProperty(currentPropertyName) && !modelNode.metaInfo().hasProperty(currentPropertyName)) return currentPropertyName; - i++; } } @@ -167,8 +164,7 @@ void DynamicPropertiesModel::resetModel() { beginResetModel(); clear(); - setHorizontalHeaderLabels( - QStringList({tr("Item"), tr("Property"), tr("Property Type"), tr("Property Value")})); + setHorizontalHeaderLabels({tr("Item"), tr("Property"), tr("Property Type"), tr("Property Value")}); if (m_view->isAttached()) { const auto nodes = selectedNodes(); @@ -180,8 +176,8 @@ void DynamicPropertiesModel::resetModel() } -//Method creates dynamic BindingProperty with the same name and type as old VariantProperty -//Value copying is optional +// Method creates dynamic BindingProperty with the same name and type as old VariantProperty +// Value copying is optional BindingProperty DynamicPropertiesModel::replaceVariantWithBinding(const PropertyName &name, bool copyValue) { if (selectedNodes().count() == 1) { @@ -211,12 +207,11 @@ BindingProperty DynamicPropertiesModel::replaceVariantWithBinding(const Property qWarning() << "DynamicPropertiesModel::replaceVariantWithBinding: no selected nodes"; } - return BindingProperty(); + return {}; } - -//Finds selected property, and changes it to empty value (QVariant()) -//If it's a BindingProperty, then replaces it with empty VariantProperty +// Finds selected property, and changes it to empty value (QVariant()) +// If it's a BindingProperty, then replaces it with empty VariantProperty void DynamicPropertiesModel::resetProperty(const PropertyName &name) { if (selectedNodes().count() == 1) { @@ -235,7 +230,7 @@ void DynamicPropertiesModel::resetProperty(const PropertyName &name) BindingProperty property = abProp.toBindingProperty(); TypeName oldType = property.dynamicTypeName(); - //removing old property, to create the new one with the same name: + // removing old property, to create the new one with the same name modelNode.removeProperty(name); VariantProperty newProperty = modelNode.variantProperty(name); @@ -249,8 +244,7 @@ void DynamicPropertiesModel::resetProperty(const PropertyName &name) } } } - } - else { + } else { qWarning() << "DynamicPropertiesModel::resetProperty: no selected nodes"; } } @@ -279,14 +273,14 @@ void DynamicPropertiesModel::bindingPropertyChanged(const BindingProperty &bindi const QList nodes = selectedNodes(); if (!nodes.contains(bindingProperty.parentModelNode())) return; + if (!m_lock) { int rowNumber = findRowForBindingProperty(bindingProperty); - if (rowNumber == -1) { + if (rowNumber == -1) addBindingProperty(bindingProperty); - } else { + else updateBindingProperty(rowNumber); - } } m_handleDataChanged = true; @@ -302,6 +296,7 @@ void DynamicPropertiesModel::abstractPropertyChanged(const AbstractProperty &pro const QList nodes = selectedNodes(); if (!nodes.contains(property.parentModelNode())) return; + int rowNumber = findRowForProperty(property); if (rowNumber > -1) { if (property.isVariantProperty()) @@ -323,6 +318,7 @@ void DynamicPropertiesModel::variantPropertyChanged(const VariantProperty &varia const QList nodes = selectedNodes(); if (!nodes.contains(variantProperty.parentModelNode())) return; + if (!m_lock) { int rowNumber = findRowForVariantProperty(variantProperty); @@ -342,6 +338,7 @@ void DynamicPropertiesModel::bindingRemoved(const BindingProperty &bindingProper const QList nodes = selectedNodes(); if (!nodes.contains(bindingProperty.parentModelNode())) return; + if (!m_lock) { int rowNumber = findRowForBindingProperty(bindingProperty); removeRow(rowNumber); @@ -357,6 +354,7 @@ void DynamicPropertiesModel::variantRemoved(const VariantProperty &variantProper const QList nodes = selectedNodes(); if (!nodes.contains(variantProperty.parentModelNode())) return; + if (!m_lock) { int rowNumber = findRowForVariantProperty(variantProperty); removeRow(rowNumber); @@ -398,7 +396,7 @@ AbstractProperty DynamicPropertiesModel::abstractPropertyForRow(int rowNumber) c if (modelNode.isValid()) return modelNode.property(targetPropertyName.toUtf8()); - return AbstractProperty(); + return {}; } BindingProperty DynamicPropertiesModel::bindingPropertyForRow(int rowNumber) const @@ -411,7 +409,7 @@ BindingProperty DynamicPropertiesModel::bindingPropertyForRow(int rowNumber) con if (modelNode.isValid()) return modelNode.bindingProperty(targetPropertyName.toUtf8()); - return BindingProperty(); + return {}; } VariantProperty DynamicPropertiesModel::variantPropertyForRow(int rowNumber) const @@ -424,7 +422,7 @@ VariantProperty DynamicPropertiesModel::variantPropertyForRow(int rowNumber) con if (modelNode.isValid()) return modelNode.variantProperty(targetPropertyName.toUtf8()); - return VariantProperty(); + return {}; } QStringList DynamicPropertiesModel::possibleTargetProperties(const BindingProperty &bindingProperty) const @@ -440,7 +438,8 @@ QStringList DynamicPropertiesModel::possibleTargetProperties(const BindingProper if (metaInfo.isValid()) { QStringList possibleProperties; - for (const auto &property : metaInfo.properties()) { + const PropertyMetaInfos props = metaInfo.properties(); + for (const auto &property : props) { if (property.isWritable()) possibleProperties.push_back(QString::fromUtf8(property.name())); } @@ -448,7 +447,7 @@ QStringList DynamicPropertiesModel::possibleTargetProperties(const BindingProper return possibleProperties; } - return QStringList(); + return {}; } void DynamicPropertiesModel::addDynamicPropertyForCurrentNode() @@ -477,11 +476,10 @@ QStringList DynamicPropertiesModel::possibleSourceProperties(const BindingProper NodeMetaInfo type; - if (auto metaInfo = bindingProperty.parentModelNode().metaInfo(); metaInfo.isValid()) { + if (auto metaInfo = bindingProperty.parentModelNode().metaInfo(); metaInfo.isValid()) type = metaInfo.property(bindingProperty.name()).propertyType(); - } else { + else qWarning() << " BindingModel::possibleSourcePropertiesForRow no meta info for target node"; - } const QString &id = stringlist.constFirst(); @@ -496,8 +494,9 @@ QStringList DynamicPropertiesModel::possibleSourceProperties(const BindingProper if (metaInfo.isValid()) { QStringList possibleProperties; - for (const auto &property : metaInfo.properties()) { - if (property.propertyType() == type) //### todo proper check + const PropertyMetaInfos props = metaInfo.properties(); + for (const auto &property : props) { + if (property.propertyType() == type) // TODO: proper check possibleProperties.push_back(QString::fromUtf8(property.name())); } return possibleProperties; @@ -505,40 +504,39 @@ QStringList DynamicPropertiesModel::possibleSourceProperties(const BindingProper qWarning() << " BindingModel::possibleSourcePropertiesForRow no meta info for source node"; } - return QStringList(); + return {}; } void DynamicPropertiesModel::deleteDynamicPropertyByRow(int rowNumber) { - m_view->executeInTransaction( - "DynamicPropertiesModel::deleteDynamicPropertyByRow", [this, rowNumber]() { - const AbstractProperty property = abstractPropertyForRow(rowNumber); - const PropertyName propertyName = property.name(); - BindingProperty bindingProperty = bindingPropertyForRow(rowNumber); - if (bindingProperty.isValid()) { - bindingProperty.parentModelNode().removeProperty(bindingProperty.name()); - } else { - VariantProperty variantProperty = variantPropertyForRow(rowNumber); - if (variantProperty.isValid()) - variantProperty.parentModelNode().removeProperty(variantProperty.name()); + m_view->executeInTransaction(__FUNCTION__, [this, rowNumber]() { + const AbstractProperty property = abstractPropertyForRow(rowNumber); + const PropertyName propertyName = property.name(); + BindingProperty bindingProperty = bindingPropertyForRow(rowNumber); + if (bindingProperty.isValid()) { + bindingProperty.parentModelNode().removeProperty(bindingProperty.name()); + } else { + VariantProperty variantProperty = variantPropertyForRow(rowNumber); + if (variantProperty.isValid()) + variantProperty.parentModelNode().removeProperty(variantProperty.name()); + } + + if (property.isValid()) { + QmlObjectNode objectNode = QmlObjectNode(property.parentModelNode()); + const auto stateOperations = objectNode.allAffectingStatesOperations(); + for (const QmlModelStateOperation &stateOperation : stateOperations) { + if (stateOperation.modelNode().hasProperty(propertyName)) + stateOperation.modelNode().removeProperty(propertyName); } - if (property.isValid()) { - QmlObjectNode objectNode = QmlObjectNode(property.parentModelNode()); - const auto stateOperations = objectNode.allAffectingStatesOperations(); - for (const QmlModelStateOperation &stateOperation : stateOperations) { - if (stateOperation.modelNode().hasProperty(propertyName)) - stateOperation.modelNode().removeProperty(propertyName); - } - - const auto timelineNodes = objectNode.allTimelines(); - for (auto &timelineNode : timelineNodes) { - QmlTimeline timeline(timelineNode); - timeline.removeKeyframesForTargetAndProperty(objectNode.modelNode(), - propertyName); - } + const QList timelineNodes = objectNode.allTimelines(); + for (auto &timelineNode : timelineNodes) { + QmlTimeline timeline(timelineNode); + timeline.removeKeyframesForTargetAndProperty(objectNode.modelNode(), + propertyName); } - }); + } + }); resetModel(); } @@ -570,7 +568,7 @@ void DynamicPropertiesModel::addProperty(const QVariant &propertyValue, propertyValueItem->setData(propertyValue, Qt::DisplayRole); items.append(propertyValueItem); - for (int i =0; i < rowCount(); i++) { + for (int i = 0; i < rowCount(); ++i) { if (data(index(i, PropertyNameRow)).toString() > propName) { insertRow(i, items); return; @@ -628,7 +626,6 @@ void DynamicPropertiesModel::updateVariantProperty(int rowNumber) if (objectNode.isValid() && !objectNode.view()->currentState().isBaseState()) value = objectNode.modelValue(variantProperty.name()); - updateDisplayRoleFromVariant(rowNumber, PropertyValueRow, value); } } @@ -638,9 +635,8 @@ void DynamicPropertiesModel::addModelNode(const ModelNode &modelNode) if (!modelNode.isValid()) return; - auto properties = modelNode.properties(); - - auto dynamicProperties = Utils::filtered(properties, [](const AbstractProperty &p) { + const QList properties = modelNode.properties(); + QList dynamicProperties = Utils::filtered(properties, [](const AbstractProperty &p) { return p.isDynamic(); }); @@ -663,10 +659,10 @@ void DynamicPropertiesModel::updateValue(int row) if (bindingProperty.isBindingProperty()) { const QString expression = data(index(row, PropertyValueRow)).toString(); - RewriterTransaction transaction = m_view->beginRewriterTransaction(QByteArrayLiteral("DynamicPropertiesModel::updateValue")); + RewriterTransaction transaction = m_view->beginRewriterTransaction(__FUNCTION__); try { bindingProperty.setDynamicTypeNameAndExpression(bindingProperty.dynamicTypeName(), expression); - transaction.commit(); //committing in the try block + transaction.commit(); // committing in the try block } catch (Exception &e) { m_exceptionError = e.description(); QTimer::singleShot(200, this, &DynamicPropertiesModel::handleException); @@ -679,10 +675,10 @@ void DynamicPropertiesModel::updateValue(int row) if (variantProperty.isVariantProperty()) { const QVariant value = data(index(row, PropertyValueRow)); - RewriterTransaction transaction = m_view->beginRewriterTransaction(QByteArrayLiteral("DynamicPropertiesModel::updateValue")); + RewriterTransaction transaction = m_view->beginRewriterTransaction(__FUNCTION__); try { variantProperty.setDynamicTypeNameAndValue(variantProperty.dynamicTypeName(), value); - transaction.commit(); //committing in the try block + transaction.commit(); // committing in the try block } catch (Exception &e) { m_exceptionError = e.description(); QTimer::singleShot(200, this, &DynamicPropertiesModel::handleException); @@ -693,17 +689,14 @@ void DynamicPropertiesModel::updateValue(int row) void DynamicPropertiesModel::updatePropertyName(int rowNumber) { const PropertyName newName = data(index(rowNumber, PropertyNameRow)).toString().toUtf8(); - if (newName.isEmpty()) { - qWarning() << "DynamicPropertiesModel::updatePropertyName invalid property name"; - return; - } + QTC_ASSERT(!newName.isEmpty(), return); BindingProperty bindingProperty = bindingPropertyForRow(rowNumber); ModelNode targetNode = bindingProperty.parentModelNode(); if (bindingProperty.isBindingProperty()) { - m_view->executeInTransaction("DynamicPropertiesModel::updatePropertyName", [bindingProperty, newName, &targetNode](){ + m_view->executeInTransaction(__FUNCTION__, [bindingProperty, newName, &targetNode]() { const QString expression = bindingProperty.expression(); const PropertyName dynamicPropertyType = bindingProperty.dynamicTypeName(); @@ -722,7 +715,7 @@ void DynamicPropertiesModel::updatePropertyName(int rowNumber) const PropertyName dynamicPropertyType = variantProperty.dynamicTypeName(); ModelNode targetNode = variantProperty.parentModelNode(); - m_view->executeInTransaction("DynamicPropertiesModel::updatePropertyName", [=](){ + m_view->executeInTransaction(__FUNCTION__, [=]() { targetNode.variantProperty(newName).setDynamicTypeNameAndValue(dynamicPropertyType, value); targetNode.removeProperty(variantProperty.name()); }); @@ -733,13 +726,8 @@ void DynamicPropertiesModel::updatePropertyName(int rowNumber) void DynamicPropertiesModel::updatePropertyType(int rowNumber) { - const TypeName newType = data(index(rowNumber, PropertyTypeRow)).toString().toLatin1(); - - if (newType.isEmpty()) { - qWarning() << "DynamicPropertiesModel::updatePropertyName invalid property type"; - return; - } + QTC_ASSERT(!newType.isEmpty(), return); BindingProperty bindingProperty = bindingPropertyForRow(rowNumber); @@ -748,7 +736,7 @@ void DynamicPropertiesModel::updatePropertyType(int rowNumber) const PropertyName propertyName = bindingProperty.name(); ModelNode targetNode = bindingProperty.parentModelNode(); - m_view->executeInTransaction("DynamicPropertiesModel::updatePropertyType", [=](){ + m_view->executeInTransaction(__FUNCTION__, [=]() { targetNode.removeProperty(bindingProperty.name()); targetNode.bindingProperty(propertyName).setDynamicTypeNameAndExpression(newType, expression); }); @@ -764,7 +752,7 @@ void DynamicPropertiesModel::updatePropertyType(int rowNumber) ModelNode targetNode = variantProperty.parentModelNode(); const PropertyName propertyName = variantProperty.name(); - m_view->executeInTransaction("DynamicPropertiesModel::updatePropertyType", [=](){ + m_view->executeInTransaction(__FUNCTION__, [=]() { targetNode.removeProperty(variantProperty.name()); if (!isValueType(newType)) { targetNode.bindingProperty(propertyName).setDynamicTypeNameAndExpression( @@ -777,26 +765,22 @@ void DynamicPropertiesModel::updatePropertyType(int rowNumber) updateCustomData(rowNumber, targetNode.variantProperty(propertyName)); - if (variantProperty.isVariantProperty()) { + if (variantProperty.isVariantProperty()) updateVariantProperty(rowNumber); - } else if (bindingProperty.isBindingProperty()) { + else if (bindingProperty.isBindingProperty()) updateBindingProperty(rowNumber); - } } } ModelNode DynamicPropertiesModel::getNodeByIdOrParent(const QString &id, const ModelNode &targetNode) const { - ModelNode modelNode; + if (id != QLatin1String("parent")) + return m_view->modelNodeForId(id); - if (id != QLatin1String("parent")) { - modelNode = m_view->modelNodeForId(id); - } else { - if (targetNode.hasParentProperty()) { - modelNode = targetNode.parentProperty().parentModelNode(); - } - } - return modelNode; + if (targetNode.hasParentProperty()) + return targetNode.parentProperty().parentModelNode(); + + return {}; } void DynamicPropertiesModel::updateCustomData(QStandardItem *item, const AbstractProperty &property) @@ -813,54 +797,56 @@ void DynamicPropertiesModel::updateCustomData(int row, const AbstractProperty &p int DynamicPropertiesModel::findRowForBindingProperty(const BindingProperty &bindingProperty) const { - for (int i=0; i < rowCount(); i++) { + for (int i = 0; i < rowCount(); ++i) { if (compareBindingProperties(bindingPropertyForRow(i), bindingProperty)) return i; } - //not found - return -1; + + return -1; // not found } int DynamicPropertiesModel::findRowForVariantProperty(const VariantProperty &variantProperty) const { - for (int i=0; i < rowCount(); i++) { + for (int i = 0; i < rowCount(); ++i) { if (compareVariantProperties(variantPropertyForRow(i), variantProperty)) return i; } - //not found - return -1; + + return -1; // not found } int DynamicPropertiesModel::findRowForProperty(const AbstractProperty &abstractProperty) const { - for (int i = 0; i < rowCount(); i++) { + for (int i = 0; i < rowCount(); ++i) { if ((abstractPropertyForRow(i).name() == abstractProperty.name())) return i; } - //not found - return -1; + + return -1; // not found } -bool DynamicPropertiesModel::getExpressionStrings(const BindingProperty &bindingProperty, QString *sourceNode, QString *sourceProperty) +bool DynamicPropertiesModel::getExpressionStrings(const BindingProperty &bindingProperty, QString *sourceNode, + QString *sourceProperty) { - //### todo we assume no expressions yet + // TODO: we assume no expressions yet const QString expression = bindingProperty.expression(); if (true) { - const QStringList stringList = expression.split(QLatin1String(".")); + const QStringList expressionParts = expression.split('.'); - *sourceNode = stringList.constFirst(); + *sourceNode = expressionParts.constFirst(); QString propertyName; - for (int i=1; i < stringList.count(); i++) { - propertyName += stringList.at(i); - if (i != stringList.count() - 1) + for (int i = 1; i < expressionParts.count(); ++i) { + propertyName += expressionParts.at(i); + if (i != expressionParts.count() - 1) propertyName += QLatin1String("."); } *sourceProperty = propertyName; } + return true; } @@ -885,7 +871,7 @@ void DynamicPropertiesModel::handleDataChanged(const QModelIndex &topLeft, const return; if (topLeft != bottomRight) { - qWarning() << "BindingModel::handleDataChanged multi edit?"; + qWarning() << __FUNCTION__ << ": multi edit?"; return; } @@ -896,7 +882,7 @@ void DynamicPropertiesModel::handleDataChanged(const QModelIndex &topLeft, const switch (currentColumn) { case TargetModelNodeRow: { - //updating user data + // updating user data } break; case PropertyNameRow: { updatePropertyName(currentRow); @@ -908,7 +894,7 @@ void DynamicPropertiesModel::handleDataChanged(const QModelIndex &topLeft, const updateValue(currentRow); } break; - default: qWarning() << "BindingModel::handleDataChanged column" << currentColumn; + default: qWarning() << __FUNCTION__ << " column" << currentColumn; } m_lock = false; @@ -926,18 +912,16 @@ const QList DynamicPropertiesModel::selectedNodes() const // Otherwise return actual selected nodes of the model. if (m_explicitSelection) return m_selectedNodes; - else - return m_view->selectedModelNodes(); + + return m_view->selectedModelNodes(); } const ModelNode DynamicPropertiesModel::singleSelectedNode() const { if (m_explicitSelection) return m_selectedNodes.first(); - else - return m_view->singleSelectedModelNode(); + + return m_view->singleSelectedModelNode(); } -} // namespace Internal - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/dynamicpropertiesmodel.h b/src/plugins/qmldesigner/components/connectioneditor/dynamicpropertiesmodel.h index 41dee31a84a..0e9b36ee71a 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/dynamicpropertiesmodel.h +++ b/src/plugins/qmldesigner/components/connectioneditor/dynamicpropertiesmodel.h @@ -3,17 +3,17 @@ #pragma once -#include -#include -#include +#include #include namespace QmlDesigner { +class AbstractProperty; class AbstractView; - -namespace Internal { +class BindingProperty; +class ModelNode; +class VariantProperty; class DynamicPropertiesModel : public QStandardItemModel { @@ -22,11 +22,13 @@ class DynamicPropertiesModel : public QStandardItemModel public: enum ColumnRoles { TargetModelNodeRow = 0, - PropertyNameRow = 1, - PropertyTypeRow = 2, - PropertyValueRow = 3 + PropertyNameRow = 1, + PropertyTypeRow = 2, + PropertyValueRow = 3 }; + DynamicPropertiesModel(bool explicitSelection, AbstractView *parent); + void bindingPropertyChanged(const BindingProperty &bindingProperty); void abstractPropertyChanged(const AbstractProperty &bindingProperty); void variantPropertyChanged(const VariantProperty &variantProperty); @@ -54,7 +56,7 @@ public: void dispatchPropertyChanges(const AbstractProperty &abstractProperty); - QmlDesigner::PropertyName unusedProperty(const QmlDesigner::ModelNode &modelNode); + PropertyName unusedProperty(const ModelNode &modelNode); static bool isValueType(const TypeName &type); static QVariant defaultValueForType(const TypeName &type); @@ -84,7 +86,7 @@ protected: void updateDisplayRole(int row, int columns, const QString &string); private: - void handleDataChanged(const QModelIndex &topLeft, const QModelIndex& bottomRight); + void handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); void handleException(); AbstractView *m_view = nullptr; @@ -95,5 +97,4 @@ private: bool m_explicitSelection = false; }; -} // namespace Internal } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/selectiondynamicpropertiesproxymodel.cpp b/src/plugins/qmldesigner/components/connectioneditor/selectiondynamicpropertiesproxymodel.cpp index 7232e834132..80cd732a9ba 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/selectiondynamicpropertiesproxymodel.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/selectiondynamicpropertiesproxymodel.cpp @@ -28,7 +28,7 @@ #include #include -using namespace QmlDesigner::Internal; +namespace QmlDesigner { SelectionDynamicPropertiesProxyModel::SelectionDynamicPropertiesProxyModel(QObject *parent) : DynamicPropertiesProxyModel(parent) @@ -42,3 +42,5 @@ void SelectionDynamicPropertiesProxyModel::registerDeclarativeType() DynamicPropertiesProxyModel::registerDeclarativeType(); qmlRegisterType("HelperWidgets", 2, 0, "SelectionDynamicPropertiesModel"); } + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/connectioneditor/selectiondynamicpropertiesproxymodel.h b/src/plugins/qmldesigner/components/connectioneditor/selectiondynamicpropertiesproxymodel.h index 124846dc860..8957abe5aff 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/selectiondynamicpropertiesproxymodel.h +++ b/src/plugins/qmldesigner/components/connectioneditor/selectiondynamicpropertiesproxymodel.h @@ -27,6 +27,8 @@ #include +namespace QmlDesigner { + class SelectionDynamicPropertiesProxyModel : public DynamicPropertiesProxyModel { Q_OBJECT @@ -35,3 +37,5 @@ public: static void registerDeclarativeType(); }; + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/materialeditor/materialeditordynamicpropertiesproxymodel.cpp b/src/plugins/qmldesigner/components/materialeditor/materialeditordynamicpropertiesproxymodel.cpp index 147ecd1d5f0..c59ca61ff1e 100644 --- a/src/plugins/qmldesigner/components/materialeditor/materialeditordynamicpropertiesproxymodel.cpp +++ b/src/plugins/qmldesigner/components/materialeditor/materialeditordynamicpropertiesproxymodel.cpp @@ -29,7 +29,7 @@ #include -using namespace QmlDesigner; +namespace QmlDesigner { MaterialEditorDynamicPropertiesProxyModel::MaterialEditorDynamicPropertiesProxyModel(QObject *parent) : DynamicPropertiesProxyModel(parent) @@ -43,3 +43,5 @@ void MaterialEditorDynamicPropertiesProxyModel::registerDeclarativeType() DynamicPropertiesProxyModel::registerDeclarativeType(); qmlRegisterType("HelperWidgets", 2, 0, "MaterialEditorDynamicPropertiesModel"); } + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/materialeditor/materialeditordynamicpropertiesproxymodel.h b/src/plugins/qmldesigner/components/materialeditor/materialeditordynamicpropertiesproxymodel.h index 9d4e6aa9a47..d2add25c65c 100644 --- a/src/plugins/qmldesigner/components/materialeditor/materialeditordynamicpropertiesproxymodel.h +++ b/src/plugins/qmldesigner/components/materialeditor/materialeditordynamicpropertiesproxymodel.h @@ -27,6 +27,8 @@ #include "dynamicpropertiesproxymodel.h" +namespace QmlDesigner { + class MaterialEditorDynamicPropertiesProxyModel : public DynamicPropertiesProxyModel { Q_OBJECT @@ -35,3 +37,5 @@ public: static void registerDeclarativeType(); }; + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp b/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp index 5c6308d15bf..f49d9429d86 100644 --- a/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp +++ b/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp @@ -43,7 +43,7 @@ namespace QmlDesigner { MaterialEditorView::MaterialEditorView(ExternalDependenciesInterface &externalDependencies) : AbstractView{externalDependencies} , m_stackedWidget(new QStackedWidget) - , m_dynamicPropertiesModel(new Internal::DynamicPropertiesModel(true, this)) + , m_dynamicPropertiesModel(new DynamicPropertiesModel(true, this)) { m_updateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F7), m_stackedWidget); connect(m_updateShortcut, &QShortcut::activated, this, &MaterialEditorView::reloadQml); @@ -290,7 +290,7 @@ void MaterialEditorView::currentTimelineChanged(const ModelNode &) m_qmlBackEnd->contextObject()->setHasActiveTimeline(QmlTimeline::hasActiveTimeline(this)); } -Internal::DynamicPropertiesModel *MaterialEditorView::dynamicPropertiesModel() const +DynamicPropertiesModel *MaterialEditorView::dynamicPropertiesModel() const { return m_dynamicPropertiesModel; } diff --git a/src/plugins/qmldesigner/components/materialeditor/materialeditorview.h b/src/plugins/qmldesigner/components/materialeditor/materialeditorview.h index e0733a34caf..d74f9e01e5e 100644 --- a/src/plugins/qmldesigner/components/materialeditor/materialeditorview.h +++ b/src/plugins/qmldesigner/components/materialeditor/materialeditorview.h @@ -18,13 +18,10 @@ QT_END_NAMESPACE namespace QmlDesigner { +class DynamicPropertiesModel; class ItemLibraryInfo; class MaterialEditorQmlBackend; -namespace Internal { -class DynamicPropertiesModel; -} - class MaterialEditorView : public AbstractView { Q_OBJECT @@ -78,7 +75,7 @@ public: void currentTimelineChanged(const ModelNode &node) override; - Internal::DynamicPropertiesModel *dynamicPropertiesModel() const; + DynamicPropertiesModel *dynamicPropertiesModel() const; static MaterialEditorView *instance(); @@ -132,7 +129,7 @@ private: QPointer m_colorDialog; QPointer m_itemLibraryInfo; - Internal::DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr; + DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr; }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/propertyeditor/dynamicpropertiesproxymodel.cpp b/src/plugins/qmldesigner/components/propertyeditor/dynamicpropertiesproxymodel.cpp index eea11429afa..689753ff8be 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/dynamicpropertiesproxymodel.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/dynamicpropertiesproxymodel.cpp @@ -25,6 +25,7 @@ #include "dynamicpropertiesproxymodel.h" +#include "bindingproperty.h" #include "propertyeditorvalue.h" #include @@ -40,7 +41,7 @@ #include -using namespace QmlDesigner; +namespace QmlDesigner { static const int propertyNameRole = Qt::UserRole + 1; static const int propertyTypeRole = Qt::UserRole + 2; @@ -52,7 +53,7 @@ DynamicPropertiesProxyModel::DynamicPropertiesProxyModel(QObject *parent) { } -void DynamicPropertiesProxyModel::initModel(QmlDesigner::Internal::DynamicPropertiesModel *model) +void DynamicPropertiesProxyModel::initModel(DynamicPropertiesModel *model) { m_model = model; @@ -79,17 +80,14 @@ void DynamicPropertiesProxyModel::initModel(QmlDesigner::Internal::DynamicProper int DynamicPropertiesProxyModel::rowCount(const QModelIndex &) const { - if (!m_model) - return 0; - - return m_model->rowCount(); + return m_model ? m_model->rowCount() : 0; } QHash DynamicPropertiesProxyModel::roleNames() const { - static QHash roleNames{{propertyNameRole, "propertyName"}, - {propertyTypeRole, "propertyType"}, - {propertyValueRole, "propertyValue"}, + static QHash roleNames{{propertyNameRole, "propertyName"}, + {propertyTypeRole, "propertyType"}, + {propertyValueRole, "propertyValue"}, {propertyBindingRole, "propertyBinding"}}; return roleNames; @@ -102,26 +100,30 @@ QVariant DynamicPropertiesProxyModel::data(const QModelIndex &index, int role) c QTC_ASSERT(property.isValid(), return QVariant()); - if (role == propertyNameRole) { + if (role == propertyNameRole) return property.name(); - } else if (propertyTypeRole) { + + if (propertyTypeRole) return property.dynamicTypeName(); - } else if (role == propertyValueRole) { + + if (role == propertyValueRole) { QmlObjectNode objectNode = property.parentQmlObjectNode(); return objectNode.modelValue(property.name()); - } else if (role == propertyBindingRole) { - if (property.isBindingProperty()) { - QmlObjectNode objectNode = property.parentQmlObjectNode(); - return objectNode.expression(property.name()); - } - return QVariant(); } + + if (role == propertyBindingRole) { + if (property.isBindingProperty()) + return property.parentQmlObjectNode().expression(property.name()); + + return {}; + } + qWarning() << Q_FUNC_INFO << "invalid role"; } else { qWarning() << Q_FUNC_INFO << "invalid index"; } - return QVariant(); + return {}; } void DynamicPropertiesProxyModel::registerDeclarativeType() @@ -131,17 +133,16 @@ void DynamicPropertiesProxyModel::registerDeclarativeType() qmlRegisterType("HelperWidgets", 2, 0, "DynamicPropertiesModel"); } -QmlDesigner::Internal::DynamicPropertiesModel *DynamicPropertiesProxyModel::dynamicPropertiesModel() const +DynamicPropertiesModel *DynamicPropertiesProxyModel::dynamicPropertiesModel() const { return m_model; } QString DynamicPropertiesProxyModel::newPropertyName() const { - auto propertiesModel = dynamicPropertiesModel(); + DynamicPropertiesModel *propsModel = dynamicPropertiesModel(); - return QString::fromUtf8(propertiesModel->unusedProperty( - propertiesModel->singleSelectedNode())); + return QString::fromUtf8(propsModel->unusedProperty(propsModel->singleSelectedNode())); } void DynamicPropertiesProxyModel::createProperty(const QString &name, const QString &type) @@ -161,23 +162,22 @@ void DynamicPropertiesProxyModel::createProperty(const QString &name, const QStr return; } try { - if (Internal::DynamicPropertiesModel::isValueType(typeName)) { - QVariant value = Internal::DynamicPropertiesModel::defaultValueForType(typeName); - modelNode.variantProperty(name.toUtf8()) - .setDynamicTypeNameAndValue(typeName, value); + if (DynamicPropertiesModel::isValueType(typeName)) { + QVariant value = DynamicPropertiesModel::defaultValueForType(typeName); + VariantProperty variantProp = modelNode.variantProperty(name.toUtf8()); + variantProp.setDynamicTypeNameAndValue(typeName, value); } else { - QString expression = Internal::DynamicPropertiesModel::defaultExpressionForType( - typeName); + QString expression = DynamicPropertiesModel::defaultExpressionForType(typeName); - modelNode.bindingProperty(name.toUtf8()) - .setDynamicTypeNameAndExpression(typeName, expression); + BindingProperty bindingProp = modelNode.bindingProperty(name.toUtf8()); + bindingProp.setDynamicTypeNameAndExpression(typeName, expression); } } catch (Exception &e) { e.showException(); } } } else { - qWarning() << " BindingModel::addBindingForCurrentNode not one node selected"; + qWarning() << __FUNCTION__ << ": not one node selected"; } } @@ -194,7 +194,7 @@ DynamicPropertyRow::DynamicPropertyRow() &PropertyEditorValue::expressionChanged, this, [this](const QString &name) { - if (!name.isEmpty()) //If name is empty the notifer is only for QML + if (!name.isEmpty()) // If name is empty the notifer is only for QML commitExpression(m_backendValue->expression()); else if (m_backendValue->expression().isEmpty()) resetValue(); @@ -254,7 +254,7 @@ DynamicPropertiesProxyModel *DynamicPropertyRow::model() const return m_model; } -QmlDesigner::PropertyEditorValue *DynamicPropertyRow::backendValue() const +PropertyEditorValue *DynamicPropertyRow::backendValue() const { return m_backendValue; } @@ -264,9 +264,9 @@ void DynamicPropertyRow::remove() m_model->dynamicPropertiesModel()->deleteDynamicPropertyByRow(m_row); } -QmlDesigner::PropertyEditorValue *DynamicPropertyRow::createProxyBackendValue() +PropertyEditorValue *DynamicPropertyRow::createProxyBackendValue() { - auto *newValue = new QmlDesigner::PropertyEditorValue(this); + auto *newValue = new PropertyEditorValue(this); m_proxyBackendValues.append(newValue); return newValue; @@ -283,7 +283,7 @@ void DynamicPropertyRow::setupBackendValue() if (!m_model) return; - QmlDesigner::AbstractProperty property = m_model->dynamicPropertiesModel()->abstractPropertyForRow(m_row); + AbstractProperty property = m_model->dynamicPropertiesModel()->abstractPropertyForRow(m_row); if (!property.isValid()) return; @@ -326,15 +326,14 @@ void DynamicPropertyRow::commitValue(const QVariant &value) auto propertiesModel = m_model->dynamicPropertiesModel(); VariantProperty variantProperty = propertiesModel->variantPropertyForRow(m_row); - if (!Internal::DynamicPropertiesModel::isValueType(variantProperty.dynamicTypeName())) + if (!DynamicPropertiesModel::isValueType(variantProperty.dynamicTypeName())) return; m_lock = true; auto unlock = qScopeGuard([this] { m_lock = false; }); auto view = propertiesModel->view(); - RewriterTransaction transaction = view->beginRewriterTransaction( - QByteArrayLiteral("DynamicPropertiesModel::commitValue")); + RewriterTransaction transaction = view->beginRewriterTransaction(__FUNCTION__); try { QmlObjectNode objectNode = variantProperty.parentQmlObjectNode(); if (view->currentState().isBaseState() @@ -347,7 +346,7 @@ void DynamicPropertyRow::commitValue(const QVariant &value) if (objectNode.isValid() && objectNode.modelValue(name) != value) objectNode.setVariantProperty(name, value); } - transaction.commit(); //committing in the try block + transaction.commit(); // committing in the try block } catch (Exception &e) { e.showException(); } @@ -355,10 +354,7 @@ void DynamicPropertyRow::commitValue(const QVariant &value) void DynamicPropertyRow::commitExpression(const QString &expression) { - if (m_lock) - return; - - if (m_row < 0) + if (m_lock || m_row < 0) return; auto propertiesModel = m_model->dynamicPropertiesModel(); @@ -369,7 +365,7 @@ void DynamicPropertyRow::commitExpression(const QString &expression) const QVariant literal = BindingProperty::convertToLiteral(bindingProperty.dynamicTypeName(), expression); - if (literal.isValid()) { //If the string can be converted to a literal we set it as a literal/value + if (literal.isValid()) { // If the string can be converted to a literal we set it as a literal/value commitValue(literal); return; } @@ -378,8 +374,7 @@ void DynamicPropertyRow::commitExpression(const QString &expression) auto unlock = qScopeGuard([this] { m_lock = false; }); auto view = propertiesModel->view(); - RewriterTransaction transaction = view->beginRewriterTransaction( - QByteArrayLiteral("DynamicPropertyRow::commitExpression")); + RewriterTransaction transaction = view->beginRewriterTransaction(__FUNCTION__); try { QString theExpression = expression; if (theExpression.isEmpty()) @@ -398,11 +393,10 @@ void DynamicPropertyRow::commitExpression(const QString &expression) objectNode.setBindingProperty(name, theExpression); } - transaction.commit(); //committing in the try block + transaction.commit(); // committing in the try block } catch (Exception &e) { e.showException(); } - return; } void DynamicPropertyRow::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &, const QList &) @@ -413,10 +407,7 @@ void DynamicPropertyRow::handleDataChanged(const QModelIndex &topLeft, const QMo void DynamicPropertyRow::resetValue() { - if (m_lock) - return; - - if (m_row < 0) + if (m_lock || m_row < 0) return; auto propertiesModel = m_model->dynamicPropertiesModel(); @@ -426,20 +417,18 @@ void DynamicPropertyRow::resetValue() TypeName typeName = property.dynamicTypeName(); if (view->currentState().isBaseState()) { - if (Internal::DynamicPropertiesModel::isValueType(typeName)) { - QVariant value = Internal::DynamicPropertiesModel::defaultValueForType(typeName); + if (DynamicPropertiesModel::isValueType(typeName)) { + QVariant value = DynamicPropertiesModel::defaultValueForType(typeName); commitValue(value); } else { - QString expression = Internal::DynamicPropertiesModel::defaultExpressionForType( - typeName); + QString expression = DynamicPropertiesModel::defaultExpressionForType(typeName); commitExpression(expression); } } else { m_lock = true; auto unlock = qScopeGuard([this] { m_lock = false; }); - RewriterTransaction transaction = view->beginRewriterTransaction( - QByteArrayLiteral("DynamicPropertyRow::resetValue")); + RewriterTransaction transaction = view->beginRewriterTransaction(__FUNCTION__); try { QmlObjectNode objectNode = property.parentQmlObjectNode(); QTC_CHECK(objectNode.isValid()); @@ -447,9 +436,11 @@ void DynamicPropertyRow::resetValue() if (objectNode.isValid() && objectNode.propertyAffectedByCurrentState(name)) objectNode.removeProperty(name); - transaction.commit(); //committing in the try block + transaction.commit(); // committing in the try block } catch (Exception &e) { e.showException(); } } } + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/propertyeditor/dynamicpropertiesproxymodel.h b/src/plugins/qmldesigner/components/propertyeditor/dynamicpropertiesproxymodel.h index 6fffe4f43dd..ec16a466d44 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/dynamicpropertiesproxymodel.h +++ b/src/plugins/qmldesigner/components/propertyeditor/dynamicpropertiesproxymodel.h @@ -30,16 +30,13 @@ #include #include -#include #include #include #include namespace QmlDesigner { -namespace Internal { + class DynamicPropertiesModel; -} -} // namespace QmlDesigner class DynamicPropertiesProxyModel : public QAbstractListModel { @@ -55,16 +52,16 @@ public: static void registerDeclarativeType(); - QmlDesigner::Internal::DynamicPropertiesModel *dynamicPropertiesModel() const; + DynamicPropertiesModel *dynamicPropertiesModel() const; Q_INVOKABLE QString newPropertyName() const; Q_INVOKABLE void createProperty(const QString &name, const QString &type); protected: - void initModel(QmlDesigner::Internal::DynamicPropertiesModel *model); + void initModel(DynamicPropertiesModel *model); private: - QmlDesigner::Internal::DynamicPropertiesModel *m_model = nullptr; + DynamicPropertiesModel *m_model = nullptr; }; class DynamicPropertyRow : public QObject @@ -109,4 +106,6 @@ private: bool m_lock = false; }; -QML_DECLARE_TYPE(DynamicPropertyRow) +} // namespace QmlDesigner + +QML_DECLARE_TYPE(QmlDesigner::DynamicPropertyRow) diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditordynamicpropertiesproxymodel.cpp b/src/plugins/qmldesigner/components/textureeditor/textureeditordynamicpropertiesproxymodel.cpp index e6f9c64c740..9ff3e3b8c41 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditordynamicpropertiesproxymodel.cpp +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditordynamicpropertiesproxymodel.cpp @@ -6,7 +6,7 @@ #include "dynamicpropertiesmodel.h" #include "textureeditorview.h" -using namespace QmlDesigner; +namespace QmlDesigner { TextureEditorDynamicPropertiesProxyModel::TextureEditorDynamicPropertiesProxyModel(QObject *parent) : DynamicPropertiesProxyModel(parent) @@ -20,3 +20,5 @@ void TextureEditorDynamicPropertiesProxyModel::registerDeclarativeType() DynamicPropertiesProxyModel::registerDeclarativeType(); qmlRegisterType("HelperWidgets", 2, 0, "TextureEditorDynamicPropertiesModel"); } + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditordynamicpropertiesproxymodel.h b/src/plugins/qmldesigner/components/textureeditor/textureeditordynamicpropertiesproxymodel.h index 5cd81b751f2..ccbf71f0097 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditordynamicpropertiesproxymodel.h +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditordynamicpropertiesproxymodel.h @@ -5,6 +5,8 @@ #include "dynamicpropertiesproxymodel.h" +namespace QmlDesigner { + class TextureEditorDynamicPropertiesProxyModel : public DynamicPropertiesProxyModel { Q_OBJECT @@ -14,3 +16,5 @@ public: static void registerDeclarativeType(); }; + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp b/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp index 07e381fb131..d6c38da9c96 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp @@ -55,7 +55,7 @@ TextureEditorView::TextureEditorView(AsynchronousImageCache &imageCache, : AbstractView{externalDependencies} , m_imageCache(imageCache) , m_stackedWidget(new QStackedWidget) - , m_dynamicPropertiesModel(new Internal::DynamicPropertiesModel(true, this)) + , m_dynamicPropertiesModel(new DynamicPropertiesModel(true, this)) { m_updateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F12), m_stackedWidget); connect(m_updateShortcut, &QShortcut::activated, this, &TextureEditorView::reloadQml); @@ -291,7 +291,7 @@ void TextureEditorView::currentTimelineChanged(const ModelNode &) m_qmlBackEnd->contextObject()->setHasActiveTimeline(QmlTimeline::hasActiveTimeline(this)); } -Internal::DynamicPropertiesModel *TextureEditorView::dynamicPropertiesModel() const +DynamicPropertiesModel *TextureEditorView::dynamicPropertiesModel() const { return m_dynamicPropertiesModel; } diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorview.h b/src/plugins/qmldesigner/components/textureeditor/textureeditorview.h index 39586cd8425..abba1906017 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditorview.h +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorview.h @@ -19,13 +19,10 @@ QT_END_NAMESPACE namespace QmlDesigner { +class DynamicPropertiesModel; class ModelNode; class TextureEditorQmlBackend; -namespace Internal { -class DynamicPropertiesModel; -} - class TextureEditorView : public AbstractView { Q_OBJECT @@ -77,7 +74,7 @@ public: void currentTimelineChanged(const ModelNode &node) override; - Internal::DynamicPropertiesModel *dynamicPropertiesModel() const; + DynamicPropertiesModel *dynamicPropertiesModel() const; static TextureEditorView *instance(); @@ -123,7 +120,7 @@ private: QPointer m_colorDialog; QPointer m_itemLibraryInfo; - Internal::DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr; + DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr; }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index 3b51d9147ea..906fb0f56e2 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -259,7 +259,7 @@ bool QmlDesignerPlugin::initialize(const QStringList & /*arguments*/, QString *e //TODO Move registering those types out of the property editor, since they are used also in the states editor Quick2PropertyEditorView::registerQmlTypes(); - if (QmlDesigner::checkEnterpriseLicense()) + if (checkEnterpriseLicense()) Core::IWizardFactory::registerFeatureProvider(new EnterpriseFeatureProvider); Exception::setWarnAboutException(!QmlDesignerPlugin::instance() ->settings() @@ -292,29 +292,29 @@ bool QmlDesignerPlugin::delayedInitialize() MetaInfo::setPluginPaths(pluginPaths); d->viewManager.registerView( - std::make_unique(d->externalDependencies)); + std::make_unique(d->externalDependencies)); auto timelineView = d->viewManager.registerView( - std::make_unique(d->externalDependencies)); + std::make_unique(d->externalDependencies)); timelineView->registerActions(); d->viewManager.registerView( - std::make_unique(d->externalDependencies)); + std::make_unique(d->externalDependencies)); auto eventlistView = d->viewManager.registerView( - std::make_unique(d->externalDependencies)); + std::make_unique(d->externalDependencies)); eventlistView->registerActions(); auto transitionEditorView = d->viewManager.registerView( - std::make_unique(d->externalDependencies)); + std::make_unique(d->externalDependencies)); transitionEditorView->registerActions(); - d->viewManager.registerFormEditorTool(std::make_unique()); - d->viewManager.registerFormEditorTool(std::make_unique()); - d->viewManager.registerFormEditorTool(std::make_unique()); + d->viewManager.registerFormEditorTool(std::make_unique()); + d->viewManager.registerFormEditorTool(std::make_unique()); + d->viewManager.registerFormEditorTool(std::make_unique()); d->viewManager.registerFormEditorTool( - std::make_unique(d->externalDependencies)); - d->viewManager.registerFormEditorTool(std::make_unique()); + std::make_unique(d->externalDependencies)); + d->viewManager.registerFormEditorTool(std::make_unique()); if (QmlProjectManager::QmlProject::isQtDesignStudio()) { d->mainWidget.initialize(); @@ -495,7 +495,7 @@ void QmlDesignerPlugin::hideDesigner() d->shortCutManager.disconnectUndoActions(currentDesignDocument()); d->documentManager.setCurrentDesignDocument(nullptr); d->shortCutManager.updateUndoActions(nullptr); - emitUsageStatisticsTime(QmlDesigner::Constants::EVENT_DESIGNMODE_TIME, m_usageTimer.elapsed()); + emitUsageStatisticsTime(Constants::EVENT_DESIGNMODE_TIME, m_usageTimer.elapsed()); } void QmlDesignerPlugin::changeEditor()