2010-01-07 12:14:35 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "componentview.h"
|
2011-05-24 18:47:33 +02:00
|
|
|
#include "componentaction.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <QtDebug>
|
|
|
|
|
|
|
|
|
|
#include <nodemetainfo.h>
|
2011-05-24 18:47:33 +02:00
|
|
|
#include <nodeabstractproperty.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
|
|
|
|
|
// silence gcc warnings about unused parameters
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
ComponentView::ComponentView(QObject *parent)
|
|
|
|
|
: AbstractView(parent),
|
|
|
|
|
m_standardItemModel(new QStandardItemModel(this)),
|
2011-05-24 18:47:33 +02:00
|
|
|
m_componentAction(new ComponentAction(this))
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ComponentView::nodeAboutToBeRemoved(const ModelNode &removedNode)
|
|
|
|
|
{
|
2011-06-09 11:34:13 +02:00
|
|
|
removeSingleNodeFromList(removedNode);
|
2011-05-24 18:47:33 +02:00
|
|
|
searchForComponentAndRemoveFromList(removedNode);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStandardItemModel *ComponentView::standardItemModel() const
|
|
|
|
|
{
|
|
|
|
|
return m_standardItemModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModelNode ComponentView::modelNode(int index) const
|
|
|
|
|
{
|
|
|
|
|
if (m_standardItemModel->hasIndex(index, 0)) {
|
|
|
|
|
QStandardItem *item = m_standardItemModel->item(index, 0);
|
|
|
|
|
return item->data(ModelNodeRole).value<ModelNode>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ModelNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::appendWholeDocumentAsComponent()
|
|
|
|
|
{
|
2010-04-08 10:30:58 +02:00
|
|
|
QStandardItem *item = new QStandardItem(tr("whole document"));
|
2010-01-07 12:14:35 +01:00
|
|
|
item->setData(QVariant::fromValue(rootModelNode()), ModelNodeRole);
|
|
|
|
|
item->setEditable(false);
|
|
|
|
|
m_standardItemModel->appendRow(item);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-09 11:34:13 +02:00
|
|
|
void ComponentView::removeSingleNodeFromList(const ModelNode &node)
|
|
|
|
|
{
|
|
|
|
|
for (int row = 0; row < m_standardItemModel->rowCount(); row++) {
|
|
|
|
|
if (m_standardItemModel->item(row)->data(ModelNodeRole).value<ModelNode>() == node)
|
|
|
|
|
m_standardItemModel->removeRow(row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void ComponentView::modelAttached(Model *model)
|
|
|
|
|
{
|
|
|
|
|
if (AbstractView::model() == model)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-05-24 18:47:33 +02:00
|
|
|
bool block = m_componentAction->blockSignals(true);
|
|
|
|
|
m_standardItemModel->clear();
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
AbstractView::modelAttached(model);
|
|
|
|
|
|
|
|
|
|
Q_ASSERT(model->masterModel());
|
|
|
|
|
appendWholeDocumentAsComponent();
|
|
|
|
|
searchForComponentAndAddToList(rootModelNode());
|
2011-05-24 18:47:33 +02:00
|
|
|
|
|
|
|
|
m_componentAction->blockSignals(block);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::modelAboutToBeDetached(Model *model)
|
|
|
|
|
{
|
2011-05-24 18:47:33 +02:00
|
|
|
bool block = m_componentAction->blockSignals(true);
|
2010-01-07 12:14:35 +01:00
|
|
|
m_standardItemModel->clear();
|
|
|
|
|
AbstractView::modelAboutToBeDetached(model);
|
2011-05-24 18:47:33 +02:00
|
|
|
m_componentAction->blockSignals(block);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ComponentAction *ComponentView::action()
|
|
|
|
|
{
|
|
|
|
|
return m_componentAction;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::nodeCreated(const ModelNode &createdNode)
|
|
|
|
|
{
|
|
|
|
|
searchForComponentAndAddToList(createdNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::searchForComponentAndAddToList(const ModelNode &node)
|
|
|
|
|
{
|
|
|
|
|
QList<ModelNode> nodeList;
|
|
|
|
|
nodeList.append(node);
|
|
|
|
|
nodeList.append(node.allSubModelNodes());
|
|
|
|
|
|
|
|
|
|
|
2011-06-09 10:53:22 +02:00
|
|
|
foreach (const ModelNode &node, nodeList) {
|
|
|
|
|
if (node.nodeSourceType() == ModelNode::ComponentSource) {
|
|
|
|
|
if (!node.id().isEmpty()) {
|
|
|
|
|
QStandardItem *item = new QStandardItem(node.id());
|
|
|
|
|
item->setData(QVariant::fromValue(node), ModelNodeRole);
|
2010-01-07 12:14:35 +01:00
|
|
|
item->setEditable(false);
|
2011-06-09 11:34:13 +02:00
|
|
|
removeSingleNodeFromList(node); //remove node if already present
|
2010-01-07 12:14:35 +01:00
|
|
|
m_standardItemModel->appendRow(item);
|
2011-05-24 18:47:33 +02:00
|
|
|
} else {
|
|
|
|
|
QString description;
|
2011-06-09 10:53:22 +02:00
|
|
|
ModelNode parentNode = node.parentProperty().parentModelNode();
|
2011-06-20 16:46:18 +02:00
|
|
|
if (parentNode.isValid()) {
|
2011-06-24 16:05:49 +02:00
|
|
|
if (parentNode.id().isEmpty()) {
|
|
|
|
|
description = parentNode.simplifiedTypeName() + QLatin1Char(' ');
|
2011-06-20 16:46:18 +02:00
|
|
|
} else {
|
2011-06-24 16:05:49 +02:00
|
|
|
description = parentNode.id() + QLatin1Char(' ');
|
2011-06-20 16:46:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-09 10:53:22 +02:00
|
|
|
description += node.parentProperty().name();
|
2011-05-24 18:47:33 +02:00
|
|
|
QStandardItem *item = new QStandardItem(description);
|
2011-06-09 10:53:22 +02:00
|
|
|
item->setData(QVariant::fromValue(node), ModelNodeRole);
|
2011-05-24 18:47:33 +02:00
|
|
|
item->setEditable(false);
|
2011-06-09 11:34:13 +02:00
|
|
|
removeSingleNodeFromList(node); //remove node if already present
|
2011-05-24 18:47:33 +02:00
|
|
|
m_standardItemModel->appendRow(item);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
2011-05-24 18:47:33 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-24 18:47:33 +02:00
|
|
|
void ComponentView::nodeRemoved(const ModelNode & /* removedNode */, const NodeAbstractProperty & /*parentProperty*/, PropertyChangeFlags /*propertyChange*/)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2011-05-24 18:47:33 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2011-05-24 18:47:33 +02:00
|
|
|
void ComponentView::searchForComponentAndRemoveFromList(const ModelNode &node)
|
|
|
|
|
{
|
|
|
|
|
QList<ModelNode> nodeList;
|
|
|
|
|
nodeList.append(node);
|
|
|
|
|
nodeList.append(node.allSubModelNodes());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (const ModelNode &childNode, nodeList) {
|
2011-06-09 10:53:22 +02:00
|
|
|
if (childNode.nodeSourceType() == ModelNode::ComponentSource) {
|
2011-06-09 11:34:13 +02:00
|
|
|
removeSingleNodeFromList(childNode);
|
2011-05-24 18:47:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-08 16:46:25 +01:00
|
|
|
void ComponentView::nodeAboutToBeReparented(const ModelNode &/*node*/, const NodeAbstractProperty &/*newPropertyParent*/, const NodeAbstractProperty &/*oldPropertyParent*/, AbstractView::PropertyChangeFlags /*propertyChange*/) {}
|
2011-06-09 10:53:22 +02:00
|
|
|
|
|
|
|
|
void ComponentView::nodeReparented(const ModelNode &node, const NodeAbstractProperty &/*newPropertyParent*/, const NodeAbstractProperty &/*oldPropertyParent*/, AbstractView::PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
|
|
|
|
searchForComponentAndAddToList(node);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void ComponentView::nodeIdChanged(const ModelNode& /*node*/, const QString& /*newId*/, const QString& /*oldId*/) {}
|
|
|
|
|
void ComponentView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& /*propertyList*/) {}
|
|
|
|
|
void ComponentView::propertiesRemoved(const QList<AbstractProperty>& /*propertyList*/) {}
|
|
|
|
|
void ComponentView::variantPropertiesChanged(const QList<VariantProperty>& /*propertyList*/, PropertyChangeFlags /*propertyChange*/) {}
|
|
|
|
|
void ComponentView::bindingPropertiesChanged(const QList<BindingProperty>& /*propertyList*/, PropertyChangeFlags /*propertyChange*/) {}
|
2010-02-10 13:02:49 +01:00
|
|
|
void ComponentView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/) {}
|
2010-06-10 17:36:14 +02:00
|
|
|
void ComponentView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/) {}
|
2010-12-16 12:05:48 +01:00
|
|
|
void ComponentView::instancePropertyChange(const QList<QPair<ModelNode, QString> > &/*propertyList*/) {}
|
2010-12-09 16:09:37 +01:00
|
|
|
void ComponentView::instancesCompleted(const QVector<ModelNode> &/*completedNodeList*/) {}
|
2011-02-01 15:54:52 +01:00
|
|
|
void ComponentView::instanceInformationsChange(const QVector<ModelNode> &/*nodeList*/) {}
|
|
|
|
|
void ComponentView::instancesRenderImageChanged(const QVector<ModelNode> &/*nodeList*/) {}
|
|
|
|
|
void ComponentView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/) {}
|
|
|
|
|
void ComponentView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList*/) {}
|
2011-06-08 17:02:03 +02:00
|
|
|
void ComponentView::nodeSourceChanged(const ModelNode &, const QString & /*newNodeSource*/) {}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2011-02-01 15:54:52 +01:00
|
|
|
void ComponentView::rewriterBeginTransaction() {}
|
|
|
|
|
void ComponentView::rewriterEndTransaction() {}
|
2011-02-02 21:52:15 +01:00
|
|
|
void ComponentView::actualStateChanged(const ModelNode &/*node*/) {}
|
2010-01-07 12:14:35 +01:00
|
|
|
void ComponentView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeList*/,
|
|
|
|
|
const QList<ModelNode> &/*lastSelectedNodeList*/) {}
|
|
|
|
|
|
|
|
|
|
void ComponentView::fileUrlChanged(const QUrl &/*oldUrl*/, const QUrl &/*newUrl*/) {}
|
|
|
|
|
|
2010-01-12 10:39:40 +01:00
|
|
|
void ComponentView::nodeOrderChanged(const NodeListProperty &/*listProperty*/, const ModelNode & /*movedNode*/, int /*oldIndex*/) {}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void ComponentView::auxiliaryDataChanged(const ModelNode &/*node*/, const QString &/*name*/, const QVariant &/*data*/) {}
|
|
|
|
|
|
2010-01-14 16:34:29 +01:00
|
|
|
void ComponentView::customNotification(const AbstractView * /*view*/, const QString &/*identifier*/, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/) {}
|
2011-02-10 15:44:40 +01:00
|
|
|
void ComponentView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/) {}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
} // namespace QmlDesigner
|