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 "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

View File

@@ -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

View File

@@ -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

View File

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

View File

@@ -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<SignalHandlerProperty> allSignals = node.signalProperties();
@@ -527,6 +525,4 @@ QStringList ConnectionModel::getPossibleSignalsForConnection(const ModelNode &co
return stringList;
}
} // namespace Internal
} // namespace QmlDesigner

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -3,32 +3,32 @@
#include "dynamicpropertiesmodel.h"
#include "connectionview.h"
#include <bindingproperty.h>
#include <nodemetainfo.h>
#include <nodeproperty.h>
#include <rewritertransaction.h>
#include <rewritingexception.h>
#include <variantproperty.h>
#include <qmldesignerconstants.h>
#include <qmldesignerplugin.h>
#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 <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <QMessageBox>
#include <QTimer>
#include <QUrl>
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();
@@ -211,10 +207,9 @@ 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
void DynamicPropertiesModel::resetProperty(const PropertyName &name)
@@ -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,15 +273,15 @@ void DynamicPropertiesModel::bindingPropertyChanged(const BindingProperty &bindi
const QList<ModelNode> 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<ModelNode> 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<ModelNode> 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<ModelNode> 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<ModelNode> 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,13 +504,12 @@ 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]() {
m_view->executeInTransaction(__FUNCTION__, [this, rowNumber]() {
const AbstractProperty property = abstractPropertyForRow(rowNumber);
const PropertyName propertyName = property.name();
BindingProperty bindingProperty = bindingPropertyForRow(rowNumber);
@@ -531,7 +529,7 @@ void DynamicPropertiesModel::deleteDynamicPropertyByRow(int rowNumber)
stateOperation.modelNode().removeProperty(propertyName);
}
const auto timelineNodes = objectNode.allTimelines();
const QList<ModelNode> timelineNodes = objectNode.allTimelines();
for (auto &timelineNode : timelineNodes) {
QmlTimeline timeline(timelineNode);
timeline.removeKeyframesForTargetAndProperty(objectNode.modelNode(),
@@ -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<AbstractProperty> properties = modelNode.properties();
QList<AbstractProperty> dynamicProperties = Utils::filtered(properties, [](const AbstractProperty &p) {
return p.isDynamic();
});
@@ -663,7 +659,7 @@ 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
@@ -679,7 +675,7 @@ 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
@@ -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;
}
@@ -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,7 +912,7 @@ const QList<ModelNode> DynamicPropertiesModel::selectedNodes() const
// Otherwise return actual selected nodes of the model.
if (m_explicitSelection)
return m_selectedNodes;
else
return m_view->selectedModelNodes();
}
@@ -934,10 +920,8 @@ const ModelNode DynamicPropertiesModel::singleSelectedNode() const
{
if (m_explicitSelection)
return m_selectedNodes.first();
else
return m_view->singleSelectedModelNode();
}
} // namespace Internal
} // namespace QmlDesigner

View File

@@ -3,17 +3,17 @@
#pragma once
#include <modelnode.h>
#include <bindingproperty.h>
#include <variantproperty.h>
#include <nodeinstanceglobal.h>
#include <QStandardItemModel>
namespace QmlDesigner {
class AbstractProperty;
class AbstractView;
namespace Internal {
class BindingProperty;
class ModelNode;
class VariantProperty;
class DynamicPropertiesModel : public QStandardItemModel
{
@@ -26,7 +26,9 @@ public:
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);
@@ -95,5 +97,4 @@ private:
bool m_explicitSelection = false;
};
} // namespace Internal
} // namespace QmlDesigner

View File

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

View File

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

View File

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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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<QColorDialog> m_colorDialog;
QPointer<ItemLibraryInfo> m_itemLibraryInfo;
Internal::DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr;
DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr;
};
} // namespace QmlDesigner

View File

@@ -25,6 +25,7 @@
#include "dynamicpropertiesproxymodel.h"
#include "bindingproperty.h"
#include "propertyeditorvalue.h"
#include <dynamicpropertiesmodel.h>
@@ -40,7 +41,7 @@
#include <QScopeGuard>
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,10 +80,7 @@ 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<int, QByteArray> DynamicPropertiesProxyModel::roleNames() const
@@ -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<DynamicPropertiesProxyModel>("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";
}
}
@@ -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()
@@ -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();
@@ -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())
@@ -402,7 +397,6 @@ void DynamicPropertyRow::commitExpression(const QString &expression)
} catch (Exception &e) {
e.showException();
}
return;
}
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()
{
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());
@@ -453,3 +442,5 @@ void DynamicPropertyRow::resetValue()
}
}
}
} // namespace QmlDesigner

View File

@@ -30,16 +30,13 @@
#include <abstractview.h>
#include <qmlitemnode.h>
#include <enumeration.h>
#include <QAbstractListModel>
#include <QColor>
#include <QtQml>
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)

View File

@@ -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<TextureEditorDynamicPropertiesProxyModel>("HelperWidgets", 2, 0, "TextureEditorDynamicPropertiesModel");
}
} // namespace QmlDesigner

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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<QColorDialog> m_colorDialog;
QPointer<ItemLibraryInfo> m_itemLibraryInfo;
Internal::DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr;
DynamicPropertiesModel *m_dynamicPropertiesModel = nullptr;
};
} // 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
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<QmlDesigner::Internal::ConnectionView>(d->externalDependencies));
std::make_unique<ConnectionView>(d->externalDependencies));
auto timelineView = d->viewManager.registerView(
std::make_unique<QmlDesigner::TimelineView>(d->externalDependencies));
std::make_unique<TimelineView>(d->externalDependencies));
timelineView->registerActions();
d->viewManager.registerView(
std::make_unique<QmlDesigner::CurveEditorView>(d->externalDependencies));
std::make_unique<CurveEditorView>(d->externalDependencies));
auto eventlistView = d->viewManager.registerView(
std::make_unique<QmlDesigner::EventListPluginView>(d->externalDependencies));
std::make_unique<EventListPluginView>(d->externalDependencies));
eventlistView->registerActions();
auto transitionEditorView = d->viewManager.registerView(
std::make_unique<QmlDesigner::TransitionEditorView>(d->externalDependencies));
std::make_unique<TransitionEditorView>(d->externalDependencies));
transitionEditorView->registerActions();
d->viewManager.registerFormEditorTool(std::make_unique<QmlDesigner::SourceTool>());
d->viewManager.registerFormEditorTool(std::make_unique<QmlDesigner::ColorTool>());
d->viewManager.registerFormEditorTool(std::make_unique<QmlDesigner::TextTool>());
d->viewManager.registerFormEditorTool(std::make_unique<SourceTool>());
d->viewManager.registerFormEditorTool(std::make_unique<ColorTool>());
d->viewManager.registerFormEditorTool(std::make_unique<TextTool>());
d->viewManager.registerFormEditorTool(
std::make_unique<QmlDesigner::PathTool>(d->externalDependencies));
d->viewManager.registerFormEditorTool(std::make_unique<QmlDesigner::TransitionTool>());
std::make_unique<PathTool>(d->externalDependencies));
d->viewManager.registerFormEditorTool(std::make_unique<TransitionTool>());
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()