QmlDesigner: Move connection classes out of Internal

Also clean up DynamicPropertiesProxyModel and DynamicPropertiesModel
classes.

Change-Id: I40a2864c1ffbd555dfea9452cd55bbeb23e9fdfa
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2023-03-16 16:26:36 +02:00
parent dbe41a6892
commit cd70e9cecb
27 changed files with 233 additions and 295 deletions

View File

@@ -11,7 +11,6 @@
#include "nodemetainfo.h" #include "nodemetainfo.h"
#include "nodeproperty.h" #include "nodeproperty.h"
#include "rewriterview.h" #include "rewriterview.h"
#include "rewritertransaction.h"
#include "addnewbackenddialog.h" #include "addnewbackenddialog.h"
@@ -20,8 +19,6 @@
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
BackendModel::BackendModel(ConnectionView *parent) : BackendModel::BackendModel(ConnectionView *parent) :
QStandardItemModel(parent) QStandardItemModel(parent)
,m_connectionView(parent) ,m_connectionView(parent)
@@ -29,7 +26,7 @@ BackendModel::BackendModel(ConnectionView *parent) :
connect(this, &QStandardItemModel::dataChanged, this, &BackendModel::handleDataChanged); connect(this, &QStandardItemModel::dataChanged, this, &BackendModel::handleDataChanged);
} }
ConnectionView *QmlDesigner::Internal::BackendModel::connectionView() const ConnectionView *BackendModel::connectionView() const
{ {
return m_connectionView; return m_connectionView;
} }
@@ -311,6 +308,4 @@ void BackendModel::handleDataChanged(const QModelIndex &topLeft, const QModelInd
m_lock = false; m_lock = false;
} }
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -8,8 +8,6 @@
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
class ConnectionView; class ConnectionView;
class BackendModel : public QStandardItemModel class BackendModel : public QStandardItemModel
@@ -47,6 +45,4 @@ private:
bool m_lock = false; bool m_lock = false;
}; };
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -18,8 +18,6 @@
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
BindingModel::BindingModel(ConnectionView *parent) BindingModel::BindingModel(ConnectionView *parent)
: QStandardItemModel(parent) : QStandardItemModel(parent)
, m_connectionView(parent) , m_connectionView(parent)
@@ -440,6 +438,4 @@ void BindingModel::handleException()
resetModel(); resetModel();
} }
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -11,8 +11,6 @@
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
class ConnectionView; class ConnectionView;
class BindingModel : public QStandardItemModel class BindingModel : public QStandardItemModel
@@ -65,6 +63,4 @@ private:
}; };
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -48,8 +48,6 @@ bool isConnection(const QmlDesigner::ModelNode &modelNode)
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
ConnectionModel::ConnectionModel(ConnectionView *parent) ConnectionModel::ConnectionModel(ConnectionView *parent)
: QStandardItemModel(parent) : QStandardItemModel(parent)
, m_connectionView(parent) , m_connectionView(parent)
@@ -351,7 +349,7 @@ void ConnectionModel::deleteConnectionByRow(int currentRow)
{ {
SignalHandlerProperty targetSignal = signalHandlerPropertyForRow(currentRow); SignalHandlerProperty targetSignal = signalHandlerPropertyForRow(currentRow);
QTC_ASSERT(targetSignal.isValid(), return ); QTC_ASSERT(targetSignal.isValid(), return );
QmlDesigner::ModelNode node = targetSignal.parentModelNode(); ModelNode node = targetSignal.parentModelNode();
QTC_ASSERT(node.isValid(), return ); QTC_ASSERT(node.isValid(), return );
QList<SignalHandlerProperty> allSignals = node.signalProperties(); QList<SignalHandlerProperty> allSignals = node.signalProperties();
@@ -527,6 +525,4 @@ QStringList ConnectionModel::getPossibleSignalsForConnection(const ModelNode &co
return stringList; return stringList;
} }
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -13,8 +13,6 @@ class BindingProperty;
class SignalHandlerProperty; class SignalHandlerProperty;
class VariantProperty; class VariantProperty;
namespace Internal {
class ConnectionView; class ConnectionView;
class ConnectionModel : public QStandardItemModel class ConnectionModel : public QStandardItemModel
@@ -73,6 +71,4 @@ private:
QString m_exceptionError; QString m_exceptionError;
}; };
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -22,8 +22,6 @@
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
ConnectionView::ConnectionView(ExternalDependenciesInterface &externalDependencies) ConnectionView::ConnectionView(ExternalDependenciesInterface &externalDependencies)
: AbstractView{externalDependencies} : AbstractView{externalDependencies}
, m_connectionViewWidget(new ConnectionViewWidget()) , m_connectionViewWidget(new ConnectionViewWidget())
@@ -278,6 +276,4 @@ ConnectionView *ConnectionView::instance()
return s_instance; return s_instance;
} }
} // namesapce Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -15,8 +15,6 @@ QT_END_NAMESPACE
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
class ConnectionViewWidget; class ConnectionViewWidget;
class BindingModel; class BindingModel;
class ConnectionModel; class ConnectionModel;
@@ -82,6 +80,4 @@ private: //variables
BackendModel *m_backendModel; BackendModel *m_backendModel;
}; };
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -34,8 +34,6 @@
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
ConnectionViewWidget::ConnectionViewWidget(QWidget *parent) : ConnectionViewWidget::ConnectionViewWidget(QWidget *parent) :
QFrame(parent), QFrame(parent),
ui(new Ui::ConnectionViewWidget) ui(new Ui::ConnectionViewWidget)
@@ -612,6 +610,4 @@ void ConnectionViewWidget::backendTableViewSelectionChanged(const QModelIndex &c
} }
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -20,8 +20,6 @@ namespace Ui { class ConnectionViewWidget; }
class ActionEditor; class ActionEditor;
class BindingEditor; class BindingEditor;
namespace Internal {
class BindingModel; class BindingModel;
class ConnectionModel; class ConnectionModel;
class DynamicPropertiesModel; class DynamicPropertiesModel;
@@ -93,6 +91,4 @@ private:
QModelIndex m_dynamicIndex; QModelIndex m_dynamicIndex;
}; };
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -20,8 +20,6 @@
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
QStringList prependOnForSignalHandler(const QStringList &signalNames) QStringList prependOnForSignalHandler(const QStringList &signalNames)
{ {
QStringList signalHandlerNames; QStringList signalHandlerNames;
@@ -408,6 +406,4 @@ QWidget *BackendDelegate::createEditor(QWidget *parent, const QStyleOptionViewIt
return widget; return widget;
} }
} // namesapce Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -9,8 +9,6 @@
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
class PropertiesComboBox : public QComboBox class PropertiesComboBox : public QComboBox
{ {
Q_OBJECT Q_OBJECT
@@ -77,6 +75,4 @@ public:
const QModelIndex &index) const override; const QModelIndex &index) const override;
}; };
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -3,32 +3,32 @@
#include "dynamicpropertiesmodel.h" #include "dynamicpropertiesmodel.h"
#include "connectionview.h" #include "bindingproperty.h"
#include "nodeabstractproperty.h"
#include <bindingproperty.h> #include "nodemetainfo.h"
#include <nodemetainfo.h> #include "qmlchangeset.h"
#include <nodeproperty.h> #include "qmldesignerconstants.h"
#include <rewritertransaction.h> #include "qmldesignerplugin.h"
#include <rewritingexception.h> #include "qmlobjectnode.h"
#include <variantproperty.h> #include "qmltimeline.h"
#include <qmldesignerconstants.h> #include "rewritertransaction.h"
#include <qmldesignerplugin.h> #include "rewritingexception.h"
#include "variantproperty.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QMessageBox> #include <QMessageBox>
#include <QTimer> #include <QTimer>
#include <QUrl>
namespace { 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; return false;
if (variantProperty01.name() != variantProperty02.name()) if (variantProp1.name() != variantProp2.name())
return false; return false;
return true; return true;
} }
@@ -87,22 +87,19 @@ QVariant convertVariantForTypeName(const QVariant &variant, const QmlDesigner::T
return returnValue; return returnValue;
} }
} //internal namespace } // namespace
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal { PropertyName DynamicPropertiesModel::unusedProperty(const ModelNode &modelNode)
QmlDesigner::PropertyName DynamicPropertiesModel::unusedProperty(const QmlDesigner::ModelNode &modelNode)
{ {
QmlDesigner::PropertyName propertyName = "property"; PropertyName propertyName = "property";
int i = 0; int i = 0;
if (modelNode.isValid() && modelNode.metaInfo().isValid()) { if (modelNode.isValid() && modelNode.metaInfo().isValid()) {
while (true) { 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)) if (!modelNode.hasProperty(currentPropertyName) && !modelNode.metaInfo().hasProperty(currentPropertyName))
return currentPropertyName; return currentPropertyName;
i++;
} }
} }
@@ -167,8 +164,7 @@ void DynamicPropertiesModel::resetModel()
{ {
beginResetModel(); beginResetModel();
clear(); clear();
setHorizontalHeaderLabels( setHorizontalHeaderLabels({tr("Item"), tr("Property"), tr("Property Type"), tr("Property Value")});
QStringList({tr("Item"), tr("Property"), tr("Property Type"), tr("Property Value")}));
if (m_view->isAttached()) { if (m_view->isAttached()) {
const auto nodes = selectedNodes(); const auto nodes = selectedNodes();
@@ -180,8 +176,8 @@ void DynamicPropertiesModel::resetModel()
} }
//Method creates dynamic BindingProperty with the same name and type as old VariantProperty // Method creates dynamic BindingProperty with the same name and type as old VariantProperty
//Value copying is optional // Value copying is optional
BindingProperty DynamicPropertiesModel::replaceVariantWithBinding(const PropertyName &name, bool copyValue) BindingProperty DynamicPropertiesModel::replaceVariantWithBinding(const PropertyName &name, bool copyValue)
{ {
if (selectedNodes().count() == 1) { if (selectedNodes().count() == 1) {
@@ -211,12 +207,11 @@ BindingProperty DynamicPropertiesModel::replaceVariantWithBinding(const Property
qWarning() << "DynamicPropertiesModel::replaceVariantWithBinding: no selected nodes"; qWarning() << "DynamicPropertiesModel::replaceVariantWithBinding: no selected nodes";
} }
return BindingProperty(); return {};
} }
// Finds selected property, and changes it to empty value (QVariant())
//Finds selected property, and changes it to empty value (QVariant()) // If it's a BindingProperty, then replaces it with empty VariantProperty
//If it's a BindingProperty, then replaces it with empty VariantProperty
void DynamicPropertiesModel::resetProperty(const PropertyName &name) void DynamicPropertiesModel::resetProperty(const PropertyName &name)
{ {
if (selectedNodes().count() == 1) { if (selectedNodes().count() == 1) {
@@ -235,7 +230,7 @@ void DynamicPropertiesModel::resetProperty(const PropertyName &name)
BindingProperty property = abProp.toBindingProperty(); BindingProperty property = abProp.toBindingProperty();
TypeName oldType = property.dynamicTypeName(); 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); modelNode.removeProperty(name);
VariantProperty newProperty = modelNode.variantProperty(name); VariantProperty newProperty = modelNode.variantProperty(name);
@@ -249,8 +244,7 @@ void DynamicPropertiesModel::resetProperty(const PropertyName &name)
} }
} }
} }
} } else {
else {
qWarning() << "DynamicPropertiesModel::resetProperty: no selected nodes"; qWarning() << "DynamicPropertiesModel::resetProperty: no selected nodes";
} }
} }
@@ -279,14 +273,14 @@ void DynamicPropertiesModel::bindingPropertyChanged(const BindingProperty &bindi
const QList<ModelNode> nodes = selectedNodes(); const QList<ModelNode> nodes = selectedNodes();
if (!nodes.contains(bindingProperty.parentModelNode())) if (!nodes.contains(bindingProperty.parentModelNode()))
return; return;
if (!m_lock) { if (!m_lock) {
int rowNumber = findRowForBindingProperty(bindingProperty); int rowNumber = findRowForBindingProperty(bindingProperty);
if (rowNumber == -1) { if (rowNumber == -1)
addBindingProperty(bindingProperty); addBindingProperty(bindingProperty);
} else { else
updateBindingProperty(rowNumber); updateBindingProperty(rowNumber);
}
} }
m_handleDataChanged = true; m_handleDataChanged = true;
@@ -302,6 +296,7 @@ void DynamicPropertiesModel::abstractPropertyChanged(const AbstractProperty &pro
const QList<ModelNode> nodes = selectedNodes(); const QList<ModelNode> nodes = selectedNodes();
if (!nodes.contains(property.parentModelNode())) if (!nodes.contains(property.parentModelNode()))
return; return;
int rowNumber = findRowForProperty(property); int rowNumber = findRowForProperty(property);
if (rowNumber > -1) { if (rowNumber > -1) {
if (property.isVariantProperty()) if (property.isVariantProperty())
@@ -323,6 +318,7 @@ void DynamicPropertiesModel::variantPropertyChanged(const VariantProperty &varia
const QList<ModelNode> nodes = selectedNodes(); const QList<ModelNode> nodes = selectedNodes();
if (!nodes.contains(variantProperty.parentModelNode())) if (!nodes.contains(variantProperty.parentModelNode()))
return; return;
if (!m_lock) { if (!m_lock) {
int rowNumber = findRowForVariantProperty(variantProperty); int rowNumber = findRowForVariantProperty(variantProperty);
@@ -342,6 +338,7 @@ void DynamicPropertiesModel::bindingRemoved(const BindingProperty &bindingProper
const QList<ModelNode> nodes = selectedNodes(); const QList<ModelNode> nodes = selectedNodes();
if (!nodes.contains(bindingProperty.parentModelNode())) if (!nodes.contains(bindingProperty.parentModelNode()))
return; return;
if (!m_lock) { if (!m_lock) {
int rowNumber = findRowForBindingProperty(bindingProperty); int rowNumber = findRowForBindingProperty(bindingProperty);
removeRow(rowNumber); removeRow(rowNumber);
@@ -357,6 +354,7 @@ void DynamicPropertiesModel::variantRemoved(const VariantProperty &variantProper
const QList<ModelNode> nodes = selectedNodes(); const QList<ModelNode> nodes = selectedNodes();
if (!nodes.contains(variantProperty.parentModelNode())) if (!nodes.contains(variantProperty.parentModelNode()))
return; return;
if (!m_lock) { if (!m_lock) {
int rowNumber = findRowForVariantProperty(variantProperty); int rowNumber = findRowForVariantProperty(variantProperty);
removeRow(rowNumber); removeRow(rowNumber);
@@ -398,7 +396,7 @@ AbstractProperty DynamicPropertiesModel::abstractPropertyForRow(int rowNumber) c
if (modelNode.isValid()) if (modelNode.isValid())
return modelNode.property(targetPropertyName.toUtf8()); return modelNode.property(targetPropertyName.toUtf8());
return AbstractProperty(); return {};
} }
BindingProperty DynamicPropertiesModel::bindingPropertyForRow(int rowNumber) const BindingProperty DynamicPropertiesModel::bindingPropertyForRow(int rowNumber) const
@@ -411,7 +409,7 @@ BindingProperty DynamicPropertiesModel::bindingPropertyForRow(int rowNumber) con
if (modelNode.isValid()) if (modelNode.isValid())
return modelNode.bindingProperty(targetPropertyName.toUtf8()); return modelNode.bindingProperty(targetPropertyName.toUtf8());
return BindingProperty(); return {};
} }
VariantProperty DynamicPropertiesModel::variantPropertyForRow(int rowNumber) const VariantProperty DynamicPropertiesModel::variantPropertyForRow(int rowNumber) const
@@ -424,7 +422,7 @@ VariantProperty DynamicPropertiesModel::variantPropertyForRow(int rowNumber) con
if (modelNode.isValid()) if (modelNode.isValid())
return modelNode.variantProperty(targetPropertyName.toUtf8()); return modelNode.variantProperty(targetPropertyName.toUtf8());
return VariantProperty(); return {};
} }
QStringList DynamicPropertiesModel::possibleTargetProperties(const BindingProperty &bindingProperty) const QStringList DynamicPropertiesModel::possibleTargetProperties(const BindingProperty &bindingProperty) const
@@ -440,7 +438,8 @@ QStringList DynamicPropertiesModel::possibleTargetProperties(const BindingProper
if (metaInfo.isValid()) { if (metaInfo.isValid()) {
QStringList possibleProperties; QStringList possibleProperties;
for (const auto &property : metaInfo.properties()) { const PropertyMetaInfos props = metaInfo.properties();
for (const auto &property : props) {
if (property.isWritable()) if (property.isWritable())
possibleProperties.push_back(QString::fromUtf8(property.name())); possibleProperties.push_back(QString::fromUtf8(property.name()));
} }
@@ -448,7 +447,7 @@ QStringList DynamicPropertiesModel::possibleTargetProperties(const BindingProper
return possibleProperties; return possibleProperties;
} }
return QStringList(); return {};
} }
void DynamicPropertiesModel::addDynamicPropertyForCurrentNode() void DynamicPropertiesModel::addDynamicPropertyForCurrentNode()
@@ -477,11 +476,10 @@ QStringList DynamicPropertiesModel::possibleSourceProperties(const BindingProper
NodeMetaInfo type; NodeMetaInfo type;
if (auto metaInfo = bindingProperty.parentModelNode().metaInfo(); metaInfo.isValid()) { if (auto metaInfo = bindingProperty.parentModelNode().metaInfo(); metaInfo.isValid())
type = metaInfo.property(bindingProperty.name()).propertyType(); type = metaInfo.property(bindingProperty.name()).propertyType();
} else { else
qWarning() << " BindingModel::possibleSourcePropertiesForRow no meta info for target node"; qWarning() << " BindingModel::possibleSourcePropertiesForRow no meta info for target node";
}
const QString &id = stringlist.constFirst(); const QString &id = stringlist.constFirst();
@@ -496,8 +494,9 @@ QStringList DynamicPropertiesModel::possibleSourceProperties(const BindingProper
if (metaInfo.isValid()) { if (metaInfo.isValid()) {
QStringList possibleProperties; QStringList possibleProperties;
for (const auto &property : metaInfo.properties()) { const PropertyMetaInfos props = metaInfo.properties();
if (property.propertyType() == type) //### todo proper check for (const auto &property : props) {
if (property.propertyType() == type) // TODO: proper check
possibleProperties.push_back(QString::fromUtf8(property.name())); possibleProperties.push_back(QString::fromUtf8(property.name()));
} }
return possibleProperties; return possibleProperties;
@@ -505,40 +504,39 @@ QStringList DynamicPropertiesModel::possibleSourceProperties(const BindingProper
qWarning() << " BindingModel::possibleSourcePropertiesForRow no meta info for source node"; qWarning() << " BindingModel::possibleSourcePropertiesForRow no meta info for source node";
} }
return QStringList(); return {};
} }
void DynamicPropertiesModel::deleteDynamicPropertyByRow(int rowNumber) void DynamicPropertiesModel::deleteDynamicPropertyByRow(int rowNumber)
{ {
m_view->executeInTransaction( m_view->executeInTransaction(__FUNCTION__, [this, rowNumber]() {
"DynamicPropertiesModel::deleteDynamicPropertyByRow", [this, rowNumber]() { const AbstractProperty property = abstractPropertyForRow(rowNumber);
const AbstractProperty property = abstractPropertyForRow(rowNumber); const PropertyName propertyName = property.name();
const PropertyName propertyName = property.name(); BindingProperty bindingProperty = bindingPropertyForRow(rowNumber);
BindingProperty bindingProperty = bindingPropertyForRow(rowNumber); if (bindingProperty.isValid()) {
if (bindingProperty.isValid()) { bindingProperty.parentModelNode().removeProperty(bindingProperty.name());
bindingProperty.parentModelNode().removeProperty(bindingProperty.name()); } else {
} else { VariantProperty variantProperty = variantPropertyForRow(rowNumber);
VariantProperty variantProperty = variantPropertyForRow(rowNumber); if (variantProperty.isValid())
if (variantProperty.isValid()) variantProperty.parentModelNode().removeProperty(variantProperty.name());
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()) { const QList<ModelNode> timelineNodes = objectNode.allTimelines();
QmlObjectNode objectNode = QmlObjectNode(property.parentModelNode()); for (auto &timelineNode : timelineNodes) {
const auto stateOperations = objectNode.allAffectingStatesOperations(); QmlTimeline timeline(timelineNode);
for (const QmlModelStateOperation &stateOperation : stateOperations) { timeline.removeKeyframesForTargetAndProperty(objectNode.modelNode(),
if (stateOperation.modelNode().hasProperty(propertyName)) propertyName);
stateOperation.modelNode().removeProperty(propertyName);
}
const auto timelineNodes = objectNode.allTimelines();
for (auto &timelineNode : timelineNodes) {
QmlTimeline timeline(timelineNode);
timeline.removeKeyframesForTargetAndProperty(objectNode.modelNode(),
propertyName);
}
} }
}); }
});
resetModel(); resetModel();
} }
@@ -570,7 +568,7 @@ void DynamicPropertiesModel::addProperty(const QVariant &propertyValue,
propertyValueItem->setData(propertyValue, Qt::DisplayRole); propertyValueItem->setData(propertyValue, Qt::DisplayRole);
items.append(propertyValueItem); items.append(propertyValueItem);
for (int i =0; i < rowCount(); i++) { for (int i = 0; i < rowCount(); ++i) {
if (data(index(i, PropertyNameRow)).toString() > propName) { if (data(index(i, PropertyNameRow)).toString() > propName) {
insertRow(i, items); insertRow(i, items);
return; return;
@@ -628,7 +626,6 @@ void DynamicPropertiesModel::updateVariantProperty(int rowNumber)
if (objectNode.isValid() && !objectNode.view()->currentState().isBaseState()) if (objectNode.isValid() && !objectNode.view()->currentState().isBaseState())
value = objectNode.modelValue(variantProperty.name()); value = objectNode.modelValue(variantProperty.name());
updateDisplayRoleFromVariant(rowNumber, PropertyValueRow, value); updateDisplayRoleFromVariant(rowNumber, PropertyValueRow, value);
} }
} }
@@ -638,9 +635,8 @@ void DynamicPropertiesModel::addModelNode(const ModelNode &modelNode)
if (!modelNode.isValid()) if (!modelNode.isValid())
return; return;
auto properties = modelNode.properties(); const QList<AbstractProperty> properties = modelNode.properties();
QList<AbstractProperty> dynamicProperties = Utils::filtered(properties, [](const AbstractProperty &p) {
auto dynamicProperties = Utils::filtered(properties, [](const AbstractProperty &p) {
return p.isDynamic(); return p.isDynamic();
}); });
@@ -663,10 +659,10 @@ void DynamicPropertiesModel::updateValue(int row)
if (bindingProperty.isBindingProperty()) { if (bindingProperty.isBindingProperty()) {
const QString expression = data(index(row, PropertyValueRow)).toString(); const QString expression = data(index(row, PropertyValueRow)).toString();
RewriterTransaction transaction = m_view->beginRewriterTransaction(QByteArrayLiteral("DynamicPropertiesModel::updateValue")); RewriterTransaction transaction = m_view->beginRewriterTransaction(__FUNCTION__);
try { try {
bindingProperty.setDynamicTypeNameAndExpression(bindingProperty.dynamicTypeName(), expression); bindingProperty.setDynamicTypeNameAndExpression(bindingProperty.dynamicTypeName(), expression);
transaction.commit(); //committing in the try block transaction.commit(); // committing in the try block
} catch (Exception &e) { } catch (Exception &e) {
m_exceptionError = e.description(); m_exceptionError = e.description();
QTimer::singleShot(200, this, &DynamicPropertiesModel::handleException); QTimer::singleShot(200, this, &DynamicPropertiesModel::handleException);
@@ -679,10 +675,10 @@ void DynamicPropertiesModel::updateValue(int row)
if (variantProperty.isVariantProperty()) { if (variantProperty.isVariantProperty()) {
const QVariant value = data(index(row, PropertyValueRow)); const QVariant value = data(index(row, PropertyValueRow));
RewriterTransaction transaction = m_view->beginRewriterTransaction(QByteArrayLiteral("DynamicPropertiesModel::updateValue")); RewriterTransaction transaction = m_view->beginRewriterTransaction(__FUNCTION__);
try { try {
variantProperty.setDynamicTypeNameAndValue(variantProperty.dynamicTypeName(), value); variantProperty.setDynamicTypeNameAndValue(variantProperty.dynamicTypeName(), value);
transaction.commit(); //committing in the try block transaction.commit(); // committing in the try block
} catch (Exception &e) { } catch (Exception &e) {
m_exceptionError = e.description(); m_exceptionError = e.description();
QTimer::singleShot(200, this, &DynamicPropertiesModel::handleException); QTimer::singleShot(200, this, &DynamicPropertiesModel::handleException);
@@ -693,17 +689,14 @@ void DynamicPropertiesModel::updateValue(int row)
void DynamicPropertiesModel::updatePropertyName(int rowNumber) void DynamicPropertiesModel::updatePropertyName(int rowNumber)
{ {
const PropertyName newName = data(index(rowNumber, PropertyNameRow)).toString().toUtf8(); const PropertyName newName = data(index(rowNumber, PropertyNameRow)).toString().toUtf8();
if (newName.isEmpty()) { QTC_ASSERT(!newName.isEmpty(), return);
qWarning() << "DynamicPropertiesModel::updatePropertyName invalid property name";
return;
}
BindingProperty bindingProperty = bindingPropertyForRow(rowNumber); BindingProperty bindingProperty = bindingPropertyForRow(rowNumber);
ModelNode targetNode = bindingProperty.parentModelNode(); ModelNode targetNode = bindingProperty.parentModelNode();
if (bindingProperty.isBindingProperty()) { if (bindingProperty.isBindingProperty()) {
m_view->executeInTransaction("DynamicPropertiesModel::updatePropertyName", [bindingProperty, newName, &targetNode](){ m_view->executeInTransaction(__FUNCTION__, [bindingProperty, newName, &targetNode]() {
const QString expression = bindingProperty.expression(); const QString expression = bindingProperty.expression();
const PropertyName dynamicPropertyType = bindingProperty.dynamicTypeName(); const PropertyName dynamicPropertyType = bindingProperty.dynamicTypeName();
@@ -722,7 +715,7 @@ void DynamicPropertiesModel::updatePropertyName(int rowNumber)
const PropertyName dynamicPropertyType = variantProperty.dynamicTypeName(); const PropertyName dynamicPropertyType = variantProperty.dynamicTypeName();
ModelNode targetNode = variantProperty.parentModelNode(); ModelNode targetNode = variantProperty.parentModelNode();
m_view->executeInTransaction("DynamicPropertiesModel::updatePropertyName", [=](){ m_view->executeInTransaction(__FUNCTION__, [=]() {
targetNode.variantProperty(newName).setDynamicTypeNameAndValue(dynamicPropertyType, value); targetNode.variantProperty(newName).setDynamicTypeNameAndValue(dynamicPropertyType, value);
targetNode.removeProperty(variantProperty.name()); targetNode.removeProperty(variantProperty.name());
}); });
@@ -733,13 +726,8 @@ void DynamicPropertiesModel::updatePropertyName(int rowNumber)
void DynamicPropertiesModel::updatePropertyType(int rowNumber) void DynamicPropertiesModel::updatePropertyType(int rowNumber)
{ {
const TypeName newType = data(index(rowNumber, PropertyTypeRow)).toString().toLatin1(); const TypeName newType = data(index(rowNumber, PropertyTypeRow)).toString().toLatin1();
QTC_ASSERT(!newType.isEmpty(), return);
if (newType.isEmpty()) {
qWarning() << "DynamicPropertiesModel::updatePropertyName invalid property type";
return;
}
BindingProperty bindingProperty = bindingPropertyForRow(rowNumber); BindingProperty bindingProperty = bindingPropertyForRow(rowNumber);
@@ -748,7 +736,7 @@ void DynamicPropertiesModel::updatePropertyType(int rowNumber)
const PropertyName propertyName = bindingProperty.name(); const PropertyName propertyName = bindingProperty.name();
ModelNode targetNode = bindingProperty.parentModelNode(); ModelNode targetNode = bindingProperty.parentModelNode();
m_view->executeInTransaction("DynamicPropertiesModel::updatePropertyType", [=](){ m_view->executeInTransaction(__FUNCTION__, [=]() {
targetNode.removeProperty(bindingProperty.name()); targetNode.removeProperty(bindingProperty.name());
targetNode.bindingProperty(propertyName).setDynamicTypeNameAndExpression(newType, expression); targetNode.bindingProperty(propertyName).setDynamicTypeNameAndExpression(newType, expression);
}); });
@@ -764,7 +752,7 @@ void DynamicPropertiesModel::updatePropertyType(int rowNumber)
ModelNode targetNode = variantProperty.parentModelNode(); ModelNode targetNode = variantProperty.parentModelNode();
const PropertyName propertyName = variantProperty.name(); const PropertyName propertyName = variantProperty.name();
m_view->executeInTransaction("DynamicPropertiesModel::updatePropertyType", [=](){ m_view->executeInTransaction(__FUNCTION__, [=]() {
targetNode.removeProperty(variantProperty.name()); targetNode.removeProperty(variantProperty.name());
if (!isValueType(newType)) { if (!isValueType(newType)) {
targetNode.bindingProperty(propertyName).setDynamicTypeNameAndExpression( targetNode.bindingProperty(propertyName).setDynamicTypeNameAndExpression(
@@ -777,26 +765,22 @@ void DynamicPropertiesModel::updatePropertyType(int rowNumber)
updateCustomData(rowNumber, targetNode.variantProperty(propertyName)); updateCustomData(rowNumber, targetNode.variantProperty(propertyName));
if (variantProperty.isVariantProperty()) { if (variantProperty.isVariantProperty())
updateVariantProperty(rowNumber); updateVariantProperty(rowNumber);
} else if (bindingProperty.isBindingProperty()) { else if (bindingProperty.isBindingProperty())
updateBindingProperty(rowNumber); updateBindingProperty(rowNumber);
}
} }
} }
ModelNode DynamicPropertiesModel::getNodeByIdOrParent(const QString &id, const ModelNode &targetNode) const 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")) { if (targetNode.hasParentProperty())
modelNode = m_view->modelNodeForId(id); return targetNode.parentProperty().parentModelNode();
} else {
if (targetNode.hasParentProperty()) { return {};
modelNode = targetNode.parentProperty().parentModelNode();
}
}
return modelNode;
} }
void DynamicPropertiesModel::updateCustomData(QStandardItem *item, const AbstractProperty &property) 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 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)) if (compareBindingProperties(bindingPropertyForRow(i), bindingProperty))
return i; return i;
} }
//not found
return -1; return -1; // not found
} }
int DynamicPropertiesModel::findRowForVariantProperty(const VariantProperty &variantProperty) const 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)) if (compareVariantProperties(variantPropertyForRow(i), variantProperty))
return i; return i;
} }
//not found
return -1; return -1; // not found
} }
int DynamicPropertiesModel::findRowForProperty(const AbstractProperty &abstractProperty) const 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())) if ((abstractPropertyForRow(i).name() == abstractProperty.name()))
return i; 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(); const QString expression = bindingProperty.expression();
if (true) { if (true) {
const QStringList stringList = expression.split(QLatin1String(".")); const QStringList expressionParts = expression.split('.');
*sourceNode = stringList.constFirst(); *sourceNode = expressionParts.constFirst();
QString propertyName; QString propertyName;
for (int i=1; i < stringList.count(); i++) { for (int i = 1; i < expressionParts.count(); ++i) {
propertyName += stringList.at(i); propertyName += expressionParts.at(i);
if (i != stringList.count() - 1) if (i != expressionParts.count() - 1)
propertyName += QLatin1String("."); propertyName += QLatin1String(".");
} }
*sourceProperty = propertyName; *sourceProperty = propertyName;
} }
return true; return true;
} }
@@ -885,7 +871,7 @@ void DynamicPropertiesModel::handleDataChanged(const QModelIndex &topLeft, const
return; return;
if (topLeft != bottomRight) { if (topLeft != bottomRight) {
qWarning() << "BindingModel::handleDataChanged multi edit?"; qWarning() << __FUNCTION__ << ": multi edit?";
return; return;
} }
@@ -896,7 +882,7 @@ void DynamicPropertiesModel::handleDataChanged(const QModelIndex &topLeft, const
switch (currentColumn) { switch (currentColumn) {
case TargetModelNodeRow: { case TargetModelNodeRow: {
//updating user data // updating user data
} break; } break;
case PropertyNameRow: { case PropertyNameRow: {
updatePropertyName(currentRow); updatePropertyName(currentRow);
@@ -908,7 +894,7 @@ void DynamicPropertiesModel::handleDataChanged(const QModelIndex &topLeft, const
updateValue(currentRow); updateValue(currentRow);
} break; } break;
default: qWarning() << "BindingModel::handleDataChanged column" << currentColumn; default: qWarning() << __FUNCTION__ << " column" << currentColumn;
} }
m_lock = false; m_lock = false;
@@ -926,18 +912,16 @@ const QList<ModelNode> DynamicPropertiesModel::selectedNodes() const
// Otherwise return actual selected nodes of the model. // Otherwise return actual selected nodes of the model.
if (m_explicitSelection) if (m_explicitSelection)
return m_selectedNodes; return m_selectedNodes;
else
return m_view->selectedModelNodes(); return m_view->selectedModelNodes();
} }
const ModelNode DynamicPropertiesModel::singleSelectedNode() const const ModelNode DynamicPropertiesModel::singleSelectedNode() const
{ {
if (m_explicitSelection) if (m_explicitSelection)
return m_selectedNodes.first(); return m_selectedNodes.first();
else
return m_view->singleSelectedModelNode(); return m_view->singleSelectedModelNode();
} }
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -3,17 +3,17 @@
#pragma once #pragma once
#include <modelnode.h> #include <nodeinstanceglobal.h>
#include <bindingproperty.h>
#include <variantproperty.h>
#include <QStandardItemModel> #include <QStandardItemModel>
namespace QmlDesigner { namespace QmlDesigner {
class AbstractProperty;
class AbstractView; class AbstractView;
class BindingProperty;
namespace Internal { class ModelNode;
class VariantProperty;
class DynamicPropertiesModel : public QStandardItemModel class DynamicPropertiesModel : public QStandardItemModel
{ {
@@ -22,11 +22,13 @@ class DynamicPropertiesModel : public QStandardItemModel
public: public:
enum ColumnRoles { enum ColumnRoles {
TargetModelNodeRow = 0, TargetModelNodeRow = 0,
PropertyNameRow = 1, PropertyNameRow = 1,
PropertyTypeRow = 2, PropertyTypeRow = 2,
PropertyValueRow = 3 PropertyValueRow = 3
}; };
DynamicPropertiesModel(bool explicitSelection, AbstractView *parent); DynamicPropertiesModel(bool explicitSelection, AbstractView *parent);
void bindingPropertyChanged(const BindingProperty &bindingProperty); void bindingPropertyChanged(const BindingProperty &bindingProperty);
void abstractPropertyChanged(const AbstractProperty &bindingProperty); void abstractPropertyChanged(const AbstractProperty &bindingProperty);
void variantPropertyChanged(const VariantProperty &variantProperty); void variantPropertyChanged(const VariantProperty &variantProperty);
@@ -54,7 +56,7 @@ public:
void dispatchPropertyChanges(const AbstractProperty &abstractProperty); void dispatchPropertyChanges(const AbstractProperty &abstractProperty);
QmlDesigner::PropertyName unusedProperty(const QmlDesigner::ModelNode &modelNode); PropertyName unusedProperty(const ModelNode &modelNode);
static bool isValueType(const TypeName &type); static bool isValueType(const TypeName &type);
static QVariant defaultValueForType(const TypeName &type); static QVariant defaultValueForType(const TypeName &type);
@@ -84,7 +86,7 @@ protected:
void updateDisplayRole(int row, int columns, const QString &string); void updateDisplayRole(int row, int columns, const QString &string);
private: private:
void handleDataChanged(const QModelIndex &topLeft, const QModelIndex& bottomRight); void handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
void handleException(); void handleException();
AbstractView *m_view = nullptr; AbstractView *m_view = nullptr;
@@ -95,5 +97,4 @@ private:
bool m_explicitSelection = false; bool m_explicitSelection = false;
}; };
} // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -28,7 +28,7 @@
#include <dynamicpropertiesmodel.h> #include <dynamicpropertiesmodel.h>
#include <connectionview.h> #include <connectionview.h>
using namespace QmlDesigner::Internal; namespace QmlDesigner {
SelectionDynamicPropertiesProxyModel::SelectionDynamicPropertiesProxyModel(QObject *parent) SelectionDynamicPropertiesProxyModel::SelectionDynamicPropertiesProxyModel(QObject *parent)
: DynamicPropertiesProxyModel(parent) : DynamicPropertiesProxyModel(parent)
@@ -42,3 +42,5 @@ void SelectionDynamicPropertiesProxyModel::registerDeclarativeType()
DynamicPropertiesProxyModel::registerDeclarativeType(); DynamicPropertiesProxyModel::registerDeclarativeType();
qmlRegisterType<SelectionDynamicPropertiesProxyModel>("HelperWidgets", 2, 0, "SelectionDynamicPropertiesModel"); qmlRegisterType<SelectionDynamicPropertiesProxyModel>("HelperWidgets", 2, 0, "SelectionDynamicPropertiesModel");
} }
} // namespace QmlDesigner

View File

@@ -27,6 +27,8 @@
#include <dynamicpropertiesproxymodel.h> #include <dynamicpropertiesproxymodel.h>
namespace QmlDesigner {
class SelectionDynamicPropertiesProxyModel : public DynamicPropertiesProxyModel class SelectionDynamicPropertiesProxyModel : public DynamicPropertiesProxyModel
{ {
Q_OBJECT Q_OBJECT
@@ -35,3 +37,5 @@ public:
static void registerDeclarativeType(); static void registerDeclarativeType();
}; };
} // namespace QmlDesigner

View File

@@ -29,7 +29,7 @@
#include <materialeditorview.h> #include <materialeditorview.h>
using namespace QmlDesigner; namespace QmlDesigner {
MaterialEditorDynamicPropertiesProxyModel::MaterialEditorDynamicPropertiesProxyModel(QObject *parent) MaterialEditorDynamicPropertiesProxyModel::MaterialEditorDynamicPropertiesProxyModel(QObject *parent)
: DynamicPropertiesProxyModel(parent) : DynamicPropertiesProxyModel(parent)
@@ -43,3 +43,5 @@ void MaterialEditorDynamicPropertiesProxyModel::registerDeclarativeType()
DynamicPropertiesProxyModel::registerDeclarativeType(); DynamicPropertiesProxyModel::registerDeclarativeType();
qmlRegisterType<MaterialEditorDynamicPropertiesProxyModel>("HelperWidgets", 2, 0, "MaterialEditorDynamicPropertiesModel"); qmlRegisterType<MaterialEditorDynamicPropertiesProxyModel>("HelperWidgets", 2, 0, "MaterialEditorDynamicPropertiesModel");
} }
} // namespace QmlDesigner

View File

@@ -27,6 +27,8 @@
#include "dynamicpropertiesproxymodel.h" #include "dynamicpropertiesproxymodel.h"
namespace QmlDesigner {
class MaterialEditorDynamicPropertiesProxyModel : public DynamicPropertiesProxyModel class MaterialEditorDynamicPropertiesProxyModel : public DynamicPropertiesProxyModel
{ {
Q_OBJECT Q_OBJECT
@@ -35,3 +37,5 @@ public:
static void registerDeclarativeType(); static void registerDeclarativeType();
}; };
} // namespace QmlDesigner

View File

@@ -43,7 +43,7 @@ namespace QmlDesigner {
MaterialEditorView::MaterialEditorView(ExternalDependenciesInterface &externalDependencies) MaterialEditorView::MaterialEditorView(ExternalDependenciesInterface &externalDependencies)
: AbstractView{externalDependencies} : AbstractView{externalDependencies}
, m_stackedWidget(new QStackedWidget) , 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); m_updateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F7), m_stackedWidget);
connect(m_updateShortcut, &QShortcut::activated, this, &MaterialEditorView::reloadQml); connect(m_updateShortcut, &QShortcut::activated, this, &MaterialEditorView::reloadQml);
@@ -290,7 +290,7 @@ void MaterialEditorView::currentTimelineChanged(const ModelNode &)
m_qmlBackEnd->contextObject()->setHasActiveTimeline(QmlTimeline::hasActiveTimeline(this)); m_qmlBackEnd->contextObject()->setHasActiveTimeline(QmlTimeline::hasActiveTimeline(this));
} }
Internal::DynamicPropertiesModel *MaterialEditorView::dynamicPropertiesModel() const DynamicPropertiesModel *MaterialEditorView::dynamicPropertiesModel() const
{ {
return m_dynamicPropertiesModel; return m_dynamicPropertiesModel;
} }

View File

@@ -18,13 +18,10 @@ QT_END_NAMESPACE
namespace QmlDesigner { namespace QmlDesigner {
class DynamicPropertiesModel;
class ItemLibraryInfo; class ItemLibraryInfo;
class MaterialEditorQmlBackend; class MaterialEditorQmlBackend;
namespace Internal {
class DynamicPropertiesModel;
}
class MaterialEditorView : public AbstractView class MaterialEditorView : public AbstractView
{ {
Q_OBJECT Q_OBJECT
@@ -78,7 +75,7 @@ public:
void currentTimelineChanged(const ModelNode &node) override; void currentTimelineChanged(const ModelNode &node) override;
Internal::DynamicPropertiesModel *dynamicPropertiesModel() const; DynamicPropertiesModel *dynamicPropertiesModel() const;
static MaterialEditorView *instance(); static MaterialEditorView *instance();
@@ -132,7 +129,7 @@ private:
QPointer<QColorDialog> m_colorDialog; QPointer<QColorDialog> m_colorDialog;
QPointer<ItemLibraryInfo> m_itemLibraryInfo; QPointer<ItemLibraryInfo> m_itemLibraryInfo;
Internal::DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr; DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -25,6 +25,7 @@
#include "dynamicpropertiesproxymodel.h" #include "dynamicpropertiesproxymodel.h"
#include "bindingproperty.h"
#include "propertyeditorvalue.h" #include "propertyeditorvalue.h"
#include <dynamicpropertiesmodel.h> #include <dynamicpropertiesmodel.h>
@@ -40,7 +41,7 @@
#include <QScopeGuard> #include <QScopeGuard>
using namespace QmlDesigner; namespace QmlDesigner {
static const int propertyNameRole = Qt::UserRole + 1; static const int propertyNameRole = Qt::UserRole + 1;
static const int propertyTypeRole = Qt::UserRole + 2; 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; m_model = model;
@@ -79,17 +80,14 @@ void DynamicPropertiesProxyModel::initModel(QmlDesigner::Internal::DynamicProper
int DynamicPropertiesProxyModel::rowCount(const QModelIndex &) const int DynamicPropertiesProxyModel::rowCount(const QModelIndex &) const
{ {
if (!m_model) return m_model ? m_model->rowCount() : 0;
return 0;
return m_model->rowCount();
} }
QHash<int, QByteArray> DynamicPropertiesProxyModel::roleNames() const QHash<int, QByteArray> DynamicPropertiesProxyModel::roleNames() const
{ {
static QHash<int, QByteArray> roleNames{{propertyNameRole, "propertyName"}, static QHash<int, QByteArray> roleNames{{propertyNameRole, "propertyName"},
{propertyTypeRole, "propertyType"}, {propertyTypeRole, "propertyType"},
{propertyValueRole, "propertyValue"}, {propertyValueRole, "propertyValue"},
{propertyBindingRole, "propertyBinding"}}; {propertyBindingRole, "propertyBinding"}};
return roleNames; return roleNames;
@@ -102,26 +100,30 @@ QVariant DynamicPropertiesProxyModel::data(const QModelIndex &index, int role) c
QTC_ASSERT(property.isValid(), return QVariant()); QTC_ASSERT(property.isValid(), return QVariant());
if (role == propertyNameRole) { if (role == propertyNameRole)
return property.name(); return property.name();
} else if (propertyTypeRole) {
if (propertyTypeRole)
return property.dynamicTypeName(); return property.dynamicTypeName();
} else if (role == propertyValueRole) {
if (role == propertyValueRole) {
QmlObjectNode objectNode = property.parentQmlObjectNode(); QmlObjectNode objectNode = property.parentQmlObjectNode();
return objectNode.modelValue(property.name()); 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"; qWarning() << Q_FUNC_INFO << "invalid role";
} else { } else {
qWarning() << Q_FUNC_INFO << "invalid index"; qWarning() << Q_FUNC_INFO << "invalid index";
} }
return QVariant(); return {};
} }
void DynamicPropertiesProxyModel::registerDeclarativeType() void DynamicPropertiesProxyModel::registerDeclarativeType()
@@ -131,17 +133,16 @@ void DynamicPropertiesProxyModel::registerDeclarativeType()
qmlRegisterType<DynamicPropertiesProxyModel>("HelperWidgets", 2, 0, "DynamicPropertiesModel"); qmlRegisterType<DynamicPropertiesProxyModel>("HelperWidgets", 2, 0, "DynamicPropertiesModel");
} }
QmlDesigner::Internal::DynamicPropertiesModel *DynamicPropertiesProxyModel::dynamicPropertiesModel() const DynamicPropertiesModel *DynamicPropertiesProxyModel::dynamicPropertiesModel() const
{ {
return m_model; return m_model;
} }
QString DynamicPropertiesProxyModel::newPropertyName() const QString DynamicPropertiesProxyModel::newPropertyName() const
{ {
auto propertiesModel = dynamicPropertiesModel(); DynamicPropertiesModel *propsModel = dynamicPropertiesModel();
return QString::fromUtf8(propertiesModel->unusedProperty( return QString::fromUtf8(propsModel->unusedProperty(propsModel->singleSelectedNode()));
propertiesModel->singleSelectedNode()));
} }
void DynamicPropertiesProxyModel::createProperty(const QString &name, const QString &type) void DynamicPropertiesProxyModel::createProperty(const QString &name, const QString &type)
@@ -161,23 +162,22 @@ void DynamicPropertiesProxyModel::createProperty(const QString &name, const QStr
return; return;
} }
try { try {
if (Internal::DynamicPropertiesModel::isValueType(typeName)) { if (DynamicPropertiesModel::isValueType(typeName)) {
QVariant value = Internal::DynamicPropertiesModel::defaultValueForType(typeName); QVariant value = DynamicPropertiesModel::defaultValueForType(typeName);
modelNode.variantProperty(name.toUtf8()) VariantProperty variantProp = modelNode.variantProperty(name.toUtf8());
.setDynamicTypeNameAndValue(typeName, value); variantProp.setDynamicTypeNameAndValue(typeName, value);
} else { } else {
QString expression = Internal::DynamicPropertiesModel::defaultExpressionForType( QString expression = DynamicPropertiesModel::defaultExpressionForType(typeName);
typeName);
modelNode.bindingProperty(name.toUtf8()) BindingProperty bindingProp = modelNode.bindingProperty(name.toUtf8());
.setDynamicTypeNameAndExpression(typeName, expression); bindingProp.setDynamicTypeNameAndExpression(typeName, expression);
} }
} catch (Exception &e) { } catch (Exception &e) {
e.showException(); e.showException();
} }
} }
} else { } else {
qWarning() << " BindingModel::addBindingForCurrentNode not one node selected"; qWarning() << __FUNCTION__ << ": not one node selected";
} }
} }
@@ -194,7 +194,7 @@ DynamicPropertyRow::DynamicPropertyRow()
&PropertyEditorValue::expressionChanged, &PropertyEditorValue::expressionChanged,
this, this,
[this](const QString &name) { [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()); commitExpression(m_backendValue->expression());
else if (m_backendValue->expression().isEmpty()) else if (m_backendValue->expression().isEmpty())
resetValue(); resetValue();
@@ -254,7 +254,7 @@ DynamicPropertiesProxyModel *DynamicPropertyRow::model() const
return m_model; return m_model;
} }
QmlDesigner::PropertyEditorValue *DynamicPropertyRow::backendValue() const PropertyEditorValue *DynamicPropertyRow::backendValue() const
{ {
return m_backendValue; return m_backendValue;
} }
@@ -264,9 +264,9 @@ void DynamicPropertyRow::remove()
m_model->dynamicPropertiesModel()->deleteDynamicPropertyByRow(m_row); 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); m_proxyBackendValues.append(newValue);
return newValue; return newValue;
@@ -283,7 +283,7 @@ void DynamicPropertyRow::setupBackendValue()
if (!m_model) if (!m_model)
return; return;
QmlDesigner::AbstractProperty property = m_model->dynamicPropertiesModel()->abstractPropertyForRow(m_row); AbstractProperty property = m_model->dynamicPropertiesModel()->abstractPropertyForRow(m_row);
if (!property.isValid()) if (!property.isValid())
return; return;
@@ -326,15 +326,14 @@ void DynamicPropertyRow::commitValue(const QVariant &value)
auto propertiesModel = m_model->dynamicPropertiesModel(); auto propertiesModel = m_model->dynamicPropertiesModel();
VariantProperty variantProperty = propertiesModel->variantPropertyForRow(m_row); VariantProperty variantProperty = propertiesModel->variantPropertyForRow(m_row);
if (!Internal::DynamicPropertiesModel::isValueType(variantProperty.dynamicTypeName())) if (!DynamicPropertiesModel::isValueType(variantProperty.dynamicTypeName()))
return; return;
m_lock = true; m_lock = true;
auto unlock = qScopeGuard([this] { m_lock = false; }); auto unlock = qScopeGuard([this] { m_lock = false; });
auto view = propertiesModel->view(); auto view = propertiesModel->view();
RewriterTransaction transaction = view->beginRewriterTransaction( RewriterTransaction transaction = view->beginRewriterTransaction(__FUNCTION__);
QByteArrayLiteral("DynamicPropertiesModel::commitValue"));
try { try {
QmlObjectNode objectNode = variantProperty.parentQmlObjectNode(); QmlObjectNode objectNode = variantProperty.parentQmlObjectNode();
if (view->currentState().isBaseState() if (view->currentState().isBaseState()
@@ -347,7 +346,7 @@ void DynamicPropertyRow::commitValue(const QVariant &value)
if (objectNode.isValid() && objectNode.modelValue(name) != value) if (objectNode.isValid() && objectNode.modelValue(name) != value)
objectNode.setVariantProperty(name, value); objectNode.setVariantProperty(name, value);
} }
transaction.commit(); //committing in the try block transaction.commit(); // committing in the try block
} catch (Exception &e) { } catch (Exception &e) {
e.showException(); e.showException();
} }
@@ -355,10 +354,7 @@ void DynamicPropertyRow::commitValue(const QVariant &value)
void DynamicPropertyRow::commitExpression(const QString &expression) void DynamicPropertyRow::commitExpression(const QString &expression)
{ {
if (m_lock) if (m_lock || m_row < 0)
return;
if (m_row < 0)
return; return;
auto propertiesModel = m_model->dynamicPropertiesModel(); auto propertiesModel = m_model->dynamicPropertiesModel();
@@ -369,7 +365,7 @@ void DynamicPropertyRow::commitExpression(const QString &expression)
const QVariant literal = BindingProperty::convertToLiteral(bindingProperty.dynamicTypeName(), const QVariant literal = BindingProperty::convertToLiteral(bindingProperty.dynamicTypeName(),
expression); 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); commitValue(literal);
return; return;
} }
@@ -378,8 +374,7 @@ void DynamicPropertyRow::commitExpression(const QString &expression)
auto unlock = qScopeGuard([this] { m_lock = false; }); auto unlock = qScopeGuard([this] { m_lock = false; });
auto view = propertiesModel->view(); auto view = propertiesModel->view();
RewriterTransaction transaction = view->beginRewriterTransaction( RewriterTransaction transaction = view->beginRewriterTransaction(__FUNCTION__);
QByteArrayLiteral("DynamicPropertyRow::commitExpression"));
try { try {
QString theExpression = expression; QString theExpression = expression;
if (theExpression.isEmpty()) if (theExpression.isEmpty())
@@ -398,11 +393,10 @@ void DynamicPropertyRow::commitExpression(const QString &expression)
objectNode.setBindingProperty(name, theExpression); objectNode.setBindingProperty(name, theExpression);
} }
transaction.commit(); //committing in the try block transaction.commit(); // committing in the try block
} catch (Exception &e) { } catch (Exception &e) {
e.showException(); e.showException();
} }
return;
} }
void DynamicPropertyRow::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &, const QList<int> &) void DynamicPropertyRow::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &, const QList<int> &)
@@ -413,10 +407,7 @@ void DynamicPropertyRow::handleDataChanged(const QModelIndex &topLeft, const QMo
void DynamicPropertyRow::resetValue() void DynamicPropertyRow::resetValue()
{ {
if (m_lock) if (m_lock || m_row < 0)
return;
if (m_row < 0)
return; return;
auto propertiesModel = m_model->dynamicPropertiesModel(); auto propertiesModel = m_model->dynamicPropertiesModel();
@@ -426,20 +417,18 @@ void DynamicPropertyRow::resetValue()
TypeName typeName = property.dynamicTypeName(); TypeName typeName = property.dynamicTypeName();
if (view->currentState().isBaseState()) { if (view->currentState().isBaseState()) {
if (Internal::DynamicPropertiesModel::isValueType(typeName)) { if (DynamicPropertiesModel::isValueType(typeName)) {
QVariant value = Internal::DynamicPropertiesModel::defaultValueForType(typeName); QVariant value = DynamicPropertiesModel::defaultValueForType(typeName);
commitValue(value); commitValue(value);
} else { } else {
QString expression = Internal::DynamicPropertiesModel::defaultExpressionForType( QString expression = DynamicPropertiesModel::defaultExpressionForType(typeName);
typeName);
commitExpression(expression); commitExpression(expression);
} }
} else { } else {
m_lock = true; m_lock = true;
auto unlock = qScopeGuard([this] { m_lock = false; }); auto unlock = qScopeGuard([this] { m_lock = false; });
RewriterTransaction transaction = view->beginRewriterTransaction( RewriterTransaction transaction = view->beginRewriterTransaction(__FUNCTION__);
QByteArrayLiteral("DynamicPropertyRow::resetValue"));
try { try {
QmlObjectNode objectNode = property.parentQmlObjectNode(); QmlObjectNode objectNode = property.parentQmlObjectNode();
QTC_CHECK(objectNode.isValid()); QTC_CHECK(objectNode.isValid());
@@ -447,9 +436,11 @@ void DynamicPropertyRow::resetValue()
if (objectNode.isValid() && objectNode.propertyAffectedByCurrentState(name)) if (objectNode.isValid() && objectNode.propertyAffectedByCurrentState(name))
objectNode.removeProperty(name); objectNode.removeProperty(name);
transaction.commit(); //committing in the try block transaction.commit(); // committing in the try block
} catch (Exception &e) { } catch (Exception &e) {
e.showException(); e.showException();
} }
} }
} }
} // namespace QmlDesigner

View File

@@ -30,16 +30,13 @@
#include <abstractview.h> #include <abstractview.h>
#include <qmlitemnode.h> #include <qmlitemnode.h>
#include <enumeration.h>
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QColor> #include <QColor>
#include <QtQml> #include <QtQml>
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal {
class DynamicPropertiesModel; class DynamicPropertiesModel;
}
} // namespace QmlDesigner
class DynamicPropertiesProxyModel : public QAbstractListModel class DynamicPropertiesProxyModel : public QAbstractListModel
{ {
@@ -55,16 +52,16 @@ public:
static void registerDeclarativeType(); static void registerDeclarativeType();
QmlDesigner::Internal::DynamicPropertiesModel *dynamicPropertiesModel() const; DynamicPropertiesModel *dynamicPropertiesModel() const;
Q_INVOKABLE QString newPropertyName() const; Q_INVOKABLE QString newPropertyName() const;
Q_INVOKABLE void createProperty(const QString &name, const QString &type); Q_INVOKABLE void createProperty(const QString &name, const QString &type);
protected: protected:
void initModel(QmlDesigner::Internal::DynamicPropertiesModel *model); void initModel(DynamicPropertiesModel *model);
private: private:
QmlDesigner::Internal::DynamicPropertiesModel *m_model = nullptr; DynamicPropertiesModel *m_model = nullptr;
}; };
class DynamicPropertyRow : public QObject class DynamicPropertyRow : public QObject
@@ -109,4 +106,6 @@ private:
bool m_lock = false; bool m_lock = false;
}; };
QML_DECLARE_TYPE(DynamicPropertyRow) } // namespace QmlDesigner
QML_DECLARE_TYPE(QmlDesigner::DynamicPropertyRow)

View File

@@ -6,7 +6,7 @@
#include "dynamicpropertiesmodel.h" #include "dynamicpropertiesmodel.h"
#include "textureeditorview.h" #include "textureeditorview.h"
using namespace QmlDesigner; namespace QmlDesigner {
TextureEditorDynamicPropertiesProxyModel::TextureEditorDynamicPropertiesProxyModel(QObject *parent) TextureEditorDynamicPropertiesProxyModel::TextureEditorDynamicPropertiesProxyModel(QObject *parent)
: DynamicPropertiesProxyModel(parent) : DynamicPropertiesProxyModel(parent)
@@ -20,3 +20,5 @@ void TextureEditorDynamicPropertiesProxyModel::registerDeclarativeType()
DynamicPropertiesProxyModel::registerDeclarativeType(); DynamicPropertiesProxyModel::registerDeclarativeType();
qmlRegisterType<TextureEditorDynamicPropertiesProxyModel>("HelperWidgets", 2, 0, "TextureEditorDynamicPropertiesModel"); qmlRegisterType<TextureEditorDynamicPropertiesProxyModel>("HelperWidgets", 2, 0, "TextureEditorDynamicPropertiesModel");
} }
} // namespace QmlDesigner

View File

@@ -5,6 +5,8 @@
#include "dynamicpropertiesproxymodel.h" #include "dynamicpropertiesproxymodel.h"
namespace QmlDesigner {
class TextureEditorDynamicPropertiesProxyModel : public DynamicPropertiesProxyModel class TextureEditorDynamicPropertiesProxyModel : public DynamicPropertiesProxyModel
{ {
Q_OBJECT Q_OBJECT
@@ -14,3 +16,5 @@ public:
static void registerDeclarativeType(); static void registerDeclarativeType();
}; };
} // namespace QmlDesigner

View File

@@ -55,7 +55,7 @@ TextureEditorView::TextureEditorView(AsynchronousImageCache &imageCache,
: AbstractView{externalDependencies} : AbstractView{externalDependencies}
, m_imageCache(imageCache) , m_imageCache(imageCache)
, m_stackedWidget(new QStackedWidget) , 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); m_updateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F12), m_stackedWidget);
connect(m_updateShortcut, &QShortcut::activated, this, &TextureEditorView::reloadQml); connect(m_updateShortcut, &QShortcut::activated, this, &TextureEditorView::reloadQml);
@@ -291,7 +291,7 @@ void TextureEditorView::currentTimelineChanged(const ModelNode &)
m_qmlBackEnd->contextObject()->setHasActiveTimeline(QmlTimeline::hasActiveTimeline(this)); m_qmlBackEnd->contextObject()->setHasActiveTimeline(QmlTimeline::hasActiveTimeline(this));
} }
Internal::DynamicPropertiesModel *TextureEditorView::dynamicPropertiesModel() const DynamicPropertiesModel *TextureEditorView::dynamicPropertiesModel() const
{ {
return m_dynamicPropertiesModel; return m_dynamicPropertiesModel;
} }

View File

@@ -19,13 +19,10 @@ QT_END_NAMESPACE
namespace QmlDesigner { namespace QmlDesigner {
class DynamicPropertiesModel;
class ModelNode; class ModelNode;
class TextureEditorQmlBackend; class TextureEditorQmlBackend;
namespace Internal {
class DynamicPropertiesModel;
}
class TextureEditorView : public AbstractView class TextureEditorView : public AbstractView
{ {
Q_OBJECT Q_OBJECT
@@ -77,7 +74,7 @@ public:
void currentTimelineChanged(const ModelNode &node) override; void currentTimelineChanged(const ModelNode &node) override;
Internal::DynamicPropertiesModel *dynamicPropertiesModel() const; DynamicPropertiesModel *dynamicPropertiesModel() const;
static TextureEditorView *instance(); static TextureEditorView *instance();
@@ -123,7 +120,7 @@ private:
QPointer<QColorDialog> m_colorDialog; QPointer<QColorDialog> m_colorDialog;
QPointer<ItemLibraryInfo> m_itemLibraryInfo; QPointer<ItemLibraryInfo> m_itemLibraryInfo;
Internal::DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr; DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -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 //TODO Move registering those types out of the property editor, since they are used also in the states editor
Quick2PropertyEditorView::registerQmlTypes(); Quick2PropertyEditorView::registerQmlTypes();
if (QmlDesigner::checkEnterpriseLicense()) if (checkEnterpriseLicense())
Core::IWizardFactory::registerFeatureProvider(new EnterpriseFeatureProvider); Core::IWizardFactory::registerFeatureProvider(new EnterpriseFeatureProvider);
Exception::setWarnAboutException(!QmlDesignerPlugin::instance() Exception::setWarnAboutException(!QmlDesignerPlugin::instance()
->settings() ->settings()
@@ -292,29 +292,29 @@ bool QmlDesignerPlugin::delayedInitialize()
MetaInfo::setPluginPaths(pluginPaths); MetaInfo::setPluginPaths(pluginPaths);
d->viewManager.registerView( d->viewManager.registerView(
std::make_unique<QmlDesigner::Internal::ConnectionView>(d->externalDependencies)); std::make_unique<ConnectionView>(d->externalDependencies));
auto timelineView = d->viewManager.registerView( auto timelineView = d->viewManager.registerView(
std::make_unique<QmlDesigner::TimelineView>(d->externalDependencies)); std::make_unique<TimelineView>(d->externalDependencies));
timelineView->registerActions(); timelineView->registerActions();
d->viewManager.registerView( d->viewManager.registerView(
std::make_unique<QmlDesigner::CurveEditorView>(d->externalDependencies)); std::make_unique<CurveEditorView>(d->externalDependencies));
auto eventlistView = d->viewManager.registerView( auto eventlistView = d->viewManager.registerView(
std::make_unique<QmlDesigner::EventListPluginView>(d->externalDependencies)); std::make_unique<EventListPluginView>(d->externalDependencies));
eventlistView->registerActions(); eventlistView->registerActions();
auto transitionEditorView = d->viewManager.registerView( auto transitionEditorView = d->viewManager.registerView(
std::make_unique<QmlDesigner::TransitionEditorView>(d->externalDependencies)); std::make_unique<TransitionEditorView>(d->externalDependencies));
transitionEditorView->registerActions(); transitionEditorView->registerActions();
d->viewManager.registerFormEditorTool(std::make_unique<QmlDesigner::SourceTool>()); d->viewManager.registerFormEditorTool(std::make_unique<SourceTool>());
d->viewManager.registerFormEditorTool(std::make_unique<QmlDesigner::ColorTool>()); d->viewManager.registerFormEditorTool(std::make_unique<ColorTool>());
d->viewManager.registerFormEditorTool(std::make_unique<QmlDesigner::TextTool>()); d->viewManager.registerFormEditorTool(std::make_unique<TextTool>());
d->viewManager.registerFormEditorTool( d->viewManager.registerFormEditorTool(
std::make_unique<QmlDesigner::PathTool>(d->externalDependencies)); std::make_unique<PathTool>(d->externalDependencies));
d->viewManager.registerFormEditorTool(std::make_unique<QmlDesigner::TransitionTool>()); d->viewManager.registerFormEditorTool(std::make_unique<TransitionTool>());
if (QmlProjectManager::QmlProject::isQtDesignStudio()) { if (QmlProjectManager::QmlProject::isQtDesignStudio()) {
d->mainWidget.initialize(); d->mainWidget.initialize();
@@ -495,7 +495,7 @@ void QmlDesignerPlugin::hideDesigner()
d->shortCutManager.disconnectUndoActions(currentDesignDocument()); d->shortCutManager.disconnectUndoActions(currentDesignDocument());
d->documentManager.setCurrentDesignDocument(nullptr); d->documentManager.setCurrentDesignDocument(nullptr);
d->shortCutManager.updateUndoActions(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() void QmlDesignerPlugin::changeEditor()