OSDN Git Service

56865566d4cae1e12eacae6d021bbe015369aa43
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / navigator / navigatortreemodel.h
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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef NAVIGATORTREEMODEL_H
35 #define NAVIGATORTREEMODEL_H
36
37 #include <modelnode.h>
38 #include <nodemetainfo.h>
39
40 #include <QStandardItem>
41 #include <QStandardItemModel>
42
43 namespace QmlDesigner {
44
45 class Model;
46 class AbstractView;
47 class ModelNode;
48
49 class NavigatorTreeModel : public QStandardItemModel
50 {
51     Q_OBJECT
52
53 #ifdef _LOCK_ITEMS_
54     struct ItemRow {
55         ItemRow()
56             : idItem(0), lockItem(0), visibilityItem(0) {}
57         ItemRow(QStandardItem *id, QStandardItem *lock, QStandardItem *visibility, const PropertyItemMap &properties)
58             : idItem(id), lockItem(lock), visibilityItem(visibility), propertyItems(properties) {}
59
60         QList<QStandardItem*> toList() const {
61             return QList<QStandardItem*>() << idItem << lockItem << visibilityItem;
62         }
63
64         QStandardItem *idItem;
65         QStandardItem *lockItem;
66         QStandardItem *visibilityItem;
67         QMap<QString, QStandardItem *> propertyItems;
68     };
69 #else
70     struct ItemRow {
71         ItemRow()
72             : idItem(0), visibilityItem(0) {}
73         ItemRow(QStandardItem *id, QStandardItem *visibility, const QMap<QString, QStandardItem *> &properties)
74             : idItem(id), visibilityItem(visibility), propertyItems(properties) {}
75
76         QList<QStandardItem*> toList() const {
77             return QList<QStandardItem*>() << idItem << visibilityItem;
78         }
79
80         QStandardItem *idItem;
81         QStandardItem *visibilityItem;
82         QMap<QString, QStandardItem *> propertyItems;
83     };
84 #endif
85
86     static const int NavigatorRole;
87
88 public:
89     NavigatorTreeModel(QObject *parent = 0);
90     ~NavigatorTreeModel();
91
92     Qt::DropActions supportedDropActions() const;
93
94     QStringList mimeTypes() const;
95     QMimeData *mimeData(const QModelIndexList &indexes) const;
96     bool dropMimeData(const QMimeData *data,
97                       Qt::DropAction action,
98                       int row,
99                       int column,
100                       const QModelIndex &parent);
101
102     void setView(AbstractView *view);
103     void clearView();
104
105     QModelIndex indexForNode(const ModelNode &node) const;
106     ModelNode nodeForIndex(const QModelIndex &index) const;
107
108     bool isInTree(const ModelNode &node) const;
109     void propagateInvisible(const ModelNode &node, const bool &invisible);
110     bool isNodeInvisible(const QModelIndex &index) const;
111     bool isNodeInvisible(const ModelNode &node) const;
112
113     void addSubTree(const ModelNode &node);
114     void removeSubTree(const ModelNode &node);
115     void updateItemRow(const ModelNode &node);
116     void updateItemRowOrder(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
117
118     void setId(const QModelIndex &index, const QString &id);
119     void setVisible(const QModelIndex &index, bool visible);
120
121 private slots:
122     void handleChangedItem(QStandardItem *item);
123
124 private:
125     bool containsNodeHash(uint hash) const;
126     ModelNode nodeForHash(uint hash) const;
127
128     bool containsNode(const ModelNode &node) const;
129     ItemRow itemRowForNode(const ModelNode &node);
130
131     ItemRow createItemRow(const ModelNode &node);
132     void updateItemRow(const ModelNode &node, ItemRow row);
133
134     void moveNodesInteractive(NodeAbstractProperty parentProperty, const QList<ModelNode> &modelNodes, int targetIndex);
135
136     QList<ModelNode> modelNodeChildren(const ModelNode &parentNode);
137
138     QString qmlTypeInQtContainer(const QString &qtContainerType) const;
139     QStringList visibleProperties(const ModelNode &node) const;
140
141     bool blockItemChangedSignal(bool block);
142
143 private:
144     QHash<ModelNode, ItemRow> m_nodeItemHash;
145     QHash<uint, ModelNode> m_nodeHash;
146     QWeakPointer<AbstractView> m_view;
147
148     bool m_blockItemChangedSignal;
149
150     QStringList m_hiddenProperties;
151 };
152
153 } // namespace QmlDesigner
154
155 #endif // NAVIGATORTREEMODEL_H