forked from qt-creator/qt-creator
QmlDesigner: Add Singleton support to Connections
Change-Id: I07eae4e381f172d7c6a23ee5b7e13273afa788b9 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -34,6 +34,8 @@
|
|||||||
#include <exception.h>
|
#include <exception.h>
|
||||||
#include <nodemetainfo.h>
|
#include <nodemetainfo.h>
|
||||||
#include <nodelistproperty.h>
|
#include <nodelistproperty.h>
|
||||||
|
#include <rewriterview.h>
|
||||||
|
#include <nodemetainfo.h>
|
||||||
|
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -209,10 +211,27 @@ void ConnectionModel::updateTargetNode(int rowNumber)
|
|||||||
ModelNode connectionNode = signalHandlerProperty.parentModelNode();
|
ModelNode connectionNode = signalHandlerProperty.parentModelNode();
|
||||||
|
|
||||||
const bool isAlias = newTarget.contains(".");
|
const bool isAlias = newTarget.contains(".");
|
||||||
|
bool isSingleton = false;
|
||||||
|
|
||||||
|
if (RewriterView* rv = connectionView()->rewriterView()) {
|
||||||
|
for (const QmlTypeData &data : rv->getQMLTypes()) {
|
||||||
|
if (!data.typeName.isEmpty()) {
|
||||||
|
if (data.typeName == newTarget) {
|
||||||
|
if (connectionView()->model()->metaInfo(data.typeName.toUtf8()).isValid()) {
|
||||||
|
isSingleton = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!newTarget.isEmpty()) {
|
if (!newTarget.isEmpty()) {
|
||||||
//if it's an alias, then let's reparent connections to alias property owner:
|
//if it's a singleton, then let's reparent connections to rootNode,
|
||||||
const ModelNode parent = connectionView()->modelNodeForId(isAlias
|
//if it's an alias, then reparent to alias property owner:
|
||||||
|
const ModelNode parent = connectionView()->modelNodeForId(isSingleton
|
||||||
|
? connectionView()->rootModelNode().id()
|
||||||
|
: isAlias
|
||||||
? newTarget.split(".").constFirst()
|
? newTarget.split(".").constFirst()
|
||||||
: newTarget);
|
: newTarget);
|
||||||
|
|
||||||
@@ -430,6 +449,28 @@ QStringList ConnectionModel::getPossibleSignalsForConnection(const ModelNode &co
|
|||||||
QStringList stringList;
|
QStringList stringList;
|
||||||
|
|
||||||
if (connection.isValid()) {
|
if (connection.isValid()) {
|
||||||
|
|
||||||
|
//separate check for singletons
|
||||||
|
if (connection.hasBindingProperty("target")) {
|
||||||
|
BindingProperty bp = connection.bindingProperty("target");
|
||||||
|
|
||||||
|
if (bp.isValid()) {
|
||||||
|
if (RewriterView *rv = connectionView()->rewriterView()) {
|
||||||
|
for (const QmlTypeData &data : rv->getQMLTypes()) {
|
||||||
|
if (!data.typeName.isEmpty()) {
|
||||||
|
if (data.typeName == bp.expression()) {
|
||||||
|
NodeMetaInfo metaInfo = connectionView()->model()->metaInfo(data.typeName.toUtf8());
|
||||||
|
if (metaInfo.isValid()) {
|
||||||
|
stringList.append(propertyNameListToStringList(metaInfo.signalNames()));
|
||||||
|
return stringList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ModelNode targetNode = getTargetNodeForConnection(connection);
|
ModelNode targetNode = getTargetNodeForConnection(connection);
|
||||||
if (targetNode.isValid() && targetNode.metaInfo().isValid()) {
|
if (targetNode.isValid() && targetNode.metaInfo().isValid()) {
|
||||||
stringList.append(propertyNameListToStringList(targetNode.metaInfo().signalNames()));
|
stringList.append(propertyNameListToStringList(targetNode.metaInfo().signalNames()));
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "bindingmodel.h"
|
#include "bindingmodel.h"
|
||||||
#include "dynamicpropertiesmodel.h"
|
#include "dynamicpropertiesmodel.h"
|
||||||
#include "connectionview.h"
|
#include "connectionview.h"
|
||||||
|
#include "nodemetainfo.h"
|
||||||
|
|
||||||
#include <bindingproperty.h>
|
#include <bindingproperty.h>
|
||||||
|
|
||||||
@@ -152,11 +153,13 @@ QWidget *BindingDelegate::createEditor(QWidget *parent, const QStyleOptionViewIt
|
|||||||
bindingComboBox->addItems(model->possibleTargetProperties(bindingProperty));
|
bindingComboBox->addItems(model->possibleTargetProperties(bindingProperty));
|
||||||
} break;
|
} break;
|
||||||
case BindingModel::SourceModelNodeRow: {
|
case BindingModel::SourceModelNodeRow: {
|
||||||
|
//common items
|
||||||
for (const ModelNode &modelNode : model->connectionView()->allModelNodes()) {
|
for (const ModelNode &modelNode : model->connectionView()->allModelNodes()) {
|
||||||
if (!modelNode.id().isEmpty()) {
|
if (!modelNode.id().isEmpty()) {
|
||||||
bindingComboBox->addItem(modelNode.id());
|
bindingComboBox->addItem(modelNode.id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//singletons:
|
||||||
if (RewriterView* rv = model->connectionView()->rewriterView()) {
|
if (RewriterView* rv = model->connectionView()->rewriterView()) {
|
||||||
for (const QmlTypeData &data : rv->getQMLTypes()) {
|
for (const QmlTypeData &data : rv->getQMLTypes()) {
|
||||||
if (!data.typeName.isEmpty()) {
|
if (!data.typeName.isEmpty()) {
|
||||||
@@ -164,6 +167,7 @@ QWidget *BindingDelegate::createEditor(QWidget *parent, const QStyleOptionViewIt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//parent:
|
||||||
if (!bindingProperty.parentModelNode().isRootNode())
|
if (!bindingProperty.parentModelNode().isRootNode())
|
||||||
bindingComboBox->addItem(QLatin1String("parent"));
|
bindingComboBox->addItem(QLatin1String("parent"));
|
||||||
} break;
|
} break;
|
||||||
@@ -306,6 +310,26 @@ QWidget *ConnectionDelegate::createEditor(QWidget *parent, const QStyleOptionVie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//singletons:
|
||||||
|
if (RewriterView* rv = connectionModel->connectionView()->rewriterView()) {
|
||||||
|
for (const QmlTypeData &data : rv->getQMLTypes()) {
|
||||||
|
if (!data.typeName.isEmpty()) {
|
||||||
|
connectionComboBox->addItem(data.typeName);
|
||||||
|
|
||||||
|
NodeMetaInfo metaInfo = connectionModel->connectionView()->model()->metaInfo(data.typeName.toUtf8());
|
||||||
|
|
||||||
|
if (metaInfo.isValid()) {
|
||||||
|
for (const PropertyName &propertyName : metaInfo.propertyNames()) {
|
||||||
|
if (metaInfo.propertyTypeName(propertyName) == "alias") {
|
||||||
|
connectionComboBox->addItem(data.typeName
|
||||||
|
+ "."
|
||||||
|
+ QString::fromUtf8(propertyName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case ConnectionModel::TargetPropertyNameRow: {
|
case ConnectionModel::TargetPropertyNameRow: {
|
||||||
connectionComboBox->addItems(prependOnForSignalHandler(connectionModel->getSignalsForRow(index.row())));
|
connectionComboBox->addItems(prependOnForSignalHandler(connectionModel->getSignalsForRow(index.row())));
|
||||||
|
Reference in New Issue
Block a user