1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "componentview.h"
36 #include <nodemetainfo.h>
37 #include <QStandardItemModel>
39 // silence gcc warnings about unused parameters
41 namespace QmlDesigner {
43 ComponentView::ComponentView(QObject *parent)
44 : AbstractView(parent),
45 m_standardItemModel(new QStandardItemModel(this)),
52 void ComponentView::nodeAboutToBeRemoved(const ModelNode &removedNode)
54 for (int index = 1; index < m_standardItemModel->rowCount(); index++) {
55 QStandardItem *item = m_standardItemModel->item(index);
56 if (item->data(ModelNodeRole).value<ModelNode>() == removedNode)
57 m_standardItemModel->removeRow(index);
61 QStandardItemModel *ComponentView::standardItemModel() const
63 return m_standardItemModel;
66 ModelNode ComponentView::modelNode(int index) const
68 if (m_standardItemModel->hasIndex(index, 0)) {
69 QStandardItem *item = m_standardItemModel->item(index, 0);
70 return item->data(ModelNodeRole).value<ModelNode>();
76 void ComponentView::appendWholeDocumentAsComponent()
78 QStandardItem *item = new QStandardItem(tr("whole document"));
79 item->setData(QVariant::fromValue(rootModelNode()), ModelNodeRole);
80 item->setEditable(false);
81 m_standardItemModel->appendRow(item);
84 void ComponentView::modelAttached(Model *model)
86 if (AbstractView::model() == model)
89 AbstractView::modelAttached(model);
91 Q_ASSERT(model->masterModel());
92 appendWholeDocumentAsComponent();
93 searchForComponentAndAddToList(rootModelNode());
96 void ComponentView::modelAboutToBeDetached(Model *model)
98 m_standardItemModel->clear();
99 AbstractView::modelAboutToBeDetached(model);
102 void ComponentView::nodeCreated(const ModelNode &createdNode)
104 searchForComponentAndAddToList(createdNode);
107 void ComponentView::searchForComponentAndAddToList(const ModelNode &node)
109 QList<ModelNode> nodeList;
110 nodeList.append(node);
111 nodeList.append(node.allSubModelNodes());
114 foreach (const ModelNode &childNode, nodeList) {
115 if (childNode.type() == "Qt/Component") {
116 if (!childNode.id().isEmpty()) {
117 QStandardItem *item = new QStandardItem(childNode.id());
118 item->setData(QVariant::fromValue(childNode), ModelNodeRole);
119 item->setEditable(false);
120 m_standardItemModel->appendRow(item);
122 } else if (node.metaInfo().isValid() && node.metaInfo().isComponent() && !m_componentList.contains(node.type())) {
123 m_componentList.append(node.type());
124 m_componentList.sort();
125 m_listChanged = true;
130 void ComponentView::nodeRemoved(const ModelNode & /*removedNode*/, const NodeAbstractProperty & /*parentProperty*/, PropertyChangeFlags /*propertyChange*/)
135 //void ComponentView::searchForComponentAndRemoveFromList(const ModelNode &node)
137 // QList<ModelNode> nodeList;
138 // nodeList.append(node);
139 // nodeList.append(node.allSubModelNodes());
142 // foreach (const ModelNode &childNode, nodeList) {
143 // if (node.type() == "Qt/Component") {
144 // if (!node.id().isEmpty()) {
145 // for(int row = 0; row < m_standardItemModel->rowCount(); row++) {
146 // if (m_standardItemModel->item(row)->text() == node.id())
147 // m_standardItemModel->removeRow(row);
150 // } else if (node.metaInfo().isComponent() && !m_componentList.contains(node.type())) {
151 // m_componentList.append(node.type());
152 // m_componentList.sort();
153 // m_listChanged = true;
157 void ComponentView::nodeAboutToBeReparented(const ModelNode &/*node*/, const NodeAbstractProperty &/*newPropertyParent*/, const NodeAbstractProperty &/*oldPropertyParent*/, AbstractView::PropertyChangeFlags /*propertyChange*/) {}
158 void ComponentView::nodeReparented(const ModelNode &/*node*/, const NodeAbstractProperty &/*newPropertyParent*/, const NodeAbstractProperty &/*oldPropertyParent*/, AbstractView::PropertyChangeFlags /*propertyChange*/) {}
159 void ComponentView::nodeIdChanged(const ModelNode& /*node*/, const QString& /*newId*/, const QString& /*oldId*/) {}
160 void ComponentView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& /*propertyList*/) {}
161 void ComponentView::propertiesRemoved(const QList<AbstractProperty>& /*propertyList*/) {}
162 void ComponentView::variantPropertiesChanged(const QList<VariantProperty>& /*propertyList*/, PropertyChangeFlags /*propertyChange*/) {}
163 void ComponentView::bindingPropertiesChanged(const QList<BindingProperty>& /*propertyList*/, PropertyChangeFlags /*propertyChange*/) {}
164 void ComponentView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/) {}
165 void ComponentView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/) {}
166 void ComponentView::instancePropertyChange(const QList<QPair<ModelNode, QString> > &/*propertyList*/) {}
167 void ComponentView::instancesCompleted(const QVector<ModelNode> &/*completedNodeList*/) {}
168 void ComponentView::instanceInformationsChange(const QVector<ModelNode> &/*nodeList*/) {}
169 void ComponentView::instancesRenderImageChanged(const QVector<ModelNode> &/*nodeList*/) {}
170 void ComponentView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/) {}
171 void ComponentView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList*/) {}
173 void ComponentView::rewriterBeginTransaction() {}
174 void ComponentView::rewriterEndTransaction() {}
175 void ComponentView::actualStateChanged(const ModelNode &/*node*/) {}
176 void ComponentView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeList*/,
177 const QList<ModelNode> &/*lastSelectedNodeList*/) {}
179 void ComponentView::fileUrlChanged(const QUrl &/*oldUrl*/, const QUrl &/*newUrl*/) {}
181 void ComponentView::nodeOrderChanged(const NodeListProperty &/*listProperty*/, const ModelNode & /*movedNode*/, int /*oldIndex*/) {}
184 void ComponentView::auxiliaryDataChanged(const ModelNode &/*node*/, const QString &/*name*/, const QVariant &/*data*/) {}
186 void ComponentView::customNotification(const AbstractView * /*view*/, const QString &/*identifier*/, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/) {}
187 void ComponentView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/) {}
189 } // namespace QmlDesigner