2015-09-18 15:38:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-09-18 15:38:15 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-09-18 15:38:15 +02:00
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-01-15 14:57:40 +01:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-09-18 15:38:15 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
#include "connectionview.h"
|
|
|
|
|
#include "connectionviewwidget.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"
|
|
|
|
|
|
|
|
|
|
#include <bindingproperty.h>
|
|
|
|
|
#include <nodeabstractproperty.h>
|
|
|
|
|
#include <variantproperty.h>
|
2019-12-05 14:33:42 +01:00
|
|
|
#include <signalhandlerproperty.h>
|
2015-09-18 15:38:15 +02:00
|
|
|
|
2020-10-06 12:29:09 +02:00
|
|
|
#include <QTableView>
|
|
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
ConnectionView::ConnectionView(QObject *parent) : AbstractView(parent),
|
|
|
|
|
m_connectionViewWidget(new ConnectionViewWidget()),
|
|
|
|
|
m_connectionModel(new ConnectionModel(this)),
|
|
|
|
|
m_bindingModel(new BindingModel(this)),
|
2016-09-26 16:05:15 +02:00
|
|
|
m_dynamicPropertiesModel(new DynamicPropertiesModel(this)),
|
|
|
|
|
m_backendModel(new BackendModel(this))
|
2015-09-18 15:38:15 +02:00
|
|
|
{
|
|
|
|
|
connectionViewWidget()->setBindingModel(m_bindingModel);
|
|
|
|
|
connectionViewWidget()->setConnectionModel(m_connectionModel);
|
2016-09-26 16:05:15 +02:00
|
|
|
connectionViewWidget()->setDynamicPropertiesModel(m_dynamicPropertiesModel);
|
|
|
|
|
connectionViewWidget()->setBackendModel(m_backendModel);
|
2015-09-18 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-24 23:56:45 +02:00
|
|
|
ConnectionView::~ConnectionView() = default;
|
2015-09-18 15:38:15 +02:00
|
|
|
|
|
|
|
|
void ConnectionView::modelAttached(Model *model)
|
|
|
|
|
{
|
|
|
|
|
AbstractView::modelAttached(model);
|
|
|
|
|
bindingModel()->selectionChanged(QList<ModelNode>());
|
|
|
|
|
dynamicPropertiesModel()->selectionChanged(QList<ModelNode>());
|
|
|
|
|
connectionModel()->resetModel();
|
|
|
|
|
connectionViewWidget()->resetItemViews();
|
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);
|
|
|
|
|
bindingModel()->selectionChanged(QList<ModelNode>());
|
|
|
|
|
dynamicPropertiesModel()->selectionChanged(QList<ModelNode>());
|
|
|
|
|
connectionModel()->resetModel();
|
|
|
|
|
connectionViewWidget()->resetItemViews();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::nodeCreated(const ModelNode & /*createdNode*/)
|
|
|
|
|
{
|
|
|
|
|
//bindings
|
|
|
|
|
connectionModel()->resetModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
2016-07-18 18:51:28 +02:00
|
|
|
bindingModel()->resetModel();
|
|
|
|
|
dynamicPropertiesModel()->resetModel();
|
2015-09-18 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::propertiesAboutToBeRemoved(const QList<AbstractProperty> & propertyList)
|
|
|
|
|
{
|
|
|
|
|
foreach (const AbstractProperty &property, propertyList) {
|
|
|
|
|
if (property.isBindingProperty()) {
|
|
|
|
|
bindingModel()->bindingRemoved(property.toBindingProperty());
|
|
|
|
|
dynamicPropertiesModel()->bindingRemoved(property.toBindingProperty());
|
|
|
|
|
} else if (property.isVariantProperty()) {
|
|
|
|
|
//### dynamicPropertiesModel->bindingRemoved(property.toVariantProperty());
|
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*/)
|
|
|
|
|
{
|
|
|
|
|
foreach (const VariantProperty &variantProperty, propertyList) {
|
|
|
|
|
if (variantProperty.isDynamic())
|
|
|
|
|
dynamicPropertiesModel()->variantPropertyChanged(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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectionView::bindingPropertiesChanged(const QList<BindingProperty> &propertyList,
|
|
|
|
|
AbstractView::PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
|
|
|
|
foreach (const BindingProperty &bindingProperty, propertyList) {
|
|
|
|
|
bindingModel()->bindingChanged(bindingProperty);
|
|
|
|
|
if (bindingProperty.isDynamic())
|
|
|
|
|
dynamicPropertiesModel()->bindingPropertyChanged(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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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*/)
|
|
|
|
|
{
|
|
|
|
|
bindingModel()->selectionChanged(selectedNodeList);
|
|
|
|
|
dynamicPropertiesModel()->selectionChanged(selectedNodeList);
|
|
|
|
|
connectionViewWidget()->bindingTableViewSelectionChanged(QModelIndex(), QModelIndex());
|
|
|
|
|
connectionViewWidget()->dynamicPropertiesTableViewSelectionChanged(QModelIndex(), QModelIndex());
|
|
|
|
|
|
|
|
|
|
if (connectionViewWidget()->currentTab() == ConnectionViewWidget::BindingTab
|
|
|
|
|
|| connectionViewWidget()->currentTab() == ConnectionViewWidget::DynamicPropertiesTab)
|
2019-01-16 18:06:21 +01:00
|
|
|
emit connectionViewWidget()->setEnabledAddButton(selectedNodeList.count() == 1);
|
2015-09-18 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-06 12:29:09 +02:00
|
|
|
void ConnectionView::auxiliaryDataChanged(const ModelNode &node,
|
|
|
|
|
const PropertyName &name,
|
|
|
|
|
const QVariant &data)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(node)
|
|
|
|
|
|
|
|
|
|
// Check if the auxiliary data is actually the locked property or if it is unlocked
|
|
|
|
|
if (name != QmlDesigner::lockedProperty || !data.toBool())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QItemSelectionModel *selectionModel = connectionTableView()->selectionModel();
|
|
|
|
|
if (!selectionModel->hasSelection())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QModelIndex modelIndex = selectionModel->currentIndex();
|
|
|
|
|
if (!modelIndex.isValid() || !model())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const int internalId = connectionModel()->data(connectionModel()->index(modelIndex.row(),
|
|
|
|
|
ConnectionModel::TargetModelNodeRow),
|
|
|
|
|
ConnectionModel::UserRoles::InternalIdRole).toInt();
|
|
|
|
|
ModelNode modelNode = modelNodeForInternalId(internalId);
|
|
|
|
|
|
|
|
|
|
if (modelNode.isValid() && ModelNode::isThisOrAncestorLocked(modelNode))
|
|
|
|
|
selectionModel->clearSelection();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 16:05:15 +02:00
|
|
|
void ConnectionView::importsChanged(const QList<Import> & /*addedImports*/, const QList<Import> & /*removedImports*/)
|
|
|
|
|
{
|
|
|
|
|
backendModel()->resetModel();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
WidgetInfo ConnectionView::widgetInfo()
|
|
|
|
|
{
|
|
|
|
|
return createWidgetInfo(m_connectionViewWidget.data(),
|
|
|
|
|
new WidgetInfo::ToolBarWidgetDefaultFactory<ConnectionViewWidget>(connectionViewWidget()),
|
|
|
|
|
QLatin1String("ConnectionView"),
|
|
|
|
|
WidgetInfo::LeftPane,
|
|
|
|
|
0,
|
|
|
|
|
tr("Connection View"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
QTableView *ConnectionView::connectionTableView() const
|
|
|
|
|
{
|
|
|
|
|
return connectionViewWidget()->connectionTableView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTableView *ConnectionView::bindingTableView() const
|
|
|
|
|
{
|
|
|
|
|
return connectionViewWidget()->bindingTableView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTableView *ConnectionView::dynamicPropertiesTableView() const
|
|
|
|
|
{
|
|
|
|
|
return connectionViewWidget()->dynamicPropertiesTableView();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 16:05:15 +02:00
|
|
|
QTableView *ConnectionView::backendView() const
|
|
|
|
|
{
|
|
|
|
|
return connectionViewWidget()->backendView();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
ConnectionViewWidget *ConnectionView::connectionViewWidget() const
|
|
|
|
|
{
|
|
|
|
|
return m_connectionViewWidget.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 15:38:15 +02:00
|
|
|
} // namesapce Internal
|
|
|
|
|
|
|
|
|
|
} // namespace QmlDesigner
|