OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / integration / componentview.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "componentview.h"
34 #include <QtDebug>
35
36 #include <nodemetainfo.h>
37 #include <QStandardItemModel>
38
39 // silence gcc warnings about unused parameters
40
41 namespace QmlDesigner {
42
43 ComponentView::ComponentView(QObject *parent)
44   : AbstractView(parent),
45     m_standardItemModel(new QStandardItemModel(this)),
46     m_listChanged(false)
47 {
48 }
49
50
51
52 void ComponentView::nodeAboutToBeRemoved(const ModelNode &removedNode)
53 {
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);
58     }
59 }
60
61 QStandardItemModel *ComponentView::standardItemModel() const
62 {
63     return m_standardItemModel;
64 }
65
66 ModelNode ComponentView::modelNode(int index) const
67 {
68     if (m_standardItemModel->hasIndex(index, 0)) {
69         QStandardItem *item = m_standardItemModel->item(index, 0);
70         return item->data(ModelNodeRole).value<ModelNode>();
71     }
72
73     return ModelNode();
74 }
75
76 void ComponentView::appendWholeDocumentAsComponent()
77 {
78     QStandardItem *item = new QStandardItem(tr("whole document"));
79     item->setData(QVariant::fromValue(rootModelNode()), ModelNodeRole);
80     item->setEditable(false);
81     m_standardItemModel->appendRow(item);
82 }
83
84 void ComponentView::modelAttached(Model *model)
85 {
86     if (AbstractView::model() == model)
87         return;
88
89     AbstractView::modelAttached(model);
90
91     Q_ASSERT(model->masterModel());
92     appendWholeDocumentAsComponent();
93     searchForComponentAndAddToList(rootModelNode());
94 }
95
96 void ComponentView::modelAboutToBeDetached(Model *model)
97 {
98     m_standardItemModel->clear();
99     AbstractView::modelAboutToBeDetached(model);
100 }
101
102 void ComponentView::nodeCreated(const ModelNode &createdNode)
103 {
104     searchForComponentAndAddToList(createdNode);
105 }
106
107 void ComponentView::searchForComponentAndAddToList(const ModelNode &node)
108 {
109     QList<ModelNode> nodeList;
110     nodeList.append(node);
111     nodeList.append(node.allSubModelNodes());
112
113
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);
121             }
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;
126     }
127     }
128 }
129
130 void ComponentView::nodeRemoved(const ModelNode & /*removedNode*/, const NodeAbstractProperty & /*parentProperty*/, PropertyChangeFlags /*propertyChange*/)
131 {
132
133 }
134
135 //void ComponentView::searchForComponentAndRemoveFromList(const ModelNode &node)
136 //{
137 //    QList<ModelNode> nodeList;
138 //    nodeList.append(node);
139 //    nodeList.append(node.allSubModelNodes());
140 //
141 //
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);
148 //                }
149 //            }
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;
154 //    }
155 //    }
156 //}
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*/) {}
172
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*/) {}
178
179 void ComponentView::fileUrlChanged(const QUrl &/*oldUrl*/, const QUrl &/*newUrl*/) {}
180
181 void ComponentView::nodeOrderChanged(const NodeListProperty &/*listProperty*/, const ModelNode & /*movedNode*/, int /*oldIndex*/) {}
182
183
184 void ComponentView::auxiliaryDataChanged(const ModelNode &/*node*/, const QString &/*name*/, const QVariant &/*data*/) {}
185
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*/) {}
188
189 } // namespace QmlDesigner