1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
|
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Designer of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of Qt Designer. This header
// file may change from version to version without notice, or even be removed.
//
// We mean it.
//
#ifndef QDESIGNER_COMMAND_H
#define QDESIGNER_COMMAND_H
#include "shared_global_p.h"
#include "shared_enums_p.h"
#include "layoutinfo_p.h"
#include "qdesigner_utils_p.h"
#include "qdesigner_formwindowcommand_p.h"
#include "qdesigner_formeditorcommand_p.h"
#include <QtDesigner/layoutdecoration.h>
#include <QtGui/QIcon>
#include <QtCore/QObject>
#include <QtCore/QPair>
#include <QtCore/QMap>
#include <QtCore/QHash>
#include <QtCore/QPoint>
#include <QtCore/QRect>
QT_BEGIN_NAMESPACE
class QDesignerContainerExtension;
class QDesignerMetaDataBaseItemInterface;
class QDesignerMenu;
class QMenuBar;
class QStatusBar;
class QToolBar;
class QToolBox;
class QTabWidget;
class QTableWidget;
class QTableWidgetItem;
class QTreeWidget;
class QTreeWidgetItem;
class QListWidget;
class QListWidgetItem;
class QComboBox;
class QStackedWidget;
class QDockWidget;
class QMainWindow;
class QFormLayout;
namespace qdesigner_internal {
class Layout;
class LayoutHelper;
class PropertySheetIconValue;
class DesignerIconCache;
struct LayoutProperties;
class QDESIGNER_SHARED_EXPORT InsertWidgetCommand: public QDesignerFormWindowCommand
{
public:
explicit InsertWidgetCommand(QDesignerFormWindowInterface *formWindow);
~InsertWidgetCommand();
void init(QWidget *widget, bool already_in_form = false, int layoutRow = -1, int layoutColumn = -1);
virtual void redo();
virtual void undo();
private:
void refreshBuddyLabels();
QPointer<QWidget> m_widget;
QDesignerLayoutDecorationExtension::InsertMode m_insertMode;
QPair<int, int> m_cell;
LayoutHelper* m_layoutHelper;
bool m_widgetWasManaged;
};
class QDESIGNER_SHARED_EXPORT ChangeZOrderCommand: public QDesignerFormWindowCommand
{
public:
explicit ChangeZOrderCommand(QDesignerFormWindowInterface *formWindow);
void init(QWidget *widget);
virtual void redo();
virtual void undo();
protected:
virtual QWidgetList reorderWidget(const QWidgetList &list, QWidget *widget) const = 0;
virtual void reorder(QWidget *widget) const = 0;
private:
QPointer<QWidget> m_widget;
QPointer<QWidget> m_oldPreceding;
QList<QWidget *> m_oldParentZOrder;
};
class QDESIGNER_SHARED_EXPORT RaiseWidgetCommand: public ChangeZOrderCommand
{
public:
explicit RaiseWidgetCommand(QDesignerFormWindowInterface *formWindow);
void init(QWidget *widget);
protected:
virtual QWidgetList reorderWidget(const QWidgetList &list, QWidget *widget) const;
virtual void reorder(QWidget *widget) const;
};
class QDESIGNER_SHARED_EXPORT LowerWidgetCommand: public ChangeZOrderCommand
{
public:
explicit LowerWidgetCommand(QDesignerFormWindowInterface *formWindow);
void init(QWidget *widget);
protected:
virtual QWidgetList reorderWidget(const QWidgetList &list, QWidget *widget) const;
virtual void reorder(QWidget *widget) const;
};
class QDESIGNER_SHARED_EXPORT AdjustWidgetSizeCommand: public QDesignerFormWindowCommand
{
public:
explicit AdjustWidgetSizeCommand(QDesignerFormWindowInterface *formWindow);
void init(QWidget *widget);
virtual void redo();
virtual void undo();
private:
QWidget *widgetForAdjust() const;
bool adjustNonLaidOutMainContainer(QWidget *integrationContainer);
void updatePropertyEditor() const;
QPointer<QWidget> m_widget;
QRect m_geometry;
};
// Helper to correctly unmanage a widget and its children for delete operations
class QDESIGNER_SHARED_EXPORT ManageWidgetCommandHelper {
public:
typedef QVector<QWidget*> WidgetVector;
ManageWidgetCommandHelper();
void init(const QDesignerFormWindowInterface *fw, QWidget *widget);
void init(QWidget *widget, const WidgetVector &managedChildren);
void manage(QDesignerFormWindowInterface *fw);
void unmanage(QDesignerFormWindowInterface *fw);
const WidgetVector &managedChildren() const { return m_managedChildren; }
private:
QWidget *m_widget;
WidgetVector m_managedChildren;
};
class QDESIGNER_SHARED_EXPORT DeleteWidgetCommand: public QDesignerFormWindowCommand
{
public:
explicit DeleteWidgetCommand(QDesignerFormWindowInterface *formWindow);
~DeleteWidgetCommand();
enum DeleteFlags { DoNotUnmanage = 0x1, DoNotSimplifyLayout = 0x2 };
void init(QWidget *widget, unsigned flags = 0);
virtual void redo();
virtual void undo();
private:
QPointer<QWidget> m_widget;
QPointer<QWidget> m_parentWidget;
QRect m_geometry;
LayoutInfo::Type m_layoutType;
LayoutHelper* m_layoutHelper;
unsigned m_flags;
QRect m_layoutPosition;
int m_splitterIndex;
bool m_layoutSimplified;
QDesignerMetaDataBaseItemInterface *m_formItem;
int m_tabOrderIndex;
int m_widgetOrderIndex;
int m_zOrderIndex;
ManageWidgetCommandHelper m_manageHelper;
};
class QDESIGNER_SHARED_EXPORT ReparentWidgetCommand: public QDesignerFormWindowCommand
{
public:
explicit ReparentWidgetCommand(QDesignerFormWindowInterface *formWindow);
void init(QWidget *widget, QWidget *parentWidget);
virtual void redo();
virtual void undo();
private:
QPointer<QWidget> m_widget;
QPoint m_oldPos;
QPoint m_newPos;
QPointer<QWidget> m_oldParentWidget;
QPointer<QWidget> m_newParentWidget;
QList<QWidget *> m_oldParentList;
QList<QWidget *> m_oldParentZOrder;
};
class QDESIGNER_SHARED_EXPORT ChangeFormLayoutItemRoleCommand : public QDesignerFormWindowCommand
{
public:
enum Operation { SpanningToLabel = 0x1, SpanningToField = 0x2, LabelToSpanning = 0x4, FieldToSpanning =0x8 };
explicit ChangeFormLayoutItemRoleCommand(QDesignerFormWindowInterface *formWindow);
void init(QWidget *widget, Operation op);
virtual void redo();
virtual void undo();
// Return a mask of possible operations of that item
static unsigned possibleOperations(QDesignerFormEditorInterface *core, QWidget *w);
private:
static QFormLayout *managedFormLayoutOf(QDesignerFormEditorInterface *core, QWidget *w);
static Operation reverseOperation(Operation op);
void doOperation(Operation op);
QPointer<QWidget> m_widget;
Operation m_operation;
};
class QDESIGNER_SHARED_EXPORT ChangeLayoutItemGeometry: public QDesignerFormWindowCommand
{
public:
explicit ChangeLayoutItemGeometry(QDesignerFormWindowInterface *formWindow);
void init(QWidget *widget, int row, int column, int rowspan, int colspan);
virtual void redo();
virtual void undo();
protected:
void changeItemPosition(const QRect &g);
private:
QPointer<QWidget> m_widget;
QRect m_oldInfo;
QRect m_newInfo;
};
class QDESIGNER_SHARED_EXPORT TabOrderCommand: public QDesignerFormWindowCommand
{
public:
explicit TabOrderCommand(QDesignerFormWindowInterface *formWindow);
void init(const QList<QWidget*> &newTabOrder);
inline QList<QWidget*> oldTabOrder() const
{ return m_oldTabOrder; }
inline QList<QWidget*> newTabOrder() const
{ return m_newTabOrder; }
virtual void redo();
virtual void undo();
private:
QDesignerMetaDataBaseItemInterface *m_widgetItem;
QList<QWidget*> m_oldTabOrder;
QList<QWidget*> m_newTabOrder;
};
class QDESIGNER_SHARED_EXPORT PromoteToCustomWidgetCommand : public QDesignerFormWindowCommand
{
public:
typedef QList<QPointer<QWidget> > WidgetList;
explicit PromoteToCustomWidgetCommand(QDesignerFormWindowInterface *formWindow);
void init(const WidgetList &widgets, const QString &customClassName);
virtual void redo();
virtual void undo();
private:
void updateSelection();
WidgetList m_widgets;
QString m_customClassName;
};
class QDESIGNER_SHARED_EXPORT DemoteFromCustomWidgetCommand : public QDesignerFormWindowCommand
{
public:
typedef PromoteToCustomWidgetCommand::WidgetList WidgetList;
explicit DemoteFromCustomWidgetCommand(QDesignerFormWindowInterface *formWindow);
void init(const WidgetList &promoted);
virtual void redo();
virtual void undo();
private:
PromoteToCustomWidgetCommand m_promote_cmd;
};
// Mixin class for storing the selection state
class QDESIGNER_SHARED_EXPORT CursorSelectionState {
Q_DISABLE_COPY(CursorSelectionState)
public:
CursorSelectionState();
void save(const QDesignerFormWindowInterface *formWindow);
void restore(QDesignerFormWindowInterface *formWindow) const;
private:
typedef QList<QPointer<QWidget> > WidgetPointerList;
WidgetPointerList m_selection;
QPointer<QWidget> m_current;
};
class QDESIGNER_SHARED_EXPORT LayoutCommand: public QDesignerFormWindowCommand
{
public:
explicit LayoutCommand(QDesignerFormWindowInterface *formWindow);
virtual ~LayoutCommand();
inline QWidgetList widgets() const { return m_widgets; }
void init(QWidget *parentWidget, const QWidgetList &widgets, LayoutInfo::Type layoutType,
QWidget *layoutBase = 0,
// Reparent/Hide instances of QLayoutWidget.
bool reparentLayoutWidget = true);
virtual void redo();
virtual void undo();
private:
QPointer<QWidget> m_parentWidget;
QWidgetList m_widgets;
QPointer<QWidget> m_layoutBase;
QPointer<Layout> m_layout;
CursorSelectionState m_cursorSelectionState;
bool m_setup;
};
class QDESIGNER_SHARED_EXPORT BreakLayoutCommand: public QDesignerFormWindowCommand
{
public:
explicit BreakLayoutCommand(QDesignerFormWindowInterface *formWindow);
virtual ~BreakLayoutCommand();
inline QWidgetList widgets() const { return m_widgets; }
void init(const QWidgetList &widgets, QWidget *layoutBase,
// Reparent/Hide instances of QLayoutWidget.
bool reparentLayoutWidget = true);
virtual void redo();
virtual void undo();
// Access the properties of the layout, 0 in case of splitters.
const LayoutProperties *layoutProperties() const;
int propertyMask() const;
private:
QWidgetList m_widgets;
QPointer<QWidget> m_layoutBase;
QPointer<Layout> m_layout;
LayoutHelper* m_layoutHelper;
LayoutProperties *m_properties;
int m_propertyMask;
CursorSelectionState m_cursorSelectionState;
};
class QDESIGNER_SHARED_EXPORT SimplifyLayoutCommand: public QDesignerFormWindowCommand
{
public:
explicit SimplifyLayoutCommand(QDesignerFormWindowInterface *formWindow);
virtual ~SimplifyLayoutCommand();
bool init(QWidget *layoutBase);
// Quick check
static bool canSimplify(QDesignerFormEditorInterface *core, const QWidget *w, int *layoutType = 0);
virtual void redo();
virtual void undo();
private:
const QRect m_area;
QWidget *m_layoutBase;
LayoutHelper* m_layoutHelper;
bool m_layoutSimplified;
};
class QDESIGNER_SHARED_EXPORT ToolBoxCommand: public QDesignerFormWindowCommand
{
public:
explicit ToolBoxCommand(QDesignerFormWindowInterface *formWindow);
virtual ~ToolBoxCommand();
void init(QToolBox *toolBox);
virtual void removePage();
virtual void addPage();
protected:
QPointer<QToolBox> m_toolBox;
QPointer<QWidget> m_widget;
int m_index;
QString m_itemText;
QIcon m_itemIcon;
};
class QDESIGNER_SHARED_EXPORT MoveToolBoxPageCommand: public ToolBoxCommand
{
public:
explicit MoveToolBoxPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~MoveToolBoxPageCommand();
void init(QToolBox *toolBox, QWidget *page, int newIndex);
virtual void redo();
virtual void undo();
private:
int m_newIndex;
int m_oldIndex;
};
class QDESIGNER_SHARED_EXPORT DeleteToolBoxPageCommand: public ToolBoxCommand
{
public:
explicit DeleteToolBoxPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~DeleteToolBoxPageCommand();
void init(QToolBox *toolBox);
virtual void redo();
virtual void undo();
};
class QDESIGNER_SHARED_EXPORT AddToolBoxPageCommand: public ToolBoxCommand
{
public:
enum InsertionMode {
InsertBefore,
InsertAfter
};
explicit AddToolBoxPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~AddToolBoxPageCommand();
void init(QToolBox *toolBox);
void init(QToolBox *toolBox, InsertionMode mode);
virtual void redo();
virtual void undo();
};
class QDESIGNER_SHARED_EXPORT TabWidgetCommand: public QDesignerFormWindowCommand
{
public:
explicit TabWidgetCommand(QDesignerFormWindowInterface *formWindow);
virtual ~TabWidgetCommand();
void init(QTabWidget *tabWidget);
virtual void removePage();
virtual void addPage();
protected:
QPointer<QTabWidget> m_tabWidget;
QPointer<QWidget> m_widget;
int m_index;
QString m_itemText;
QIcon m_itemIcon;
};
class QDESIGNER_SHARED_EXPORT DeleteTabPageCommand: public TabWidgetCommand
{
public:
explicit DeleteTabPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~DeleteTabPageCommand();
void init(QTabWidget *tabWidget);
virtual void redo();
virtual void undo();
};
class QDESIGNER_SHARED_EXPORT AddTabPageCommand: public TabWidgetCommand
{
public:
enum InsertionMode {
InsertBefore,
InsertAfter
};
explicit AddTabPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~AddTabPageCommand();
void init(QTabWidget *tabWidget);
void init(QTabWidget *tabWidget, InsertionMode mode);
virtual void redo();
virtual void undo();
};
class QDESIGNER_SHARED_EXPORT MoveTabPageCommand: public TabWidgetCommand
{
public:
explicit MoveTabPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~MoveTabPageCommand();
void init(QTabWidget *tabWidget, QWidget *page,
const QIcon &icon, const QString &label,
int index, int newIndex);
virtual void redo();
virtual void undo();
private:
int m_newIndex;
int m_oldIndex;
QPointer<QWidget> m_page;
QString m_label;
QIcon m_icon;
};
class QDESIGNER_SHARED_EXPORT StackedWidgetCommand: public QDesignerFormWindowCommand
{
public:
explicit StackedWidgetCommand(QDesignerFormWindowInterface *formWindow);
virtual ~StackedWidgetCommand();
void init(QStackedWidget *stackedWidget);
virtual void removePage();
virtual void addPage();
protected:
QPointer<QStackedWidget> m_stackedWidget;
QPointer<QWidget> m_widget;
int m_index;
};
class QDESIGNER_SHARED_EXPORT MoveStackedWidgetCommand: public StackedWidgetCommand
{
public:
explicit MoveStackedWidgetCommand(QDesignerFormWindowInterface *formWindow);
virtual ~MoveStackedWidgetCommand();
void init(QStackedWidget *stackedWidget, QWidget *page, int newIndex);
virtual void redo();
virtual void undo();
private:
int m_newIndex;
int m_oldIndex;
};
class QDESIGNER_SHARED_EXPORT DeleteStackedWidgetPageCommand: public StackedWidgetCommand
{
public:
explicit DeleteStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~DeleteStackedWidgetPageCommand();
void init(QStackedWidget *stackedWidget);
virtual void redo();
virtual void undo();
};
class QDESIGNER_SHARED_EXPORT AddStackedWidgetPageCommand: public StackedWidgetCommand
{
public:
enum InsertionMode {
InsertBefore,
InsertAfter
};
explicit AddStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~AddStackedWidgetPageCommand();
void init(QStackedWidget *stackedWidget);
void init(QStackedWidget *stackedWidget, InsertionMode mode);
virtual void redo();
virtual void undo();
};
class QDESIGNER_SHARED_EXPORT CreateMenuBarCommand: public QDesignerFormWindowCommand
{
public:
explicit CreateMenuBarCommand(QDesignerFormWindowInterface *formWindow);
void init(QMainWindow *mainWindow);
virtual void undo();
virtual void redo();
private:
QPointer<QMainWindow> m_mainWindow;
QPointer<QMenuBar> m_menuBar;
};
class QDESIGNER_SHARED_EXPORT DeleteMenuBarCommand: public QDesignerFormWindowCommand
{
public:
explicit DeleteMenuBarCommand(QDesignerFormWindowInterface *formWindow);
void init(QMenuBar *menuBar);
virtual void undo();
virtual void redo();
private:
QPointer<QMainWindow> m_mainWindow;
QPointer<QMenuBar> m_menuBar;
};
class QDESIGNER_SHARED_EXPORT CreateStatusBarCommand: public QDesignerFormWindowCommand
{
public:
explicit CreateStatusBarCommand(QDesignerFormWindowInterface *formWindow);
void init(QMainWindow *mainWindow);
virtual void undo();
virtual void redo();
private:
QPointer<QMainWindow> m_mainWindow;
QPointer<QStatusBar> m_statusBar;
};
class QDESIGNER_SHARED_EXPORT DeleteStatusBarCommand: public QDesignerFormWindowCommand
{
public:
explicit DeleteStatusBarCommand(QDesignerFormWindowInterface *formWindow);
void init(QStatusBar *statusBar);
virtual void undo();
virtual void redo();
private:
QPointer<QMainWindow> m_mainWindow;
QPointer<QStatusBar> m_statusBar;
};
class QDESIGNER_SHARED_EXPORT AddToolBarCommand: public QDesignerFormWindowCommand
{
public:
explicit AddToolBarCommand(QDesignerFormWindowInterface *formWindow);
void init(QMainWindow *mainWindow);
virtual void undo();
virtual void redo();
private:
QPointer<QMainWindow> m_mainWindow;
QPointer<QToolBar> m_toolBar;
};
class QDESIGNER_SHARED_EXPORT DeleteToolBarCommand: public QDesignerFormWindowCommand
{
public:
explicit DeleteToolBarCommand(QDesignerFormWindowInterface *formWindow);
void init(QToolBar *toolBar);
virtual void undo();
virtual void redo();
private:
QPointer<QMainWindow> m_mainWindow;
QPointer<QToolBar> m_toolBar;
};
class QDESIGNER_SHARED_EXPORT DockWidgetCommand: public QDesignerFormWindowCommand
{
public:
explicit DockWidgetCommand(const QString &description, QDesignerFormWindowInterface *formWindow);
virtual ~DockWidgetCommand();
void init(QDockWidget *dockWidget);
protected:
QPointer<QDockWidget> m_dockWidget;
};
class QDESIGNER_SHARED_EXPORT AddDockWidgetCommand: public QDesignerFormWindowCommand
{
public:
explicit AddDockWidgetCommand(QDesignerFormWindowInterface *formWindow);
void init(QMainWindow *mainWindow, QDockWidget *dockWidget);
void init(QMainWindow *mainWindow);
virtual void undo();
virtual void redo();
private:
QPointer<QMainWindow> m_mainWindow;
QPointer<QDockWidget> m_dockWidget;
};
class QDESIGNER_SHARED_EXPORT ContainerWidgetCommand: public QDesignerFormWindowCommand
{
public:
explicit ContainerWidgetCommand(QDesignerFormWindowInterface *formWindow);
virtual ~ContainerWidgetCommand();
QDesignerContainerExtension *containerExtension() const;
void init(QWidget *containerWidget);
virtual void removePage();
virtual void addPage();
protected:
QPointer<QWidget> m_containerWidget;
QPointer<QWidget> m_widget;
int m_index;
};
class QDESIGNER_SHARED_EXPORT DeleteContainerWidgetPageCommand: public ContainerWidgetCommand
{
public:
explicit DeleteContainerWidgetPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~DeleteContainerWidgetPageCommand();
void init(QWidget *containerWidget, ContainerType ct);
virtual void redo();
virtual void undo();
};
class QDESIGNER_SHARED_EXPORT AddContainerWidgetPageCommand: public ContainerWidgetCommand
{
public:
enum InsertionMode {
InsertBefore,
InsertAfter
};
explicit AddContainerWidgetPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~AddContainerWidgetPageCommand();
void init(QWidget *containerWidget, ContainerType ct, InsertionMode mode);
virtual void redo();
virtual void undo();
};
class QDESIGNER_SHARED_EXPORT ChangeCurrentPageCommand: public QDesignerFormWindowCommand
{
public:
explicit ChangeCurrentPageCommand(QDesignerFormWindowInterface *formWindow);
virtual ~ChangeCurrentPageCommand();
QDesignerContainerExtension *containerExtension() const;
void init(QWidget *containerWidget, int newIndex);
virtual void redo();
virtual void undo();
protected:
QPointer<QWidget> m_containerWidget;
QPointer<QWidget> m_widget;
int m_oldIndex;
int m_newIndex;
};
struct QDESIGNER_SHARED_EXPORT ItemData {
ItemData() {}
ItemData(const QListWidgetItem *item, bool editor);
ItemData(const QTableWidgetItem *item, bool editor);
ItemData(const QTreeWidgetItem *item, int column);
QListWidgetItem *createListItem(DesignerIconCache *iconCache, bool editor) const;
QTableWidgetItem *createTableItem(DesignerIconCache *iconCache, bool editor) const;
void fillTreeItemColumn(QTreeWidgetItem *item, int column, DesignerIconCache *iconCache) const;
bool isValid() const { return !m_properties.isEmpty(); }
bool operator==(const ItemData &rhs) const { return m_properties == rhs.m_properties; }
bool operator!=(const ItemData &rhs) const { return m_properties != rhs.m_properties; }
QHash<int, QVariant> m_properties;
};
struct QDESIGNER_SHARED_EXPORT ListContents {
ListContents() {}
ListContents(const QTreeWidgetItem *item);
QTreeWidgetItem *createTreeItem(DesignerIconCache *iconCache) const;
void createFromListWidget(const QListWidget *listWidget, bool editor);
void applyToListWidget(QListWidget *listWidget, DesignerIconCache *iconCache, bool editor) const;
void createFromComboBox(const QComboBox *listWidget);
void applyToComboBox(QComboBox *listWidget, DesignerIconCache *iconCache) const;
bool operator==(const ListContents &rhs) const { return m_items == rhs.m_items; }
bool operator!=(const ListContents &rhs) const { return m_items != rhs.m_items; }
QList<ItemData> m_items;
};
// Data structure representing the contents of a QTableWidget with
// methods to retrieve and apply for ChangeTableContentsCommand
struct QDESIGNER_SHARED_EXPORT TableWidgetContents {
typedef QPair<int, int> CellRowColumnAddress;
typedef QMap<CellRowColumnAddress, ItemData> TableItemMap;
TableWidgetContents();
void clear();
void fromTableWidget(const QTableWidget *tableWidget, bool editor);
void applyToTableWidget(QTableWidget *tableWidget, DesignerIconCache *iconCache, bool editor) const;
bool operator==(const TableWidgetContents &rhs) const;
bool operator!=(const TableWidgetContents &rhs) const { return !(*this == rhs); }
static bool nonEmpty(const QTableWidgetItem *item, int headerColumn);
static QString defaultHeaderText(int i);
static void insertHeaderItem(const QTableWidgetItem *item, int i, ListContents *header, bool editor);
int m_columnCount;
int m_rowCount;
ListContents m_horizontalHeader;
ListContents m_verticalHeader;
TableItemMap m_items;
};
class QDESIGNER_SHARED_EXPORT ChangeTableContentsCommand: public QDesignerFormWindowCommand
{
public:
explicit ChangeTableContentsCommand(QDesignerFormWindowInterface *formWindow);
void init(QTableWidget *tableWidget, const TableWidgetContents &oldCont, const TableWidgetContents &newCont);
virtual void redo();
virtual void undo();
private:
QPointer<QTableWidget> m_tableWidget;
TableWidgetContents m_oldContents;
TableWidgetContents m_newContents;
DesignerIconCache *m_iconCache;
};
// Data structure representing the contents of a QTreeWidget with
// methods to retrieve and apply for ChangeTreeContentsCommand
struct QDESIGNER_SHARED_EXPORT TreeWidgetContents {
struct ItemContents : public ListContents {
ItemContents() : m_itemFlags(-1) {}
ItemContents(const QTreeWidgetItem *item, bool editor);
QTreeWidgetItem *createTreeItem(DesignerIconCache *iconCache, bool editor) const;
bool operator==(const ItemContents &rhs) const;
bool operator!=(const ItemContents &rhs) const { return !(*this == rhs); }
int m_itemFlags;
//bool m_firstColumnSpanned:1;
//bool m_hidden:1;
//bool m_expanded:1;
QList<ItemContents> m_children;
};
void clear();
void fromTreeWidget(const QTreeWidget *treeWidget, bool editor);
void applyToTreeWidget(QTreeWidget *treeWidget, DesignerIconCache *iconCache, bool editor) const;
bool operator==(const TreeWidgetContents &rhs) const;
bool operator!=(const TreeWidgetContents &rhs) const { return !(*this == rhs); }
ListContents m_headerItem;
QList<ItemContents> m_rootItems;
};
class QDESIGNER_SHARED_EXPORT ChangeTreeContentsCommand: public QDesignerFormWindowCommand
{
public:
explicit ChangeTreeContentsCommand(QDesignerFormWindowInterface *formWindow);
void init(QTreeWidget *treeWidget, const TreeWidgetContents &oldState, const TreeWidgetContents &newState);
virtual void redo();
virtual void undo();
enum ApplyIconStrategy {
SetIconStrategy,
ResetIconStrategy
};
private:
QPointer<QTreeWidget> m_treeWidget;
TreeWidgetContents m_oldState;
TreeWidgetContents m_newState;
DesignerIconCache *m_iconCache;
};
class QDESIGNER_SHARED_EXPORT ChangeListContentsCommand: public QDesignerFormWindowCommand
{
public:
explicit ChangeListContentsCommand(QDesignerFormWindowInterface *formWindow);
void init(QListWidget *listWidget, const ListContents &oldItems, const ListContents &items);
void init(QComboBox *comboBox, const ListContents &oldItems, const ListContents &items);
virtual void redo();
virtual void undo();
private:
QPointer<QListWidget> m_listWidget;
QPointer<QComboBox> m_comboBox;
ListContents m_oldItemsState;
ListContents m_newItemsState;
DesignerIconCache *m_iconCache;
};
class QDESIGNER_SHARED_EXPORT AddActionCommand : public QDesignerFormWindowCommand
{
public:
explicit AddActionCommand(QDesignerFormWindowInterface *formWindow);
void init(QAction *action);
virtual void redo();
virtual void undo();
private:
QAction *m_action;
};
// Note: This command must be executed within a macro since it
// makes the form emit objectRemoved() which might cause other components
// to add commands (for example, removal of signals and slots
class QDESIGNER_SHARED_EXPORT RemoveActionCommand : public QDesignerFormWindowCommand
{
public:
explicit RemoveActionCommand(QDesignerFormWindowInterface *formWindow);
void init(QAction *action);
virtual void redo();
virtual void undo();
struct ActionDataItem {
ActionDataItem(QAction *_before = 0, QWidget *_widget = 0)
: before(_before), widget(_widget) {}
QAction *before;
QWidget *widget;
};
typedef QList<ActionDataItem> ActionData;
private:
QAction *m_action;
ActionData m_actionData;
};
class QDESIGNER_SHARED_EXPORT ActionInsertionCommand : public QDesignerFormWindowCommand
{
protected:
ActionInsertionCommand(const QString &text, QDesignerFormWindowInterface *formWindow);
public:
void init(QWidget *parentWidget, QAction *action, QAction *beforeAction = 0, bool update = true);
protected:
void insertAction();
void removeAction();
private:
QWidget *m_parentWidget;
QAction *m_action;
QAction *m_beforeAction;
bool m_update;
};
class QDESIGNER_SHARED_EXPORT InsertActionIntoCommand : public ActionInsertionCommand
{
public:
explicit InsertActionIntoCommand(QDesignerFormWindowInterface *formWindow);
virtual void redo() { insertAction(); }
virtual void undo() { removeAction(); }
};
class QDESIGNER_SHARED_EXPORT RemoveActionFromCommand : public ActionInsertionCommand
{
public:
explicit RemoveActionFromCommand(QDesignerFormWindowInterface *formWindow);
virtual void redo() { removeAction(); }
virtual void undo() { insertAction(); }
};
class QDESIGNER_SHARED_EXPORT MenuActionCommand : public QDesignerFormWindowCommand
{
public:
void init(QAction *action, QAction *actionBefore, QWidget *associatedWidget, QWidget *objectToSelect);
protected:
MenuActionCommand(const QString &text, QDesignerFormWindowInterface *formWindow);
void insertMenu();
void removeMenu();
private:
QAction *m_action;
QAction *m_actionBefore;
QWidget *m_menuParent;
QWidget *m_associatedWidget;
QWidget *m_objectToSelect;
};
class QDESIGNER_SHARED_EXPORT AddMenuActionCommand : public MenuActionCommand
{
public:
explicit AddMenuActionCommand(QDesignerFormWindowInterface *formWindow);
virtual void redo() { insertMenu(); }
virtual void undo() { removeMenu(); }
};
class QDESIGNER_SHARED_EXPORT RemoveMenuActionCommand : public MenuActionCommand
{
public:
explicit RemoveMenuActionCommand(QDesignerFormWindowInterface *formWindow);
virtual void redo() { removeMenu(); }
virtual void undo() { insertMenu(); }
};
class QDESIGNER_SHARED_EXPORT CreateSubmenuCommand : public QDesignerFormWindowCommand
{
public:
explicit CreateSubmenuCommand(QDesignerFormWindowInterface *formWindow);
void init(QDesignerMenu *menu, QAction *action, QObject *m_objectToSelect = 0);
virtual void redo();
virtual void undo();
private:
QAction *m_action;
QDesignerMenu *m_menu;
QObject *m_objectToSelect;
};
} // namespace qdesigner_internal
QT_END_NAMESPACE
#endif // QDESIGNER_COMMAND_H
|