author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
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 |
** 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 |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
**sw |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "abstractformbuilder.h" |
|
43 |
#include "formbuilderextra_p.h" |
|
44 |
#include "resourcebuilder_p.h" |
|
45 |
#include "textbuilder_p.h" |
|
46 |
#include "ui4_p.h" |
|
47 |
#include "properties_p.h" |
|
48 |
||
49 |
#include <QtCore/QVariant> |
|
50 |
#include <QtCore/QMetaProperty> |
|
51 |
#include <QtCore/QFileInfo> |
|
52 |
#include <QtCore/QDir> |
|
53 |
#include <QtCore/QQueue> |
|
54 |
#include <QtCore/QHash> |
|
55 |
#include <QtCore/qdebug.h> |
|
56 |
#include <QtCore/QCoreApplication> |
|
57 |
||
58 |
#include <QtGui/QAction> |
|
59 |
#include <QtGui/QActionGroup> |
|
60 |
#include <QtGui/QButtonGroup> |
|
61 |
#include <QtGui/QComboBox> |
|
62 |
#include <QtGui/QFontComboBox> |
|
63 |
#include <QtGui/QGridLayout> |
|
64 |
#ifndef QT_NO_FORMLAYOUT |
|
65 |
# include <QtGui/QFormLayout> |
|
66 |
#endif |
|
67 |
#include <QtGui/QIcon> |
|
68 |
#include <QtGui/QListWidget> |
|
69 |
#include <QtGui/QMainWindow> |
|
70 |
#include <QtGui/QPixmap> |
|
71 |
#include <QtGui/QStatusBar> |
|
72 |
#include <QtGui/QTreeWidget> |
|
73 |
#include <QtGui/QTableWidget> |
|
74 |
#include <QtGui/QWidget> |
|
75 |
#include <QtGui/QSplitter> |
|
76 |
#include <QtGui/QScrollArea> |
|
77 |
#include <QtGui/QAbstractButton> |
|
78 |
#include <QtGui/QAbstractItemView> |
|
79 |
#include <QtGui/QHeaderView> |
|
80 |
#ifndef QFORMINTERNAL_NAMESPACE |
|
81 |
# include <private/qlayout_p.h> // Compiling within Designer |
|
82 |
#endif |
|
83 |
||
84 |
#include <QtXml/QXmlStreamReader> |
|
85 |
||
86 |
#include <QtGui/QDialog> |
|
87 |
||
88 |
// containers |
|
89 |
#include <QtGui/QToolBox> |
|
90 |
#include <QtGui/QStackedWidget> |
|
91 |
#include <QtGui/QTabWidget> |
|
92 |
#include <QtGui/QToolBar> |
|
93 |
#include <QtGui/QMenuBar> |
|
94 |
#include <QtGui/QDockWidget> |
|
95 |
#include <QtGui/QMdiArea> |
|
96 |
#include <QtGui/QWorkspace> |
|
97 |
#include <QtGui/QWizard> |
|
98 |
#include <QtGui/QWizardPage> |
|
99 |
||
100 |
#include <QtCore/qdebug.h> |
|
101 |
||
102 |
#include <limits.h> |
|
103 |
||
104 |
Q_DECLARE_METATYPE(QWidgetList) |
|
105 |
||
106 |
static const char *buttonGroupPropertyC = "buttonGroup"; |
|
107 |
||
108 |
QT_BEGIN_NAMESPACE |
|
109 |
||
110 |
#ifdef QFORMINTERNAL_NAMESPACE |
|
111 |
using namespace QFormInternal; |
|
112 |
#endif |
|
113 |
||
114 |
class QFriendlyLayout: public QLayout |
|
115 |
{ |
|
116 |
public: |
|
117 |
inline QFriendlyLayout() { Q_ASSERT(0); } |
|
118 |
||
119 |
#ifdef QFORMINTERNAL_NAMESPACE |
|
120 |
friend class QFormInternal::QAbstractFormBuilder; |
|
121 |
#else |
|
122 |
friend class QAbstractFormBuilder; |
|
123 |
#endif |
|
124 |
}; |
|
125 |
||
126 |
/*! |
|
127 |
\class QAbstractFormBuilder |
|
128 |
||
129 |
\brief The QAbstractFormBuilder class provides a default |
|
130 |
implementation for classes that create user interfaces at |
|
131 |
run-time. |
|
132 |
||
133 |
\inmodule QtDesigner |
|
134 |
||
135 |
QAbstractFormBuilder provides a standard interface and a default |
|
136 |
implementation for constructing forms from user interface |
|
137 |
files. It is not intended to be instantiated directly. Use the |
|
138 |
QFormBuilder class to create user interfaces from UI files at |
|
139 |
run-time. For example: |
|
140 |
||
141 |
\snippet doc/src/snippets/code/tools_designer_src_lib_uilib_abstractformbuilder.cpp 0 |
|
142 |
||
143 |
To override certain aspects of the form builder's behavior, |
|
144 |
subclass QAbstractFormBuilder and reimplement the relevant virtual |
|
145 |
functions: |
|
146 |
||
147 |
\list |
|
148 |
\o load() handles reading of UI format files from arbitrary |
|
149 |
QIODevices, and construction of widgets from the XML data |
|
150 |
that they contain. |
|
151 |
\o save() handles saving of widget details in UI format to |
|
152 |
arbitrary QIODevices. |
|
153 |
\o workingDirectory() and setWorkingDirectory() control the |
|
154 |
directory in which forms are held. The form builder looks for |
|
155 |
other resources on paths relative to this directory. |
|
156 |
\endlist |
|
157 |
||
158 |
The QFormBuilder class is typically used by custom components and |
|
159 |
applications that embed \QD. Standalone applications that need to |
|
160 |
dynamically generate user interfaces at run-time use the |
|
161 |
QUiLoader, found in the QtUiTools module. |
|
162 |
||
163 |
\sa {QtUiTools Module} |
|
164 |
*/ |
|
165 |
||
166 |
/*! |
|
167 |
Constructs a new form builder.*/ |
|
168 |
QAbstractFormBuilder::QAbstractFormBuilder() : |
|
169 |
m_defaultMargin(INT_MIN), |
|
170 |
m_defaultSpacing(INT_MIN) |
|
171 |
{ |
|
172 |
setResourceBuilder(new QResourceBuilder()); |
|
173 |
setTextBuilder(new QTextBuilder()); |
|
174 |
} |
|
175 |
||
176 |
/*! |
|
177 |
Destroys the form builder.*/ |
|
178 |
QAbstractFormBuilder::~QAbstractFormBuilder() |
|
179 |
{ |
|
180 |
QFormBuilderExtra::removeInstance(this); |
|
181 |
} |
|
182 |
||
183 |
||
184 |
/*! |
|
185 |
\fn QWidget *QAbstractFormBuilder::load(QIODevice *device, QWidget *parent) |
|
186 |
||
187 |
Loads an XML representation of a widget from the given \a device, |
|
188 |
and constructs a new widget with the specified \a parent. |
|
189 |
||
190 |
\sa save() |
|
191 |
*/ |
|
192 |
QWidget *QAbstractFormBuilder::load(QIODevice *dev, QWidget *parentWidget) |
|
193 |
{ |
|
194 |
QXmlStreamReader reader; |
|
195 |
reader.setDevice(dev); |
|
196 |
DomUI ui; |
|
197 |
bool initialized = false; |
|
198 |
||
199 |
const QString uiElement = QLatin1String("ui"); |
|
200 |
while (!reader.atEnd()) { |
|
201 |
if (reader.readNext() == QXmlStreamReader::StartElement) { |
|
202 |
if (reader.name().compare(uiElement, Qt::CaseInsensitive) == 0) { |
|
203 |
ui.read(reader); |
|
204 |
initialized = true; |
|
205 |
} else { |
|
206 |
reader.raiseError(QCoreApplication::translate("QAbstractFormBuilder", "Unexpected element <%1>").arg(reader.name().toString())); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
if (reader.hasError()) { |
|
211 |
uiLibWarning(QCoreApplication::translate("QAbstractFormBuilder", "An error has occurred while reading the UI file at line %1, column %2: %3") |
|
212 |
.arg(reader.lineNumber()).arg(reader.columnNumber()) |
|
213 |
.arg(reader.errorString())); |
|
214 |
return 0; |
|
215 |
} |
|
216 |
if (!initialized) { |
|
217 |
uiLibWarning(QCoreApplication::translate("QAbstractFormBuilder", "Invalid UI file: The root element <ui> is missing.")); |
|
218 |
return 0; |
|
219 |
} |
|
220 |
||
221 |
QWidget *widget = create(&ui, parentWidget); |
|
222 |
return widget; |
|
223 |
} |
|
224 |
||
225 |
/*! |
|
226 |
\internal |
|
227 |
*/ |
|
228 |
QWidget *QAbstractFormBuilder::create(DomUI *ui, QWidget *parentWidget) |
|
229 |
{ |
|
230 |
typedef QFormBuilderExtra::ButtonGroupHash ButtonGroupHash; |
|
231 |
||
232 |
QFormBuilderExtra *formBuilderPrivate = QFormBuilderExtra::instance(this); |
|
233 |
formBuilderPrivate->clear(); |
|
234 |
if (const DomLayoutDefault *def = ui->elementLayoutDefault()) { |
|
235 |
m_defaultMargin = def->hasAttributeMargin() ? def->attributeMargin() : INT_MIN; |
|
236 |
m_defaultSpacing = def->hasAttributeSpacing() ? def->attributeSpacing() : INT_MIN; |
|
237 |
} |
|
238 |
||
239 |
DomWidget *ui_widget = ui->elementWidget(); |
|
240 |
if (!ui_widget) |
|
241 |
return 0; |
|
242 |
||
243 |
initialize(ui); |
|
244 |
||
245 |
if (const DomButtonGroups *domButtonGroups = ui->elementButtonGroups()) |
|
246 |
formBuilderPrivate->registerButtonGroups(domButtonGroups); |
|
247 |
||
248 |
if (QWidget *widget = create(ui_widget, parentWidget)) { |
|
249 |
// Reparent button groups that were actually created to main container for them to be found in the signal/slot part |
|
250 |
const ButtonGroupHash &buttonGroups = formBuilderPrivate->buttonGroups(); |
|
251 |
if (!buttonGroups.empty()) { |
|
252 |
const ButtonGroupHash::const_iterator cend = buttonGroups.constEnd(); |
|
253 |
for (ButtonGroupHash::const_iterator it = buttonGroups.constBegin(); it != cend; ++it) |
|
254 |
if (it.value().second) |
|
255 |
it.value().second->setParent(widget); |
|
256 |
} |
|
257 |
createConnections(ui->elementConnections(), widget); |
|
258 |
createResources(ui->elementResources()); // maybe this should go first, before create()... |
|
259 |
applyTabStops(widget, ui->elementTabStops()); |
|
260 |
formBuilderPrivate->applyInternalProperties(); |
|
261 |
reset(); |
|
262 |
formBuilderPrivate->clear(); |
|
263 |
return widget; |
|
264 |
} |
|
265 |
formBuilderPrivate->clear(); |
|
266 |
return 0; |
|
267 |
} |
|
268 |
||
269 |
/*! |
|
270 |
\internal |
|
271 |
Retrieve relevant information from the custom widgets section. |
|
272 |
Called by create(DomUI *, QWidget *); call manually if you |
|
273 |
just use create(DomWidget *, QWidget *) on some child widget of DomUI. |
|
274 |
*/ |
|
275 |
||
276 |
void QAbstractFormBuilder::initialize(const DomUI *ui) |
|
277 |
{ |
|
278 |
typedef QList<DomCustomWidget*> DomCustomWidgetList; |
|
279 |
||
280 |
DomCustomWidgets *domCustomWidgets = ui->elementCustomWidgets(); |
|
281 |
createCustomWidgets(domCustomWidgets); |
|
282 |
||
283 |
if (domCustomWidgets) { |
|
284 |
const DomCustomWidgetList customWidgets = domCustomWidgets->elementCustomWidget(); |
|
285 |
if (!customWidgets.empty()) { |
|
286 |
QFormBuilderExtra *formBuilderPrivate = QFormBuilderExtra::instance(this); |
|
287 |
const DomCustomWidgetList::const_iterator cend = customWidgets.constEnd(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
for (DomCustomWidgetList::const_iterator it = customWidgets.constBegin(); it != cend; ++it) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
formBuilderPrivate->storeCustomWidgetData((*it)->elementClass(), *it); |
0 | 290 |
} |
291 |
} |
|
292 |
} |
|
293 |
||
294 |
/*! |
|
295 |
\internal |
|
296 |
*/ |
|
297 |
QWidget *QAbstractFormBuilder::create(DomWidget *ui_widget, QWidget *parentWidget) |
|
298 |
{ |
|
299 |
QWidget *w = createWidget(ui_widget->attributeClass(), parentWidget, ui_widget->attributeName()); |
|
300 |
if (!w) |
|
301 |
return 0; |
|
302 |
||
303 |
applyProperties(w, ui_widget->elementProperty()); |
|
304 |
||
305 |
foreach (DomAction *ui_action, ui_widget->elementAction()) { |
|
306 |
QAction *child_action = create(ui_action, w); |
|
307 |
Q_UNUSED( child_action ); |
|
308 |
} |
|
309 |
||
310 |
foreach (DomActionGroup *ui_action_group, ui_widget->elementActionGroup()) { |
|
311 |
QActionGroup *child_action_group = create(ui_action_group, w); |
|
312 |
Q_UNUSED( child_action_group ); |
|
313 |
} |
|
314 |
||
315 |
QWidgetList children; |
|
316 |
foreach (DomWidget *ui_child, ui_widget->elementWidget()) { |
|
317 |
if (QWidget *child = create(ui_child, w)) { |
|
318 |
children += child; |
|
319 |
} else { |
|
320 |
const QString className = ui_child->elementClass().empty() ? QString() : ui_child->elementClass().front(); |
|
321 |
uiLibWarning(QCoreApplication::translate("QAbstractFormBuilder", "The creation of a widget of the class '%1' failed.").arg(className)); |
|
322 |
} |
|
323 |
} |
|
324 |
||
325 |
foreach (DomLayout *ui_lay, ui_widget->elementLayout()) { |
|
326 |
QLayout *child_lay = create(ui_lay, 0, w); |
|
327 |
Q_UNUSED( child_lay ); |
|
328 |
} |
|
329 |
||
330 |
const QList<DomActionRef *> addActions = ui_widget->elementAddAction(); |
|
331 |
if (!addActions.empty()) { |
|
332 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
333 |
foreach (DomActionRef *ui_action_ref, addActions) { |
|
334 |
const QString name = ui_action_ref->attributeName(); |
|
335 |
if (name == strings.separator) { |
|
336 |
QAction *sep = new QAction(w); |
|
337 |
sep->setSeparator(true); |
|
338 |
w->addAction(sep); |
|
339 |
addMenuAction(sep); |
|
340 |
} else if (QAction *a = m_actions.value(name)) { |
|
341 |
w->addAction(a); |
|
342 |
} else if (QActionGroup *g = m_actionGroups.value(name)) { |
|
343 |
w->addActions(g->actions()); |
|
344 |
} else if (QMenu *menu = qFindChild<QMenu*>(w, name)) { |
|
345 |
w->addAction(menu->menuAction()); |
|
346 |
addMenuAction(menu->menuAction()); |
|
347 |
} |
|
348 |
} |
|
349 |
} |
|
350 |
||
351 |
loadExtraInfo(ui_widget, w, parentWidget); |
|
352 |
#ifndef QT_FORMBUILDER_NO_SCRIPT |
|
353 |
QString scriptErrorMessage; |
|
354 |
QFormBuilderExtra *extra = QFormBuilderExtra::instance(this); |
|
355 |
extra->formScriptRunner().run(ui_widget, |
|
356 |
extra->customWidgetScript(ui_widget->attributeClass()), |
|
357 |
w, children, &scriptErrorMessage); |
|
358 |
#endif |
|
359 |
addItem(ui_widget, w, parentWidget); |
|
360 |
||
361 |
if (qobject_cast<QDialog *>(w) && parentWidget) |
|
362 |
w->setAttribute(Qt::WA_Moved, false); // So that QDialog::setVisible(true) will center it |
|
363 |
||
364 |
const QStringList zOrderNames = ui_widget->elementZOrder(); |
|
365 |
if (!zOrderNames.isEmpty()) { |
|
366 |
QList<QWidget *> zOrder = qVariantValue<QWidgetList>(w->property("_q_zOrder")); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
367 |
foreach (const QString &widgetName, zOrderNames) { |
0 | 368 |
if (QWidget *child = qFindChild<QWidget*>(w, widgetName)) { |
369 |
if (child->parentWidget() == w) { |
|
370 |
zOrder.removeAll(child); |
|
371 |
zOrder.append(child); |
|
372 |
child->raise(); |
|
373 |
} |
|
374 |
} |
|
375 |
} |
|
376 |
w->setProperty("_q_zOrder", qVariantFromValue(zOrder)); |
|
377 |
} |
|
378 |
||
379 |
return w; |
|
380 |
} |
|
381 |
||
382 |
/*! |
|
383 |
\internal |
|
384 |
*/ |
|
385 |
QAction *QAbstractFormBuilder::create(DomAction *ui_action, QObject *parent) |
|
386 |
{ |
|
387 |
QAction *a = createAction(parent, ui_action->attributeName()); |
|
388 |
if (!a) |
|
389 |
return 0; |
|
390 |
||
391 |
m_actions.insert(ui_action->attributeName(), a); |
|
392 |
applyProperties(a, ui_action->elementProperty()); |
|
393 |
return a; |
|
394 |
} |
|
395 |
||
396 |
/*! |
|
397 |
\internal |
|
398 |
*/ |
|
399 |
QActionGroup *QAbstractFormBuilder::create(DomActionGroup *ui_action_group, QObject *parent) |
|
400 |
{ |
|
401 |
QActionGroup *a = createActionGroup(parent, ui_action_group->attributeName()); |
|
402 |
if (!a) |
|
403 |
return 0; |
|
404 |
m_actionGroups.insert(ui_action_group->attributeName(), a); |
|
405 |
applyProperties(a, ui_action_group->elementProperty()); |
|
406 |
||
407 |
foreach (DomAction *ui_action, ui_action_group->elementAction()) { |
|
408 |
QAction *child_action = create(ui_action, a); |
|
409 |
Q_UNUSED( child_action ); |
|
410 |
} |
|
411 |
||
412 |
foreach (DomActionGroup *g, ui_action_group->elementActionGroup()) { |
|
413 |
QActionGroup *child_action_group = create(g, parent); |
|
414 |
Q_UNUSED( child_action_group ); |
|
415 |
} |
|
416 |
||
417 |
return a; |
|
418 |
} |
|
419 |
||
420 |
// figure out the toolbar area of a DOM attrib list. |
|
421 |
// By legacy, it is stored as an integer. As of 4.3.0, it is the enumeration value. |
|
422 |
Qt::ToolBarArea QAbstractFormBuilder::toolbarAreaFromDOMAttributes(const DomPropertyHash &attributes) { |
|
423 |
const DomProperty *attr = attributes.value(QFormBuilderStrings::instance().toolBarAreaAttribute); |
|
424 |
if (!attr) |
|
425 |
return Qt::TopToolBarArea; |
|
426 |
switch(attr->kind()) { |
|
427 |
case DomProperty::Number: |
|
428 |
return static_cast<Qt::ToolBarArea>(attr->elementNumber()); |
|
429 |
case DomProperty::Enum: |
|
430 |
return enumKeyOfObjectToValue<QAbstractFormBuilderGadget, Qt::ToolBarArea>("toolBarArea", attr->elementEnum().toLatin1()); |
|
431 |
default: |
|
432 |
break; |
|
433 |
} |
|
434 |
return Qt::TopToolBarArea; |
|
435 |
} |
|
436 |
||
437 |
/*! |
|
438 |
\internal |
|
439 |
*/ |
|
440 |
bool QAbstractFormBuilder::addItem(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget) |
|
441 |
{ |
|
442 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
443 |
const DomPropertyHash attributes = propertyMap(ui_widget->elementAttribute()); |
|
444 |
||
445 |
if (parentWidget == 0) |
|
446 |
return true; |
|
447 |
// Check special cases. First: Custom container |
|
448 |
const QString className = QLatin1String(parentWidget->metaObject()->className()); |
|
449 |
const QString addPageMethod = QFormBuilderExtra::instance(this)->customWidgetAddPageMethod(className); |
|
450 |
if (!addPageMethod.isEmpty()) { |
|
451 |
// If this fails ( non-existent or non-slot), use ContainerExtension in Designer, else it can't be helped |
|
452 |
return QMetaObject::invokeMethod(parentWidget, addPageMethod.toUtf8().constData(), Qt::DirectConnection, Q_ARG(QWidget*, widget)); |
|
453 |
} |
|
454 |
||
455 |
if (QMainWindow *mw = qobject_cast<QMainWindow*>(parentWidget)) { |
|
456 |
||
457 |
#ifndef QT_NO_MENUBAR |
|
458 |
// the menubar |
|
459 |
if (QMenuBar *menuBar = qobject_cast<QMenuBar*>(widget)) { |
|
460 |
mw->setMenuBar(menuBar); |
|
461 |
return true; |
|
462 |
} |
|
463 |
#endif |
|
464 |
||
465 |
#ifndef QT_NO_TOOLBAR |
|
466 |
// apply the toolbar's attributes |
|
467 |
else if (QToolBar *toolBar = qobject_cast<QToolBar*>(widget)) { |
|
468 |
mw->addToolBar(toolbarAreaFromDOMAttributes(attributes), toolBar); |
|
469 |
// check break |
|
470 |
if (const DomProperty *attr = attributes.value(strings.toolBarBreakAttribute)) |
|
471 |
if (attr->elementBool() == strings.trueValue) |
|
472 |
mw->insertToolBarBreak (toolBar); |
|
473 |
||
474 |
return true; |
|
475 |
} |
|
476 |
#endif |
|
477 |
||
478 |
#ifndef QT_NO_STATUSBAR |
|
479 |
// statusBar |
|
480 |
else if (QStatusBar *statusBar = qobject_cast<QStatusBar*>(widget)) { |
|
481 |
mw->setStatusBar(statusBar); |
|
482 |
return true; |
|
483 |
} |
|
484 |
#endif |
|
485 |
||
486 |
#ifndef QT_NO_DOCKWIDGET |
|
487 |
// apply the dockwidget's attributes |
|
488 |
else if (QDockWidget *dockWidget = qobject_cast<QDockWidget*>(widget)) { |
|
489 |
if (const DomProperty *attr = attributes.value(strings.dockWidgetAreaAttribute)) { |
|
490 |
Qt::DockWidgetArea area = static_cast<Qt::DockWidgetArea>(attr->elementNumber()); |
|
491 |
if (!dockWidget->isAreaAllowed(area)) { |
|
492 |
if (dockWidget->isAreaAllowed(Qt::LeftDockWidgetArea)) |
|
493 |
area = Qt::LeftDockWidgetArea; |
|
494 |
else if (dockWidget->isAreaAllowed(Qt::RightDockWidgetArea)) |
|
495 |
area = Qt::RightDockWidgetArea; |
|
496 |
else if (dockWidget->isAreaAllowed(Qt::TopDockWidgetArea)) |
|
497 |
area = Qt::TopDockWidgetArea; |
|
498 |
else if (dockWidget->isAreaAllowed(Qt::BottomDockWidgetArea)) |
|
499 |
area = Qt::BottomDockWidgetArea; |
|
500 |
} |
|
501 |
mw->addDockWidget(area, dockWidget); |
|
502 |
} else { |
|
503 |
mw->addDockWidget(Qt::LeftDockWidgetArea, dockWidget); |
|
504 |
} |
|
505 |
return true; |
|
506 |
} |
|
507 |
#endif |
|
508 |
||
509 |
else if (! mw->centralWidget()) { |
|
510 |
mw->setCentralWidget(widget); |
|
511 |
return true; |
|
512 |
} |
|
513 |
} |
|
514 |
||
515 |
#ifndef QT_NO_TABWIDGET |
|
516 |
else if (QTabWidget *tabWidget = qobject_cast<QTabWidget*>(parentWidget)) { |
|
517 |
widget->setParent(0); |
|
518 |
||
519 |
const int tabIndex = tabWidget->count(); |
|
520 |
if (const DomProperty *titleP = attributes.value(strings.titleAttribute, 0)) |
|
521 |
tabWidget->addTab(widget, toString(titleP->elementString())); |
|
522 |
else |
|
523 |
tabWidget->addTab(widget, strings.defaultTitle); |
|
524 |
||
525 |
if (DomProperty *picon = attributes.value(strings.iconAttribute)) { |
|
526 |
QVariant v = resourceBuilder()->loadResource(workingDirectory(), picon); |
|
527 |
QVariant nativeValue = resourceBuilder()->toNativeValue(v); |
|
528 |
tabWidget->setTabIcon(tabIndex, qvariant_cast<QIcon>(nativeValue)); |
|
529 |
} |
|
530 |
||
531 |
#ifndef QT_NO_TOOLTIP |
|
532 |
if (const DomProperty *ptoolTip = attributes.value(strings.toolTipAttribute)) { |
|
533 |
tabWidget->setTabToolTip(tabIndex, toString(ptoolTip->elementString())); |
|
534 |
} |
|
535 |
#endif |
|
536 |
||
537 |
#ifndef QT_NO_WHATSTHIS |
|
538 |
if (const DomProperty *pwhatsThis = attributes.value(strings.whatsThisAttribute)) { |
|
539 |
tabWidget->setTabWhatsThis(tabIndex, toString(pwhatsThis->elementString())); |
|
540 |
} |
|
541 |
#endif |
|
542 |
||
543 |
return true; |
|
544 |
} |
|
545 |
#endif |
|
546 |
||
547 |
#ifndef QT_NO_TOOLBOX |
|
548 |
else if (QToolBox *toolBox = qobject_cast<QToolBox*>(parentWidget)) { |
|
549 |
const int tabIndex = toolBox->count(); |
|
550 |
if (const DomProperty *labelP = attributes.value(strings.labelAttribute, 0)) |
|
551 |
toolBox->addItem(widget, toString(labelP->elementString())); |
|
552 |
else |
|
553 |
toolBox->addItem(widget, strings.defaultTitle); |
|
554 |
||
555 |
if (DomProperty *picon = attributes.value(strings.iconAttribute)) { |
|
556 |
QVariant v = resourceBuilder()->loadResource(workingDirectory(), picon); |
|
557 |
QVariant nativeValue = resourceBuilder()->toNativeValue(v); |
|
558 |
toolBox->setItemIcon(tabIndex, qvariant_cast<QIcon>(nativeValue)); |
|
559 |
} |
|
560 |
||
561 |
#ifndef QT_NO_TOOLTIP |
|
562 |
if (const DomProperty *ptoolTip = attributes.value(strings.toolTipAttribute)) { |
|
563 |
toolBox->setItemToolTip(tabIndex, toString(ptoolTip->elementString())); |
|
564 |
} |
|
565 |
#endif |
|
566 |
||
567 |
return true; |
|
568 |
} |
|
569 |
#endif |
|
570 |
||
571 |
#ifndef QT_NO_STACKEDWIDGET |
|
572 |
else if (QStackedWidget *stackedWidget = qobject_cast<QStackedWidget*>(parentWidget)) { |
|
573 |
stackedWidget->addWidget(widget); |
|
574 |
return true; |
|
575 |
} |
|
576 |
#endif |
|
577 |
||
578 |
#ifndef QT_NO_SPLITTER |
|
579 |
else if (QSplitter *splitter = qobject_cast<QSplitter*>(parentWidget)) { |
|
580 |
splitter->addWidget(widget); |
|
581 |
return true; |
|
582 |
} |
|
583 |
#endif |
|
584 |
||
585 |
#ifndef QT_NO_MDIAREA |
|
586 |
else if (QMdiArea *mdiArea = qobject_cast<QMdiArea*>(parentWidget)) { |
|
587 |
mdiArea->addSubWindow(widget); |
|
588 |
return true; |
|
589 |
} |
|
590 |
#endif |
|
591 |
||
592 |
#ifndef QT_NO_WORKSPACE |
|
593 |
else if (QWorkspace *ws = qobject_cast<QWorkspace*>(parentWidget)) { |
|
594 |
ws->addWindow(widget); |
|
595 |
return true; |
|
596 |
} |
|
597 |
#endif |
|
598 |
||
599 |
#ifndef QT_NO_DOCKWIDGET |
|
600 |
else if (QDockWidget *dockWidget = qobject_cast<QDockWidget*>(parentWidget)) { |
|
601 |
dockWidget->setWidget(widget); |
|
602 |
return true; |
|
603 |
} |
|
604 |
#endif |
|
605 |
||
606 |
#ifndef QT_NO_SCROLLAREA |
|
607 |
else if (QScrollArea *scrollArea = qobject_cast<QScrollArea*>(parentWidget)) { |
|
608 |
scrollArea->setWidget(widget); |
|
609 |
return true; |
|
610 |
} |
|
611 |
#endif |
|
612 |
||
613 |
#ifndef QT_NO_WIZARD |
|
614 |
else if (QWizard *wizard = qobject_cast<QWizard *>(parentWidget)) { |
|
615 |
QWizardPage *page = qobject_cast<QWizardPage*>(widget); |
|
616 |
if (!page) { |
|
617 |
uiLibWarning(QCoreApplication::translate("QAbstractFormBuilder", "Attempt to add child that is not of class QWizardPage to QWizard.")); |
|
618 |
return false; |
|
619 |
} |
|
620 |
wizard->addPage(page); |
|
621 |
return true; |
|
622 |
} |
|
623 |
#endif |
|
624 |
return false; |
|
625 |
} |
|
626 |
||
627 |
/*! |
|
628 |
\internal |
|
629 |
*/ |
|
630 |
void QAbstractFormBuilder::layoutInfo(DomLayout *ui_layout, QObject *parent, int *margin, int *spacing) |
|
631 |
{ |
|
632 |
Q_UNUSED(parent) |
|
633 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
634 |
const DomPropertyHash properties = propertyMap(ui_layout->elementProperty()); |
|
635 |
||
636 |
int mar = INT_MIN; |
|
637 |
int spac = INT_MIN; |
|
638 |
if (const DomProperty *p = properties.value(strings.marginProperty, 0)) |
|
639 |
mar = p->elementNumber(); |
|
640 |
||
641 |
if (const DomProperty *p = properties.value(strings.spacingProperty, 0)) |
|
642 |
spac = p->elementNumber(); |
|
643 |
||
644 |
#ifdef Q_OS_MAC |
|
645 |
// here we recognize UI file < 4.3 (no we don't store margin property) |
|
646 |
if (mar != INT_MIN) { |
|
647 |
const int defaultMargin = parent->inherits("QLayoutWidget") ? 0 : 9; |
|
648 |
if (mar == defaultMargin) |
|
649 |
mar = INT_MIN; |
|
650 |
if (spac == 6) |
|
651 |
spac = INT_MIN; |
|
652 |
||
653 |
if (mar == INT_MIN || spac == INT_MIN) { |
|
654 |
QList<DomProperty *> properties = ui_layout->elementProperty(); |
|
655 |
QMutableListIterator<DomProperty *> it(properties); |
|
656 |
while (it.hasNext()) { |
|
657 |
DomProperty *prop = it.next(); |
|
658 |
if ((mar == INT_MIN && prop->attributeName() == strings.marginProperty) || |
|
659 |
(spac == INT_MIN && prop->attributeName() == strings.spacingProperty)) { |
|
660 |
it.remove(); |
|
661 |
delete prop; |
|
662 |
} |
|
663 |
} |
|
664 |
ui_layout->setElementProperty(properties); |
|
665 |
} |
|
666 |
} |
|
667 |
#endif |
|
668 |
if (margin) |
|
669 |
*margin = mar; |
|
670 |
if (spacing) |
|
671 |
*spacing = spac; |
|
672 |
} |
|
673 |
||
674 |
/*! |
|
675 |
\internal |
|
676 |
*/ |
|
677 |
QLayout *QAbstractFormBuilder::create(DomLayout *ui_layout, QLayout *parentLayout, QWidget *parentWidget) |
|
678 |
{ |
|
679 |
QObject *p = parentLayout; |
|
680 |
||
681 |
if (p == 0) |
|
682 |
p = parentWidget; |
|
683 |
||
684 |
Q_ASSERT(p != 0); |
|
685 |
||
686 |
bool tracking = false; |
|
687 |
||
688 |
if (p == parentWidget && parentWidget->layout()) { |
|
689 |
tracking = true; |
|
690 |
p = parentWidget->layout(); |
|
691 |
} |
|
692 |
||
693 |
QLayout *layout = createLayout(ui_layout->attributeClass(), p, ui_layout->hasAttributeName() ? ui_layout->attributeName() : QString()); |
|
694 |
||
695 |
if (layout == 0) |
|
696 |
return 0; |
|
697 |
||
698 |
if (tracking && layout->parent() == 0) { |
|
699 |
QBoxLayout *box = qobject_cast<QBoxLayout*>(parentWidget->layout()); |
|
700 |
if (!box) { // only QBoxLayout is supported |
|
701 |
const QString widgetClass = QString::fromUtf8(parentWidget->metaObject()->className()); |
|
702 |
const QString layoutClass = QString::fromUtf8(parentWidget->layout()->metaObject()->className()); |
|
703 |
const QString msg = QCoreApplication::translate("QAbstractFormBuilder", "Attempt to add a layout to a widget '%1' (%2) which already has a layout of non-box type %3.\n" |
|
704 |
"This indicates an inconsistency in the ui-file."). |
|
705 |
arg(parentWidget->objectName(), widgetClass, layoutClass); |
|
706 |
uiLibWarning(msg); |
|
707 |
return 0; |
|
708 |
} |
|
709 |
box->addLayout(layout); |
|
710 |
} |
|
711 |
||
712 |
int margin = INT_MIN, spacing = INT_MIN; |
|
713 |
layoutInfo(ui_layout, p, &margin, &spacing); |
|
714 |
||
715 |
if (margin != INT_MIN) { |
|
716 |
layout->setMargin(margin); |
|
717 |
} else { |
|
718 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
719 |
int left, top, right, bottom; |
|
720 |
left = top = right = bottom = -1; |
|
721 |
layout->getContentsMargins(&left, &top, &right, &bottom); |
|
722 |
||
723 |
const DomPropertyHash properties = propertyMap(ui_layout->elementProperty()); |
|
724 |
||
725 |
if (const DomProperty *p = properties.value(strings.leftMarginProperty, 0)) |
|
726 |
left = p->elementNumber(); |
|
727 |
||
728 |
if (const DomProperty *p = properties.value(strings.topMarginProperty, 0)) |
|
729 |
top = p->elementNumber(); |
|
730 |
||
731 |
if (const DomProperty *p = properties.value(strings.rightMarginProperty, 0)) |
|
732 |
right = p->elementNumber(); |
|
733 |
||
734 |
if (const DomProperty *p = properties.value(strings.bottomMarginProperty, 0)) |
|
735 |
bottom = p->elementNumber(); |
|
736 |
||
737 |
layout->setContentsMargins(left, top, right, bottom); |
|
738 |
} |
|
739 |
||
740 |
if (spacing != INT_MIN) { |
|
741 |
layout->setSpacing(spacing); |
|
742 |
} else { |
|
743 |
QGridLayout *grid = qobject_cast<QGridLayout *>(layout); |
|
744 |
if (grid) { |
|
745 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
746 |
const DomPropertyHash properties = propertyMap(ui_layout->elementProperty()); |
|
747 |
||
748 |
if (const DomProperty *p = properties.value(strings.horizontalSpacingProperty, 0)) |
|
749 |
grid->setHorizontalSpacing(p->elementNumber()); |
|
750 |
if (const DomProperty *p = properties.value(strings.verticalSpacingProperty, 0)) |
|
751 |
grid->setVerticalSpacing(p->elementNumber()); |
|
752 |
} |
|
753 |
} |
|
754 |
||
755 |
applyProperties(layout, ui_layout->elementProperty()); |
|
756 |
||
757 |
foreach (DomLayoutItem *ui_item, ui_layout->elementItem()) { |
|
758 |
if (QLayoutItem *item = create(ui_item, layout, parentWidget)) { |
|
759 |
addItem(ui_item, item, layout); |
|
760 |
} |
|
761 |
} |
|
762 |
// Check the box stretch attributes |
|
763 |
if (QBoxLayout *box = qobject_cast<QBoxLayout*>(layout)) { |
|
764 |
const QString boxStretch = ui_layout->attributeStretch(); |
|
765 |
if (!boxStretch.isEmpty()) |
|
766 |
QFormBuilderExtra::setBoxLayoutStretch(boxStretch, box); |
|
767 |
} |
|
768 |
// Check the grid stretch/minimum size attributes |
|
769 |
if (QGridLayout *grid = qobject_cast<QGridLayout*>(layout)) { |
|
770 |
// Stretch |
|
771 |
const QString gridRowStretch = ui_layout->attributeRowStretch(); |
|
772 |
if (!gridRowStretch.isEmpty()) |
|
773 |
QFormBuilderExtra::setGridLayoutRowStretch(gridRowStretch, grid); |
|
774 |
const QString gridColumnStretch = ui_layout->attributeColumnStretch(); |
|
775 |
if (!gridColumnStretch.isEmpty()) |
|
776 |
QFormBuilderExtra::setGridLayoutColumnStretch(gridColumnStretch, grid); |
|
777 |
// Minimum size |
|
778 |
const QString gridColumnMinimumWidth = ui_layout->attributeColumnMinimumWidth(); |
|
779 |
if (!gridColumnMinimumWidth.isEmpty()) |
|
780 |
QFormBuilderExtra::setGridLayoutColumnMinimumWidth(gridColumnMinimumWidth, grid); |
|
781 |
const QString gridRowMinimumHeight = ui_layout->attributeRowMinimumHeight(); |
|
782 |
if (!gridRowMinimumHeight.isEmpty()) |
|
783 |
QFormBuilderExtra::setGridLayoutRowMinimumHeight(gridRowMinimumHeight, grid); |
|
784 |
} |
|
785 |
return layout; |
|
786 |
} |
|
787 |
||
788 |
#ifndef QT_NO_FORMLAYOUT |
|
789 |
static inline QFormLayout::ItemRole formLayoutRole(int column, int colspan) |
|
790 |
{ |
|
791 |
if (colspan > 1) |
|
792 |
return QFormLayout::SpanningRole; |
|
793 |
return column == 0 ? QFormLayout::LabelRole : QFormLayout::FieldRole; |
|
794 |
} |
|
795 |
#endif |
|
796 |
||
797 |
/*! |
|
798 |
\internal |
|
799 |
*/ |
|
800 |
bool QAbstractFormBuilder::addItem(DomLayoutItem *ui_item, QLayoutItem *item, QLayout *layout) |
|
801 |
{ |
|
802 |
// Calling addChildWidget(), etc. is required to maintain consistency of the layouts, |
|
803 |
// see documentation of addItem(), which should ideally not be used. |
|
804 |
if (item->widget()) { |
|
805 |
static_cast<QFriendlyLayout*>(layout)->addChildWidget(item->widget()); |
|
806 |
} else if (item->layout()) { |
|
807 |
static_cast<QFriendlyLayout*>(layout)->addChildLayout(item->layout()); |
|
808 |
} else if (item->spacerItem()) { |
|
809 |
// nothing to do |
|
810 |
} else { |
|
811 |
return false; |
|
812 |
} |
|
813 |
||
814 |
if (QGridLayout *grid = qobject_cast<QGridLayout*>(layout)) { |
|
815 |
const int rowSpan = ui_item->hasAttributeRowSpan() ? ui_item->attributeRowSpan() : 1; |
|
816 |
const int colSpan = ui_item->hasAttributeColSpan() ? ui_item->attributeColSpan() : 1; |
|
817 |
grid->addItem(item, ui_item->attributeRow(), ui_item->attributeColumn(), |
|
818 |
rowSpan, colSpan, item->alignment()); |
|
819 |
return true; |
|
820 |
} |
|
821 |
#ifndef QT_NO_FORMLAYOUT |
|
822 |
if (QFormLayout *form = qobject_cast<QFormLayout *>(layout)) { |
|
823 |
const int row = ui_item->attributeRow(); |
|
824 |
const int colSpan = ui_item->hasAttributeColSpan() ? ui_item->attributeColSpan() : 1; |
|
825 |
form->setItem(row, formLayoutRole(ui_item->attributeColumn(), colSpan), item); |
|
826 |
return true; |
|
827 |
} |
|
828 |
||
829 |
#endif |
|
830 |
layout->addItem(item); |
|
831 |
return true; |
|
832 |
} |
|
833 |
||
834 |
/*! |
|
835 |
\internal |
|
836 |
*/ |
|
837 |
QLayoutItem *QAbstractFormBuilder::create(DomLayoutItem *ui_layoutItem, QLayout *layout, QWidget *parentWidget) |
|
838 |
{ |
|
839 |
switch (ui_layoutItem->kind()) { |
|
840 |
case DomLayoutItem::Widget: { |
|
841 |
if (QWidget *w = create(ui_layoutItem->elementWidget(), parentWidget)) |
|
842 |
#ifdef QFORMINTERNAL_NAMESPACE // uilib |
|
843 |
return new QWidgetItemV2(w); |
|
844 |
#else // Within Designer: Use factory method that returns special items that refuse to shrink to 0,0 |
|
845 |
return QLayoutPrivate::createWidgetItem(layout, w); |
|
846 |
#endif |
|
847 |
qWarning() << QCoreApplication::translate("QAbstractFormBuilder", "Empty widget item in %1 '%2'.").arg(QString::fromUtf8(layout->metaObject()->className()), layout->objectName()); |
|
848 |
return 0; |
|
849 |
} |
|
850 |
case DomLayoutItem::Spacer: { |
|
851 |
QSize size(0, 0); |
|
852 |
QSizePolicy::Policy sizeType = QSizePolicy::Expanding; |
|
853 |
bool isVspacer = false; |
|
854 |
||
855 |
const DomSpacer *ui_spacer = ui_layoutItem->elementSpacer(); |
|
856 |
||
857 |
const QMetaEnum sizePolicy_enum = metaEnum<QAbstractFormBuilderGadget>("sizeType"); |
|
858 |
const QMetaEnum orientation_enum = metaEnum<QAbstractFormBuilderGadget>("orientation"); |
|
859 |
||
860 |
const QList<DomProperty *> spacerProperties = ui_spacer->elementProperty(); |
|
861 |
if (!spacerProperties.empty()) { |
|
862 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
863 |
foreach (DomProperty *p, spacerProperties) { |
|
864 |
const QVariant v = toVariant(&QAbstractFormBuilderGadget::staticMetaObject, p); // ### remove me |
|
865 |
if (v.isNull()) |
|
866 |
continue; |
|
867 |
if (p->attributeName() == strings.sizeHintProperty && p->kind() == DomProperty::Size) { |
|
868 |
size = v.toSize(); // ### remove me |
|
869 |
} else if (p->attributeName() == strings.sizeTypeProperty && p->kind() == DomProperty::Enum) { |
|
870 |
sizeType = static_cast<QSizePolicy::Policy>(v.toInt()); |
|
871 |
} else if (p->attributeName() == strings.orientationProperty && p->kind() == DomProperty::Enum) { |
|
872 |
const Qt::Orientation o = static_cast<Qt::Orientation>(v.toInt()); |
|
873 |
isVspacer = (o == Qt::Vertical); |
|
874 |
} |
|
875 |
} |
|
876 |
} |
|
877 |
||
878 |
QSpacerItem *spacer = 0; |
|
879 |
if (isVspacer) |
|
880 |
spacer = new QSpacerItem(size.width(), size.height(), QSizePolicy::Minimum, sizeType); |
|
881 |
else |
|
882 |
spacer = new QSpacerItem(size.width(), size.height(), sizeType, QSizePolicy::Minimum); |
|
883 |
return spacer; } |
|
884 |
||
885 |
case DomLayoutItem::Layout: |
|
886 |
return create(ui_layoutItem->elementLayout(), layout, parentWidget); |
|
887 |
||
888 |
default: |
|
889 |
break; |
|
890 |
} |
|
891 |
||
892 |
return 0; |
|
893 |
} |
|
894 |
||
895 |
/*! |
|
896 |
\internal |
|
897 |
*/ |
|
898 |
void QAbstractFormBuilder::applyProperties(QObject *o, const QList<DomProperty*> &properties) |
|
899 |
{ |
|
900 |
typedef QList<DomProperty*> DomPropertyList; |
|
901 |
||
902 |
if (properties.empty()) |
|
903 |
return; |
|
904 |
||
905 |
QFormBuilderExtra *fb = QFormBuilderExtra::instance(this); |
|
906 |
||
907 |
const DomPropertyList::const_iterator cend = properties.constEnd(); |
|
908 |
for (DomPropertyList::const_iterator it = properties.constBegin(); it != cend; ++it) { |
|
909 |
const QVariant v = toVariant(o->metaObject(), *it); |
|
910 |
if (!v.isNull()) { |
|
911 |
const QString attributeName = (*it)->attributeName(); |
|
912 |
if (!fb->applyPropertyInternally(o, attributeName, v)) |
|
913 |
o->setProperty(attributeName.toUtf8(), v); |
|
914 |
} |
|
915 |
} |
|
916 |
} |
|
917 |
||
918 |
||
919 |
/*! |
|
920 |
\internal |
|
921 |
Check whether a property is applied internally by QAbstractFormBuilder. Call this |
|
922 |
from overwritten applyProperties(). |
|
923 |
*/ |
|
924 |
||
925 |
bool QAbstractFormBuilder::applyPropertyInternally(QObject *o, const QString &propertyName, const QVariant &value) |
|
926 |
{ |
|
927 |
return QFormBuilderExtra::instance(this)->applyPropertyInternally(o,propertyName, value); |
|
928 |
} |
|
929 |
||
930 |
/*! |
|
931 |
\internal |
|
932 |
*/ |
|
933 |
||
934 |
QVariant QAbstractFormBuilder::toVariant(const QMetaObject *meta, DomProperty *p) |
|
935 |
{ |
|
936 |
return domPropertyToVariant(this, meta, p); |
|
937 |
} |
|
938 |
||
939 |
/*! |
|
940 |
\internal |
|
941 |
*/ |
|
942 |
void QAbstractFormBuilder::setupColorGroup(QPalette &palette, QPalette::ColorGroup colorGroup, |
|
943 |
DomColorGroup *group) |
|
944 |
{ |
|
945 |
// old format |
|
946 |
const QList<DomColor*> colors = group->elementColor(); |
|
947 |
for (int role = 0; role < colors.size(); ++role) { |
|
948 |
const DomColor *color = colors.at(role); |
|
949 |
const QColor c(color->elementRed(), color->elementGreen(), color->elementBlue()); |
|
950 |
palette.setColor(colorGroup, QPalette::ColorRole(role), c); |
|
951 |
} |
|
952 |
||
953 |
// new format |
|
954 |
const QMetaEnum colorRole_enum = metaEnum<QAbstractFormBuilderGadget>("colorRole"); |
|
955 |
||
956 |
const QList<DomColorRole*> colorRoles = group->elementColorRole(); |
|
957 |
for (int role = 0; role < colorRoles.size(); ++role) { |
|
958 |
const DomColorRole *colorRole = colorRoles.at(role); |
|
959 |
||
960 |
if (colorRole->hasAttributeRole()) { |
|
961 |
const int r = colorRole_enum.keyToValue(colorRole->attributeRole().toLatin1()); |
|
962 |
if (r != -1) { |
|
963 |
const QBrush br = setupBrush(colorRole->elementBrush()); |
|
964 |
palette.setBrush(colorGroup, static_cast<QPalette::ColorRole>(r), br); |
|
965 |
} |
|
966 |
} |
|
967 |
} |
|
968 |
} |
|
969 |
||
970 |
/*! |
|
971 |
\internal |
|
972 |
*/ |
|
973 |
DomColorGroup *QAbstractFormBuilder::saveColorGroup(const QPalette &palette) |
|
974 |
{ |
|
975 |
||
976 |
const QMetaEnum colorRole_enum = metaEnum<QAbstractFormBuilderGadget>("colorRole"); |
|
977 |
||
978 |
DomColorGroup *group = new DomColorGroup(); |
|
979 |
QList<DomColorRole*> colorRoles; |
|
980 |
||
981 |
const uint mask = palette.resolve(); |
|
982 |
for (int role = QPalette::WindowText; role < QPalette::NColorRoles; ++role) { |
|
983 |
if (mask & (1 << role)) { |
|
984 |
QBrush br = palette.brush(QPalette::ColorRole(role)); |
|
985 |
||
986 |
DomColorRole *colorRole = new DomColorRole(); |
|
987 |
colorRole->setElementBrush(saveBrush(br)); |
|
988 |
colorRole->setAttributeRole(QLatin1String(colorRole_enum.valueToKey(role))); |
|
989 |
colorRoles.append(colorRole); |
|
990 |
} |
|
991 |
} |
|
992 |
||
993 |
group->setElementColorRole(colorRoles); |
|
994 |
return group; |
|
995 |
} |
|
996 |
||
997 |
/*! |
|
998 |
\internal |
|
999 |
*/ |
|
1000 |
QBrush QAbstractFormBuilder::setupBrush(DomBrush *brush) |
|
1001 |
{ |
|
1002 |
QBrush br; |
|
1003 |
if (!brush->hasAttributeBrushStyle()) |
|
1004 |
return br; |
|
1005 |
||
1006 |
const Qt::BrushStyle style = enumKeyOfObjectToValue<QAbstractFormBuilderGadget, Qt::BrushStyle>("brushStyle", brush->attributeBrushStyle().toLatin1()); |
|
1007 |
||
1008 |
if (style == Qt::LinearGradientPattern || |
|
1009 |
style == Qt::RadialGradientPattern || |
|
1010 |
style == Qt::ConicalGradientPattern) { |
|
1011 |
const QMetaEnum gradientType_enum = metaEnum<QAbstractFormBuilderGadget>("gradientType"); |
|
1012 |
const QMetaEnum gradientSpread_enum = metaEnum<QAbstractFormBuilderGadget>("gradientSpread"); |
|
1013 |
const QMetaEnum gradientCoordinate_enum = metaEnum<QAbstractFormBuilderGadget>("gradientCoordinate"); |
|
1014 |
||
1015 |
const DomGradient *gradient = brush->elementGradient(); |
|
1016 |
const QGradient::Type type = enumKeyToValue<QGradient::Type>(gradientType_enum, gradient->attributeType().toLatin1()); |
|
1017 |
||
1018 |
||
1019 |
QGradient *gr = 0; |
|
1020 |
||
1021 |
if (type == QGradient::LinearGradient) { |
|
1022 |
gr = new QLinearGradient(QPointF(gradient->attributeStartX(), gradient->attributeStartY()), |
|
1023 |
QPointF(gradient->attributeEndX(), gradient->attributeEndY())); |
|
1024 |
} else if (type == QGradient::RadialGradient) { |
|
1025 |
gr = new QRadialGradient(QPointF(gradient->attributeCentralX(), gradient->attributeCentralY()), |
|
1026 |
gradient->attributeRadius(), |
|
1027 |
QPointF(gradient->attributeFocalX(), gradient->attributeFocalY())); |
|
1028 |
} else if (type == QGradient::ConicalGradient) { |
|
1029 |
gr = new QConicalGradient(QPointF(gradient->attributeCentralX(), gradient->attributeCentralY()), |
|
1030 |
gradient->attributeAngle()); |
|
1031 |
} |
|
1032 |
if (!gr) |
|
1033 |
return br; |
|
1034 |
||
1035 |
const QGradient::Spread spread = enumKeyToValue<QGradient::Spread>(gradientSpread_enum, gradient->attributeSpread().toLatin1()); |
|
1036 |
gr->setSpread(spread); |
|
1037 |
||
1038 |
const QGradient::CoordinateMode coord = enumKeyToValue<QGradient::CoordinateMode>(gradientCoordinate_enum, gradient->attributeCoordinateMode().toLatin1()); |
|
1039 |
gr->setCoordinateMode(coord); |
|
1040 |
||
1041 |
const QList<DomGradientStop *> stops = gradient->elementGradientStop(); |
|
1042 |
QListIterator<DomGradientStop *> it(stops); |
|
1043 |
while (it.hasNext()) { |
|
1044 |
const DomGradientStop *stop = it.next(); |
|
1045 |
const DomColor *color = stop->elementColor(); |
|
1046 |
gr->setColorAt(stop->attributePosition(), QColor::fromRgb(color->elementRed(), |
|
1047 |
color->elementGreen(), color->elementBlue(), color->attributeAlpha())); |
|
1048 |
} |
|
1049 |
br = QBrush(*gr); |
|
1050 |
delete gr; |
|
1051 |
} else if (style == Qt::TexturePattern) { |
|
1052 |
const DomProperty *texture = brush->elementTexture(); |
|
1053 |
if (texture && texture->kind() == DomProperty::Pixmap) { |
|
1054 |
br.setTexture(domPropertyToPixmap(texture)); |
|
1055 |
} |
|
1056 |
} else { |
|
1057 |
const DomColor *color = brush->elementColor(); |
|
1058 |
br.setColor(QColor::fromRgb(color->elementRed(), |
|
1059 |
color->elementGreen(), color->elementBlue(), color->attributeAlpha())); |
|
1060 |
br.setStyle((Qt::BrushStyle)style); |
|
1061 |
} |
|
1062 |
return br; |
|
1063 |
} |
|
1064 |
||
1065 |
/*! |
|
1066 |
\internal |
|
1067 |
*/ |
|
1068 |
DomBrush *QAbstractFormBuilder::saveBrush(const QBrush &br) |
|
1069 |
{ |
|
1070 |
const QMetaEnum brushStyle_enum = metaEnum<QAbstractFormBuilderGadget>("brushStyle"); |
|
1071 |
||
1072 |
DomBrush *brush = new DomBrush(); |
|
1073 |
const Qt::BrushStyle style = br.style(); |
|
1074 |
brush->setAttributeBrushStyle(QLatin1String(brushStyle_enum.valueToKey(style))); |
|
1075 |
if (style == Qt::LinearGradientPattern || |
|
1076 |
style == Qt::RadialGradientPattern || |
|
1077 |
style == Qt::ConicalGradientPattern) { |
|
1078 |
const QMetaEnum gradientType_enum = metaEnum<QAbstractFormBuilderGadget>("gradientType"); |
|
1079 |
const QMetaEnum gradientSpread_enum = metaEnum<QAbstractFormBuilderGadget>("gradientSpread"); |
|
1080 |
const QMetaEnum gradientCoordinate_enum = metaEnum<QAbstractFormBuilderGadget>("gradientCoordinate"); |
|
1081 |
||
1082 |
DomGradient *gradient = new DomGradient(); |
|
1083 |
const QGradient *gr = br.gradient(); |
|
1084 |
const QGradient::Type type = gr->type(); |
|
1085 |
gradient->setAttributeType(QLatin1String(gradientType_enum.valueToKey(type))); |
|
1086 |
gradient->setAttributeSpread(QLatin1String(gradientSpread_enum.valueToKey(gr->spread()))); |
|
1087 |
gradient->setAttributeCoordinateMode(QLatin1String(gradientCoordinate_enum.valueToKey(gr->coordinateMode()))); |
|
1088 |
QList<DomGradientStop *> stops; |
|
1089 |
QGradientStops st = gr->stops(); |
|
1090 |
QVectorIterator<QPair<qreal, QColor> > it(st); |
|
1091 |
while (it.hasNext()) { |
|
1092 |
const QPair<qreal, QColor> pair = it.next(); |
|
1093 |
DomGradientStop *stop = new DomGradientStop(); |
|
1094 |
stop->setAttributePosition(pair.first); |
|
1095 |
DomColor *color = new DomColor(); |
|
1096 |
color->setElementRed(pair.second.red()); |
|
1097 |
color->setElementGreen(pair.second.green()); |
|
1098 |
color->setElementBlue(pair.second.blue()); |
|
1099 |
color->setAttributeAlpha(pair.second.alpha()); |
|
1100 |
stop->setElementColor(color); |
|
1101 |
stops.append(stop); |
|
1102 |
} |
|
1103 |
gradient->setElementGradientStop(stops); |
|
1104 |
if (type == QGradient::LinearGradient) { |
|
1105 |
QLinearGradient *lgr = (QLinearGradient *)(gr); |
|
1106 |
gradient->setAttributeStartX(lgr->start().x()); |
|
1107 |
gradient->setAttributeStartY(lgr->start().y()); |
|
1108 |
gradient->setAttributeEndX(lgr->finalStop().x()); |
|
1109 |
gradient->setAttributeEndY(lgr->finalStop().y()); |
|
1110 |
} else if (type == QGradient::RadialGradient) { |
|
1111 |
QRadialGradient *rgr = (QRadialGradient *)(gr); |
|
1112 |
gradient->setAttributeCentralX(rgr->center().x()); |
|
1113 |
gradient->setAttributeCentralY(rgr->center().y()); |
|
1114 |
gradient->setAttributeFocalX(rgr->focalPoint().x()); |
|
1115 |
gradient->setAttributeFocalY(rgr->focalPoint().y()); |
|
1116 |
gradient->setAttributeRadius(rgr->radius()); |
|
1117 |
} else if (type == QGradient::ConicalGradient) { |
|
1118 |
QConicalGradient *cgr = (QConicalGradient *)(gr); |
|
1119 |
gradient->setAttributeCentralX(cgr->center().x()); |
|
1120 |
gradient->setAttributeCentralY(cgr->center().y()); |
|
1121 |
gradient->setAttributeAngle(cgr->angle()); |
|
1122 |
} |
|
1123 |
||
1124 |
brush->setElementGradient(gradient); |
|
1125 |
} else if (style == Qt::TexturePattern) { |
|
1126 |
const QPixmap pixmap = br.texture(); |
|
1127 |
if (!pixmap.isNull()) { |
|
1128 |
DomProperty *p = new DomProperty; |
|
1129 |
setPixmapProperty(*p, pixmapPaths(pixmap)); |
|
1130 |
brush->setElementTexture(p); |
|
1131 |
} |
|
1132 |
} else { |
|
1133 |
QColor c = br.color(); |
|
1134 |
DomColor *color = new DomColor(); |
|
1135 |
color->setElementRed(c.red()); |
|
1136 |
color->setElementGreen(c.green()); |
|
1137 |
color->setElementBlue(c.blue()); |
|
1138 |
color->setAttributeAlpha(c.alpha()); |
|
1139 |
brush->setElementColor(color); |
|
1140 |
} |
|
1141 |
return brush; |
|
1142 |
} |
|
1143 |
||
1144 |
/*! |
|
1145 |
\internal |
|
1146 |
*/ |
|
1147 |
QWidget *QAbstractFormBuilder::createWidget(const QString &widgetName, QWidget *parentWidget, const QString &name) |
|
1148 |
{ |
|
1149 |
Q_UNUSED(widgetName); |
|
1150 |
Q_UNUSED(parentWidget); |
|
1151 |
Q_UNUSED(name); |
|
1152 |
return 0; |
|
1153 |
} |
|
1154 |
||
1155 |
/*! |
|
1156 |
\internal |
|
1157 |
*/ |
|
1158 |
QLayout *QAbstractFormBuilder::createLayout(const QString &layoutName, QObject *parent, const QString &name) |
|
1159 |
{ |
|
1160 |
Q_UNUSED(layoutName); |
|
1161 |
Q_UNUSED(parent); |
|
1162 |
Q_UNUSED(name); |
|
1163 |
return 0; |
|
1164 |
} |
|
1165 |
||
1166 |
/*! |
|
1167 |
\internal |
|
1168 |
*/ |
|
1169 |
QAction *QAbstractFormBuilder::createAction(QObject *parent, const QString &name) |
|
1170 |
{ |
|
1171 |
QAction *action = new QAction(parent); |
|
1172 |
action->setObjectName(name); |
|
1173 |
return action; |
|
1174 |
} |
|
1175 |
||
1176 |
/*! |
|
1177 |
\internal |
|
1178 |
*/ |
|
1179 |
QActionGroup *QAbstractFormBuilder::createActionGroup(QObject *parent, const QString &name) |
|
1180 |
{ |
|
1181 |
QActionGroup *g = new QActionGroup(parent); |
|
1182 |
g->setObjectName(name); |
|
1183 |
return g; |
|
1184 |
} |
|
1185 |
||
1186 |
/*! |
|
1187 |
\fn void QAbstractFormBuilder::save(QIODevice *device, QWidget *widget) |
|
1188 |
||
1189 |
Saves an XML representation of the given \a widget to the |
|
1190 |
specified \a device in the standard UI file format. |
|
1191 |
||
1192 |
\sa load()*/ |
|
1193 |
void QAbstractFormBuilder::save(QIODevice *dev, QWidget *widget) |
|
1194 |
{ |
|
1195 |
DomWidget *ui_widget = createDom(widget, 0); |
|
1196 |
Q_ASSERT( ui_widget != 0 ); |
|
1197 |
||
1198 |
DomUI *ui = new DomUI(); |
|
1199 |
ui->setAttributeVersion(QLatin1String("4.0")); |
|
1200 |
ui->setElementWidget(ui_widget); |
|
1201 |
||
1202 |
saveDom(ui, widget); |
|
1203 |
||
1204 |
QXmlStreamWriter writer(dev); |
|
1205 |
writer.setAutoFormatting(true); |
|
1206 |
writer.setAutoFormattingIndent(1); |
|
1207 |
writer.writeStartDocument(); |
|
1208 |
ui->write(writer); |
|
1209 |
writer.writeEndDocument(); |
|
1210 |
||
1211 |
m_laidout.clear(); |
|
1212 |
||
1213 |
delete ui; |
|
1214 |
} |
|
1215 |
||
1216 |
/*! |
|
1217 |
\internal |
|
1218 |
*/ |
|
1219 |
void QAbstractFormBuilder::saveDom(DomUI *ui, QWidget *widget) |
|
1220 |
{ |
|
1221 |
ui->setElementClass(widget->objectName()); |
|
1222 |
||
1223 |
if (DomConnections *ui_connections = saveConnections()) { |
|
1224 |
ui->setElementConnections(ui_connections); |
|
1225 |
} |
|
1226 |
||
1227 |
if (DomCustomWidgets *ui_customWidgets = saveCustomWidgets()) { |
|
1228 |
ui->setElementCustomWidgets(ui_customWidgets); |
|
1229 |
} |
|
1230 |
||
1231 |
if (DomTabStops *ui_tabStops = saveTabStops()) { |
|
1232 |
ui->setElementTabStops(ui_tabStops); |
|
1233 |
} |
|
1234 |
||
1235 |
if (DomResources *ui_resources = saveResources()) { |
|
1236 |
ui->setElementResources(ui_resources); |
|
1237 |
} |
|
1238 |
if (DomButtonGroups *ui_buttonGroups = saveButtonGroups(widget)) |
|
1239 |
ui->setElementButtonGroups(ui_buttonGroups); |
|
1240 |
} |
|
1241 |
||
1242 |
/*! |
|
1243 |
\internal |
|
1244 |
*/ |
|
1245 |
DomConnections *QAbstractFormBuilder::saveConnections() |
|
1246 |
{ |
|
1247 |
return new DomConnections; |
|
1248 |
} |
|
1249 |
||
1250 |
/*! |
|
1251 |
\internal |
|
1252 |
*/ |
|
1253 |
||
1254 |
DomWidget *QAbstractFormBuilder::createDom(QWidget *widget, DomWidget *ui_parentWidget, bool recursive) |
|
1255 |
{ |
|
1256 |
DomWidget *ui_widget = new DomWidget(); |
|
1257 |
ui_widget->setAttributeClass(QLatin1String(widget->metaObject()->className())); |
|
1258 |
ui_widget->setElementProperty(computeProperties(widget)); |
|
1259 |
||
1260 |
if (recursive) { |
|
1261 |
if (QLayout *layout = widget->layout()) { |
|
1262 |
if (DomLayout *ui_layout = createDom(layout, 0, ui_parentWidget)) { |
|
1263 |
QList<DomLayout*> ui_layouts; |
|
1264 |
ui_layouts.append(ui_layout); |
|
1265 |
||
1266 |
ui_widget->setElementLayout(ui_layouts); |
|
1267 |
} |
|
1268 |
} |
|
1269 |
} |
|
1270 |
||
1271 |
// widgets, actions and action groups |
|
1272 |
QList<DomWidget*> ui_widgets; |
|
1273 |
QList<DomAction*> ui_actions; |
|
1274 |
QList<DomActionGroup*> ui_action_groups; |
|
1275 |
||
1276 |
QList<QObject*> children; |
|
1277 |
||
1278 |
// splitters need to store their children in the order specified by child indexes, |
|
1279 |
// not the order of the child list. |
|
1280 |
#ifndef QT_NO_SPLITTER |
|
1281 |
if (const QSplitter *splitter = qobject_cast<const QSplitter*>(widget)) { |
|
1282 |
const int count = splitter->count(); |
|
1283 |
for (int i = 0; i < count; ++i) |
|
1284 |
children.append(splitter->widget(i)); |
|
1285 |
} else |
|
1286 |
#endif |
|
1287 |
{ |
|
1288 |
QList<QObject *> childObjects = widget->children(); |
|
1289 |
||
1290 |
const QList<QWidget *> list = qVariantValue<QWidgetList>(widget->property("_q_widgetOrder")); |
|
1291 |
foreach (QWidget *w, list) { |
|
1292 |
if (childObjects.contains(w)) { |
|
1293 |
children.append(w); |
|
1294 |
childObjects.removeAll(w); |
|
1295 |
} |
|
1296 |
} |
|
1297 |
children += childObjects; |
|
1298 |
||
1299 |
const QList<QWidget *> zOrder = qVariantValue<QWidgetList>(widget->property("_q_zOrder")); |
|
1300 |
if (list != zOrder) { |
|
1301 |
QStringList zOrderList; |
|
1302 |
QListIterator<QWidget* > itZOrder(zOrder); |
|
1303 |
while (itZOrder.hasNext()) |
|
1304 |
zOrderList.append(itZOrder.next()->objectName()); |
|
1305 |
ui_widget->setElementZOrder(zOrderList); |
|
1306 |
} |
|
1307 |
} |
|
1308 |
||
1309 |
foreach (QObject *obj, children) { |
|
1310 |
if (QWidget *childWidget = qobject_cast<QWidget*>(obj)) { |
|
1311 |
if (m_laidout.contains(childWidget) || recursive == false) |
|
1312 |
continue; |
|
1313 |
||
1314 |
if (QMenu *menu = qobject_cast<QMenu *>(childWidget)) { |
|
1315 |
QList<QAction *> actions = menu->parentWidget()->actions(); |
|
1316 |
QListIterator<QAction *> it(actions); |
|
1317 |
bool found = false; |
|
1318 |
while (it.hasNext()) { |
|
1319 |
if (it.next()->menu() == menu) |
|
1320 |
found = true; |
|
1321 |
} |
|
1322 |
if (!found) |
|
1323 |
continue; |
|
1324 |
} |
|
1325 |
||
1326 |
if (DomWidget *ui_child = createDom(childWidget, ui_widget)) { |
|
1327 |
ui_widgets.append(ui_child); |
|
1328 |
} |
|
1329 |
} else if (QAction *childAction = qobject_cast<QAction*>(obj)) { |
|
1330 |
if (childAction->actionGroup() != 0) { |
|
1331 |
// it will be added later. |
|
1332 |
continue; |
|
1333 |
} |
|
1334 |
||
1335 |
if (DomAction *ui_action = createDom(childAction)) { |
|
1336 |
ui_actions.append(ui_action); |
|
1337 |
} |
|
1338 |
} else if (QActionGroup *childActionGroup = qobject_cast<QActionGroup*>(obj)) { |
|
1339 |
if (DomActionGroup *ui_action_group = createDom(childActionGroup)) { |
|
1340 |
ui_action_groups.append(ui_action_group); |
|
1341 |
} |
|
1342 |
} |
|
1343 |
} |
|
1344 |
||
1345 |
// add-action |
|
1346 |
QList<DomActionRef*> ui_action_refs; |
|
1347 |
foreach (QAction *action, widget->actions()) { |
|
1348 |
if (DomActionRef *ui_action_ref = createActionRefDom(action)) { |
|
1349 |
ui_action_refs.append(ui_action_ref); |
|
1350 |
} |
|
1351 |
} |
|
1352 |
||
1353 |
if (recursive) |
|
1354 |
ui_widget->setElementWidget(ui_widgets); |
|
1355 |
||
1356 |
ui_widget->setElementAction(ui_actions); |
|
1357 |
ui_widget->setElementActionGroup(ui_action_groups); |
|
1358 |
ui_widget->setElementAddAction(ui_action_refs); |
|
1359 |
||
1360 |
saveExtraInfo(widget, ui_widget, ui_parentWidget); |
|
1361 |
||
1362 |
return ui_widget; |
|
1363 |
} |
|
1364 |
||
1365 |
/*! |
|
1366 |
\internal |
|
1367 |
*/ |
|
1368 |
DomActionRef *QAbstractFormBuilder::createActionRefDom(QAction *action) |
|
1369 |
{ |
|
1370 |
QString name = action->objectName(); |
|
1371 |
||
1372 |
if (action->menu() != 0) |
|
1373 |
name = action->menu()->objectName(); |
|
1374 |
||
1375 |
DomActionRef *ui_action_ref = new DomActionRef(); |
|
1376 |
if (action->isSeparator()) |
|
1377 |
ui_action_ref->setAttributeName(QFormBuilderStrings::instance().separator); |
|
1378 |
else |
|
1379 |
ui_action_ref->setAttributeName(name); |
|
1380 |
||
1381 |
return ui_action_ref; |
|
1382 |
} |
|
1383 |
||
1384 |
/*! |
|
1385 |
\internal |
|
1386 |
*/ |
|
1387 |
DomLayout *QAbstractFormBuilder::createDom(QLayout *layout, DomLayout *ui_layout, DomWidget *ui_parentWidget) |
|
1388 |
{ |
|
1389 |
Q_UNUSED(ui_layout) |
|
1390 |
DomLayout *lay = new DomLayout(); |
|
1391 |
lay->setAttributeClass(QLatin1String(layout->metaObject()->className())); |
|
1392 |
const QString objectName = layout->objectName(); |
|
1393 |
if (!objectName.isEmpty()) |
|
1394 |
lay->setAttributeName(objectName); |
|
1395 |
lay->setElementProperty(computeProperties(layout)); |
|
1396 |
||
1397 |
QList<DomLayoutItem*> ui_items; |
|
1398 |
||
1399 |
QMap<QObject *, QLayoutItem *> objectToItem; |
|
1400 |
QList<QLayoutItem *> spacerItems; |
|
1401 |
QList<QLayoutItem *> newList; |
|
1402 |
||
1403 |
for (int idx=0; layout->itemAt(idx); ++idx) { |
|
1404 |
QLayoutItem *item = layout->itemAt(idx); |
|
1405 |
if (item->widget()) |
|
1406 |
objectToItem[item->widget()] = item; |
|
1407 |
else if (item->layout()) |
|
1408 |
objectToItem[item->layout()] = item; |
|
1409 |
else if (item->spacerItem()) |
|
1410 |
spacerItems.append(item); |
|
1411 |
newList.append(item); |
|
1412 |
} |
|
1413 |
||
1414 |
if (qobject_cast<QGridLayout *>(layout)) { |
|
1415 |
newList.clear(); |
|
1416 |
QList<QObject *> childrenList = layout->parentWidget()->children(); |
|
1417 |
foreach (QObject *o, childrenList) { |
|
1418 |
if (objectToItem.contains(o)) |
|
1419 |
newList.append(objectToItem[o]); |
|
1420 |
} |
|
1421 |
newList += spacerItems; |
|
1422 |
} |
|
1423 |
||
1424 |
foreach (QLayoutItem *item, newList) { |
|
1425 |
DomLayoutItem *ui_item = createDom(item, lay, ui_parentWidget); |
|
1426 |
if (ui_item) |
|
1427 |
ui_items.append(ui_item); |
|
1428 |
} |
|
1429 |
||
1430 |
lay->setElementItem(ui_items); |
|
1431 |
||
1432 |
return lay; |
|
1433 |
} |
|
1434 |
||
1435 |
/*! |
|
1436 |
\internal |
|
1437 |
*/ |
|
1438 |
DomLayoutItem *QAbstractFormBuilder::createDom(QLayoutItem *item, DomLayout *ui_layout, DomWidget *ui_parentWidget) |
|
1439 |
{ |
|
1440 |
DomLayoutItem *ui_item = new DomLayoutItem(); |
|
1441 |
||
1442 |
if (item->widget()) { |
|
1443 |
ui_item->setElementWidget(createDom(item->widget(), ui_parentWidget)); |
|
1444 |
m_laidout.insert(item->widget(), true); |
|
1445 |
} else if (item->layout()) { |
|
1446 |
ui_item->setElementLayout(createDom(item->layout(), ui_layout, ui_parentWidget)); |
|
1447 |
} else if (item->spacerItem()) { |
|
1448 |
ui_item->setElementSpacer(createDom(item->spacerItem(), ui_layout, ui_parentWidget)); |
|
1449 |
} |
|
1450 |
||
1451 |
return ui_item; |
|
1452 |
} |
|
1453 |
||
1454 |
/*! |
|
1455 |
\internal |
|
1456 |
*/ |
|
1457 |
DomSpacer *QAbstractFormBuilder::createDom(QSpacerItem *spacer, DomLayout *ui_layout, DomWidget *ui_parentWidget) |
|
1458 |
{ |
|
1459 |
Q_UNUSED(ui_layout); |
|
1460 |
Q_UNUSED(ui_parentWidget); |
|
1461 |
||
1462 |
DomSpacer *ui_spacer = new DomSpacer(); |
|
1463 |
QList<DomProperty*> properties; |
|
1464 |
||
1465 |
DomProperty *prop = 0; |
|
1466 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1467 |
// sizeHint property |
|
1468 |
prop = new DomProperty(); |
|
1469 |
prop->setAttributeName(strings.sizeHintProperty); |
|
1470 |
prop->setElementSize(new DomSize()); |
|
1471 |
prop->elementSize()->setElementWidth(spacer->sizeHint().width()); |
|
1472 |
prop->elementSize()->setElementHeight(spacer->sizeHint().height()); |
|
1473 |
properties.append(prop); |
|
1474 |
||
1475 |
// orientation property |
|
1476 |
prop = new DomProperty(); // ### we don't implemented the case where expandingDirections() is both Vertical and Horizontal |
|
1477 |
prop->setAttributeName(strings.orientationProperty); |
|
1478 |
prop->setElementEnum((spacer->expandingDirections() & Qt::Horizontal) ? strings.qtHorizontal : strings.qtVertical); |
|
1479 |
properties.append(prop); |
|
1480 |
||
1481 |
ui_spacer->setElementProperty(properties); |
|
1482 |
return ui_spacer; |
|
1483 |
} |
|
1484 |
||
1485 |
/*! |
|
1486 |
\internal |
|
1487 |
*/ |
|
1488 |
DomProperty *QAbstractFormBuilder::createProperty(QObject *obj, const QString &pname, const QVariant &v) |
|
1489 |
{ |
|
1490 |
if (!checkProperty(obj, pname)) { |
|
1491 |
return 0; |
|
1492 |
} |
|
1493 |
return variantToDomProperty(this, obj->metaObject(), pname, v); |
|
1494 |
} |
|
1495 |
||
1496 |
/*! |
|
1497 |
\internal |
|
1498 |
*/ |
|
1499 |
QList<DomProperty*> QAbstractFormBuilder::computeProperties(QObject *obj) |
|
1500 |
{ |
|
1501 |
QList<DomProperty*> lst; |
|
1502 |
||
1503 |
const QMetaObject *meta = obj->metaObject(); |
|
1504 |
||
1505 |
QHash<QByteArray, bool> properties; |
|
1506 |
const int propertyCount = meta->propertyCount(); |
|
1507 |
for(int i=0; i < propertyCount; ++i) |
|
1508 |
properties.insert(meta->property(i).name(), true); |
|
1509 |
||
1510 |
const QList<QByteArray> propertyNames = properties.keys(); |
|
1511 |
||
1512 |
const int propertyNamesCount = propertyNames.size(); |
|
1513 |
for(int i=0; i<propertyNamesCount ; ++i) { |
|
1514 |
const QString pname = QString::fromUtf8(propertyNames.at(i)); |
|
1515 |
const QMetaProperty prop = meta->property(meta->indexOfProperty(pname.toUtf8())); |
|
1516 |
||
1517 |
if (!prop.isWritable() || !checkProperty(obj, QLatin1String(prop.name()))) |
|
1518 |
continue; |
|
1519 |
||
1520 |
const QVariant v = prop.read(obj); |
|
1521 |
||
1522 |
DomProperty *dom_prop = 0; |
|
1523 |
if (v.type() == QVariant::Int) { |
|
1524 |
dom_prop = new DomProperty(); |
|
1525 |
||
1526 |
if (prop.isFlagType()) |
|
1527 |
uiLibWarning(QCoreApplication::translate("QAbstractFormBuilder", "Flags property are not supported yet.")); |
|
1528 |
||
1529 |
if (prop.isEnumType()) { |
|
1530 |
QString scope = QString::fromUtf8(prop.enumerator().scope()); |
|
1531 |
if (scope.size()) |
|
1532 |
scope += QString::fromUtf8("::"); |
|
1533 |
const QString e = QString::fromUtf8(prop.enumerator().valueToKey(v.toInt())); |
|
1534 |
if (e.size()) |
|
1535 |
dom_prop->setElementEnum(scope + e); |
|
1536 |
} else |
|
1537 |
dom_prop->setElementNumber(v.toInt()); |
|
1538 |
dom_prop->setAttributeName(pname); |
|
1539 |
} else { |
|
1540 |
dom_prop = createProperty(obj, pname, v); |
|
1541 |
} |
|
1542 |
||
1543 |
if (!dom_prop || dom_prop->kind() == DomProperty::Unknown) |
|
1544 |
delete dom_prop; |
|
1545 |
else |
|
1546 |
lst.append(dom_prop); |
|
1547 |
} |
|
1548 |
||
1549 |
return lst; |
|
1550 |
} |
|
1551 |
||
1552 |
||
1553 |
/*! |
|
1554 |
\internal |
|
1555 |
\typedef QAbstractFormBuilder::DomPropertyHash |
|
1556 |
\typedef QAbstractFormBuilder::IconPaths |
|
1557 |
*/ |
|
1558 |
||
1559 |
||
1560 |
/*! |
|
1561 |
\internal |
|
1562 |
*/ |
|
1563 |
QAbstractFormBuilder::DomPropertyHash QAbstractFormBuilder::propertyMap(const QList<DomProperty*> &properties) |
|
1564 |
{ |
|
1565 |
DomPropertyHash map; |
|
1566 |
||
1567 |
foreach (DomProperty *p, properties) |
|
1568 |
map.insert(p->attributeName(), p); |
|
1569 |
||
1570 |
return map; |
|
1571 |
} |
|
1572 |
||
1573 |
/*! |
|
1574 |
\internal |
|
1575 |
*/ |
|
1576 |
bool QAbstractFormBuilder::checkProperty(QObject *obj, const QString &prop) const |
|
1577 |
{ |
|
1578 |
Q_UNUSED(obj); |
|
1579 |
Q_UNUSED(prop); |
|
1580 |
||
1581 |
return true; |
|
1582 |
} |
|
1583 |
||
1584 |
/*! |
|
1585 |
\internal |
|
1586 |
*/ |
|
1587 |
QString QAbstractFormBuilder::toString(const DomString *str) |
|
1588 |
{ |
|
1589 |
return str ? str->text() : QString(); |
|
1590 |
} |
|
1591 |
||
1592 |
/*! |
|
1593 |
\internal |
|
1594 |
*/ |
|
1595 |
void QAbstractFormBuilder::applyTabStops(QWidget *widget, DomTabStops *tabStops) |
|
1596 |
{ |
|
1597 |
if (!tabStops) |
|
1598 |
return; |
|
1599 |
||
1600 |
QWidget *lastWidget = 0; |
|
1601 |
||
1602 |
const QStringList l = tabStops->elementTabStop(); |
|
1603 |
for (int i=0; i<l.size(); ++i) { |
|
1604 |
const QString name = l.at(i); |
|
1605 |
||
1606 |
QWidget *child = qFindChild<QWidget*>(widget, name); |
|
1607 |
if (!child) { |
|
1608 |
uiLibWarning(QCoreApplication::translate("QAbstractFormBuilder", "While applying tab stops: The widget '%1' could not be found.").arg(name)); |
|
1609 |
continue; |
|
1610 |
} |
|
1611 |
||
1612 |
if (i == 0) { |
|
1613 |
lastWidget = qFindChild<QWidget*>(widget, name); |
|
1614 |
continue; |
|
1615 |
} else if (!child || !lastWidget) { |
|
1616 |
continue; |
|
1617 |
} |
|
1618 |
||
1619 |
QWidget::setTabOrder(lastWidget, child); |
|
1620 |
||
1621 |
lastWidget = qFindChild<QWidget*>(widget, name); |
|
1622 |
} |
|
1623 |
} |
|
1624 |
||
1625 |
/*! |
|
1626 |
\internal |
|
1627 |
*/ |
|
1628 |
DomCustomWidgets *QAbstractFormBuilder::saveCustomWidgets() |
|
1629 |
{ |
|
1630 |
return 0; |
|
1631 |
} |
|
1632 |
||
1633 |
/*! |
|
1634 |
\internal |
|
1635 |
*/ |
|
1636 |
DomTabStops *QAbstractFormBuilder::saveTabStops() |
|
1637 |
{ |
|
1638 |
return 0; |
|
1639 |
} |
|
1640 |
||
1641 |
/*! |
|
1642 |
\internal |
|
1643 |
*/ |
|
1644 |
DomResources *QAbstractFormBuilder::saveResources() |
|
1645 |
{ |
|
1646 |
return 0; |
|
1647 |
} |
|
1648 |
||
1649 |
/*! |
|
1650 |
\internal |
|
1651 |
\since 4.5 |
|
1652 |
*/ |
|
1653 |
||
1654 |
DomButtonGroups *QAbstractFormBuilder::saveButtonGroups(const QWidget *mainContainer) |
|
1655 |
{ |
|
1656 |
// Save fst order buttongroup children of maincontainer |
|
1657 |
typedef QList<QButtonGroup*> ButtonGroupList; |
|
1658 |
const QObjectList mchildren = mainContainer->children(); |
|
1659 |
if (mchildren.empty()) |
|
1660 |
return 0; |
|
1661 |
QList<DomButtonGroup*> domGroups; |
|
1662 |
const QObjectList::const_iterator cend = mchildren.constEnd(); |
|
1663 |
for (QObjectList::const_iterator it = mchildren.constBegin(); it != cend; ++it) |
|
1664 |
if (QButtonGroup *bg = qobject_cast<QButtonGroup *>(*it)) |
|
1665 |
if (DomButtonGroup* dg = createDom(bg)) |
|
1666 |
domGroups.push_back(dg); |
|
1667 |
||
1668 |
if (domGroups.empty()) |
|
1669 |
return 0; |
|
1670 |
DomButtonGroups *rc = new DomButtonGroups; |
|
1671 |
rc->setElementButtonGroup(domGroups); |
|
1672 |
return rc; |
|
1673 |
} |
|
1674 |
||
1675 |
// VC6 would not find templated members, so we use statics and this utter hack. |
|
1676 |
class FriendlyFB : public QAbstractFormBuilder { |
|
1677 |
public: |
|
1678 |
using QAbstractFormBuilder::saveResource; |
|
1679 |
using QAbstractFormBuilder::saveText; |
|
1680 |
using QAbstractFormBuilder::resourceBuilder; |
|
1681 |
using QAbstractFormBuilder::textBuilder; |
|
1682 |
using QAbstractFormBuilder::toVariant; |
|
1683 |
}; |
|
1684 |
||
1685 |
template<class T> |
|
1686 |
static void storeItemFlags(const T *item, QList<DomProperty*> *properties) |
|
1687 |
{ |
|
1688 |
static const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1689 |
static const Qt::ItemFlags defaultFlags = T().flags(); |
|
1690 |
static const QMetaEnum itemFlags_enum = metaEnum<QAbstractFormBuilderGadget>("itemFlags"); |
|
1691 |
||
1692 |
if (item->flags() != defaultFlags) { |
|
1693 |
DomProperty *p = new DomProperty; |
|
1694 |
p->setAttributeName(strings.flagsAttribute); |
|
1695 |
p->setElementSet(QString::fromAscii(itemFlags_enum.valueToKeys(item->flags()))); |
|
1696 |
properties->append(p); |
|
1697 |
} |
|
1698 |
} |
|
1699 |
||
1700 |
#ifndef Q_CC_RVCT |
|
1701 |
// RVCT does not accept static inline functions if one argument is templated type |
|
1702 |
// For this reason all necessary function variants are explicityly written for it. |
|
1703 |
template<class T> |
|
1704 |
static void storeItemProps(QAbstractFormBuilder *abstractFormBuilder, const T *item, |
|
1705 |
QList<DomProperty*> *properties) |
|
1706 |
{ |
|
1707 |
static const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1708 |
FriendlyFB * const formBuilder = static_cast<FriendlyFB *>(abstractFormBuilder); |
|
1709 |
||
1710 |
DomProperty *p; |
|
1711 |
QVariant v; |
|
1712 |
||
1713 |
foreach (const QFormBuilderStrings::TextRoleNName &it, strings.itemTextRoles) |
|
1714 |
if ((p = formBuilder->saveText(it.second, item->data(it.first.second)))) |
|
1715 |
properties->append(p); |
|
1716 |
||
1717 |
foreach (const QFormBuilderStrings::RoleNName &it, strings.itemRoles) |
|
1718 |
if ((v = item->data(it.first)).isValid() && |
|
1719 |
(p = variantToDomProperty(abstractFormBuilder, |
|
1720 |
static_cast<const QMetaObject *>(&QAbstractFormBuilderGadget::staticMetaObject), |
|
1721 |
it.second, v))) |
|
1722 |
properties->append(p); |
|
1723 |
||
1724 |
if ((p = formBuilder->saveResource(item->data(Qt::DecorationPropertyRole)))) |
|
1725 |
properties->append(p); |
|
1726 |
} |
|
1727 |
||
1728 |
template<class T> |
|
1729 |
static void storeItemPropsNFlags(QAbstractFormBuilder *abstractFormBuilder, const T *item, |
|
1730 |
QList<DomProperty*> *properties) |
|
1731 |
{ |
|
1732 |
storeItemProps<T>(abstractFormBuilder, item, properties); |
|
1733 |
storeItemFlags<T>(item, properties); |
|
1734 |
} |
|
1735 |
||
1736 |
template<class T> |
|
1737 |
static void loadItemProps(QAbstractFormBuilder *abstractFormBuilder, T *item, |
|
1738 |
const QHash<QString, DomProperty*> &properties) |
|
1739 |
{ |
|
1740 |
static const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1741 |
FriendlyFB * const formBuilder = static_cast<FriendlyFB *>(abstractFormBuilder); |
|
1742 |
||
1743 |
DomProperty *p; |
|
1744 |
QVariant v; |
|
1745 |
||
1746 |
foreach (const QFormBuilderStrings::TextRoleNName &it, strings.itemTextRoles) |
|
1747 |
if ((p = properties.value(it.second))) { |
|
1748 |
v = formBuilder->textBuilder()->loadText(p); |
|
1749 |
QVariant nativeValue = formBuilder->textBuilder()->toNativeValue(v); |
|
1750 |
item->setData(it.first.first, qVariantValue<QString>(nativeValue)); |
|
1751 |
item->setData(it.first.second, v); |
|
1752 |
} |
|
1753 |
||
1754 |
foreach (const QFormBuilderStrings::RoleNName &it, strings.itemRoles) |
|
1755 |
if ((p = properties.value(it.second)) && |
|
1756 |
(v = formBuilder->toVariant(&QAbstractFormBuilderGadget::staticMetaObject, p)).isValid()) |
|
1757 |
item->setData(it.first, v); |
|
1758 |
||
1759 |
if ((p = properties.value(strings.iconAttribute))) { |
|
1760 |
v = formBuilder->resourceBuilder()->loadResource(formBuilder->workingDirectory(), p); |
|
1761 |
QVariant nativeValue = formBuilder->resourceBuilder()->toNativeValue(v); |
|
1762 |
item->setIcon(qVariantValue<QIcon>(nativeValue)); |
|
1763 |
item->setData(Qt::DecorationPropertyRole, v); |
|
1764 |
} |
|
1765 |
} |
|
1766 |
||
1767 |
template<class T> |
|
1768 |
static void loadItemPropsNFlags(QAbstractFormBuilder *abstractFormBuilder, T *item, |
|
1769 |
const QHash<QString, DomProperty*> &properties) |
|
1770 |
{ |
|
1771 |
static const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1772 |
static const QMetaEnum itemFlags_enum = metaEnum<QAbstractFormBuilderGadget>("itemFlags"); |
|
1773 |
||
1774 |
loadItemProps<T>(abstractFormBuilder, item, properties); |
|
1775 |
||
1776 |
DomProperty *p; |
|
1777 |
if ((p = properties.value(strings.flagsAttribute)) && p->kind() == DomProperty::Set) |
|
1778 |
item->setFlags(enumKeysToValue<Qt::ItemFlags>(itemFlags_enum, p->elementSet().toAscii())); |
|
1779 |
} |
|
1780 |
||
1781 |
#else |
|
1782 |
||
1783 |
static void storeItemProps(QAbstractFormBuilder *abstractFormBuilder, const QTableWidgetItem *item, |
|
1784 |
QList<DomProperty*> *properties) |
|
1785 |
{ |
|
1786 |
static const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1787 |
FriendlyFB * const formBuilder = static_cast<FriendlyFB *>(abstractFormBuilder); |
|
1788 |
||
1789 |
DomProperty *p; |
|
1790 |
QVariant v; |
|
1791 |
||
1792 |
foreach (const QFormBuilderStrings::TextRoleNName &it, strings.itemTextRoles) |
|
1793 |
if ((p = formBuilder->saveText(it.second, item->data(it.first.second)))) |
|
1794 |
properties->append(p); |
|
1795 |
||
1796 |
foreach (const QFormBuilderStrings::RoleNName &it, strings.itemRoles) |
|
1797 |
if ((v = item->data(it.first)).isValid() && |
|
1798 |
(p = variantToDomProperty(abstractFormBuilder, |
|
1799 |
static_cast<const QMetaObject *>(&QAbstractFormBuilderGadget::staticMetaObject), |
|
1800 |
it.second, v))) |
|
1801 |
properties->append(p); |
|
1802 |
||
1803 |
if ((p = formBuilder->saveResource(item->data(Qt::DecorationPropertyRole)))) |
|
1804 |
properties->append(p); |
|
1805 |
} |
|
1806 |
||
1807 |
static void storeItemProps(QAbstractFormBuilder *abstractFormBuilder, const QListWidgetItem *item, |
|
1808 |
QList<DomProperty*> *properties) |
|
1809 |
{ |
|
1810 |
static const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1811 |
FriendlyFB * const formBuilder = static_cast<FriendlyFB *>(abstractFormBuilder); |
|
1812 |
||
1813 |
DomProperty *p; |
|
1814 |
QVariant v; |
|
1815 |
||
1816 |
foreach (const QFormBuilderStrings::TextRoleNName &it, strings.itemTextRoles) |
|
1817 |
if ((p = formBuilder->saveText(it.second, item->data(it.first.second)))) |
|
1818 |
properties->append(p); |
|
1819 |
||
1820 |
foreach (const QFormBuilderStrings::RoleNName &it, strings.itemRoles) |
|
1821 |
if ((v = item->data(it.first)).isValid() && |
|
1822 |
(p = variantToDomProperty(abstractFormBuilder, |
|
1823 |
static_cast<const QMetaObject *>(&QAbstractFormBuilderGadget::staticMetaObject), |
|
1824 |
it.second, v))) |
|
1825 |
properties->append(p); |
|
1826 |
||
1827 |
if ((p = formBuilder->saveResource(item->data(Qt::DecorationPropertyRole)))) |
|
1828 |
properties->append(p); |
|
1829 |
} |
|
1830 |
||
1831 |
static void storeItemPropsNFlags(QAbstractFormBuilder *abstractFormBuilder, const QTableWidgetItem *item, |
|
1832 |
QList<DomProperty*> *properties) |
|
1833 |
{ |
|
1834 |
storeItemProps(abstractFormBuilder, item, properties); |
|
1835 |
storeItemFlags(item, properties); |
|
1836 |
} |
|
1837 |
||
1838 |
static void storeItemPropsNFlags(QAbstractFormBuilder *abstractFormBuilder, const QListWidgetItem *item, |
|
1839 |
QList<DomProperty*> *properties) |
|
1840 |
{ |
|
1841 |
storeItemProps(abstractFormBuilder, item, properties); |
|
1842 |
storeItemFlags(item, properties); |
|
1843 |
} |
|
1844 |
||
1845 |
static void loadItemProps(QAbstractFormBuilder *abstractFormBuilder, QTableWidgetItem *item, |
|
1846 |
const QHash<QString, DomProperty*> &properties) |
|
1847 |
{ |
|
1848 |
static const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1849 |
FriendlyFB * const formBuilder = static_cast<FriendlyFB *>(abstractFormBuilder); |
|
1850 |
||
1851 |
DomProperty *p; |
|
1852 |
QVariant v; |
|
1853 |
||
1854 |
foreach (const QFormBuilderStrings::TextRoleNName &it, strings.itemTextRoles) |
|
1855 |
if ((p = properties.value(it.second))) { |
|
1856 |
v = formBuilder->textBuilder()->loadText(p); |
|
1857 |
QVariant nativeValue = formBuilder->textBuilder()->toNativeValue(v); |
|
1858 |
item->setData(it.first.first, qVariantValue<QString>(nativeValue)); |
|
1859 |
item->setData(it.first.second, v); |
|
1860 |
} |
|
1861 |
||
1862 |
foreach (const QFormBuilderStrings::RoleNName &it, strings.itemRoles) |
|
1863 |
if ((p = properties.value(it.second)) && |
|
1864 |
(v = formBuilder->toVariant(&QAbstractFormBuilderGadget::staticMetaObject, p)).isValid()) |
|
1865 |
item->setData(it.first, v); |
|
1866 |
||
1867 |
if ((p = properties.value(strings.iconAttribute))) { |
|
1868 |
v = formBuilder->resourceBuilder()->loadResource(formBuilder->workingDirectory(), p); |
|
1869 |
QVariant nativeValue = formBuilder->resourceBuilder()->toNativeValue(v); |
|
1870 |
item->setIcon(qVariantValue<QIcon>(nativeValue)); |
|
1871 |
item->setData(Qt::DecorationPropertyRole, v); |
|
1872 |
} |
|
1873 |
} |
|
1874 |
||
1875 |
static void loadItemProps(QAbstractFormBuilder *abstractFormBuilder, QListWidgetItem *item, |
|
1876 |
const QHash<QString, DomProperty*> &properties) |
|
1877 |
{ |
|
1878 |
static const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1879 |
FriendlyFB * const formBuilder = static_cast<FriendlyFB *>(abstractFormBuilder); |
|
1880 |
||
1881 |
DomProperty *p; |
|
1882 |
QVariant v; |
|
1883 |
||
1884 |
foreach (const QFormBuilderStrings::TextRoleNName &it, strings.itemTextRoles) |
|
1885 |
if ((p = properties.value(it.second))) { |
|
1886 |
v = formBuilder->textBuilder()->loadText(p); |
|
1887 |
QVariant nativeValue = formBuilder->textBuilder()->toNativeValue(v); |
|
1888 |
item->setData(it.first.first, qVariantValue<QString>(nativeValue)); |
|
1889 |
item->setData(it.first.second, v); |
|
1890 |
} |
|
1891 |
||
1892 |
foreach (const QFormBuilderStrings::RoleNName &it, strings.itemRoles) |
|
1893 |
if ((p = properties.value(it.second)) && |
|
1894 |
(v = formBuilder->toVariant(&QAbstractFormBuilderGadget::staticMetaObject, p)).isValid()) |
|
1895 |
item->setData(it.first, v); |
|
1896 |
||
1897 |
if ((p = properties.value(strings.iconAttribute))) { |
|
1898 |
v = formBuilder->resourceBuilder()->loadResource(formBuilder->workingDirectory(), p); |
|
1899 |
QVariant nativeValue = formBuilder->resourceBuilder()->toNativeValue(v); |
|
1900 |
item->setIcon(qVariantValue<QIcon>(nativeValue)); |
|
1901 |
item->setData(Qt::DecorationPropertyRole, v); |
|
1902 |
} |
|
1903 |
} |
|
1904 |
||
1905 |
static void loadItemPropsNFlags(QAbstractFormBuilder *abstractFormBuilder, QTableWidgetItem *item, |
|
1906 |
const QHash<QString, DomProperty*> &properties) |
|
1907 |
{ |
|
1908 |
static const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1909 |
static const QMetaEnum itemFlags_enum = metaEnum<QAbstractFormBuilderGadget>("itemFlags"); |
|
1910 |
||
1911 |
loadItemProps(abstractFormBuilder, item, properties); |
|
1912 |
||
1913 |
DomProperty *p; |
|
1914 |
if ((p = properties.value(strings.flagsAttribute)) && p->kind() == DomProperty::Set) |
|
1915 |
item->setFlags(enumKeysToValue<Qt::ItemFlags>(itemFlags_enum, p->elementSet().toAscii())); |
|
1916 |
} |
|
1917 |
||
1918 |
static void loadItemPropsNFlags(QAbstractFormBuilder *abstractFormBuilder, QListWidgetItem *item, |
|
1919 |
const QHash<QString, DomProperty*> &properties) |
|
1920 |
{ |
|
1921 |
static const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1922 |
static const QMetaEnum itemFlags_enum = metaEnum<QAbstractFormBuilderGadget>("itemFlags"); |
|
1923 |
||
1924 |
loadItemProps(abstractFormBuilder, item, properties); |
|
1925 |
||
1926 |
DomProperty *p; |
|
1927 |
if ((p = properties.value(strings.flagsAttribute)) && p->kind() == DomProperty::Set) |
|
1928 |
item->setFlags(enumKeysToValue<Qt::ItemFlags>(itemFlags_enum, p->elementSet().toAscii())); |
|
1929 |
} |
|
1930 |
||
1931 |
#endif |
|
1932 |
||
1933 |
/*! |
|
1934 |
\internal |
|
1935 |
*/ |
|
1936 |
void QAbstractFormBuilder::saveTreeWidgetExtraInfo(QTreeWidget *treeWidget, DomWidget *ui_widget, DomWidget *ui_parentWidget) |
|
1937 |
{ |
|
1938 |
Q_UNUSED(ui_parentWidget); |
|
1939 |
||
1940 |
QList<DomColumn*> columns; |
|
1941 |
DomProperty *p; |
|
1942 |
QVariant v; |
|
1943 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
1944 |
// save the header |
|
1945 |
for (int c = 0; c<treeWidget->columnCount(); ++c) { |
|
1946 |
DomColumn *column = new DomColumn; |
|
1947 |
||
1948 |
QList<DomProperty*> properties; |
|
1949 |
||
1950 |
foreach (const QFormBuilderStrings::TextRoleNName &it, strings.itemTextRoles) { |
|
1951 |
p = saveText(it.second, treeWidget->headerItem()->data(c, it.first.second)); |
|
1952 |
// Prevent uic 4.4.X from crashing if it cannot find a column text |
|
1953 |
if (!p && it.first.first == Qt::EditRole && it.second == QLatin1String("text")) { |
|
1954 |
DomString *defaultHeader = new DomString; |
|
1955 |
defaultHeader->setText(QString::number(c + 1)); |
|
1956 |
defaultHeader->setAttributeNotr(QLatin1String("true")); |
|
1957 |
p = new DomProperty; |
|
1958 |
p->setAttributeName(it.second); |
|
1959 |
p->setElementString(defaultHeader); |
|
1960 |
} |
|
1961 |
if (p) |
|
1962 |
properties.append(p); |
|
1963 |
} |
|
1964 |
||
1965 |
foreach (const QFormBuilderStrings::RoleNName &it, strings.itemRoles) |
|
1966 |
if ((v = treeWidget->headerItem()->data(c, it.first)).isValid() && |
|
1967 |
(p = variantToDomProperty(this, &QAbstractFormBuilderGadget::staticMetaObject, it.second, v))) |
|
1968 |
properties.append(p); |
|
1969 |
||
1970 |
if ((p = saveResource(treeWidget->headerItem()->data(c, Qt::DecorationPropertyRole)))) |
|
1971 |
properties.append(p); |
|
1972 |
||
1973 |
column->setElementProperty(properties); |
|
1974 |
columns.append(column); |
|
1975 |
} |
|
1976 |
||
1977 |
ui_widget->setElementColumn(columns); |
|
1978 |
||
1979 |
QList<DomItem *> items = ui_widget->elementItem(); |
|
1980 |
||
1981 |
QQueue<QPair<QTreeWidgetItem *, DomItem *> > pendingQueue; |
|
1982 |
for (int i = 0; i < treeWidget->topLevelItemCount(); i++) |
|
1983 |
pendingQueue.enqueue(qMakePair(treeWidget->topLevelItem(i), (DomItem *)0)); |
|
1984 |
||
1985 |
while (!pendingQueue.isEmpty()) { |
|
1986 |
const QPair<QTreeWidgetItem *, DomItem *> pair = pendingQueue.dequeue(); |
|
1987 |
QTreeWidgetItem *item = pair.first; |
|
1988 |
DomItem *parentDomItem = pair.second; |
|
1989 |
||
1990 |
DomItem *currentDomItem = new DomItem; |
|
1991 |
||
1992 |
QList<DomProperty*> properties; |
|
1993 |
for (int c = 0; c < treeWidget->columnCount(); c++) { |
|
1994 |
foreach (const QFormBuilderStrings::TextRoleNName &it, strings.itemTextRoles) |
|
1995 |
if ((p = saveText(it.second, item->data(c, it.first.second)))) |
|
1996 |
properties.append(p); |
|
1997 |
||
1998 |
foreach (const QFormBuilderStrings::RoleNName &it, strings.itemRoles) |
|
1999 |
if ((v = item->data(c, it.first)).isValid() && |
|
2000 |
(p = variantToDomProperty(this, &QAbstractFormBuilderGadget::staticMetaObject, it.second, v))) |
|
2001 |
properties.append(p); |
|
2002 |
||
2003 |
if ((p = saveResource(item->data(c, Qt::DecorationPropertyRole)))) |
|
2004 |
properties.append(p); |
|
2005 |
} |
|
2006 |
storeItemFlags(item, &properties); |
|
2007 |
currentDomItem->setElementProperty(properties); |
|
2008 |
||
2009 |
if (parentDomItem) { |
|
2010 |
QList<DomItem *> childrenItems = parentDomItem->elementItem(); |
|
2011 |
childrenItems.append(currentDomItem); |
|
2012 |
parentDomItem->setElementItem(childrenItems); |
|
2013 |
} else |
|
2014 |
items.append(currentDomItem); |
|
2015 |
||
2016 |
for (int i = 0; i < item->childCount(); i++) |
|
2017 |
pendingQueue.enqueue(qMakePair(item->child(i), currentDomItem)); |
|
2018 |
} |
|
2019 |
||
2020 |
ui_widget->setElementItem(items); |
|
2021 |
} |
|
2022 |
||
2023 |
/*! |
|
2024 |
\internal |
|
2025 |
*/ |
|
2026 |
void QAbstractFormBuilder::saveTableWidgetExtraInfo(QTableWidget *tableWidget, DomWidget *ui_widget, DomWidget *ui_parentWidget) |
|
2027 |
{ |
|
2028 |
Q_UNUSED(ui_parentWidget); |
|
2029 |
||
2030 |
// save the horizontal header |
|
2031 |
QList<DomColumn*> columns; |
|
2032 |
for (int c = 0; c < tableWidget->columnCount(); c++) { |
|
2033 |
QList<DomProperty*> properties; |
|
2034 |
QTableWidgetItem *item = tableWidget->horizontalHeaderItem(c); |
|
2035 |
if (item) |
|
2036 |
storeItemProps(this, item, &properties); |
|
2037 |
||
2038 |
DomColumn *column = new DomColumn; |
|
2039 |
column->setElementProperty(properties); |
|
2040 |
columns.append(column); |
|
2041 |
} |
|
2042 |
ui_widget->setElementColumn(columns); |
|
2043 |
||
2044 |
// save the vertical header |
|
2045 |
QList<DomRow*> rows; |
|
2046 |
for (int r = 0; r < tableWidget->rowCount(); r++) { |
|
2047 |
QList<DomProperty*> properties; |
|
2048 |
QTableWidgetItem *item = tableWidget->verticalHeaderItem(r); |
|
2049 |
if (item) |
|
2050 |
storeItemProps(this, item, &properties); |
|
2051 |
||
2052 |
DomRow *row = new DomRow; |
|
2053 |
row->setElementProperty(properties); |
|
2054 |
rows.append(row); |
|
2055 |
} |
|
2056 |
ui_widget->setElementRow(rows); |
|
2057 |
||
2058 |
QList<DomItem *> items = ui_widget->elementItem(); |
|
2059 |
for (int r = 0; r < tableWidget->rowCount(); r++) |
|
2060 |
for (int c = 0; c < tableWidget->columnCount(); c++) { |
|
2061 |
QTableWidgetItem *item = tableWidget->item(r, c); |
|
2062 |
if (item) { |
|
2063 |
QList<DomProperty*> properties; |
|
2064 |
storeItemPropsNFlags(this, item, &properties); |
|
2065 |
||
2066 |
DomItem *domItem = new DomItem; |
|
2067 |
domItem->setAttributeRow(r); |
|
2068 |
domItem->setAttributeColumn(c); |
|
2069 |
domItem->setElementProperty(properties); |
|
2070 |
items.append(domItem); |
|
2071 |
} |
|
2072 |
} |
|
2073 |
||
2074 |
ui_widget->setElementItem(items); |
|
2075 |
} |
|
2076 |
||
2077 |
/*! |
|
2078 |
\internal |
|
2079 |
*/ |
|
2080 |
void QAbstractFormBuilder::saveListWidgetExtraInfo(QListWidget *listWidget, DomWidget *ui_widget, DomWidget *ui_parentWidget) |
|
2081 |
{ |
|
2082 |
Q_UNUSED(ui_parentWidget); |
|
2083 |
||
2084 |
QList<DomItem*> ui_items = ui_widget->elementItem(); |
|
2085 |
for (int i=0; i<listWidget->count(); ++i) { |
|
2086 |
QList<DomProperty*> properties; |
|
2087 |
storeItemPropsNFlags(this, listWidget->item(i), &properties); |
|
2088 |
||
2089 |
DomItem *ui_item = new DomItem(); |
|
2090 |
ui_item->setElementProperty(properties); |
|
2091 |
ui_items.append(ui_item); |
|
2092 |
} |
|
2093 |
||
2094 |
ui_widget->setElementItem(ui_items); |
|
2095 |
} |
|
2096 |
||
2097 |
/*! |
|
2098 |
\internal |
|
2099 |
*/ |
|
2100 |
void QAbstractFormBuilder::saveComboBoxExtraInfo(QComboBox *comboBox, DomWidget *ui_widget, DomWidget *ui_parentWidget) |
|
2101 |
{ |
|
2102 |
Q_UNUSED(ui_parentWidget); |
|
2103 |
QList<DomItem*> ui_items = ui_widget->elementItem(); |
|
2104 |
||
2105 |
const int count = comboBox->count(); |
|
2106 |
for (int i=0; i < count; ++i) { |
|
2107 |
// We might encounter items for which both builders return 0 in Designer |
|
2108 |
// (indicating a custom combo adding items in the constructor). Ignore those. |
|
2109 |
DomProperty *textProperty = saveText(QFormBuilderStrings::instance().textAttribute, |
|
2110 |
comboBox->itemData(i, Qt::DisplayPropertyRole)); |
|
2111 |
DomProperty *iconProperty = saveResource(comboBox->itemData(i, Qt::DecorationPropertyRole)); |
|
2112 |
if (textProperty || iconProperty) { |
|
2113 |
QList<DomProperty*> properties; |
|
2114 |
if (textProperty) |
|
2115 |
properties.push_back(textProperty); |
|
2116 |
if (iconProperty) |
|
2117 |
properties.push_back(iconProperty); |
|
2118 |
||
2119 |
DomItem *ui_item = new DomItem(); |
|
2120 |
ui_item->setElementProperty(properties); |
|
2121 |
ui_items.push_back(ui_item); |
|
2122 |
} |
|
2123 |
} |
|
2124 |
||
2125 |
ui_widget->setElementItem(ui_items); |
|
2126 |
} |
|
2127 |
||
2128 |
/*! |
|
2129 |
\internal |
|
2130 |
\since 4.5 |
|
2131 |
*/ |
|
2132 |
||
2133 |
void QAbstractFormBuilder::saveButtonExtraInfo(const QAbstractButton *widget, DomWidget *ui_widget, DomWidget *) |
|
2134 |
{ |
|
2135 |
typedef QList<DomProperty*> DomPropertyList; |
|
2136 |
if (const QButtonGroup *buttonGroup = widget->group()) { |
|
2137 |
DomPropertyList attributes = ui_widget->elementAttribute(); |
|
2138 |
DomString *domString = new DomString(); |
|
2139 |
domString->setText(buttonGroup->objectName()); |
|
2140 |
DomProperty *domProperty = new DomProperty(); |
|
2141 |
domProperty->setAttributeName(QLatin1String(buttonGroupPropertyC)); |
|
2142 |
domProperty->setElementString(domString); |
|
2143 |
attributes += domProperty; |
|
2144 |
ui_widget->setElementAttribute(attributes); |
|
2145 |
} |
|
2146 |
} |
|
2147 |
||
2148 |
/*! |
|
2149 |
\internal |
|
2150 |
\since 4.5 |
|
2151 |
*/ |
|
2152 |
void QAbstractFormBuilder::saveItemViewExtraInfo(const QAbstractItemView *itemView, |
|
2153 |
DomWidget *ui_widget, DomWidget *) |
|
2154 |
{ |
|
2155 |
// |
|
2156 |
// Special handling for qtableview/qtreeview fake header attributes |
|
2157 |
// |
|
2158 |
static QStringList realPropertyNames = |
|
2159 |
(QStringList() << QLatin1String("visible") |
|
2160 |
<< QLatin1String("cascadingSectionResizes") |
|
2161 |
<< QLatin1String("defaultSectionSize") |
|
2162 |
<< QLatin1String("highlightSections") |
|
2163 |
<< QLatin1String("minimumSectionSize") |
|
2164 |
<< QLatin1String("showSortIndicator") |
|
2165 |
<< QLatin1String("stretchLastSection")); |
|
2166 |
||
2167 |
if (const QTreeView *treeView = qobject_cast<const QTreeView*>(itemView)) { |
|
2168 |
QList<DomProperty*> viewProperties = ui_widget->elementAttribute(); |
|
2169 |
QList<DomProperty*> headerProperties = computeProperties(treeView->header()); |
|
2170 |
foreach (const QString &realPropertyName, realPropertyNames) { |
|
2171 |
const QString upperPropertyName = realPropertyName.at(0).toUpper() |
|
2172 |
+ realPropertyName.mid(1); |
|
2173 |
const QString fakePropertyName = QLatin1String("header") + upperPropertyName; |
|
2174 |
foreach (DomProperty *property, headerProperties) { |
|
2175 |
if (property->attributeName() == realPropertyName) { |
|
2176 |
property->setAttributeName(fakePropertyName); |
|
2177 |
viewProperties << property; |
|
2178 |
} |
|
2179 |
} |
|
2180 |
} |
|
2181 |
ui_widget->setElementAttribute(viewProperties); |
|
2182 |
} else if (const QTableView *tableView = qobject_cast<const QTableView*>(itemView)) { |
|
2183 |
static QStringList headerPrefixes = |
|
2184 |
(QStringList() << QLatin1String("horizontalHeader") |
|
2185 |
<< QLatin1String("verticalHeader")); |
|
2186 |
||
2187 |
QList<DomProperty*> viewProperties = ui_widget->elementAttribute(); |
|
2188 |
foreach (const QString &headerPrefix, headerPrefixes) { |
|
2189 |
QList<DomProperty*> headerProperties; |
|
2190 |
if (headerPrefix == QLatin1String("horizontalHeader")) |
|
2191 |
headerProperties = computeProperties(tableView->horizontalHeader()); |
|
2192 |
else |
|
2193 |
headerProperties = computeProperties(tableView->verticalHeader()); |
|
2194 |
foreach (const QString &realPropertyName, realPropertyNames) { |
|
2195 |
const QString upperPropertyName = realPropertyName.at(0).toUpper() |
|
2196 |
+ realPropertyName.mid(1); |
|
2197 |
const QString fakePropertyName = headerPrefix + upperPropertyName; |
|
2198 |
foreach (DomProperty *property, headerProperties) { |
|
2199 |
if (property->attributeName() == realPropertyName) { |
|
2200 |
property->setAttributeName(fakePropertyName); |
|
2201 |
viewProperties << property; |
|
2202 |
} |
|
2203 |
} |
|
2204 |
} |
|
2205 |
} |
|
2206 |
ui_widget->setElementAttribute(viewProperties); |
|
2207 |
} |
|
2208 |
} |
|
2209 |
||
2210 |
/*! |
|
2211 |
\internal |
|
2212 |
\since 4.4 |
|
2213 |
*/ |
|
2214 |
||
2215 |
void QAbstractFormBuilder::setResourceBuilder(QResourceBuilder *builder) |
|
2216 |
{ |
|
2217 |
QFormBuilderExtra::instance(this)->setResourceBuilder(builder); |
|
2218 |
} |
|
2219 |
||
2220 |
/*! |
|
2221 |
\internal |
|
2222 |
\since 4.4 |
|
2223 |
*/ |
|
2224 |
||
2225 |
QResourceBuilder *QAbstractFormBuilder::resourceBuilder() const |
|
2226 |
{ |
|
2227 |
return QFormBuilderExtra::instance(this)->resourceBuilder(); |
|
2228 |
} |
|
2229 |
||
2230 |
/*! |
|
2231 |
\internal |
|
2232 |
\since 4.5 |
|
2233 |
*/ |
|
2234 |
||
2235 |
void QAbstractFormBuilder::setTextBuilder(QTextBuilder *builder) |
|
2236 |
{ |
|
2237 |
QFormBuilderExtra::instance(this)->setTextBuilder(builder); |
|
2238 |
} |
|
2239 |
||
2240 |
/*! |
|
2241 |
\internal |
|
2242 |
\since 4.5 |
|
2243 |
*/ |
|
2244 |
||
2245 |
QTextBuilder *QAbstractFormBuilder::textBuilder() const |
|
2246 |
{ |
|
2247 |
return QFormBuilderExtra::instance(this)->textBuilder(); |
|
2248 |
} |
|
2249 |
||
2250 |
/*! |
|
2251 |
\internal |
|
2252 |
*/ |
|
2253 |
void QAbstractFormBuilder::saveExtraInfo(QWidget *widget, DomWidget *ui_widget, |
|
2254 |
DomWidget *ui_parentWidget) |
|
2255 |
{ |
|
2256 |
if (QListWidget *listWidget = qobject_cast<QListWidget*>(widget)) { |
|
2257 |
saveListWidgetExtraInfo(listWidget, ui_widget, ui_parentWidget); |
|
2258 |
} else if (QTreeWidget *treeWidget = qobject_cast<QTreeWidget*>(widget)) { |
|
2259 |
saveTreeWidgetExtraInfo(treeWidget, ui_widget, ui_parentWidget); |
|
2260 |
} else if (QTableWidget *tableWidget = qobject_cast<QTableWidget*>(widget)) { |
|
2261 |
saveTableWidgetExtraInfo(tableWidget, ui_widget, ui_parentWidget); |
|
2262 |
} else if (QComboBox *comboBox = qobject_cast<QComboBox*>(widget)) { |
|
2263 |
if (!qobject_cast<QFontComboBox*>(widget)) |
|
2264 |
saveComboBoxExtraInfo(comboBox, ui_widget, ui_parentWidget); |
|
2265 |
} else if(QAbstractButton *ab = qobject_cast<QAbstractButton *>(widget)) { |
|
2266 |
saveButtonExtraInfo(ab, ui_widget, ui_parentWidget); |
|
2267 |
} |
|
2268 |
if (QAbstractItemView *itemView = qobject_cast<QAbstractItemView *>(widget)) { |
|
2269 |
saveItemViewExtraInfo(itemView, ui_widget, ui_parentWidget); |
|
2270 |
} |
|
2271 |
} |
|
2272 |
||
2273 |
/*! |
|
2274 |
\internal |
|
2275 |
*/ |
|
2276 |
void QAbstractFormBuilder::loadListWidgetExtraInfo(DomWidget *ui_widget, QListWidget *listWidget, QWidget *parentWidget) |
|
2277 |
{ |
|
2278 |
Q_UNUSED(parentWidget); |
|
2279 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
2280 |
const QMetaEnum itemFlags_enum = metaEnum<QAbstractFormBuilderGadget>("itemFlags"); |
|
2281 |
||
2282 |
foreach (DomItem *ui_item, ui_widget->elementItem()) { |
|
2283 |
const DomPropertyHash properties = propertyMap(ui_item->elementProperty()); |
|
2284 |
QListWidgetItem *item = new QListWidgetItem(listWidget); |
|
2285 |
#ifndef Q_CC_RVCT |
|
2286 |
loadItemPropsNFlags<QListWidgetItem>(this, item, properties); |
|
2287 |
#else |
|
2288 |
loadItemPropsNFlags(this, item, properties); |
|
2289 |
#endif |
|
2290 |
} |
|
2291 |
||
2292 |
DomProperty *currentRow = propertyMap(ui_widget->elementProperty()).value(strings.currentRowProperty); |
|
2293 |
if (currentRow) |
|
2294 |
listWidget->setCurrentRow(currentRow->elementNumber()); |
|
2295 |
} |
|
2296 |
||
2297 |
/*! |
|
2298 |
\internal |
|
2299 |
*/ |
|
2300 |
void QAbstractFormBuilder::loadTreeWidgetExtraInfo(DomWidget *ui_widget, QTreeWidget *treeWidget, QWidget *parentWidget) |
|
2301 |
{ |
|
2302 |
Q_UNUSED(parentWidget); |
|
2303 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
2304 |
const QMetaEnum itemFlags_enum = metaEnum<QAbstractFormBuilderGadget>("itemFlags"); |
|
2305 |
const QList<DomColumn*> columns = ui_widget->elementColumn(); |
|
2306 |
if (columns.count() > 0) |
|
2307 |
treeWidget->setColumnCount(columns.count()); |
|
2308 |
||
2309 |
for (int i = 0; i<columns.count(); ++i) { |
|
2310 |
const DomColumn *c = columns.at(i); |
|
2311 |
const DomPropertyHash properties = propertyMap(c->elementProperty()); |
|
2312 |
||
2313 |
DomProperty *p; |
|
2314 |
QVariant v; |
|
2315 |
||
2316 |
foreach (const QFormBuilderStrings::RoleNName &it, strings.itemRoles) |
|
2317 |
if ((p = properties.value(it.second)) && |
|
2318 |
(v = toVariant(&QAbstractFormBuilderGadget::staticMetaObject, p)).isValid()) |
|
2319 |
treeWidget->headerItem()->setData(i, it.first, v); |
|
2320 |
||
2321 |
foreach (const QFormBuilderStrings::TextRoleNName &it, strings.itemTextRoles) |
|
2322 |
if ((p = properties.value(it.second))) { |
|
2323 |
v = textBuilder()->loadText(p); |
|
2324 |
QVariant nativeValue = textBuilder()->toNativeValue(v); |
|
2325 |
treeWidget->headerItem()->setData(i, it.first.first, qVariantValue<QString>(nativeValue)); |
|
2326 |
treeWidget->headerItem()->setData(i, it.first.second, v); |
|
2327 |
} |
|
2328 |
||
2329 |
if ((p = properties.value(strings.iconAttribute))) { |
|
2330 |
v = resourceBuilder()->loadResource(workingDirectory(), p); |
|
2331 |
QVariant nativeValue = resourceBuilder()->toNativeValue(v); |
|
2332 |
treeWidget->headerItem()->setIcon(i, qVariantValue<QIcon>(nativeValue)); |
|
2333 |
treeWidget->headerItem()->setData(i, Qt::DecorationPropertyRole, v); |
|
2334 |
} |
|
2335 |
} |
|
2336 |
||
2337 |
QQueue<QPair<DomItem *, QTreeWidgetItem *> > pendingQueue; |
|
2338 |
foreach (DomItem *ui_item, ui_widget->elementItem()) |
|
2339 |
pendingQueue.enqueue(qMakePair(ui_item, (QTreeWidgetItem *)0)); |
|
2340 |
||
2341 |
while (!pendingQueue.isEmpty()) { |
|
2342 |
const QPair<DomItem *, QTreeWidgetItem *> pair = pendingQueue.dequeue(); |
|
2343 |
const DomItem *domItem = pair.first; |
|
2344 |
QTreeWidgetItem *parentItem = pair.second; |
|
2345 |
||
2346 |
QTreeWidgetItem *currentItem = 0; |
|
2347 |
||
2348 |
if (parentItem) |
|
2349 |
currentItem = new QTreeWidgetItem(parentItem); |
|
2350 |
else |
|
2351 |
currentItem = new QTreeWidgetItem(treeWidget); |
|
2352 |
||
2353 |
const QList<DomProperty *> properties = domItem->elementProperty(); |
|
2354 |
int col = -1; |
|
2355 |
foreach (DomProperty *property, properties) { |
|
2356 |
if (property->attributeName() == strings.flagsAttribute && !property->elementSet().isEmpty()) { |
|
2357 |
currentItem->setFlags(enumKeysToValue<Qt::ItemFlags>(itemFlags_enum, property->elementSet().toAscii())); |
|
2358 |
} else if (property->attributeName() == strings.textAttribute && property->elementString()) { |
|
2359 |
col++; |
|
2360 |
QVariant textV = textBuilder()->loadText(property); |
|
2361 |
QVariant nativeValue = textBuilder()->toNativeValue(textV); |
|
2362 |
currentItem->setText(col, qVariantValue<QString>(nativeValue)); |
|
2363 |
currentItem->setData(col, Qt::DisplayPropertyRole, textV); |
|
2364 |
} else if (col >= 0) { |
|
2365 |
if (property->attributeName() == strings.iconAttribute) { |
|
2366 |
QVariant v = resourceBuilder()->loadResource(workingDirectory(), property); |
|
2367 |
if (v.isValid()) { |
|
2368 |
QVariant nativeValue = resourceBuilder()->toNativeValue(v); |
|
2369 |
currentItem->setIcon(col, qVariantValue<QIcon>(nativeValue)); |
|
2370 |
currentItem->setData(col, Qt::DecorationPropertyRole, v); |
|
2371 |
} |
|
2372 |
} else { |
|
2373 |
QVariant v; |
|
2374 |
int role = strings.treeItemRoleHash.value(property->attributeName(), (Qt::ItemDataRole)-1); |
|
2375 |
if (role >= 0) { |
|
2376 |
if ((v = toVariant(&QAbstractFormBuilderGadget::staticMetaObject, property)).isValid()) |
|
2377 |
currentItem->setData(col, role, v); |
|
2378 |
} else { |
|
2379 |
QPair<Qt::ItemDataRole, Qt::ItemDataRole> rolePair = |
|
2380 |
strings.treeItemTextRoleHash.value(property->attributeName(), |
|
2381 |
qMakePair((Qt::ItemDataRole)-1, (Qt::ItemDataRole)-1)); |
|
2382 |
if (rolePair.first >= 0) { |
|
2383 |
QVariant textV = textBuilder()->loadText(property); |
|
2384 |
QVariant nativeValue = textBuilder()->toNativeValue(textV); |
|
2385 |
currentItem->setData(col, rolePair.first, qVariantValue<QString>(nativeValue)); |
|
2386 |
currentItem->setData(col, rolePair.second, textV); |
|
2387 |
} |
|
2388 |
} |
|
2389 |
} |
|
2390 |
} |
|
2391 |
} |
|
2392 |
||
2393 |
foreach (DomItem *childItem, domItem->elementItem()) |
|
2394 |
pendingQueue.enqueue(qMakePair(childItem, currentItem)); |
|
2395 |
||
2396 |
} |
|
2397 |
} |
|
2398 |
||
2399 |
/*! |
|
2400 |
\internal |
|
2401 |
*/ |
|
2402 |
void QAbstractFormBuilder::loadTableWidgetExtraInfo(DomWidget *ui_widget, QTableWidget *tableWidget, QWidget *parentWidget) |
|
2403 |
{ |
|
2404 |
Q_UNUSED(parentWidget); |
|
2405 |
||
2406 |
const QList<DomColumn*> columns = ui_widget->elementColumn(); |
|
2407 |
if (columns.count() > 0) |
|
2408 |
tableWidget->setColumnCount(columns.count()); |
|
2409 |
for (int i = 0; i< columns.count(); i++) { |
|
2410 |
DomColumn *c = columns.at(i); |
|
2411 |
const DomPropertyHash properties = propertyMap(c->elementProperty()); |
|
2412 |
||
2413 |
if (!properties.isEmpty()) { |
|
2414 |
QTableWidgetItem *item = new QTableWidgetItem; |
|
2415 |
loadItemProps(this, item, properties); |
|
2416 |
tableWidget->setHorizontalHeaderItem(i, item); |
|
2417 |
} |
|
2418 |
} |
|
2419 |
||
2420 |
const QList<DomRow*> rows = ui_widget->elementRow(); |
|
2421 |
if (rows.count() > 0) |
|
2422 |
tableWidget->setRowCount(rows.count()); |
|
2423 |
for (int i = 0; i< rows.count(); i++) { |
|
2424 |
const DomRow *r = rows.at(i); |
|
2425 |
const DomPropertyHash properties = propertyMap(r->elementProperty()); |
|
2426 |
||
2427 |
if (!properties.isEmpty()) { |
|
2428 |
QTableWidgetItem *item = new QTableWidgetItem; |
|
2429 |
loadItemProps(this, item, properties); |
|
2430 |
tableWidget->setVerticalHeaderItem(i, item); |
|
2431 |
} |
|
2432 |
} |
|
2433 |
||
2434 |
foreach (DomItem *ui_item, ui_widget->elementItem()) { |
|
2435 |
if (ui_item->hasAttributeRow() && ui_item->hasAttributeColumn()) { |
|
2436 |
const DomPropertyHash properties = propertyMap(ui_item->elementProperty()); |
|
2437 |
QTableWidgetItem *item = new QTableWidgetItem; |
|
2438 |
loadItemPropsNFlags(this, item, properties); |
|
2439 |
tableWidget->setItem(ui_item->attributeRow(), ui_item->attributeColumn(), item); |
|
2440 |
} |
|
2441 |
} |
|
2442 |
} |
|
2443 |
||
2444 |
/*! |
|
2445 |
\internal |
|
2446 |
*/ |
|
2447 |
void QAbstractFormBuilder::loadComboBoxExtraInfo(DomWidget *ui_widget, QComboBox *comboBox, QWidget *parentWidget) |
|
2448 |
{ |
|
2449 |
Q_UNUSED(parentWidget); |
|
2450 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
2451 |
foreach (DomItem *ui_item, ui_widget->elementItem()) { |
|
2452 |
const DomPropertyHash properties = propertyMap(ui_item->elementProperty()); |
|
2453 |
QString text; |
|
2454 |
QIcon icon; |
|
2455 |
QVariant textData; |
|
2456 |
QVariant iconData; |
|
2457 |
||
2458 |
DomProperty *p = 0; |
|
2459 |
||
2460 |
p = properties.value(strings.textAttribute); |
|
2461 |
if (p && p->elementString()) { |
|
2462 |
textData = textBuilder()->loadText(p); |
|
2463 |
text = qVariantValue<QString>(textBuilder()->toNativeValue(textData)); |
|
2464 |
} |
|
2465 |
||
2466 |
p = properties.value(strings.iconAttribute); |
|
2467 |
if (p) { |
|
2468 |
iconData = resourceBuilder()->loadResource(workingDirectory(), p); |
|
2469 |
icon = qVariantValue<QIcon>(resourceBuilder()->toNativeValue(iconData)); |
|
2470 |
} |
|
2471 |
||
2472 |
comboBox->addItem(icon, text); |
|
2473 |
comboBox->setItemData((comboBox->count()-1), iconData, Qt::DecorationPropertyRole); |
|
2474 |
comboBox->setItemData((comboBox->count()-1), textData, Qt::DisplayPropertyRole); |
|
2475 |
} |
|
2476 |
||
2477 |
DomProperty *currentIndex = propertyMap(ui_widget->elementProperty()).value(strings.currentIndexProperty); |
|
2478 |
if (currentIndex) |
|
2479 |
comboBox->setCurrentIndex(currentIndex->elementNumber()); |
|
2480 |
} |
|
2481 |
||
2482 |
// Get the button group name out of a widget's attribute list |
|
2483 |
static QString buttonGroupName(const DomWidget *ui_widget) |
|
2484 |
{ |
|
2485 |
typedef QList<DomProperty*> DomPropertyList; |
|
2486 |
const DomPropertyList attributes = ui_widget->elementAttribute(); |
|
2487 |
if (attributes.empty()) |
|
2488 |
return QString(); |
|
2489 |
const QString buttonGroupProperty = QLatin1String(buttonGroupPropertyC); |
|
2490 |
const DomPropertyList::const_iterator cend = attributes.constEnd(); |
|
2491 |
for (DomPropertyList::const_iterator it = attributes.constBegin(); it != cend; ++it) |
|
2492 |
if ( (*it)->attributeName() == buttonGroupProperty) |
|
2493 |
return (*it)->elementString()->text(); |
|
2494 |
return QString(); |
|
2495 |
} |
|
2496 |
||
2497 |
/*! |
|
2498 |
\internal |
|
2499 |
\since 4.5 |
|
2500 |
*/ |
|
2501 |
||
2502 |
void QAbstractFormBuilder::loadButtonExtraInfo(const DomWidget *ui_widget, QAbstractButton *button, QWidget *) |
|
2503 |
{ |
|
2504 |
typedef QFormBuilderExtra::ButtonGroupEntry ButtonGroupEntry; |
|
2505 |
typedef QFormBuilderExtra::ButtonGroupHash ButtonGroupHash; |
|
2506 |
||
2507 |
const QString groupName = buttonGroupName(ui_widget); |
|
2508 |
if (groupName.isEmpty()) |
|
2509 |
return; |
|
2510 |
// Find entry |
|
2511 |
QFormBuilderExtra *extra = QFormBuilderExtra::instance(this); |
|
2512 |
ButtonGroupHash &buttonGroups = extra->buttonGroups(); |
|
2513 |
ButtonGroupHash::iterator it = buttonGroups.find(groupName); |
|
2514 |
if (it == buttonGroups.end()) { |
|
2515 |
#ifdef QFORMINTERNAL_NAMESPACE // Suppress the warning when copying in Designer |
|
2516 |
uiLibWarning(QCoreApplication::translate("QAbstractFormBuilder", "Invalid QButtonGroup reference '%1' referenced by '%2'.").arg(groupName, button->objectName())); |
|
2517 |
#endif |
|
2518 |
return; |
|
2519 |
} |
|
2520 |
// Create button group on demand? |
|
2521 |
QButtonGroup *&group = it.value().second; |
|
2522 |
if (group == 0) { |
|
2523 |
group = new QButtonGroup; |
|
2524 |
group->setObjectName(groupName); |
|
2525 |
applyProperties(group, it.value().first->elementProperty()); |
|
2526 |
} |
|
2527 |
group->addButton(button); |
|
2528 |
} |
|
2529 |
||
2530 |
/*! |
|
2531 |
\internal |
|
2532 |
\since 4.5 |
|
2533 |
*/ |
|
2534 |
void QAbstractFormBuilder::loadItemViewExtraInfo(DomWidget *ui_widget, QAbstractItemView *itemView, |
|
2535 |
QWidget *) |
|
2536 |
{ |
|
2537 |
// |
|
2538 |
// Special handling for qtableview/qtreeview fake header attributes |
|
2539 |
// |
|
2540 |
static QStringList realPropertyNames = |
|
2541 |
(QStringList() << QLatin1String("visible") |
|
2542 |
<< QLatin1String("cascadingSectionResizes") |
|
2543 |
<< QLatin1String("defaultSectionSize") |
|
2544 |
<< QLatin1String("highlightSections") |
|
2545 |
<< QLatin1String("minimumSectionSize") |
|
2546 |
<< QLatin1String("showSortIndicator") |
|
2547 |
<< QLatin1String("stretchLastSection")); |
|
2548 |
||
2549 |
if (QTreeView *treeView = qobject_cast<QTreeView*>(itemView)) { |
|
2550 |
QList<DomProperty*> allAttributes = ui_widget->elementAttribute(); |
|
2551 |
QList<DomProperty*> headerProperties; |
|
2552 |
foreach (const QString &realPropertyName, realPropertyNames) { |
|
2553 |
const QString upperPropertyName = realPropertyName.at(0).toUpper() |
|
2554 |
+ realPropertyName.mid(1); |
|
2555 |
const QString fakePropertyName = QLatin1String("header") + upperPropertyName; |
|
2556 |
foreach (DomProperty *attr, allAttributes) { |
|
2557 |
if (attr->attributeName() == fakePropertyName) { |
|
2558 |
attr->setAttributeName(realPropertyName); |
|
2559 |
headerProperties << attr; |
|
2560 |
} |
|
2561 |
} |
|
2562 |
} |
|
2563 |
applyProperties(treeView->header(), headerProperties); |
|
2564 |
} else if (QTableView *tableView = qobject_cast<QTableView*>(itemView)) { |
|
2565 |
static QStringList headerPrefixes = |
|
2566 |
(QStringList() << QLatin1String("horizontalHeader") |
|
2567 |
<< QLatin1String("verticalHeader")); |
|
2568 |
||
2569 |
QList<DomProperty*> allAttributes = ui_widget->elementAttribute(); |
|
2570 |
foreach (const QString &headerPrefix, headerPrefixes) { |
|
2571 |
QList<DomProperty*> headerProperties; |
|
2572 |
foreach (const QString &realPropertyName, realPropertyNames) { |
|
2573 |
const QString upperPropertyName = realPropertyName.at(0).toUpper() |
|
2574 |
+ realPropertyName.mid(1); |
|
2575 |
const QString fakePropertyName = headerPrefix + upperPropertyName; |
|
2576 |
foreach (DomProperty *attr, allAttributes) { |
|
2577 |
if (attr->attributeName() == fakePropertyName) { |
|
2578 |
attr->setAttributeName(realPropertyName); |
|
2579 |
headerProperties << attr; |
|
2580 |
} |
|
2581 |
} |
|
2582 |
} |
|
2583 |
if (headerPrefix == QLatin1String("horizontalHeader")) |
|
2584 |
applyProperties(tableView->horizontalHeader(), headerProperties); |
|
2585 |
else |
|
2586 |
applyProperties(tableView->verticalHeader(), headerProperties); |
|
2587 |
} |
|
2588 |
} |
|
2589 |
} |
|
2590 |
||
2591 |
/*! |
|
2592 |
\internal |
|
2593 |
*/ |
|
2594 |
void QAbstractFormBuilder::loadExtraInfo(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget) |
|
2595 |
{ |
|
2596 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
2597 |
if (0) { |
|
2598 |
#ifndef QT_NO_LISTWIDGET |
|
2599 |
} else if (QListWidget *listWidget = qobject_cast<QListWidget*>(widget)) { |
|
2600 |
loadListWidgetExtraInfo(ui_widget, listWidget, parentWidget); |
|
2601 |
#endif |
|
2602 |
#ifndef QT_NO_TREEWIDGET |
|
2603 |
} else if (QTreeWidget *treeWidget = qobject_cast<QTreeWidget*>(widget)) { |
|
2604 |
loadTreeWidgetExtraInfo(ui_widget, treeWidget, parentWidget); |
|
2605 |
#endif |
|
2606 |
#ifndef QT_NO_TABLEWIDGET |
|
2607 |
} else if (QTableWidget *tableWidget = qobject_cast<QTableWidget*>(widget)) { |
|
2608 |
loadTableWidgetExtraInfo(ui_widget, tableWidget, parentWidget); |
|
2609 |
#endif |
|
2610 |
#ifndef QT_NO_COMBOBOX |
|
2611 |
} else if (QComboBox *comboBox = qobject_cast<QComboBox*>(widget)) { |
|
2612 |
if (!qobject_cast<QFontComboBox *>(widget)) |
|
2613 |
loadComboBoxExtraInfo(ui_widget, comboBox, parentWidget); |
|
2614 |
#endif |
|
2615 |
#ifndef QT_NO_TABWIDGET |
|
2616 |
} else if (QTabWidget *tabWidget = qobject_cast<QTabWidget*>(widget)) { |
|
2617 |
const DomProperty *currentIndex = propertyMap(ui_widget->elementProperty()).value(strings.currentIndexProperty); |
|
2618 |
if (currentIndex) |
|
2619 |
tabWidget->setCurrentIndex(currentIndex->elementNumber()); |
|
2620 |
#endif |
|
2621 |
#ifndef QT_NO_STACKEDWIDGET |
|
2622 |
} else if (QStackedWidget *stackedWidget = qobject_cast<QStackedWidget*>(widget)) { |
|
2623 |
const DomProperty *currentIndex = propertyMap(ui_widget->elementProperty()).value(strings.currentIndexProperty); |
|
2624 |
if (currentIndex) |
|
2625 |
stackedWidget->setCurrentIndex(currentIndex->elementNumber()); |
|
2626 |
#endif |
|
2627 |
#ifndef QT_NO_TOOLBOX |
|
2628 |
} else if (QToolBox *toolBox = qobject_cast<QToolBox*>(widget)) { |
|
2629 |
const DomProperty *currentIndex = propertyMap(ui_widget->elementProperty()).value(strings.currentIndexProperty); |
|
2630 |
if (currentIndex) |
|
2631 |
toolBox->setCurrentIndex(currentIndex->elementNumber()); |
|
2632 |
const DomProperty *tabSpacing = propertyMap(ui_widget->elementProperty()).value(strings.tabSpacingProperty); |
|
2633 |
if (tabSpacing) |
|
2634 |
toolBox->layout()->setSpacing(tabSpacing->elementNumber()); |
|
2635 |
#endif |
|
2636 |
} else if (QAbstractButton *ab = qobject_cast<QAbstractButton *>(widget)) { |
|
2637 |
loadButtonExtraInfo(ui_widget, ab, parentWidget); |
|
2638 |
} |
|
2639 |
if (QAbstractItemView *itemView = qobject_cast<QAbstractItemView *>(widget)) { |
|
2640 |
loadItemViewExtraInfo(ui_widget, itemView, parentWidget); |
|
2641 |
} |
|
2642 |
} |
|
2643 |
||
2644 |
/*! |
|
2645 |
\internal |
|
2646 |
*/ |
|
2647 |
QIcon QAbstractFormBuilder::nameToIcon(const QString &filePath, const QString &qrcPath) |
|
2648 |
{ |
|
2649 |
Q_UNUSED(filePath) |
|
2650 |
Q_UNUSED(qrcPath) |
|
2651 |
qWarning() << "QAbstractFormBuilder::nameToIcon() is obsoleted"; |
|
2652 |
return QIcon(); |
|
2653 |
} |
|
2654 |
||
2655 |
/*! |
|
2656 |
\internal |
|
2657 |
*/ |
|
2658 |
QString QAbstractFormBuilder::iconToFilePath(const QIcon &pm) const |
|
2659 |
{ |
|
2660 |
Q_UNUSED(pm) |
|
2661 |
qWarning() << "QAbstractFormBuilder::iconToFilePath() is obsoleted"; |
|
2662 |
return QString(); |
|
2663 |
} |
|
2664 |
||
2665 |
/*! |
|
2666 |
\internal |
|
2667 |
*/ |
|
2668 |
QString QAbstractFormBuilder::iconToQrcPath(const QIcon &pm) const |
|
2669 |
{ |
|
2670 |
Q_UNUSED(pm) |
|
2671 |
qWarning() << "QAbstractFormBuilder::iconToQrcPath() is obsoleted"; |
|
2672 |
return QString(); |
|
2673 |
} |
|
2674 |
||
2675 |
/*! |
|
2676 |
\internal |
|
2677 |
*/ |
|
2678 |
QPixmap QAbstractFormBuilder::nameToPixmap(const QString &filePath, const QString &qrcPath) |
|
2679 |
{ |
|
2680 |
Q_UNUSED(filePath) |
|
2681 |
Q_UNUSED(qrcPath) |
|
2682 |
qWarning() << "QAbstractFormBuilder::nameToPixmap() is obsoleted"; |
|
2683 |
return QPixmap(); |
|
2684 |
} |
|
2685 |
||
2686 |
/*! |
|
2687 |
\internal |
|
2688 |
*/ |
|
2689 |
QString QAbstractFormBuilder::pixmapToFilePath(const QPixmap &pm) const |
|
2690 |
{ |
|
2691 |
Q_UNUSED(pm) |
|
2692 |
qWarning() << "QAbstractFormBuilder::pixmapToFilePath() is obsoleted"; |
|
2693 |
return QString(); |
|
2694 |
} |
|
2695 |
||
2696 |
/*! |
|
2697 |
\internal |
|
2698 |
*/ |
|
2699 |
QString QAbstractFormBuilder::pixmapToQrcPath(const QPixmap &pm) const |
|
2700 |
{ |
|
2701 |
Q_UNUSED(pm) |
|
2702 |
qWarning() << "QAbstractFormBuilder::pixmapToQrcPath() is obsoleted"; |
|
2703 |
return QString(); |
|
2704 |
} |
|
2705 |
||
2706 |
/*! |
|
2707 |
Returns the current working directory of the form builder. |
|
2708 |
||
2709 |
\sa setWorkingDirectory() */ |
|
2710 |
QDir QAbstractFormBuilder::workingDirectory() const |
|
2711 |
{ |
|
2712 |
return m_workingDirectory; |
|
2713 |
} |
|
2714 |
||
2715 |
/*! |
|
2716 |
Sets the current working directory of the form builder to the |
|
2717 |
specified \a directory. |
|
2718 |
||
2719 |
\sa workingDirectory()*/ |
|
2720 |
void QAbstractFormBuilder::setWorkingDirectory(const QDir &directory) |
|
2721 |
{ |
|
2722 |
m_workingDirectory = directory; |
|
2723 |
} |
|
2724 |
||
2725 |
/*! |
|
2726 |
\internal |
|
2727 |
*/ |
|
2728 |
DomAction *QAbstractFormBuilder::createDom(QAction *action) |
|
2729 |
{ |
|
2730 |
if (action->parentWidget() == action->menu() || action->isSeparator()) |
|
2731 |
return 0; |
|
2732 |
||
2733 |
DomAction *ui_action = new DomAction; |
|
2734 |
ui_action->setAttributeName(action->objectName()); |
|
2735 |
||
2736 |
const QList<DomProperty*> properties = computeProperties(action); |
|
2737 |
ui_action->setElementProperty(properties); |
|
2738 |
||
2739 |
return ui_action; |
|
2740 |
} |
|
2741 |
||
2742 |
/*! |
|
2743 |
\internal |
|
2744 |
\since 4.5 |
|
2745 |
*/ |
|
2746 |
||
2747 |
DomButtonGroup *QAbstractFormBuilder::createDom(QButtonGroup *buttonGroup) |
|
2748 |
{ |
|
2749 |
if (buttonGroup->buttons().count() == 0) // Empty group left over on form? |
|
2750 |
return 0; |
|
2751 |
DomButtonGroup *domButtonGroup = new DomButtonGroup; |
|
2752 |
domButtonGroup->setAttributeName(buttonGroup->objectName()); |
|
2753 |
||
2754 |
QList<DomProperty*> properties = computeProperties(buttonGroup); |
|
2755 |
domButtonGroup->setElementProperty(properties); |
|
2756 |
return domButtonGroup; |
|
2757 |
} |
|
2758 |
||
2759 |
/*! |
|
2760 |
\internal |
|
2761 |
*/ |
|
2762 |
DomActionGroup *QAbstractFormBuilder::createDom(QActionGroup *actionGroup) |
|
2763 |
{ |
|
2764 |
DomActionGroup *ui_action_group = new DomActionGroup; |
|
2765 |
ui_action_group->setAttributeName(actionGroup->objectName()); |
|
2766 |
||
2767 |
QList<DomProperty*> properties = computeProperties(actionGroup); |
|
2768 |
ui_action_group->setElementProperty(properties); |
|
2769 |
||
2770 |
QList<DomAction*> ui_actions; |
|
2771 |
||
2772 |
foreach (QAction *action, actionGroup->actions()) { |
|
2773 |
if (DomAction *ui_action = createDom(action)) { |
|
2774 |
ui_actions.append(ui_action); |
|
2775 |
} |
|
2776 |
} |
|
2777 |
||
2778 |
ui_action_group->setElementAction(ui_actions); |
|
2779 |
||
2780 |
return ui_action_group; |
|
2781 |
} |
|
2782 |
||
2783 |
/*! |
|
2784 |
\internal |
|
2785 |
*/ |
|
2786 |
void QAbstractFormBuilder::addMenuAction(QAction *action) |
|
2787 |
{ |
|
2788 |
Q_UNUSED(action); |
|
2789 |
} |
|
2790 |
||
2791 |
/*! |
|
2792 |
\internal |
|
2793 |
*/ |
|
2794 |
void QAbstractFormBuilder::reset() |
|
2795 |
{ |
|
2796 |
m_laidout.clear(); |
|
2797 |
m_actions.clear(); |
|
2798 |
m_actionGroups.clear(); |
|
2799 |
m_defaultMargin = INT_MIN; |
|
2800 |
m_defaultSpacing = INT_MIN; |
|
2801 |
} |
|
2802 |
||
2803 |
/*! |
|
2804 |
\internal |
|
2805 |
Access meta enumeration for Qt::ToolBarArea |
|
2806 |
*/ |
|
2807 |
||
2808 |
QMetaEnum QAbstractFormBuilder::toolBarAreaMetaEnum() |
|
2809 |
{ |
|
2810 |
return metaEnum<QAbstractFormBuilderGadget>("toolBarArea"); |
|
2811 |
} |
|
2812 |
||
2813 |
/*! |
|
2814 |
\internal |
|
2815 |
Return paths of an icon. |
|
2816 |
*/ |
|
2817 |
||
2818 |
QAbstractFormBuilder::IconPaths QAbstractFormBuilder::iconPaths(const QIcon &icon) const |
|
2819 |
{ |
|
2820 |
Q_UNUSED(icon); |
|
2821 |
qWarning() << "QAbstractFormBuilder::iconPaths() is obsoleted"; |
|
2822 |
return IconPaths(); |
|
2823 |
} |
|
2824 |
||
2825 |
/*! |
|
2826 |
\internal |
|
2827 |
Return paths of a pixmap. |
|
2828 |
*/ |
|
2829 |
||
2830 |
QAbstractFormBuilder::IconPaths QAbstractFormBuilder::pixmapPaths(const QPixmap &pixmap) const |
|
2831 |
{ |
|
2832 |
Q_UNUSED(pixmap); |
|
2833 |
qWarning() << "QAbstractFormBuilder::pixmapPaths() is obsoleted"; |
|
2834 |
return IconPaths(); |
|
2835 |
} |
|
2836 |
||
2837 |
/*! |
|
2838 |
\internal |
|
2839 |
Set up a DOM property with icon. |
|
2840 |
*/ |
|
2841 |
||
2842 |
void QAbstractFormBuilder::setIconProperty(DomProperty &p, const IconPaths &ip) const |
|
2843 |
{ |
|
2844 |
DomResourceIcon *dpi = new DomResourceIcon; |
|
2845 |
||
2846 |
/* TODO |
|
2847 |
if (!ip.second.isEmpty()) |
|
2848 |
pix->setAttributeResource(ip.second); |
|
2849 |
*/ |
|
2850 |
dpi->setText(ip.first); |
|
2851 |
||
2852 |
p.setAttributeName(QFormBuilderStrings::instance().iconAttribute); |
|
2853 |
p.setElementIconSet(dpi); |
|
2854 |
} |
|
2855 |
||
2856 |
/*! |
|
2857 |
\internal |
|
2858 |
Set up a DOM property with pixmap. |
|
2859 |
*/ |
|
2860 |
||
2861 |
void QAbstractFormBuilder::setPixmapProperty(DomProperty &p, const IconPaths &ip) const |
|
2862 |
{ |
|
2863 |
DomResourcePixmap *pix = new DomResourcePixmap; |
|
2864 |
if (!ip.second.isEmpty()) |
|
2865 |
pix->setAttributeResource(ip.second); |
|
2866 |
||
2867 |
pix->setText(ip.first); |
|
2868 |
||
2869 |
p.setAttributeName(QFormBuilderStrings::instance().pixmapAttribute); |
|
2870 |
p.setElementPixmap(pix); |
|
2871 |
} |
|
2872 |
||
2873 |
/*! |
|
2874 |
\internal |
|
2875 |
Convenience. Return DOM property for icon; 0 if icon.isNull(). |
|
2876 |
*/ |
|
2877 |
||
2878 |
DomProperty* QAbstractFormBuilder::iconToDomProperty(const QIcon &icon) const |
|
2879 |
{ |
|
2880 |
Q_UNUSED(icon); |
|
2881 |
qWarning() << "QAbstractFormBuilder::iconToDomProperty() is obsoleted"; |
|
2882 |
return 0; |
|
2883 |
} |
|
2884 |
||
2885 |
/*! |
|
2886 |
\internal |
|
2887 |
\since 4.4 |
|
2888 |
*/ |
|
2889 |
||
2890 |
DomProperty *QAbstractFormBuilder::saveResource(const QVariant &v) const |
|
2891 |
{ |
|
2892 |
if (v.isNull()) |
|
2893 |
return 0; |
|
2894 |
||
2895 |
DomProperty *p = resourceBuilder()->saveResource(workingDirectory(), v); |
|
2896 |
if (p) |
|
2897 |
p->setAttributeName(QFormBuilderStrings::instance().iconAttribute); |
|
2898 |
return p; |
|
2899 |
} |
|
2900 |
||
2901 |
/*! |
|
2902 |
\internal |
|
2903 |
\since 4.5 |
|
2904 |
*/ |
|
2905 |
||
2906 |
DomProperty *QAbstractFormBuilder::saveText(const QString &attributeName, const QVariant &v) const |
|
2907 |
{ |
|
2908 |
if (v.isNull()) |
|
2909 |
return 0; |
|
2910 |
||
2911 |
DomProperty *p = textBuilder()->saveText(v); |
|
2912 |
if (p) |
|
2913 |
p->setAttributeName(attributeName); |
|
2914 |
return p; |
|
2915 |
} |
|
2916 |
||
2917 |
/*! |
|
2918 |
\internal |
|
2919 |
Return the appropriate DOM pixmap for an image dom property. |
|
2920 |
From 4.4 - unused |
|
2921 |
*/ |
|
2922 |
||
2923 |
const DomResourcePixmap *QAbstractFormBuilder::domPixmap(const DomProperty* p) { |
|
2924 |
switch (p->kind()) { |
|
2925 |
case DomProperty::IconSet: |
|
2926 |
qDebug() << "** WARNING QAbstractFormBuilder::domPixmap() called for icon set!"; |
|
2927 |
break; |
|
2928 |
case DomProperty::Pixmap: |
|
2929 |
return p->elementPixmap(); |
|
2930 |
default: |
|
2931 |
break; |
|
2932 |
} |
|
2933 |
return 0; |
|
2934 |
} |
|
2935 |
||
2936 |
/*! |
|
2937 |
\internal |
|
2938 |
Create icon from DOM. |
|
2939 |
From 4.4 - unused |
|
2940 |
*/ |
|
2941 |
||
2942 |
QIcon QAbstractFormBuilder::domPropertyToIcon(const DomResourcePixmap *icon) |
|
2943 |
{ |
|
2944 |
Q_UNUSED(icon); |
|
2945 |
qWarning() << "QAbstractFormBuilder::domPropertyToIcon() is obsoleted"; |
|
2946 |
return QIcon(); |
|
2947 |
} |
|
2948 |
||
2949 |
/*! |
|
2950 |
\internal |
|
2951 |
Create icon from DOM. Assert if !domPixmap |
|
2952 |
From 4.4 - unused |
|
2953 |
*/ |
|
2954 |
||
2955 |
QIcon QAbstractFormBuilder::domPropertyToIcon(const DomProperty* p) |
|
2956 |
{ |
|
2957 |
Q_UNUSED(p); |
|
2958 |
qWarning() << "QAbstractFormBuilder::domPropertyToIcon() is obsoleted"; |
|
2959 |
return QIcon(); |
|
2960 |
} |
|
2961 |
||
2962 |
||
2963 |
/*! |
|
2964 |
\internal |
|
2965 |
Create pixmap from DOM. |
|
2966 |
From 4.4 - unused |
|
2967 |
*/ |
|
2968 |
||
2969 |
QPixmap QAbstractFormBuilder::domPropertyToPixmap(const DomResourcePixmap* pixmap) |
|
2970 |
{ |
|
2971 |
Q_UNUSED(pixmap); |
|
2972 |
qWarning() << "QAbstractFormBuilder::domPropertyToPixmap() is obsoleted"; |
|
2973 |
return QPixmap(); |
|
2974 |
} |
|
2975 |
||
2976 |
||
2977 |
/*! |
|
2978 |
\internal |
|
2979 |
Create pixmap from DOM. Assert if !domPixmap |
|
2980 |
From 4.4 - unused |
|
2981 |
*/ |
|
2982 |
||
2983 |
QPixmap QAbstractFormBuilder::domPropertyToPixmap(const DomProperty* p) |
|
2984 |
{ |
|
2985 |
Q_UNUSED(p); |
|
2986 |
qWarning() << "QAbstractFormBuilder::domPropertyToPixmap() is obsoleted"; |
|
2987 |
return QPixmap(); |
|
2988 |
} |
|
2989 |
||
2990 |
/*! |
|
2991 |
\fn void QAbstractFormBuilder::createConnections ( DomConnections *, QWidget * ) |
|
2992 |
\internal |
|
2993 |
*/ |
|
2994 |
||
2995 |
/*! |
|
2996 |
\fn void QAbstractFormBuilder::createCustomWidgets ( DomCustomWidgets * ) |
|
2997 |
\internal |
|
2998 |
*/ |
|
2999 |
||
3000 |
/*! |
|
3001 |
\fn void QAbstractFormBuilder::createResources ( DomResources * ) |
|
3002 |
\internal |
|
3003 |
*/ |
|
3004 |
||
3005 |
/*! |
|
3006 |
\fn QFormScriptRunner *QAbstractFormBuilder::formScriptRunner() const |
|
3007 |
\internal |
|
3008 |
\since 4.3 |
|
3009 |
*/ |
|
3010 |
#ifndef QT_FORMBUILDER_NO_SCRIPT |
|
3011 |
QFormScriptRunner *QAbstractFormBuilder::formScriptRunner() const |
|
3012 |
{ |
|
3013 |
return &(QFormBuilderExtra::instance(this)->formScriptRunner()); |
|
3014 |
} |
|
3015 |
#endif |
|
3016 |
||
3017 |
/*! |
|
3018 |
Sets whether the execution of scripts is enabled to \a enabled. |
|
3019 |
\since 4.3 |
|
3020 |
\internal |
|
3021 |
*/ |
|
3022 |
||
3023 |
void QAbstractFormBuilder::setScriptingEnabled(bool enabled) |
|
3024 |
{ |
|
3025 |
#ifdef QT_FORMBUILDER_NO_SCRIPT |
|
3026 |
if (enabled) |
|
3027 |
uiLibWarning(QCoreApplication::translate("QAbstractFormBuilder", "This version of the uitools library is linked without script support.")); |
|
3028 |
#else |
|
3029 |
QFormScriptRunner::Options options = formScriptRunner()->options(); |
|
3030 |
if (enabled) |
|
3031 |
options &= ~QFormScriptRunner::DisableScripts; |
|
3032 |
else |
|
3033 |
options |= QFormScriptRunner::DisableScripts; |
|
3034 |
formScriptRunner()->setOptions(options); |
|
3035 |
#endif |
|
3036 |
} |
|
3037 |
||
3038 |
/*! |
|
3039 |
Returns whether the execution of scripts is enabled. |
|
3040 |
\sa setScriptingEnabled() |
|
3041 |
\since 4.3 |
|
3042 |
\internal |
|
3043 |
*/ |
|
3044 |
||
3045 |
bool QAbstractFormBuilder::isScriptingEnabled() const |
|
3046 |
{ |
|
3047 |
#ifdef QT_FORMBUILDER_NO_SCRIPT |
|
3048 |
return false; |
|
3049 |
#else |
|
3050 |
return !(formScriptRunner()->options() & QFormScriptRunner::DisableScripts); |
|
3051 |
#endif |
|
3052 |
} |
|
3053 |
||
3054 |
QT_END_NAMESPACE |