Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlayout_widget_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists for the convenience
9// of Qt Designer. This header
10// file may change from version to version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QLAYOUT_WIDGET_H
16#define QLAYOUT_WIDGET_H
17
19
20#include <QtDesigner/layoutdecoration.h>
21
22#include <QtCore/qpointer.h>
23#include <QtCore/qvariant.h>
24#include <QtWidgets/qwidget.h>
25#include <QtWidgets/qlayout.h>
26
28
29class QDesignerFormWindowInterface;
30class QDesignerFormEditorInterface;
31class QGridLayout;
32class QFormLayout;
33
34namespace qdesigner_internal {
35// ---- LayoutProperties: Helper struct that stores all layout-relevant properties
36// with functions to retrieve and apply to property sheets. Can be used to store the state
37// for undo commands and while rebuilding layouts.
39{
41 void clear();
42
45
60
61 // return a PropertyMask of visible properties
62 static int visibleProperties(const QLayout *layout);
63
64 // Retrieve from /apply to sheet: A property mask is returned indicating the properties found in the sheet
65 int fromPropertySheet(const QDesignerFormEditorInterface *core, QLayout *l, int mask = AllProperties);
66 int toPropertySheet(const QDesignerFormEditorInterface *core, QLayout *l, int mask = AllProperties, bool applyChanged = true) const;
67
70
73
74 QVariant m_objectName; // receives a PropertySheetStringValue
76#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
79#else
84#endif
85
94
97
100
103
106
109};
110
111// -- LayoutHelper: For use with the 'insert widget'/'delete widget' command,
112// able to store and restore states.
113// This could become part of 'QDesignerLayoutDecorationExtensionV2',
114// but to keep any existing old extensions working, it is provided as
115// separate class with a factory function.
117protected:
119
120public:
122
123 virtual ~LayoutHelper();
124
125 static LayoutHelper *createLayoutHelper(int type);
126
127 static int indexOf(const QLayout *lt, const QWidget *widget);
128
129 // Return area of an item (x == columns)
130 QRect itemInfo(QLayout *lt, const QWidget *widget) const;
131
132 virtual QRect itemInfo(QLayout *lt, int index) const = 0;
133 virtual void insertWidget(QLayout *lt, const QRect &info, QWidget *w) = 0;
134 virtual void removeWidget(QLayout *lt, QWidget *widget) = 0;
135 // Since 4.5: The 'morphing' feature requires an API for replacing widgets on layouts.
136 virtual void replaceWidget(QLayout *lt, QWidget *before, QWidget *after) = 0;
137
138 // Simplify a grid, remove empty columns, rows within the rectangle
139 // The DeleteWidget command restricts the area to be simplified.
140 virtual bool canSimplify(const QDesignerFormEditorInterface *core, const QWidget *widgetWithManagedLayout, const QRect &restrictionArea) const = 0;
141 virtual void simplify(const QDesignerFormEditorInterface *core, QWidget *widgetWithManagedLayout, const QRect &restrictionArea) = 0;
142
143 // Push and pop a state. Can be used for implementing undo for
144 // simplify/row, column insertion commands, provided that
145 // the widgets remain the same.
146 virtual void pushState(const QDesignerFormEditorInterface *core, const QWidget *widgetWithManagedLayout) = 0;
147 virtual void popState(const QDesignerFormEditorInterface *core, QWidget *widgetWithManagedLayout) = 0;
148};
149
150// Base class for layout decoration extensions.
151class QDESIGNER_SHARED_EXPORT QLayoutSupport: public QObject, public QDesignerLayoutDecorationExtension
152{
153 Q_OBJECT
154 Q_INTERFACES(QDesignerLayoutDecorationExtension)
155
156protected:
157 QLayoutSupport(QDesignerFormWindowInterface *formWindow, QWidget *widget, LayoutHelper *helper, QObject *parent = nullptr);
158
159public:
160 ~QLayoutSupport() override;
161
162 inline QDesignerFormWindowInterface *formWindow() const { return m_formWindow; }
163
164 // DecorationExtension V2
165 LayoutHelper* helper() const { return m_helper; }
166
167 // DecorationExtension
168 int currentIndex() const override { return m_currentIndex; }
169
170 InsertMode currentInsertMode() const override { return m_currentInsertMode; }
171
172 std::pair<int, int> currentCell() const override { return m_currentCell; }
173
174 int findItemAt(const QPoint &pos) const override;
175 int indexOf(QWidget *widget) const override;
176 int indexOf(QLayoutItem *item) const override;
177
178 void adjustIndicator(const QPoint &pos, int index) override;
179
180 QWidgetList widgets(QLayout *layout) const override;
181
182 // Pad empty cells with dummy spacers. Called by layouting commands.
183 static void createEmptyCells(QGridLayout *gridLayout);
184 // remove dummy spacers in the area. Returns false if there are non-empty items in the way
185 static bool removeEmptyCells(QGridLayout *gridLayout, const QRect &area);
186 static void createEmptyCells(QFormLayout *formLayout); // ditto.
187 static bool removeEmptyCells(QFormLayout *formLayout, const QRect &area);
188
189 // grid helpers: find item index
190 static int findItemAt(QGridLayout *, int row, int column);
191 using QDesignerLayoutDecorationExtension::findItemAt;
192 // grid helpers: Quick check whether simplify should be enabled for grids. May return false positives.
193 static bool canSimplifyQuickCheck(const QGridLayout *);
194 static bool canSimplifyQuickCheck(const QFormLayout *fl);
195 // Factory function, create layout support according to layout type of widget
196 static QLayoutSupport *createLayoutSupport(QDesignerFormWindowInterface *formWindow, QWidget *widget, QObject *parent = nullptr);
197
198protected:
199 // figure out insertion position and mode from indicator on empty cell if supported
200 virtual void setCurrentCellFromIndicatorOnEmptyCell(int index) = 0;
201 // figure out insertion position and mode from indicator
202 virtual void setCurrentCellFromIndicator(Qt::Orientation indicatorOrientation, int index, int increment) = 0;
203
204 // Overwrite to return the extended geometry of an item, that is,
205 // if it is a border item, include the widget border for the indicator to work correctly
206 virtual QRect extendedGeometry(int index) const = 0;
207 virtual bool supportsIndicatorOrientation(Qt::Orientation indicatorOrientation) const = 0;
208
209 QRect itemInfo(int index) const override;
210 QLayout *layout() const;
211 QGridLayout *gridLayout() const;
212 QWidget *widget() const { return m_widget; }
213
214 void setInsertMode(InsertMode im);
215 void setCurrentCell(const std::pair<int, int> &cell);
216
217private:
218 enum Indicator { LeftIndicator, TopIndicator, RightIndicator, BottomIndicator, NumIndicators };
219
220 void hideIndicator(Indicator i);
221 void showIndicator(Indicator i, const QRect &geometry, const QPalette &);
222
223 QDesignerFormWindowInterface *m_formWindow;
224 LayoutHelper* m_helper;
225
226 QPointer<QWidget> m_widget;
227 QPointer<QWidget> m_indicators[NumIndicators];
228 int m_currentIndex;
229 InsertMode m_currentInsertMode;
230 std::pair<int, int> m_currentCell;
231};
232} // namespace qdesigner_internal
233
234// Red layout widget.
236{
237 Q_OBJECT
238public:
239 explicit QLayoutWidget(QDesignerFormWindowInterface *formWindow, QWidget *parent = nullptr);
240
241 int layoutLeftMargin() const;
242 void setLayoutLeftMargin(int layoutMargin);
243
244 int layoutTopMargin() const;
245 void setLayoutTopMargin(int layoutMargin);
246
247 int layoutRightMargin() const;
248 void setLayoutRightMargin(int layoutMargin);
249
250 int layoutBottomMargin() const;
251 void setLayoutBottomMargin(int layoutMargin);
252
253 inline QDesignerFormWindowInterface *formWindow() const { return m_formWindow; }
254
255protected:
256 bool event(QEvent *e) override;
257 void paintEvent(QPaintEvent *e) override;
258
259private:
260 QDesignerFormWindowInterface *m_formWindow;
261 int m_leftMargin;
262 int m_topMargin;
263 int m_rightMargin;
264 int m_bottomMargin;
265};
266
267QT_END_NAMESPACE
268
269#endif // QDESIGNER_WIDGET_H
static bool canBeBuddy(QWidget *w, QDesignerFormWindowInterface *form)
static QString buddy(QLabel *label, QDesignerFormEditorInterface *core)
static constexpr auto buddyPropertyC
#define QT_BUDDYEDITOR_EXPORT
The QDesignerMetaDataBaseItemInterface class provides an interface to individual items in \QD's meta ...
friend class QWidget
Definition qpainter.h:431
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, InsertionMode mode)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
void init(QTabWidget *tabWidget, InsertionMode mode)
AddTabPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
AddToolBarCommand(QDesignerFormWindowInterface *formWindow)
void init(QMainWindow *mainWindow, Qt::ToolBarArea area)
void undo() override
Reverts a change to the document.
AddToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QToolBox *toolBox, InsertionMode mode)
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
CreateMenuBarCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
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.
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 redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
DeleteMenuBarCommand(QDesignerFormWindowInterface *formWindow)
DeleteStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
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.
DeleteTabPageCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
DeleteToolBarCommand(QDesignerFormWindowInterface *formWindow)
DeleteToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
DockWidgetCommand(const QString &description, QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
InsertActionIntoCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
static LayoutHelper * createLayoutHelper(int type)
void init(QAction *action, QAction *actionBefore, QWidget *associatedWidget, QWidget *objectToSelect)
MenuActionCommand(const QString &text, QDesignerFormWindowInterface *formWindow)
const KeyToValueMap & keyToValueMap() const
const QStringList & keys() const
const QString & scope() const
void addKey(IntType value, const QString &name)
const QString & enumName() const
IntType keyToValue(QStringView key, bool *ok=nullptr) const
void appendQualifiedName(const QString &key, SerializationMode sm, QString &target) const
const QString & separator() const
QString valueToKey(IntType value, bool *ok=nullptr) const
MetaEnum(const QString &enumName, const QString &scope, const QString &separator)
void init(QStackedWidget *stackedWidget, QWidget *page, int newIndex)
MoveStackedWidgetCommand(QDesignerFormWindowInterface *formWindow)
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.
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.
QDesignerIntegration * integration(QDesignerFormWindowInterface *fw) const
PropertyHelper(QObject *object, SpecialProperty specialProperty, QDesignerPropertySheetExtension *sheet, int index)
void setOldValue(const QVariant &oldValue)
Value restoreDefaultValue(QDesignerFormWindowInterface *fw)
Value restoreOldValue(QDesignerFormWindowInterface *fw)
bool canMerge(const PropertyHelper &other) const
virtual Value setValue(QDesignerFormWindowInterface *fw, const QVariant &value, bool changed, quint64 subPropertyMask)
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.
StackedWidgetCommand(QDesignerFormWindowInterface *formWindow)
void init(QStackedWidget *stackedWidget)
TabWidgetCommand(QDesignerFormWindowInterface *formWindow)
ToolBoxCommand(QDesignerFormWindowInterface *formWindow)
int valueOf(const QVariant &value, bool *ok=nullptr)
bool isObjectAncestorOf(QObject *ancestor, QObject *child)
bool isCentralWidget(QDesignerFormWindowInterface *fw, QWidget *widget)
Auxiliary methods to store/retrieve settings.
enum SpecialProperty getSpecialProperty(const QString &propertyName)
QDESIGNER_SHARED_EXPORT void getFormLayoutItemPosition(const QFormLayout *formLayout, int index, int *rowPtr, int *columnPtr=nullptr, int *rowspanPtr=nullptr, int *colspanPtr=nullptr)
QDESIGNER_SHARED_EXPORT QDebug operator<<(QDebug, const PropertySheetIconValue &)
static QUndoCommand * createBuddyCommand(QDesignerFormWindowInterface *fw, QLabel *label, QWidget *buddy)
QDESIGNER_SHARED_EXPORT void formLayoutAddWidget(QFormLayout *formLayout, QWidget *w, const QRect &r, bool insert)
QDESIGNER_SHARED_EXPORT void designerWarning(const QString &message)
QDESIGNER_SHARED_EXPORT void reloadIconResources(DesignerIconCache *iconCache, QObject *object)
QDESIGNER_SHARED_EXPORT bool runUIC(const QString &fileName, UicLanguage language, QByteArray &ba, QString &errorMessage)
#define QDESIGNER_SHARED_EXPORT