15#ifndef QDESIGNER_COMMAND_H
16#define QDESIGNER_COMMAND_H
25#include <QtDesigner/layoutdecoration.h>
27#include <QtGui/qicon.h>
29#include <QtCore/qcompare.h>
30#include <QtCore/qhash.h>
31#include <QtCore/qlist.h>
32#include <QtCore/qmap.h>
33#include <QtCore/qobject.h>
34#include <QtCore/qpair.h>
35#include <QtCore/qpoint.h>
36#include <QtCore/qpointer.h>
37#include <QtCore/qrect.h>
51class QTableWidgetItem;
66class PropertySheetIconValue;
67class DesignerIconCache;
68struct LayoutProperties;
328 void save(
const QDesignerFormWindowInterface *formWindow);
329 void restore(QDesignerFormWindowInterface *formWindow)
const;
333 WidgetPointerList m_selection;
334 QPointer<QWidget> m_current;
341 explicit LayoutCommand(QDesignerFormWindowInterface *formWindow);
342 ~LayoutCommand() override;
344 QWidgetList widgets()
const {
return m_widgets; }
346 void init(QWidget *parentWidget,
const QWidgetList &widgets, LayoutInfo::Type layoutType,
347 QWidget *layoutBase =
nullptr,
349 bool reparentLayoutWidget =
true);
351 void redo() override;
352 void undo() override;
355 QPointer<QWidget> m_parentWidget;
356 QWidgetList m_widgets;
357 QPointer<QWidget> m_layoutBase;
358 QPointer<Layout> m_layout;
359 CursorSelectionState m_cursorSelectionState;
367 explicit BreakLayoutCommand(QDesignerFormWindowInterface *formWindow);
368 ~BreakLayoutCommand() override;
370 QWidgetList widgets()
const {
return m_widgets; }
372 void init(
const QWidgetList &widgets, QWidget *layoutBase,
374 bool reparentLayoutWidget =
true);
376 void redo() override;
377 void undo() override;
380 const LayoutProperties *layoutProperties()
const;
381 int propertyMask()
const;
384 QWidgetList m_widgets;
385 QPointer<QWidget> m_layoutBase;
386 QPointer<Layout> m_layout;
387 LayoutHelper* m_layoutHelper;
388 LayoutProperties *m_properties;
390 CursorSelectionState m_cursorSelectionState;
396 explicit SimplifyLayoutCommand(QDesignerFormWindowInterface *formWindow);
397 ~SimplifyLayoutCommand() override;
399 bool init(QWidget *layoutBase);
402 static bool canSimplify(QDesignerFormEditorInterface *core,
const QWidget *w,
int *layoutType =
nullptr);
404 void redo() override;
405 void undo() override;
409 QWidget *m_layoutBase;
410 LayoutHelper* m_layoutHelper;
411 bool m_layoutSimplified;
418 explicit ToolBoxCommand(QDesignerFormWindowInterface *formWindow);
421 void init(QToolBox *toolBox);
441 void init(QToolBox *toolBox,
QWidget *page,
int newIndex);
458 void init(QToolBox *toolBox);
475 void init(QToolBox *toolBox);
489 void init(QTabWidget *tabWidget);
509 void init(QTabWidget *tabWidget);
526 void init(QTabWidget *tabWidget);
541 const QIcon &icon,
const QString &label,
542 int index,
int newIndex);
550 QPointer<QWidget> m_page;
562 void init(QStackedWidget *stackedWidget);
580 void init(QStackedWidget *stackedWidget,
QWidget *page,
int newIndex);
597 void init(QStackedWidget *stackedWidget);
614 void init(QStackedWidget *stackedWidget);
627 void init(QMainWindow *mainWindow);
633 QPointer<QMainWindow> m_mainWindow;
634 QPointer<QMenuBar> m_menuBar;
643 void init(QMenuBar *menuBar);
649 QPointer<QMainWindow> m_mainWindow;
650 QPointer<QMenuBar> m_menuBar;
659 void init(QMainWindow *mainWindow);
665 QPointer<QMainWindow> m_mainWindow;
666 QPointer<QStatusBar> m_statusBar;
673 explicit DeleteStatusBarCommand(QDesignerFormWindowInterface *formWindow);
675 void init(QStatusBar *statusBar);
677 void undo() override;
678 void redo() override;
681 QPointer<QMainWindow> m_mainWindow;
682 QPointer<QStatusBar> m_statusBar;
691 void init(QMainWindow *mainWindow, Qt::ToolBarArea area);
697 QPointer<QMainWindow> m_mainWindow;
698 QPointer<QToolBar> m_toolBar;
707 void init(QToolBar *toolBar);
713 QPointer<QMainWindow> m_mainWindow;
714 QPointer<QToolBar> m_toolBar;
721 explicit DockWidgetCommand(
const QString &description, QDesignerFormWindowInterface *formWindow);
724 void init(QDockWidget *dockWidget);
734 explicit AddDockWidgetCommand(QDesignerFormWindowInterface *formWindow);
736 void init(QMainWindow *mainWindow, QDockWidget *dockWidget);
737 void init(QMainWindow *mainWindow);
739 void undo() override;
740 void redo() override;
743 QPointer<QMainWindow> m_mainWindow;
744 QPointer<QDockWidget> m_dockWidget;
751 explicit ContainerWidgetCommand(QDesignerFormWindowInterface *formWindow);
752 ~ContainerWidgetCommand() override;
754 QDesignerContainerExtension *containerExtension()
const;
756 void init(QWidget *containerWidget);
762 QPointer<QWidget> m_containerWidget;
763 QPointer<QWidget> m_widget;
771 explicit DeleteContainerWidgetPageCommand(QDesignerFormWindowInterface *formWindow);
772 ~DeleteContainerWidgetPageCommand() override;
774 void init(QWidget *containerWidget, ContainerType ct);
776 void redo() override;
777 void undo() override;
788 explicit AddContainerWidgetPageCommand(QDesignerFormWindowInterface *formWindow);
789 ~AddContainerWidgetPageCommand() override;
791 void init(QWidget *containerWidget, ContainerType ct, InsertionMode mode);
793 void redo() override;
794 void undo() override;
801 explicit ChangeCurrentPageCommand(QDesignerFormWindowInterface *formWindow);
802 ~ChangeCurrentPageCommand() override;
804 QDesignerContainerExtension *containerExtension()
const;
806 void init(QWidget *containerWidget,
int newIndex);
808 void redo() override;
809 void undo() override;
812 QPointer<QWidget> m_containerWidget;
813 QPointer<QWidget> m_widget;
819 ItemData() =
default;
821 ItemData(
const QListWidgetItem *item,
bool editor);
822 ItemData(
const QTableWidgetItem *item,
bool editor);
823 ItemData(
const QTreeWidgetItem *item,
int column);
824 QListWidgetItem *createListItem(DesignerIconCache *iconCache,
bool editor)
const;
825 QTableWidgetItem *createTableItem(DesignerIconCache *iconCache,
bool editor)
const;
826 void fillTreeItemColumn(QTreeWidgetItem *item,
int column, DesignerIconCache *iconCache)
const;
828 bool isValid()
const {
return !m_properties.isEmpty(); }
830 QHash<
int, QVariant> m_properties;
832 friend bool comparesEqual(
const ItemData &lhs,
const ItemData &rhs)
noexcept
834 return lhs.m_properties == rhs.m_properties;
836 Q_DECLARE_EQUALITY_COMPARABLE(ItemData)
840 ListContents() =
default;
842 ListContents(
const QTreeWidgetItem *item);
843 QTreeWidgetItem *createTreeItem(DesignerIconCache *iconCache)
const;
845 void createFromListWidget(
const QListWidget *listWidget,
bool editor);
846 void applyToListWidget(QListWidget *listWidget, DesignerIconCache *iconCache,
848 Qt::Alignment alignmentDefault = Qt::AlignLeading | Qt::AlignVCenter)
const;
849 void createFromComboBox(
const QComboBox *listWidget);
850 void applyToComboBox(QComboBox *listWidget, DesignerIconCache *iconCache)
const;
852 QList<ItemData> m_items;
854 friend bool comparesEqual(
const ListContents &lhs,
const ListContents &rhs)
noexcept
856 return lhs.m_items == rhs.m_items;
858 Q_DECLARE_EQUALITY_COMPARABLE(ListContents)
865 using CellRowColumnAddress = std::pair<
int,
int>;
867 TableWidgetContents();
870 void fromTableWidget(
const QTableWidget *tableWidget,
bool editor);
871 void applyToTableWidget(QTableWidget *tableWidget, DesignerIconCache *iconCache,
bool editor)
const;
873 static bool nonEmpty(
const QTableWidgetItem *item,
int headerColumn);
874 static QString defaultHeaderText(
int i);
875 static void insertHeaderItem(
const QTableWidgetItem *item,
int i, ListContents *header,
bool editor);
877 int m_columnCount = 0;
879 ListContents m_horizontalHeader;
880 ListContents m_verticalHeader;
881 QMap<CellRowColumnAddress, ItemData> m_items;
884 bool comparesEqual(
const TableWidgetContents &lhs,
885 const TableWidgetContents &rhs)
noexcept;
886 Q_DECLARE_EQUALITY_COMPARABLE(TableWidgetContents)
892 explicit ChangeTableContentsCommand(QDesignerFormWindowInterface *formWindow);
894 void init(QTableWidget *tableWidget,
const TableWidgetContents &oldCont,
const TableWidgetContents &newCont);
895 void redo() override;
896 void undo() override;
899 QPointer<QTableWidget> m_tableWidget;
900 TableWidgetContents m_oldContents;
901 TableWidgetContents m_newContents;
902 DesignerIconCache *m_iconCache;
909 struct ItemContents :
public ListContents {
910 ItemContents() =
default;
911 ItemContents(
const QTreeWidgetItem *item,
bool editor);
912 QTreeWidgetItem *createTreeItem(DesignerIconCache *iconCache,
bool editor)
const;
914 int m_itemFlags = -1;
918 QList<ItemContents> m_children;
921 bool comparesEqual(
const ItemContents &lhs,
922 const ItemContents &rhs)
noexcept;
923 Q_DECLARE_EQUALITY_COMPARABLE(ItemContents)
928 void fromTreeWidget(
const QTreeWidget *treeWidget,
bool editor);
929 void applyToTreeWidget(QTreeWidget *treeWidget, DesignerIconCache *iconCache,
bool editor)
const;
931 ListContents m_headerItem;
932 QList<ItemContents> m_rootItems;
934 friend bool comparesEqual(
const TreeWidgetContents &lhs,
935 const TreeWidgetContents &rhs)
noexcept
937 return lhs.m_headerItem == rhs.m_headerItem && lhs.m_rootItems == rhs.m_rootItems;
939 Q_DECLARE_EQUALITY_COMPARABLE(TreeWidgetContents)
946 explicit ChangeTreeContentsCommand(QDesignerFormWindowInterface *formWindow);
948 void init(QTreeWidget *treeWidget,
const TreeWidgetContents &oldState,
const TreeWidgetContents &newState);
949 void redo() override;
950 void undo() override;
951 enum ApplyIconStrategy {
956 QPointer<QTreeWidget> m_treeWidget;
957 TreeWidgetContents m_oldState;
958 TreeWidgetContents m_newState;
959 DesignerIconCache *m_iconCache;
966 explicit ChangeListContentsCommand(QDesignerFormWindowInterface *formWindow);
968 void init(QListWidget *listWidget,
const ListContents &oldItems,
const ListContents &items);
969 void init(QComboBox *comboBox,
const ListContents &oldItems,
const ListContents &items);
970 void redo() override;
971 void undo() override;
973 QPointer<QListWidget> m_listWidget;
974 QPointer<QComboBox> m_comboBox;
975 ListContents m_oldItemsState;
976 ListContents m_newItemsState;
977 DesignerIconCache *m_iconCache;
984 explicit AddActionCommand(QDesignerFormWindowInterface *formWindow);
985 void init(QAction *action);
986 void redo() override;
987 void undo() override;
989 QAction *m_action =
nullptr;
999 explicit RemoveActionCommand(QDesignerFormWindowInterface *formWindow);
1000 void init(QAction *action);
1001 void redo() override;
1002 void undo() override;
1004 struct ActionDataItem {
1005 ActionDataItem(QAction *_before =
nullptr, QWidget *_widget =
nullptr)
1006 : before(_before), widget(_widget) {}
1010 using ActionData = QList<ActionDataItem>;
1013 QAction *m_action =
nullptr;
1015 ActionData m_actionData;
1025 void init(
QWidget *parentWidget, QAction *action, QAction *beforeAction =
nullptr,
bool update =
true);
1034 QAction *m_beforeAction;
1061 void init(QAction *action, QAction *actionBefore,
QWidget *associatedWidget,
QWidget *objectToSelect);
1064 MenuActionCommand(
const QString &text, QDesignerFormWindowInterface *formWindow);
1070 QAction *m_actionBefore;
1101 void init(QDesignerMenu *menu, QAction *action, QObject *m_objectToSelect =
nullptr);
1106 QDesignerMenu *m_menu;
1107 QObject *m_objectToSelect;
static bool canBeBuddy(QWidget *w, QDesignerFormWindowInterface *form)
static QString buddy(QLabel *label, QDesignerFormEditorInterface *core)
static constexpr auto buddyPropertyC
#define QT_BUDDYEDITOR_EXPORT
void init(QWidget *parentWidget, QAction *action, QAction *beforeAction=nullptr, bool update=true)
ActionInsertionCommand(const QString &text, QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
AddMenuActionCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
AddStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void init(QStackedWidget *stackedWidget)
void init(QStackedWidget *stackedWidget, InsertionMode mode)
~AddStackedWidgetPageCommand() override
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
~AddTabPageCommand() override
void init(QTabWidget *tabWidget, InsertionMode mode)
void init(QTabWidget *tabWidget)
AddTabPageCommand(QDesignerFormWindowInterface *formWindow)
AddToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QToolBox *toolBox, InsertionMode mode)
~AddToolBoxPageCommand() override
void init(QToolBox *toolBox)
void undo() override
Reverts a change to the document.
void setBackground(QWidget *background) override
QDesignerFormWindowInterface * formWindow() const
void endConnection(QWidget *target, const QPoint &pos) override
void widgetRemoved(QWidget *w) override
QWidget * widgetAt(const QPoint &pos) const override
Connection * createConnection(QWidget *source, QWidget *destination) override
void createContextMenu(QMenu &menu) override
void deleteSelected() override
CreateMenuBarCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QMainWindow *mainWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
void init(QMainWindow *mainWindow)
CreateStatusBarCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void init(QDesignerMenu *menu, QAction *action, QObject *m_objectToSelect=nullptr)
CreateSubmenuCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void restore(QDesignerFormWindowInterface *formWindow) const
void save(const QDesignerFormWindowInterface *formWindow)
void init(QMenuBar *menuBar)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
DeleteMenuBarCommand(QDesignerFormWindowInterface *formWindow)
DeleteStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
void init(QStackedWidget *stackedWidget)
void redo() override
Applies a change to the document.
~DeleteStackedWidgetPageCommand() override
void undo() override
Reverts a change to the document.
void init(QTabWidget *tabWidget)
void redo() override
Applies a change to the document.
~DeleteTabPageCommand() override
void undo() override
Reverts a change to the document.
DeleteTabPageCommand(QDesignerFormWindowInterface *formWindow)
void init(QToolBox *toolBox)
DeleteToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
~DeleteToolBoxPageCommand() override
void undo() override
Reverts a change to the document.
InsertActionIntoCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QAction *action, QAction *actionBefore, QWidget *associatedWidget, QWidget *objectToSelect)
MenuActionCommand(const QString &text, QDesignerFormWindowInterface *formWindow)
~MoveTabPageCommand() override
void undo() override
Reverts a change to the document.
MoveTabPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QTabWidget *tabWidget, QWidget *page, const QIcon &icon, const QString &label, int index, int newIndex)
MoveToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QToolBox *toolBox, QWidget *page, int newIndex)
void undo() override
Reverts a change to the document.
~MoveToolBoxPageCommand() override
RemoveActionFromCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
RemoveMenuActionCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static QUndoCommand * createBuddyCommand(QDesignerFormWindowInterface *fw, QLabel *label, QWidget *buddy)
#define QDESIGNER_SHARED_EXPORT