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 ITEMLIBRARYMODEL_H
35 #define ITEMLIBRARYMODEL_H
40 #include <QScriptEngine>
41 #include <private/qdeclarativelistmodel_p.h>
43 QT_FORWARD_DECLARE_CLASS(QMimeData)
45 namespace QmlDesigner {
47 class ItemLibraryInfo;
48 class ItemLibraryEntry;
54 class ItemLibrarySortedModel: public QDeclarativeListModel {
56 ItemLibrarySortedModel(QObject *parent = 0);
57 ~ItemLibrarySortedModel();
61 void addElement(T *element, int libId);
62 void removeElement(int libId);
64 bool elementVisible(int libId) const;
65 bool setElementVisible(int libId, bool visible);
67 const QMap<int, T *> &elements() const;
69 T *elementModel(int libId);
70 int findElement(int libId) const;
71 int visibleElementPosition(int libId) const;
79 QMap<int, T *> m_elementModels;
80 QList<struct order_struct> m_elementOrder;
84 class ItemLibraryItemModel: public QScriptValue {
86 ItemLibraryItemModel(QScriptEngine *scriptEngine, int itemLibId, const QString &itemName);
87 ~ItemLibraryItemModel();
89 int itemLibId() const;
90 QString itemName() const;
92 void setItemIconPath(const QString &iconPath);
93 void setItemIconSize(const QSize &itemIconSize);
95 bool operator<(const ItemLibraryItemModel &other) const;
98 QWeakPointer<QScriptEngine> m_scriptEngine;
106 class ItemLibrarySectionModel: public QScriptValue {
108 ItemLibrarySectionModel(QScriptEngine *scriptEngine, int sectionLibId, const QString §ionName, QObject *parent = 0);
110 QString sectionName() const;
112 void addSectionEntry(ItemLibraryItemModel *sectionEntry);
113 void removeSectionEntry(int itemLibId);
115 int visibleItemIndex(int itemLibId);
116 bool isItemVisible(int itemLibId);
118 bool updateSectionVisibility(const QString &searchText, bool *changed);
119 void updateItemIconSize(const QSize &itemIconSize);
121 bool operator<(const ItemLibrarySectionModel &other) const;
125 ItemLibrarySortedModel<ItemLibraryItemModel> m_sectionEntries;
129 class ItemLibraryModel: public ItemLibrarySortedModel<ItemLibrarySectionModel> {
131 Q_PROPERTY(QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged)
134 explicit ItemLibraryModel(QScriptEngine *scriptEngine, QObject *parent = 0);
137 QString searchText() const;
139 void update(ItemLibraryInfo *itemLibraryInfo, Model *model);
141 QString getTypeName(int libId);
142 QMimeData *getMimeData(int libId);
143 QIcon getIcon(int libId);
146 void setSearchText(const QString &searchText);
147 void setItemIconSize(const QSize &itemIconSize);
149 int getItemSectionIndex(int itemLibId);
150 int getSectionLibId(int itemLibId);
151 bool isItemVisible(int itemLibId);
154 void qmlModelChanged();
155 void searchTextChanged();
156 void visibilityChanged();
157 void sectionVisibilityChanged(int changedSectionLibId);
160 void updateVisibility();
162 int getWidth(const ItemLibraryEntry &entry);
163 int getHeight(const ItemLibraryEntry &entry);
164 QPixmap createDragPixmap(int width, int height);
166 QWeakPointer<QScriptEngine> m_scriptEngine;
167 QMap<int, ItemLibraryEntry> m_itemInfos;
168 QMap<int, int> m_sections;
170 QString m_searchText;
171 QSize m_itemIconSize;
175 } // namespace Internal
176 } // namespace QmlDesigner
178 #endif // ITEMLIBRARYMODEL_H