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;
330 void save(
const QDesignerFormWindowInterface *formWindow);
331 void restore(QDesignerFormWindowInterface *formWindow)
const;
335 WidgetPointerList m_selection;
336 QPointer<QWidget> m_current;
343 explicit LayoutCommand(QDesignerFormWindowInterface *formWindow);
344 ~LayoutCommand() override;
346 inline QWidgetList widgets()
const {
return m_widgets; }
348 void init(QWidget *parentWidget,
const QWidgetList &widgets, LayoutInfo::Type layoutType,
349 QWidget *layoutBase =
nullptr,
351 bool reparentLayoutWidget =
true);
353 void redo() override;
354 void undo() override;
357 QPointer<QWidget> m_parentWidget;
358 QWidgetList m_widgets;
359 QPointer<QWidget> m_layoutBase;
360 QPointer<Layout> m_layout;
361 CursorSelectionState m_cursorSelectionState;
369 explicit BreakLayoutCommand(QDesignerFormWindowInterface *formWindow);
370 ~BreakLayoutCommand() override;
372 inline QWidgetList widgets()
const {
return m_widgets; }
374 void init(
const QWidgetList &widgets, QWidget *layoutBase,
376 bool reparentLayoutWidget =
true);
378 void redo() override;
379 void undo() override;
382 const LayoutProperties *layoutProperties()
const;
383 int propertyMask()
const;
386 QWidgetList m_widgets;
387 QPointer<QWidget> m_layoutBase;
388 QPointer<Layout> m_layout;
389 LayoutHelper* m_layoutHelper;
390 LayoutProperties *m_properties;
392 CursorSelectionState m_cursorSelectionState;
398 explicit SimplifyLayoutCommand(QDesignerFormWindowInterface *formWindow);
399 ~SimplifyLayoutCommand() override;
401 bool init(QWidget *layoutBase);
404 static bool canSimplify(QDesignerFormEditorInterface *core,
const QWidget *w,
int *layoutType =
nullptr);
406 void redo() override;
407 void undo() override;
411 QWidget *m_layoutBase;
412 LayoutHelper* m_layoutHelper;
413 bool m_layoutSimplified;
420 explicit ToolBoxCommand(QDesignerFormWindowInterface *formWindow);
423 void init(QToolBox *toolBox);
443 void init(QToolBox *toolBox,
QWidget *page,
int newIndex);
460 void init(QToolBox *toolBox);
477 void init(QToolBox *toolBox);
491 void init(QTabWidget *tabWidget);
511 void init(QTabWidget *tabWidget);
528 void init(QTabWidget *tabWidget);
543 const QIcon &icon,
const QString &label,
544 int index,
int newIndex);
552 QPointer<QWidget> m_page;
564 void init(QStackedWidget *stackedWidget);
582 void init(QStackedWidget *stackedWidget,
QWidget *page,
int newIndex);
599 void init(QStackedWidget *stackedWidget);
616 void init(QStackedWidget *stackedWidget);
629 void init(QMainWindow *mainWindow);
635 QPointer<QMainWindow> m_mainWindow;
636 QPointer<QMenuBar> m_menuBar;
645 void init(QMenuBar *menuBar);
651 QPointer<QMainWindow> m_mainWindow;
652 QPointer<QMenuBar> m_menuBar;
661 void init(QMainWindow *mainWindow);
667 QPointer<QMainWindow> m_mainWindow;
668 QPointer<QStatusBar> m_statusBar;
675 explicit DeleteStatusBarCommand(QDesignerFormWindowInterface *formWindow);
677 void init(QStatusBar *statusBar);
679 void undo() override;
680 void redo() override;
683 QPointer<QMainWindow> m_mainWindow;
684 QPointer<QStatusBar> m_statusBar;
693 void init(QMainWindow *mainWindow, Qt::ToolBarArea area);
699 QPointer<QMainWindow> m_mainWindow;
700 QPointer<QToolBar> m_toolBar;
709 void init(QToolBar *toolBar);
715 QPointer<QMainWindow> m_mainWindow;
716 QPointer<QToolBar> m_toolBar;
723 explicit DockWidgetCommand(
const QString &description, QDesignerFormWindowInterface *formWindow);
726 void init(QDockWidget *dockWidget);
736 explicit AddDockWidgetCommand(QDesignerFormWindowInterface *formWindow);
738 void init(QMainWindow *mainWindow, QDockWidget *dockWidget);
739 void init(QMainWindow *mainWindow);
741 void undo() override;
742 void redo() override;
745 QPointer<QMainWindow> m_mainWindow;
746 QPointer<QDockWidget> m_dockWidget;
753 explicit ContainerWidgetCommand(QDesignerFormWindowInterface *formWindow);
754 ~ContainerWidgetCommand() override;
756 QDesignerContainerExtension *containerExtension()
const;
758 void init(QWidget *containerWidget);
764 QPointer<QWidget> m_containerWidget;
765 QPointer<QWidget> m_widget;
773 explicit DeleteContainerWidgetPageCommand(QDesignerFormWindowInterface *formWindow);
774 ~DeleteContainerWidgetPageCommand() override;
776 void init(QWidget *containerWidget, ContainerType ct);
778 void redo() override;
779 void undo() override;
790 explicit AddContainerWidgetPageCommand(QDesignerFormWindowInterface *formWindow);
791 ~AddContainerWidgetPageCommand() override;
793 void init(QWidget *containerWidget, ContainerType ct, InsertionMode mode);
795 void redo() override;
796 void undo() override;
803 explicit ChangeCurrentPageCommand(QDesignerFormWindowInterface *formWindow);
804 ~ChangeCurrentPageCommand() override;
806 QDesignerContainerExtension *containerExtension()
const;
808 void init(QWidget *containerWidget,
int newIndex);
810 void redo() override;
811 void undo() override;
814 QPointer<QWidget> m_containerWidget;
815 QPointer<QWidget> m_widget;
821 ItemData() =
default;
823 ItemData(
const QListWidgetItem *item,
bool editor);
824 ItemData(
const QTableWidgetItem *item,
bool editor);
825 ItemData(
const QTreeWidgetItem *item,
int column);
826 QListWidgetItem *createListItem(DesignerIconCache *iconCache,
bool editor)
const;
827 QTableWidgetItem *createTableItem(DesignerIconCache *iconCache,
bool editor)
const;
828 void fillTreeItemColumn(QTreeWidgetItem *item,
int column, DesignerIconCache *iconCache)
const;
830 bool isValid()
const {
return !m_properties.isEmpty(); }
832 QHash<
int, QVariant> m_properties;
834 friend bool comparesEqual(
const ItemData &lhs,
const ItemData &rhs)
noexcept
836 return lhs.m_properties == rhs.m_properties;
838 Q_DECLARE_EQUALITY_COMPARABLE(ItemData)
842 ListContents() =
default;
844 ListContents(
const QTreeWidgetItem *item);
845 QTreeWidgetItem *createTreeItem(DesignerIconCache *iconCache)
const;
847 void createFromListWidget(
const QListWidget *listWidget,
bool editor);
848 void applyToListWidget(QListWidget *listWidget, DesignerIconCache *iconCache,
850 Qt::Alignment alignmentDefault = Qt::AlignLeading | Qt::AlignVCenter)
const;
851 void createFromComboBox(
const QComboBox *listWidget);
852 void applyToComboBox(QComboBox *listWidget, DesignerIconCache *iconCache)
const;
854 QList<ItemData> m_items;
856 friend bool comparesEqual(
const ListContents &lhs,
const ListContents &rhs)
noexcept
858 return lhs.m_items == rhs.m_items;
860 Q_DECLARE_EQUALITY_COMPARABLE(ListContents)
867 using CellRowColumnAddress = std::pair<
int,
int>;
869 TableWidgetContents();
872 void fromTableWidget(
const QTableWidget *tableWidget,
bool editor);
873 void applyToTableWidget(QTableWidget *tableWidget, DesignerIconCache *iconCache,
bool editor)
const;
875 static bool nonEmpty(
const QTableWidgetItem *item,
int headerColumn);
876 static QString defaultHeaderText(
int i);
877 static void insertHeaderItem(
const QTableWidgetItem *item,
int i, ListContents *header,
bool editor);
879 int m_columnCount = 0;
881 ListContents m_horizontalHeader;
882 ListContents m_verticalHeader;
883 QMap<CellRowColumnAddress, ItemData> m_items;
886 bool comparesEqual(
const TableWidgetContents &lhs,
887 const TableWidgetContents &rhs)
noexcept;
888 Q_DECLARE_EQUALITY_COMPARABLE(TableWidgetContents)
894 explicit ChangeTableContentsCommand(QDesignerFormWindowInterface *formWindow);
896 void init(QTableWidget *tableWidget,
const TableWidgetContents &oldCont,
const TableWidgetContents &newCont);
897 void redo() override;
898 void undo() override;
901 QPointer<QTableWidget> m_tableWidget;
902 TableWidgetContents m_oldContents;
903 TableWidgetContents m_newContents;
904 DesignerIconCache *m_iconCache;
911 struct ItemContents :
public ListContents {
912 ItemContents() =
default;
913 ItemContents(
const QTreeWidgetItem *item,
bool editor);
914 QTreeWidgetItem *createTreeItem(DesignerIconCache *iconCache,
bool editor)
const;
916 int m_itemFlags = -1;
920 QList<ItemContents> m_children;
923 bool comparesEqual(
const ItemContents &lhs,
924 const ItemContents &rhs)
noexcept;
925 Q_DECLARE_EQUALITY_COMPARABLE(ItemContents)
930 void fromTreeWidget(
const QTreeWidget *treeWidget,
bool editor);
931 void applyToTreeWidget(QTreeWidget *treeWidget, DesignerIconCache *iconCache,
bool editor)
const;
933 ListContents m_headerItem;
934 QList<ItemContents> m_rootItems;
936 friend bool comparesEqual(
const TreeWidgetContents &lhs,
937 const TreeWidgetContents &rhs)
noexcept
939 return lhs.m_headerItem == rhs.m_headerItem && lhs.m_rootItems == rhs.m_rootItems;
941 Q_DECLARE_EQUALITY_COMPARABLE(TreeWidgetContents)
948 explicit ChangeTreeContentsCommand(QDesignerFormWindowInterface *formWindow);
950 void init(QTreeWidget *treeWidget,
const TreeWidgetContents &oldState,
const TreeWidgetContents &newState);
951 void redo() override;
952 void undo() override;
953 enum ApplyIconStrategy {
958 QPointer<QTreeWidget> m_treeWidget;
959 TreeWidgetContents m_oldState;
960 TreeWidgetContents m_newState;
961 DesignerIconCache *m_iconCache;
968 explicit ChangeListContentsCommand(QDesignerFormWindowInterface *formWindow);
970 void init(QListWidget *listWidget,
const ListContents &oldItems,
const ListContents &items);
971 void init(QComboBox *comboBox,
const ListContents &oldItems,
const ListContents &items);
972 void redo() override;
973 void undo() override;
975 QPointer<QListWidget> m_listWidget;
976 QPointer<QComboBox> m_comboBox;
977 ListContents m_oldItemsState;
978 ListContents m_newItemsState;
979 DesignerIconCache *m_iconCache;
986 explicit AddActionCommand(QDesignerFormWindowInterface *formWindow);
987 void init(QAction *action);
988 void redo() override;
989 void undo() override;
1001 explicit RemoveActionCommand(QDesignerFormWindowInterface *formWindow);
1002 void init(QAction *action);
1003 void redo() override;
1004 void undo() override;
1006 struct ActionDataItem {
1007 ActionDataItem(QAction *_before =
nullptr, QWidget *_widget =
nullptr)
1008 : before(_before), widget(_widget) {}
1012 using ActionData = QList<ActionDataItem>;
1017 ActionData m_actionData;
1027 void init(
QWidget *parentWidget, QAction *action, QAction *beforeAction =
nullptr,
bool update =
true);
1036 QAction *m_beforeAction;
1063 void init(QAction *action, QAction *actionBefore,
QWidget *associatedWidget,
QWidget *objectToSelect);
1066 MenuActionCommand(
const QString &text, QDesignerFormWindowInterface *formWindow);
1072 QAction *m_actionBefore;
1103 void init(QDesignerMenu *menu, QAction *action, QObject *m_objectToSelect =
nullptr);
1108 QDesignerMenu *m_menu;
1109 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