2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
#include "connectionview.h"
|
|
|
|
|
|
2016-09-26 16:05:15 +02:00
|
|
|
#include "backendmodel.h"
|
2015-09-18 15:38:15 +02:00
|
|
|
#include "bindingmodel.h"
|
|
|
|
|
#include "connectionmodel.h"
|
|
|
|
|
#include "dynamicpropertiesmodel.h"
|
2023-08-29 18:10:37 +02:00
|
|
|
#include "propertytreemodel.h"
|
2023-07-04 19:57:59 +02:00
|
|
|
#include "theme.h"
|
2015-09-18 15:38:15 +02:00
|
|
|
|
|
|
|
|
#include <bindingproperty.h>
|
|
|
|
|
#include <nodeabstractproperty.h>
|
2019-12-05 14:33:42 +01:00
|
|
|
#include <signalhandlerproperty.h>
|
2023-08-25 16:53:39 +02:00
|
|
|
#include <variantproperty.h>
|
2022-07-07 19:02:41 +02:00
|
|
|
#include <viewmanager.h>
|
2023-08-25 16:53:39 +02:00
|
|
|
#include <qmldesignerconstants.h>
|
|
|
|
|
#include <qmldesignerplugin.h>
|
2022-07-07 19:02:41 +02:00
|
|
|
|
2023-07-04 19:57:59 +02:00
|
|
|
#include <studioquickwidget.h>
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/messagebox.h>
|
|
|
|
|
|
2022-07-07 19:02:41 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2015-09-18 15:38:15 +02:00
|
|
|
|
2023-07-04 19:57:59 +02:00
|
|
|
#include <QQmlEngine>
|
|
|
|
|
#include <QShortcut>
|
2020-10-06 12:29:09 +02:00
|
|
|
#include <QTableView>
|
|
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
2023-07-04 19:57:59 +02:00
|
|
|
static QString propertyEditorResourcesPath()
|
|
|
|
|
{
|
|
|
|
|
#ifdef SHARE_QML_PATH
|
|
|
|
|
if (qEnvironmentVariableIsSet("LOAD_QML_FROM_SOURCE"))
|
|
|
|
|
return QLatin1String(SHARE_QML_PATH) + "/propertyEditorQmlSources";
|
|
|
|
|
#endif
|
|
|
|
|
return Core::ICore::resourcePath("qmldesigner/propertyEditorQmlSources").toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ConnectionViewQuickWidget : public StudioQuickWidget
|
|
|
|
|
{
|
|
|
|
|
// Q_OBJECT carefull
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ConnectionViewQuickWidget(ConnectionView *connectionEditorView)
|
|
|
|
|
: m_connectionEditorView(connectionEditorView)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
engine()->addImportPath(qmlSourcesPath());
|
|
|
|
|
engine()->addImportPath(propertyEditorResourcesPath() + "/imports");
|
|
|
|
|
engine()->addImportPath(qmlSourcesPath() + "/imports");
|
|
|
|
|
|
|
|
|
|
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_F12), this);
|
|
|
|
|
connect(m_qmlSourceUpdateShortcut,
|
|
|
|
|
&QShortcut::activated,
|
|
|
|
|
this,
|
|
|
|
|
&ConnectionViewQuickWidget::reloadQmlSource);
|
|
|
|
|
|
2023-08-25 16:53:39 +02:00
|
|
|
quickWidget()->setObjectName(Constants::OBJECT_NAME_CONNECTION_EDITOR);
|
2023-07-04 19:57:59 +02:00
|
|
|
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
|
|
auto map = registerPropertyMap("ConnectionsEditorEditorBackend");
|
|
|
|
|
qmlRegisterAnonymousType<DynamicPropertiesModel>("ConnectionsEditorEditorBackend", 1);
|
|
|
|
|
qmlRegisterAnonymousType<DynamicPropertiesModelBackendDelegate>(
|
|
|
|
|
"ConnectionsEditorEditorBackend", 1);
|
|
|
|
|
|
|
|
|
|
map->setProperties(
|
2023-08-23 12:12:07 +02:00
|
|
|
{{"connectionModel", QVariant::fromValue(m_connectionEditorView->connectionModel())}});
|
|
|
|
|
|
|
|
|
|
map->setProperties(
|
|
|
|
|
{{"bindingModel", QVariant::fromValue(m_connectionEditorView->bindingModel())}});
|
|
|
|
|
|
|
|
|
|
map->setProperties(
|
|
|
|
|
{{"dynamicPropertiesModel",
|
2023-07-04 19:57:59 +02:00
|
|
|
QVariant::fromValue(m_connectionEditorView->dynamicPropertiesModel())}});
|
|
|
|
|
|
2023-08-29 18:10:37 +02:00
|
|
|
qmlRegisterType<ConnectionModelBackendDelegate>("ConnectionsEditorEditorBackend",
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
"DynamicPropertiesModelBackendDelegate");
|
|
|
|
|
|
|
|
|
|
qmlRegisterType<ConnectionModelStatementDelegate>("ConnectionsEditorEditorBackend",
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
"ConnectionModelStatementDelegate");
|
|
|
|
|
|
2023-09-04 16:45:54 +02:00
|
|
|
qmlRegisterType<ConditionListModel>("ConnectionsEditorEditorBackend", 1, 0, "ConditionListModel");
|
|
|
|
|
|
|
|
|
|
qmlRegisterType<PropertyTreeModel>("ConnectionsEditorEditorBackend", 1, 0, "PropertyTreeModel");
|
|
|
|
|
qmlRegisterType<PropertyListProxyModel>("ConnectionsEditorEditorBackend",
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
"PropertyListProxyModel");
|
2023-08-29 18:10:37 +02:00
|
|
|
|
2023-07-04 19:57:59 +02:00
|
|
|
Theme::setupTheme(engine());
|
|
|
|
|
|
|
|
|
|
setMinimumWidth(195);
|
|
|
|
|
setMinimumHeight(195);
|
|
|
|
|
|
|
|
|
|
// init the first load of the QML UI elements
|
|
|
|
|
reloadQmlSource();
|
|
|
|
|
}
|
|
|
|
|
~ConnectionViewQuickWidget() = default;
|
|
|
|
|
|
|
|
|
|
static QString qmlSourcesPath()
|
|
|
|
|
{
|
|
|
|
|
#ifdef SHARE_QML_PATH
|
|
|
|
|
if (qEnvironmentVariableIsSet("LOAD_QML_FROM_SOURCE"))
|
|
|
|
|
return QLatin1String(SHARE_QML_PATH) + "/connectionseditor";
|
|
|
|
|
#endif
|
|
|
|
|
return Core::ICore::resourcePath("qmldesigner/connectionseditor").toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void reloadQmlSource()
|
|
|
|
|
{
|
|
|
|
|
QString connectionEditorQmlFilePath = qmlSourcesPath() + QStringLiteral("/Main.qml");
|
|
|
|
|
QTC_ASSERT(QFileInfo::exists(connectionEditorQmlFilePath), return );
|
|
|
|
|
setSource(QUrl::fromLocalFile(connectionEditorQmlFilePath));
|
|
|
|
|
|
|
|
|
|
if (!rootObject()) {
|
|
|
|
|
QString errorString;
|
|
|
|
|
for (const QQmlError &error : errors())
|
|
|
|
|
errorString += "\n" + error.toString();
|
|
|
|
|
|
|
|
|
|
Core::AsynchronousMessageBox::warning(
|
|
|
|
|
tr("Cannot Create QtQuick View"),
|
|
|
|
|
tr("ConnectionsEditorWidget: %1 cannot be created.%2")
|
|
|
|
|
.arg(qmlSourcesPath(), errorString));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QPointer<ConnectionView> m_connectionEditorView;
|
|
|
|
|
QShortcut *m_qmlSourceUpdateShortcut;
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-15 15:01:49 +02:00
|
|
|
ConnectionView::ConnectionView(ExternalDependenciesInterface &externalDependencies)
|
2023-08-23 12:12:07 +02:00
|
|
|
: AbstractView{externalDependencies}
|
|
|
|
|
, m_connectionModel(new ConnectionModel(this))
|
|
|
|
|
, m_bindingModel(new BindingModel(this))
|
|
|
|
|
, m_dynamicPropertiesModel(new DynamicPropertiesModel(false, this))
|
|
|
|
|
, m_backendModel(new BackendModel(this))
|
|
|
|
|
, m_connectionViewQuickWidget(new ConnectionViewQuickWidget(this))
|
|
|
|
|
{}
|
2015-09-18 15:38:15 +02:00
|
|
|
|
2023-07-04 19:57:59 +02:00
|
|
|
ConnectionView::~ConnectionView()
|
|
|
|
|
{
|
|
|
|
|
// Ensure that QML is deleted first to avoid calling back to C++.
|
|
|
|
|
delete m_connectionViewQuickWidget.data();
|
|
|
|
|
}
|
2015-09-18 15:38:15 +02:00
|
|
|
void ConnectionView::modelAttached(Model *model)
|
|
|
|
|
{
|
|
|
|
|
AbstractView::modelAttached(model);
|
2023-08-23 12:12:07 +02:00
|
|
|
bindingModel()->reset();
|
2022-07-22 16:46:48 +02:00
|
|
|
dynamicPropertiesModel()->reset();
|
2015-09-18 15:38:15 +02:00
|
|
|
connectionModel()->resetModel();
|
2016-09-26 16:05:15 +02:00
|
|
|
backendModel()->resetModel();
|
2015-09-18 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::modelAboutToBeDetached(Model *model)
|
|
|
|
|
{
|
|
|
|
|
AbstractView::modelAboutToBeDetached(model);
|
2023-08-23 12:12:07 +02:00
|
|
|
bindingModel()->reset();
|
2022-07-22 16:46:48 +02:00
|
|
|
dynamicPropertiesModel()->reset();
|
2015-09-18 15:38:15 +02:00
|
|
|
connectionModel()->resetModel();
|
2023-09-19 18:17:01 +02:00
|
|
|
connectionModel()->modelAboutToBeDetached();
|
2015-09-18 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::nodeCreated(const ModelNode & /*createdNode*/)
|
|
|
|
|
{
|
|
|
|
|
connectionModel()->resetModel();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-18 17:34:39 +02:00
|
|
|
void ConnectionView::nodeAboutToBeRemoved(const ModelNode &removedNode)
|
|
|
|
|
{
|
|
|
|
|
connectionModel()->nodeAboutToBeRemoved(removedNode);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
void ConnectionView::nodeRemoved(const ModelNode & /*removedNode*/,
|
|
|
|
|
const NodeAbstractProperty & /*parentProperty*/,
|
|
|
|
|
AbstractView::PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
|
|
|
|
connectionModel()->resetModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::nodeReparented(const ModelNode & /*node*/, const NodeAbstractProperty & /*newPropertyParent*/,
|
|
|
|
|
const NodeAbstractProperty & /*oldPropertyParent*/, AbstractView::PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
|
|
|
|
connectionModel()->resetModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::nodeIdChanged(const ModelNode & /*node*/, const QString & /*newId*/, const QString & /*oldId*/)
|
|
|
|
|
{
|
|
|
|
|
connectionModel()->resetModel();
|
2023-08-23 12:12:07 +02:00
|
|
|
bindingModel()->reset();
|
|
|
|
|
dynamicPropertiesModel()->reset();
|
2015-09-18 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-06 14:03:37 +02:00
|
|
|
void ConnectionView::propertiesRemoved(const QList<AbstractProperty> &propertyList)
|
|
|
|
|
{
|
|
|
|
|
for (const AbstractProperty &property : propertyList) {
|
|
|
|
|
if (property.isDefaultProperty())
|
|
|
|
|
connectionModel()->resetModel();
|
2022-09-09 16:33:23 +02:00
|
|
|
|
|
|
|
|
dynamicPropertiesModel()->dispatchPropertyChanges(property);
|
2021-04-06 14:03:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::propertiesAboutToBeRemoved(const QList<AbstractProperty> &propertyList)
|
2015-09-18 15:38:15 +02:00
|
|
|
{
|
2022-05-10 13:41:44 +02:00
|
|
|
for (const AbstractProperty &property : propertyList) {
|
2015-09-18 15:38:15 +02:00
|
|
|
if (property.isBindingProperty()) {
|
2023-08-23 12:12:07 +02:00
|
|
|
bindingModel()->removeItem(property);
|
|
|
|
|
dynamicPropertiesModel()->removeItem(property);
|
2015-09-18 15:38:15 +02:00
|
|
|
} else if (property.isVariantProperty()) {
|
2023-08-23 12:12:07 +02:00
|
|
|
dynamicPropertiesModel()->removeItem(property);
|
2019-12-11 11:25:13 +01:00
|
|
|
} else if (property.isSignalHandlerProperty()) {
|
|
|
|
|
connectionModel()->removeRowFromTable(property.toSignalHandlerProperty());
|
2015-09-18 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::variantPropertiesChanged(const QList<VariantProperty> &propertyList,
|
|
|
|
|
AbstractView::PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
2022-05-10 13:41:44 +02:00
|
|
|
for (const VariantProperty &variantProperty : propertyList) {
|
2015-09-18 15:38:15 +02:00
|
|
|
if (variantProperty.isDynamic())
|
2023-08-23 12:12:07 +02:00
|
|
|
dynamicPropertiesModel()->updateItem(variantProperty);
|
2016-09-26 16:05:15 +02:00
|
|
|
if (variantProperty.isDynamic() && variantProperty.parentModelNode().isRootNode())
|
|
|
|
|
backendModel()->resetModel();
|
2015-09-18 15:38:15 +02:00
|
|
|
|
|
|
|
|
connectionModel()->variantPropertyChanged(variantProperty);
|
|
|
|
|
|
2022-09-09 16:33:23 +02:00
|
|
|
dynamicPropertiesModel()->dispatchPropertyChanges(variantProperty);
|
|
|
|
|
}
|
2015-09-18 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::bindingPropertiesChanged(const QList<BindingProperty> &propertyList,
|
|
|
|
|
AbstractView::PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
2022-05-10 13:41:44 +02:00
|
|
|
for (const BindingProperty &bindingProperty : propertyList) {
|
2023-08-23 12:12:07 +02:00
|
|
|
bindingModel()->updateItem(bindingProperty);
|
2015-09-18 15:38:15 +02:00
|
|
|
if (bindingProperty.isDynamic())
|
2023-08-23 12:12:07 +02:00
|
|
|
dynamicPropertiesModel()->updateItem(bindingProperty);
|
2016-09-26 16:05:15 +02:00
|
|
|
if (bindingProperty.isDynamic() && bindingProperty.parentModelNode().isRootNode())
|
|
|
|
|
backendModel()->resetModel();
|
2015-09-18 15:38:15 +02:00
|
|
|
|
|
|
|
|
connectionModel()->bindingPropertyChanged(bindingProperty);
|
2022-09-09 16:33:23 +02:00
|
|
|
|
|
|
|
|
dynamicPropertiesModel()->dispatchPropertyChanges(bindingProperty);
|
2015-09-18 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-05 14:33:42 +01:00
|
|
|
void ConnectionView::signalHandlerPropertiesChanged(const QVector<SignalHandlerProperty> &propertyList,
|
|
|
|
|
AbstractView::PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
|
|
|
|
for (const SignalHandlerProperty &signalHandlerProperty : propertyList)
|
|
|
|
|
connectionModel()->abstractPropertyChanged(signalHandlerProperty);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
void ConnectionView::selectedNodesChanged(const QList<ModelNode> & selectedNodeList,
|
|
|
|
|
const QList<ModelNode> & /*lastSelectedNodeList*/)
|
|
|
|
|
{
|
2023-08-23 12:12:07 +02:00
|
|
|
bindingModel()->reset(selectedNodeList);
|
2022-07-22 16:46:48 +02:00
|
|
|
dynamicPropertiesModel()->reset();
|
2020-10-06 12:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-30 13:14:17 +02:00
|
|
|
void ConnectionView::importsChanged(const Imports & /*addedImports*/, const Imports & /*removedImports*/)
|
2016-09-26 16:05:15 +02:00
|
|
|
{
|
|
|
|
|
backendModel()->resetModel();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-14 12:28:16 +02:00
|
|
|
void ConnectionView::currentStateChanged(const ModelNode &)
|
2022-09-09 16:31:50 +02:00
|
|
|
{
|
|
|
|
|
dynamicPropertiesModel()->reset();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
WidgetInfo ConnectionView::widgetInfo()
|
|
|
|
|
{
|
2023-08-23 12:12:07 +02:00
|
|
|
return createWidgetInfo(m_connectionViewQuickWidget.data(),
|
2015-09-18 15:38:15 +02:00
|
|
|
QLatin1String("ConnectionView"),
|
|
|
|
|
WidgetInfo::LeftPane,
|
|
|
|
|
0,
|
2022-07-04 17:58:45 +02:00
|
|
|
tr("Connections"));
|
2015-09-18 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ConnectionView::hasWidget() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 11:25:13 +01:00
|
|
|
bool ConnectionView::isWidgetEnabled()
|
|
|
|
|
{
|
|
|
|
|
return widgetInfo().widget->isEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
ConnectionModel *ConnectionView::connectionModel() const
|
|
|
|
|
{
|
|
|
|
|
return m_connectionModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BindingModel *ConnectionView::bindingModel() const
|
|
|
|
|
{
|
|
|
|
|
return m_bindingModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DynamicPropertiesModel *ConnectionView::dynamicPropertiesModel() const
|
|
|
|
|
{
|
|
|
|
|
return m_dynamicPropertiesModel;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 16:05:15 +02:00
|
|
|
BackendModel *ConnectionView::backendModel() const
|
|
|
|
|
{
|
|
|
|
|
return m_backendModel;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-04 19:57:59 +02:00
|
|
|
int ConnectionView::currentIndex() const
|
|
|
|
|
{
|
|
|
|
|
return m_currentIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::setCurrentIndex(int i)
|
|
|
|
|
{
|
|
|
|
|
if (m_currentIndex == i)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_currentIndex = i;
|
|
|
|
|
emit currentIndexChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 19:02:41 +02:00
|
|
|
ConnectionView *ConnectionView::instance()
|
|
|
|
|
{
|
|
|
|
|
static ConnectionView *s_instance = nullptr;
|
|
|
|
|
|
|
|
|
|
if (s_instance)
|
|
|
|
|
return s_instance;
|
|
|
|
|
|
|
|
|
|
const auto views = QmlDesignerPlugin::instance()->viewManager().views();
|
|
|
|
|
for (auto *view : views) {
|
|
|
|
|
ConnectionView *myView = qobject_cast<ConnectionView*>(view);
|
|
|
|
|
if (myView)
|
|
|
|
|
s_instance = myView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(s_instance, return nullptr);
|
|
|
|
|
return s_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
} // namespace QmlDesigner
|