1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Designer of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "abstractformwindowmanager.h"
43 
44 #include <QtCore/QMap>
45 
46 QT_BEGIN_NAMESPACE
47 
48 /*!
49     \class QDesignerFormWindowManagerInterface
50 
51     \brief The QDesignerFormWindowManagerInterface class allows you to
52     manipulate the collection of form windows in Qt Designer, and
53     control Qt Designer's form editing actions.
54 
55     \inmodule QtDesigner
56 
57     QDesignerFormWindowManagerInterface is not intended to be
58     instantiated directly. \QD uses the form window manager to
59     control the various form windows in its workspace. You can
60     retrieve an interface to \QD's form window manager using
61     the QDesignerFormEditorInterface::formWindowManager()
62     function. For example:
63 
64     \snippet doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowmanager.cpp 0
65 
66     When implementing a custom widget plugin, a pointer to \QD's
67     current QDesignerFormEditorInterface object (\c formEditor in the
68     example above) is provided by the
69     QDesignerCustomWidgetInterface::initialize() function's parameter.
70     You must subclass the QDesignerCustomWidgetInterface to expose
71     your plugin to Qt Designer.
72 
73     The form window manager interface provides the createFormWindow()
74     function that enables you to create a new form window which you
75     can add to the collection of form windows that the manager
76     maintains, using the addFormWindow() slot. It also provides the
77     formWindowCount() function returning the number of form windows
78     currently under the manager's control, the formWindow() function
79     returning the form window associated with a given index, and the
80     activeFormWindow() function returning the currently selected form
81     window. The removeFormWindow() slot allows you to reduce the
82     number of form windows the manager must maintain, and the
83     setActiveFormWindow() slot allows you to change the form window
84     focus in \QD's workspace.
85 
86     In addition, QDesignerFormWindowManagerInterface contains a
87     collection of functions that enables you to intervene and control
88     \QD's form editing actions. All these functions return the
89     original action, making it possible to propagate the function
90     further after intervention.
91 
92     Finally, the interface provides three signals which are emitted
93     when a form window is added, when the currently selected form
94     window changes, or when a form window is removed, respectively. All
95     the signals carry the form window in question as their parameter.
96 
97     \sa QDesignerFormEditorInterface, QDesignerFormWindowInterface
98 */
99 
100 // ------------- QDesignerFormWindowManagerInterfacePrivate
101 
102 struct QDesignerFormWindowManagerInterfacePrivate {
103     QDesignerFormWindowManagerInterfacePrivate();
104     QAction *m_simplifyLayoutAction;
105     QAction *m_formLayoutAction;
106 };
107 
QDesignerFormWindowManagerInterfacePrivate()108 QDesignerFormWindowManagerInterfacePrivate::QDesignerFormWindowManagerInterfacePrivate() :
109     m_simplifyLayoutAction(0),
110     m_formLayoutAction(0)
111 {
112 }
113 
114 typedef QMap<const QDesignerFormWindowManagerInterface *, QDesignerFormWindowManagerInterfacePrivate *> FormWindowManagerPrivateMap;
115 
Q_GLOBAL_STATIC(FormWindowManagerPrivateMap,g_FormWindowManagerPrivateMap)116 Q_GLOBAL_STATIC(FormWindowManagerPrivateMap, g_FormWindowManagerPrivateMap)
117 
118 /*!
119     Constructs an interface with the given \a parent for the form window
120     manager.
121 */
122 QDesignerFormWindowManagerInterface::QDesignerFormWindowManagerInterface(QObject *parent)
123     : QObject(parent)
124 {
125     g_FormWindowManagerPrivateMap()->insert(this, new QDesignerFormWindowManagerInterfacePrivate);
126 }
127 
128 /*!
129     Destroys the interface for the form window manager.
130 */
~QDesignerFormWindowManagerInterface()131 QDesignerFormWindowManagerInterface::~QDesignerFormWindowManagerInterface()
132 {
133     FormWindowManagerPrivateMap *fwmpm = g_FormWindowManagerPrivateMap();
134     const FormWindowManagerPrivateMap::iterator it = fwmpm->find(this);
135     Q_ASSERT(it !=  fwmpm->end());
136     delete it.value();
137     fwmpm->erase(it);
138 }
139 
140 /*!
141     Allows you to intervene and control \QD's "cut" action. The function
142     returns the original action.
143 
144     \sa QAction
145 */
actionCut() const146 QAction *QDesignerFormWindowManagerInterface::actionCut() const
147 {
148     return 0;
149 }
150 
151 /*!
152     Allows you to intervene and control \QD's "copy" action. The
153     function returns the original action.
154 
155     \sa QAction
156 */
actionCopy() const157 QAction *QDesignerFormWindowManagerInterface::actionCopy() const
158 {
159     return 0;
160 }
161 
162 /*!
163     Allows you to intervene and control \QD's "paste" action. The
164     function returns the original action.
165 
166     \sa QAction
167 */
actionPaste() const168 QAction *QDesignerFormWindowManagerInterface::actionPaste() const
169 {
170     return 0;
171 }
172 
173 /*!
174     Allows you to intervene and control \QD's "delete" action. The function
175     returns the original action.
176 
177     \sa QAction
178 */
actionDelete() const179 QAction *QDesignerFormWindowManagerInterface::actionDelete() const
180 {
181     return 0;
182 }
183 
184 /*!
185     Allows you to intervene and control \QD's "select all" action. The
186     function returns the original action.
187 
188     \sa QAction
189 */
actionSelectAll() const190 QAction *QDesignerFormWindowManagerInterface::actionSelectAll() const
191 {
192     return 0;
193 }
194 
195 /*!
196     Allows you to intervene and control the action of lowering a form
197     window in \QD's workspace. The function returns the original
198     action.
199 
200     \sa QAction
201 */
actionLower() const202 QAction *QDesignerFormWindowManagerInterface::actionLower() const
203 {
204     return 0;
205 }
206 
207 /*!
208     Allows you to intervene and control the action of raising of a
209     form window in \QD's workspace. The function returns the original
210     action.
211 
212     \sa QAction
213 */
actionRaise() const214 QAction *QDesignerFormWindowManagerInterface::actionRaise() const
215 {
216     return 0;
217 }
218 
219 /*!
220     Allows you to intervene and control a request for horizontal
221     layout for a form window in \QD's workspace. The function returns
222     the original action.
223 
224     \sa QAction
225 */
actionHorizontalLayout() const226 QAction *QDesignerFormWindowManagerInterface::actionHorizontalLayout() const
227 {
228     return 0;
229 }
230 
231 /*!
232     Allows you to intervene and control a request for vertical layout
233     for a form window in \QD's workspace. The function returns the
234     original action.
235 
236     \sa QAction
237 */
actionVerticalLayout() const238 QAction *QDesignerFormWindowManagerInterface::actionVerticalLayout() const
239 {
240     return 0;
241 }
242 
243 /*!
244     Allows you to intervene and control \QD's "split horizontal"
245     action. The function returns the original action.
246 
247     \sa QAction
248 */
actionSplitHorizontal() const249 QAction *QDesignerFormWindowManagerInterface::actionSplitHorizontal() const
250 {
251     return 0;
252 }
253 
254 /*!
255     Allows you to intervene and control \QD's "split vertical"
256     action. The function returns the original action.
257 
258     \sa QAction
259 */
actionSplitVertical() const260 QAction *QDesignerFormWindowManagerInterface::actionSplitVertical() const
261 {
262     return 0;
263 }
264 
265 /*!
266     Allows you to intervene and control a request for grid layout for
267     a form window in \QD's workspace. The function returns the
268     original action.
269 
270     \sa QAction
271 */
actionGridLayout() const272 QAction *QDesignerFormWindowManagerInterface::actionGridLayout() const
273 {
274     return 0;
275 }
276 
277 /*!
278     Allows you to intervene and control \QD's "form layout" action. The
279     function returns the original action.
280 
281 FormWindowManagerPrivateMap *fwmpm = g_FormWindowManagerPrivateMap();    \sa QAction
282     \since 4.4
283 */
284 
actionFormLayout() const285 QAction *QDesignerFormWindowManagerInterface::actionFormLayout() const
286 {
287     const QDesignerFormWindowManagerInterfacePrivate *d = g_FormWindowManagerPrivateMap()->value(this);
288     Q_ASSERT(d);
289     return d->m_formLayoutAction;
290 }
291 
292 /*!
293     Sets the "form layout" action to \a action.
294 
295     \internal
296     \since 4.4
297 */
298 
setActionFormLayout(QAction * action)299 void QDesignerFormWindowManagerInterface::setActionFormLayout(QAction *action)
300 {
301     QDesignerFormWindowManagerInterfacePrivate *d = g_FormWindowManagerPrivateMap()->value(this);
302     Q_ASSERT(d);
303     d->m_formLayoutAction = action;
304 }
305 
306 /*!
307     Allows you to intervene and control \QD's "break layout" action. The
308     function returns the original action.
309 
310     \sa QAction
311 */
actionBreakLayout() const312 QAction *QDesignerFormWindowManagerInterface::actionBreakLayout() const
313 {
314     return 0;
315 }
316 
317 /*!
318     Allows you to intervene and control \QD's "adjust size" action. The
319     function returns the original action.
320 
321     \sa QAction
322 */
actionAdjustSize() const323 QAction *QDesignerFormWindowManagerInterface::actionAdjustSize() const
324 {
325     return 0;
326 }
327 
328 /*!
329     Allows you to intervene and control \QD's "simplify layout" action. The
330     function returns the original action.
331 
332     \sa QAction
333     \since 4.4
334 */
335 
actionSimplifyLayout() const336 QAction *QDesignerFormWindowManagerInterface::actionSimplifyLayout() const
337 {
338     const QDesignerFormWindowManagerInterfacePrivate *d = g_FormWindowManagerPrivateMap()->value(this);
339     Q_ASSERT(d);
340     return d->m_simplifyLayoutAction;
341 }
342 
343 /*!
344     Sets the "simplify layout" action to \a action.
345 
346     \internal
347     \since 4.4
348 */
349 
setActionSimplifyLayout(QAction * action)350 void QDesignerFormWindowManagerInterface::setActionSimplifyLayout(QAction *action)
351 {
352     QDesignerFormWindowManagerInterfacePrivate *d = g_FormWindowManagerPrivateMap()->value(this);
353     Q_ASSERT(d);
354     d->m_simplifyLayoutAction = action;
355 }
356 
357 /*!
358    Returns the currently active form window in \QD's workspace.
359 
360    \sa setActiveFormWindow(), removeFormWindow()
361 */
activeFormWindow() const362 QDesignerFormWindowInterface *QDesignerFormWindowManagerInterface::activeFormWindow() const
363 {
364     return 0;
365 }
366 
367 /*!
368     Returns a pointer to \QD's current QDesignerFormEditorInterface
369     object.
370 */
core() const371 QDesignerFormEditorInterface *QDesignerFormWindowManagerInterface::core() const
372 {
373     return 0;
374 }
375 
376 /*!
377    Adds the given \a formWindow to the collection of windows that
378    \QD's form window manager maintains.
379 
380    \sa formWindowAdded()
381 */
addFormWindow(QDesignerFormWindowInterface * formWindow)382 void QDesignerFormWindowManagerInterface::addFormWindow(QDesignerFormWindowInterface *formWindow)
383 {
384     Q_UNUSED(formWindow);
385 }
386 
387 /*!
388    Removes the given \a formWindow from the collection of windows that
389    \QD's form window manager maintains.
390 
391    \sa formWindow(), formWindowRemoved()
392 */
removeFormWindow(QDesignerFormWindowInterface * formWindow)393 void QDesignerFormWindowManagerInterface::removeFormWindow(QDesignerFormWindowInterface *formWindow)
394 {
395     Q_UNUSED(formWindow);
396 }
397 
398 /*!
399    Sets the given \a formWindow to be the currently active form window in
400    \QD's workspace.
401 
402    \sa activeFormWindow(), activeFormWindowChanged()
403 */
setActiveFormWindow(QDesignerFormWindowInterface * formWindow)404 void QDesignerFormWindowManagerInterface::setActiveFormWindow(QDesignerFormWindowInterface *formWindow)
405 {
406     Q_UNUSED(formWindow);
407 }
408 
409 /*!
410    Returns the number of form windows maintained by \QD's form window
411    manager.
412 */
formWindowCount() const413 int QDesignerFormWindowManagerInterface::formWindowCount() const
414 {
415     return 0;
416 }
417 
418 /*!
419    Returns the form window at the given \a index.
420 
421    \sa setActiveFormWindow(), removeFormWindow()
422 */
formWindow(int index) const423 QDesignerFormWindowInterface *QDesignerFormWindowManagerInterface::formWindow(int index) const
424 {
425     Q_UNUSED(index);
426     return 0;
427 }
428 
429 /*!
430   \fn QDesignerFormWindowInterface *QDesignerFormWindowManagerInterface::createFormWindow(QWidget *parent, Qt::WindowFlags flags)
431 
432    Creates a form window with the given \a parent and the given window
433    \a flags.
434 
435    \sa addFormWindow()
436 */
createFormWindow(QWidget * parentWidget,Qt::WindowFlags flags)437 QDesignerFormWindowInterface *QDesignerFormWindowManagerInterface::createFormWindow(QWidget *parentWidget, Qt::WindowFlags flags)
438 {
439     Q_UNUSED(parentWidget);
440     Q_UNUSED(flags);
441     return 0;
442 }
443 
444 /*!
445     Allows you to intervene and control \QD's "undo" action. The
446     function returns the original action.
447 
448     \sa QAction
449 */
actionUndo() const450 QAction *QDesignerFormWindowManagerInterface::actionUndo() const
451 {
452     return 0;
453 }
454 
455 /*!
456     Allows you to intervene and control \QD's "redo" action. The
457     function returns the original action.
458 
459     \sa QAction
460 */
actionRedo() const461 QAction *QDesignerFormWindowManagerInterface::actionRedo() const
462 {
463     return 0;
464 }
465 
466 /*!
467     \fn void QDesignerFormWindowManagerInterface::formWindowAdded(QDesignerFormWindowInterface *formWindow)
468 
469     This signal is emitted when a new form window is added to the
470     collection of windows that \QD's form window manager maintains. A
471     pointer to the new \a formWindow is passed as an argument.
472 
473     \sa addFormWindow(), setActiveFormWindow()
474 */
475 
476 /*!
477     \fn void QDesignerFormWindowManagerInterface::formWindowRemoved(QDesignerFormWindowInterface *formWindow)
478 
479     This signal is emitted when a form window is removed from the
480     collection of windows that \QD's form window manager maintains. A
481     pointer to the removed \a formWindow is passed as an argument.
482 
483     \sa removeFormWindow()
484 */
485 
486 /*!
487     \fn void QDesignerFormWindowManagerInterface::activeFormWindowChanged(QDesignerFormWindowInterface *formWindow)
488 
489     This signal is emitted when the contents of the currently active
490     form window in \QD's workspace changed. A pointer to the currently
491     active \a formWindow is passed as an argument.
492 
493     \sa activeFormWindow()
494 */
495 
496 /*!
497     \fn void QDesignerFormWindowManagerInterface::dragItems(const QList<QDesignerDnDItemInterface*> &item_list)
498 
499     \internal
500 */
501 
502 QT_END_NAMESPACE
503