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 **************************************************************************/
35 #include "abstractproperty.h"
36 #include "modelnode.h"
37 #include "invalidmodelnodeexception.h"
38 #include "invalidargumentexception.h"
39 #include "metainfoparser.h"
40 #include "iwidgetplugin.h"
42 #include "model/variantparser.h"
43 #include "pluginmanager/widgetpluginmanager.h"
47 #include <QtAlgorithms>
53 namespace QmlDesigner {
58 Q_DISABLE_COPY(MetaInfoPrivate)
60 typedef QSharedPointer<MetaInfoPrivate> Pointer;
61 typedef QWeakPointer<MetaInfoPrivate> WeakPointer;
64 MetaInfoPrivate(MetaInfo *q);
71 QScopedPointer<ItemLibraryInfo> m_itemLibraryInfo;
77 MetaInfoPrivate::MetaInfoPrivate(MetaInfo *q) :
78 m_itemLibraryInfo(new ItemLibraryInfo()),
80 m_isInitialized(false)
83 m_itemLibraryInfo->setBaseInfo(MetaInfo::global().itemLibraryInfo());
86 void MetaInfoPrivate::clear()
88 m_itemLibraryInfo->clearEntries();
89 m_isInitialized = false;
92 void MetaInfoPrivate::initialize()
95 m_isInitialized = true;
98 QString static inline stripPrefix(const QString &typeName)
100 QStringList list = typeName.split('.');
101 if (list.count() == 2)
106 static inline bool isDepricatedQtType(const QString &typeName)
108 if (typeName.length() < 8)
111 return typeName.contains("Qt.");
114 void MetaInfoPrivate::parseXmlFiles()
116 Internal::WidgetPluginManager pluginManager;
117 foreach (const QString &pluginDir, m_q->s_pluginDirs)
118 pluginManager.addPath(pluginDir);
119 QList<IWidgetPlugin *> widgetPluginList = pluginManager.instances();
120 foreach (IWidgetPlugin *plugin, widgetPluginList) {
121 Internal::MetaInfoParser parser(*m_q);
122 parser.parseFile(plugin->metaInfo());
126 } // namespace Internal
128 using QmlDesigner::Internal::MetaInfoPrivate;
130 MetaInfo MetaInfo::s_global;
131 QStringList MetaInfo::s_pluginDirs;
135 \class QmlDesigner::MetaInfo
137 \brief The MetaInfo class provides meta information about qml types and properties.
141 \brief Constructs a copy of the given meta info.
143 MetaInfo::MetaInfo(const MetaInfo &metaInfo) :
149 \brief Creates a meta information object with just the qml types registered statically.
150 You almost always want to use Model::metaInfo() instead!
152 You almost certainly want to access the meta information for the model.
154 \see Model::metaInfo()
156 MetaInfo::MetaInfo() :
157 m_p(new MetaInfoPrivate(this))
161 MetaInfo::~MetaInfo()
166 \brief Assigns other to this meta information and returns a reference to this meta information.
168 MetaInfo& MetaInfo::operator=(const MetaInfo &other)
174 ItemLibraryInfo *MetaInfo::itemLibraryInfo() const
176 return m_p->m_itemLibraryInfo.data();
180 \brief Access to the global meta information object.
181 You almost always want to use Model::metaInfo() instead.
183 Internally all meta information objects share this "global" object
184 where static qml type information is stored.
186 MetaInfo MetaInfo::global()
188 if (!s_global.m_p->m_isInitialized) {
189 s_global.m_p = QSharedPointer<MetaInfoPrivate>(new MetaInfoPrivate(&s_global));
190 s_global.m_p->initialize();
196 \brief Clears the global meta information object.
198 This method should be called once on application shutdown to free static data structures.
200 void MetaInfo::clearGlobal()
202 if (s_global.m_p->m_isInitialized) {
203 s_global.m_p->clear();
207 void MetaInfo::setPluginPaths(const QStringList &paths)
209 s_pluginDirs = paths;
212 bool MetaInfo::isGlobal() const
214 return (this->m_p == s_global.m_p);
217 bool operator==(const MetaInfo &first, const MetaInfo &second)
219 return first.m_p == second.m_p;
222 bool operator!=(const MetaInfo &first, const MetaInfo &second)
224 return !(first == second);
227 } //namespace QmlDesigner