1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef NAVIGATORTREEMODEL_H
35 #define NAVIGATORTREEMODEL_H
37 #include <modelnode.h>
38 #include <nodemetainfo.h>
40 #include <QStandardItem>
41 #include <QStandardItemModel>
43 namespace QmlDesigner {
49 class NavigatorTreeModel : public QStandardItemModel
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) {}
60 QList<QStandardItem*> toList() const {
61 return QList<QStandardItem*>() << idItem << lockItem << visibilityItem;
64 QStandardItem *idItem;
65 QStandardItem *lockItem;
66 QStandardItem *visibilityItem;
67 QMap<QString, QStandardItem *> propertyItems;
72 : idItem(0), visibilityItem(0) {}
73 ItemRow(QStandardItem *id, QStandardItem *visibility, const QMap<QString, QStandardItem *> &properties)
74 : idItem(id), visibilityItem(visibility), propertyItems(properties) {}
76 QList<QStandardItem*> toList() const {
77 return QList<QStandardItem*>() << idItem << visibilityItem;
80 QStandardItem *idItem;
81 QStandardItem *visibilityItem;
82 QMap<QString, QStandardItem *> propertyItems;
86 static const int NavigatorRole;
89 NavigatorTreeModel(QObject *parent = 0);
90 ~NavigatorTreeModel();
92 Qt::DropActions supportedDropActions() const;
94 QStringList mimeTypes() const;
95 QMimeData *mimeData(const QModelIndexList &indexes) const;
96 bool dropMimeData(const QMimeData *data,
97 Qt::DropAction action,
100 const QModelIndex &parent);
102 void setView(AbstractView *view);
105 QModelIndex indexForNode(const ModelNode &node) const;
106 ModelNode nodeForIndex(const QModelIndex &index) const;
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;
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);
118 void setId(const QModelIndex &index, const QString &id);
119 void setVisible(const QModelIndex &index, bool visible);
122 void handleChangedItem(QStandardItem *item);
125 bool containsNodeHash(uint hash) const;
126 ModelNode nodeForHash(uint hash) const;
128 bool containsNode(const ModelNode &node) const;
129 ItemRow itemRowForNode(const ModelNode &node);
131 ItemRow createItemRow(const ModelNode &node);
132 void updateItemRow(const ModelNode &node, ItemRow row);
134 void moveNodesInteractive(NodeAbstractProperty parentProperty, const QList<ModelNode> &modelNodes, int targetIndex);
136 QList<ModelNode> modelNodeChildren(const ModelNode &parentNode);
138 QString qmlTypeInQtContainer(const QString &qtContainerType) const;
139 QStringList visibleProperties(const ModelNode &node) const;
141 bool blockItemChangedSignal(bool block);
144 QHash<ModelNode, ItemRow> m_nodeItemHash;
145 QHash<uint, ModelNode> m_nodeHash;
146 QWeakPointer<AbstractView> m_view;
148 bool m_blockItemChangedSignal;
150 QStringList m_hiddenProperties;
153 } // namespace QmlDesigner
155 #endif // NAVIGATORTREEMODEL_H