1
1
/****************************************************************************
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
7
** This file is part of the Qt Designer of the Qt Toolkit.
8
9
** $QT_BEGIN_LICENSE:LGPL$
10
** Licensees holding valid Qt Commercial licenses may use this file in
11
** accordance with the Qt Commercial License Agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Nokia.
10
** No Commercial Usage
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
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
** In addition, as a special exception, Nokia gives you certain
24
** additional rights. These rights are described in the Nokia Qt LGPL
25
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
28
** GNU General Public License Usage
29
** Alternatively, this file may be used under the terms of the GNU
30
** General Public License version 3.0 as published by the Free Software
31
** Foundation and appearing in the file LICENSE.GPL included in the
32
** packaging of this file. Please review the following information to
33
** ensure the GNU General Public License version 3.0 requirements will be
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at http://www.qtsoftware.com/contact.
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights. These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
38
38
** $QT_END_LICENSE$
40
40
****************************************************************************/
72
72
static const char *customwidgetElementC = "customwidget";
73
73
static const char *extendsElementC = "extends";
74
74
static const char *addPageMethodC = "addpagemethod";
75
static const char *propertySpecsC = "propertyspecifications";
76
static const char *stringPropertySpecC = "stringpropertyspecification";
77
static const char *stringPropertyNameAttrC = "name";
78
static const char *stringPropertyTypeAttrC = "type";
79
static const char *stringPropertyNoTrAttrC = "notr";
75
80
static const char *jambiLanguageC = "jambi";
77
82
enum { debugPluginManager = 0 };
220
231
return m_d->pluginPath;
234
bool QDesignerCustomWidgetData::xmlStringPropertyType(const QString &name, StringPropertyType *type) const
236
QDesignerCustomWidgetSharedData::StringPropertyTypeMap::const_iterator it = m_d->xmlStringPropertyTypeMap.constFind(name);
237
if (it == m_d->xmlStringPropertyTypeMap.constEnd()) {
238
*type = StringPropertyType(qdesigner_internal::ValidationRichText, true);
223
245
// Wind a QXmlStreamReader until it finds an element. Returns index or one of FindResult
224
246
enum FindResult { FindError = -2, ElementNotFound = -1 };
249
271
return QDesignerPluginManager::tr("An XML error was encountered when parsing the XML of the custom widget %1: %2").arg(name, errorMessage);
274
static inline QString msgAttributeMissing(const QString &name)
276
return QDesignerPluginManager::tr("A required attribute ('%1') is missing.").arg(name);
279
static qdesigner_internal::TextPropertyValidationMode typeStringToType(const QString &v, bool *ok)
282
if (v == QLatin1String("multiline"))
283
return qdesigner_internal::ValidationMultiLine;
284
if (v == QLatin1String("richtext"))
285
return qdesigner_internal::ValidationRichText;
286
if (v == QLatin1String("stylesheet"))
287
return qdesigner_internal::ValidationStyleSheet;
288
if (v == QLatin1String("singleline"))
289
return qdesigner_internal::ValidationSingleLine;
290
if (v == QLatin1String("objectname"))
291
return qdesigner_internal::ValidationObjectName;
292
if (v == QLatin1String("objectnamescope"))
293
return qdesigner_internal::ValidationObjectNameScope;
294
if (v == QLatin1String("url"))
295
return qdesigner_internal::ValidationURL;
297
return qdesigner_internal::ValidationRichText;
300
static bool parsePropertySpecs(QXmlStreamReader &sr,
301
QDesignerCustomWidgetSharedData::StringPropertyTypeMap *rc,
302
QString *errorMessage)
304
const QString propertySpecs = QLatin1String(propertySpecsC);
305
const QString stringPropertySpec = QLatin1String(stringPropertySpecC);
306
const QString stringPropertyTypeAttr = QLatin1String(stringPropertyTypeAttrC);
307
const QString stringPropertyNoTrAttr = QLatin1String(stringPropertyNoTrAttrC);
308
const QString stringPropertyNameAttr = QLatin1String(stringPropertyNameAttrC);
310
while (!sr.atEnd()) {
311
switch(sr.readNext()) {
312
case QXmlStreamReader::StartElement: {
313
if (sr.name() != stringPropertySpec) {
314
*errorMessage = QDesignerPluginManager::tr("An invalid property specification ('%1') was encountered. Supported types: %2").arg(sr.name().toString(), stringPropertySpec);
317
const QXmlStreamAttributes atts = sr.attributes();
318
const QString name = atts.value(stringPropertyNameAttr).toString();
319
const QString type = atts.value(stringPropertyTypeAttr).toString();
320
const QString notrS = atts.value(stringPropertyNoTrAttr).toString(); //Optional
322
if (type.isEmpty()) {
323
*errorMessage = msgAttributeMissing(stringPropertyTypeAttr);
326
if (name.isEmpty()) {
327
*errorMessage = msgAttributeMissing(stringPropertyNameAttr);
331
const bool noTr = notrS == QLatin1String("true") || notrS == QLatin1String("1");
332
QDesignerCustomWidgetSharedData::StringPropertyType v(typeStringToType(type, &typeOk), !noTr);
334
*errorMessage = QDesignerPluginManager::tr("'%1' is not a valid string property specification.").arg(type);
340
case QXmlStreamReader::EndElement: // Outer </stringproperties>
341
if (sr.name() == propertySpecs)
252
350
QDesignerCustomWidgetData::ParseResult
253
351
QDesignerCustomWidgetData::parseXml(const QString &xml, const QString &name, QString *errorMessage)
314
// Find <extends>, <addPageMethod>
412
// Find <extends>, <addPageMethod>, <stringproperties>
315
413
elements.clear();
316
414
elements.push_back(QLatin1String(extendsElementC));
317
415
elements.push_back(QLatin1String(addPageMethodC));
416
elements.push_back(QLatin1String(propertySpecsC));
319
418
switch (findElement(elements, sr)) {
654
761
return m_d->m_customWidgetData.at(index);
764
QDesignerCustomWidgetData QDesignerPluginManager::customWidgetData(const QString &name) const
766
const int count = m_d->m_customWidgets.size();
767
for (int i = 0; i < count; i++)
768
if (m_d->m_customWidgets.at(i)->name() == name)
769
return m_d->m_customWidgetData.at(i);
770
return QDesignerCustomWidgetData();
657
773
QObjectList QDesignerPluginManager::instances() const
659
775
QStringList plugins = registeredPlugins();