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// Qt-Security score:significant reason:default
4
5//
6// W A R N I N G
7// -------------
8//
9// This file is not part of the Qt API. It exists for the convenience
10// of Qt Designer. This header
11// file may change from version to version without notice, or even be removed.
12//
13// We mean it.
14//
15
16#ifndef QLAYOUT_WIDGET_H
17#define QLAYOUT_WIDGET_H
18
20
21#include <QtDesigner/layoutdecoration.h>
22
23#include <QtCore/qpointer.h>
24#include <QtCore/qvariant.h>
25#include <QtWidgets/qwidget.h>
26#include <QtWidgets/qlayout.h>
27
29
30class QDesignerFormWindowInterface;
31class QDesignerFormEditorInterface;
32class QGridLayout;
33class QFormLayout;
34
35namespace qdesigner_internal {
36// ---- LayoutProperties: Helper struct that stores all layout-relevant properties
37// with functions to retrieve and apply to property sheets. Can be used to store the state
38// for undo commands and while rebuilding layouts.
40{
42 void clear();
43
46
61
62 // return a PropertyMask of visible properties
63 static int visibleProperties(const QLayout *layout);
64
65 // Retrieve from /apply to sheet: A property mask is returned indicating the properties found in the sheet
66 int fromPropertySheet(const QDesignerFormEditorInterface *core, QLayout *l, int mask = AllProperties);
67 int toPropertySheet(const QDesignerFormEditorInterface *core, QLayout *l, int mask = AllProperties, bool applyChanged = true) const;
68
71
74
75 QVariant m_objectName; // receives a PropertySheetStringValue
77#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
80#else
85#endif
86
95
98
101
104
107
110};
111
112// -- LayoutHelper: For use with the 'insert widget'/'delete widget' command,
113// able to store and restore states.
114// This could become part of 'QDesignerLayoutDecorationExtensionV2',
115// but to keep any existing old extensions working, it is provided as
116// separate class with a factory function.
118protected:
120
121public:
123
124 virtual ~LayoutHelper();
125
126 static LayoutHelper *createLayoutHelper(int type);
127
128 static int indexOf(const QLayout *lt, const QWidget *widget);
129
130 // Return area of an item (x == columns)
131 QRect itemInfo(QLayout *lt, const QWidget *widget) const;
132
133 virtual QRect itemInfo(QLayout *lt, int index) const = 0;
134 virtual void insertWidget(QLayout *lt, const QRect &info, QWidget *w) = 0;
135 virtual void removeWidget(QLayout *lt, QWidget *widget) = 0;
136 // Since 4.5: The 'morphing' feature requires an API for replacing widgets on layouts.
137 virtual void replaceWidget(QLayout *lt, QWidget *before, QWidget *after) = 0;
138
139 // Simplify a grid, remove empty columns, rows within the rectangle
140 // The DeleteWidget command restricts the area to be simplified.
141 virtual bool canSimplify(const QDesignerFormEditorInterface *core, const QWidget *widgetWithManagedLayout, const QRect &restrictionArea) const = 0;
142 virtual void simplify(const QDesignerFormEditorInterface *core, QWidget *widgetWithManagedLayout, const QRect &restrictionArea) = 0;
143
144 // Push and pop a state. Can be used for implementing undo for
145 // simplify/row, column insertion commands, provided that
146 // the widgets remain the same.
147 virtual void pushState(const QDesignerFormEditorInterface *core, const QWidget *widgetWithManagedLayout) = 0;
148 virtual void popState(const QDesignerFormEditorInterface *core, QWidget *widgetWithManagedLayout) = 0;
149};
150
151// Base class for layout decoration extensions.
152class QDESIGNER_SHARED_EXPORT QLayoutSupport: public QObject, public QDesignerLayoutDecorationExtension
153{
154 Q_OBJECT
155 Q_INTERFACES(QDesignerLayoutDecorationExtension)
156
157protected:
158 QLayoutSupport(QDesignerFormWindowInterface *formWindow, QWidget *widget, LayoutHelper *helper, QObject *parent = nullptr);
159
160public:
161 ~QLayoutSupport() override;
162
163 QDesignerFormWindowInterface *formWindow() const { return m_formWindow; }
164
165 // DecorationExtension V2
166 LayoutHelper* helper() const { return m_helper; }
167
168 // DecorationExtension
169 int currentIndex() const override { return m_currentIndex; }
170
171 InsertMode currentInsertMode() const override { return m_currentInsertMode; }
172
173 std::pair<int, int> currentCell() const override { return m_currentCell; }
174
175 int findItemAt(const QPoint &pos) const override;
176 int indexOf(QWidget *widget) const override;
177 int indexOf(QLayoutItem *item) const override;
178
179 void adjustIndicator(const QPoint &pos, int index) override;
180
181 QWidgetList widgets(QLayout *layout) const override;
182
183 // Pad empty cells with dummy spacers. Called by layouting commands.
184 static void createEmptyCells(QGridLayout *gridLayout);
185 // remove dummy spacers in the area. Returns false if there are non-empty items in the way
186 static bool removeEmptyCells(QGridLayout *gridLayout, const QRect &area);
187 static void createEmptyCells(QFormLayout *formLayout); // ditto.
188 static bool removeEmptyCells(QFormLayout *formLayout, const QRect &area);
189
190 // grid helpers: find item index
191 static int findItemAt(QGridLayout *, int row, int column);
192 using QDesignerLayoutDecorationExtension::findItemAt;
193 // grid helpers: Quick check whether simplify should be enabled for grids. May return false positives.
194 static bool canSimplifyQuickCheck(const QGridLayout *);
195 static bool canSimplifyQuickCheck(const QFormLayout *fl);
196 // Factory function, create layout support according to layout type of widget
197 static QLayoutSupport *createLayoutSupport(QDesignerFormWindowInterface *formWindow, QWidget *widget, QObject *parent = nullptr);
198
199protected:
200 // figure out insertion position and mode from indicator on empty cell if supported
201 virtual void setCurrentCellFromIndicatorOnEmptyCell(int index) = 0;
202 // figure out insertion position and mode from indicator
203 virtual void setCurrentCellFromIndicator(Qt::Orientation indicatorOrientation, int index, int increment) = 0;
204
205 // Overwrite to return the extended geometry of an item, that is,
206 // if it is a border item, include the widget border for the indicator to work correctly
207 virtual QRect extendedGeometry(int index) const = 0;
208 virtual bool supportsIndicatorOrientation(Qt::Orientation indicatorOrientation) const = 0;
209
210 QRect itemInfo(int index) const override;
211 QLayout *layout() const;
212 QGridLayout *gridLayout() const;
213 QWidget *widget() const { return m_widget; }
214
215 void setInsertMode(InsertMode im);
216 void setCurrentCell(const std::pair<int, int> &cell);
217
218private:
219 enum Indicator { LeftIndicator, TopIndicator, RightIndicator, BottomIndicator, NumIndicators };
220
221 void hideIndicator(Indicator i);
222 void showIndicator(Indicator i, const QRect &geometry, const QPalette &);
223
224 QDesignerFormWindowInterface *m_formWindow;
225 LayoutHelper* m_helper;
226
227 QPointer<QWidget> m_widget;
228 QPointer<QWidget> m_indicators[NumIndicators];
229 int m_currentIndex;
230 InsertMode m_currentInsertMode;
231 std::pair<int, int> m_currentCell;
232};
233} // namespace qdesigner_internal
234
235// Red layout widget.
237{
238 Q_OBJECT
239public:
240 explicit QLayoutWidget(QDesignerFormWindowInterface *formWindow, QWidget *parent = nullptr);
241
242 int layoutLeftMargin() const;
243 void setLayoutLeftMargin(int layoutMargin);
244
245 int layoutTopMargin() const;
246 void setLayoutTopMargin(int layoutMargin);
247
248 int layoutRightMargin() const;
249 void setLayoutRightMargin(int layoutMargin);
250
251 int layoutBottomMargin() const;
252 void setLayoutBottomMargin(int layoutMargin);
253
254 QDesignerFormWindowInterface *formWindow() const { return m_formWindow; }
255
256protected:
257 bool event(QEvent *e) override;
258 void paintEvent(QPaintEvent *e) override;
259
260private:
261 QDesignerFormWindowInterface *m_formWindow;
262 int m_leftMargin;
263 int m_topMargin;
264 int m_rightMargin;
265 int m_bottomMargin;
266};
267
268QT_END_NAMESPACE
269
270#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:432
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)
Combined button and popup list for selecting options.
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)
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)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2618
QT_END_NAMESPACE Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QtOhos::enums::kit::ShareKit::systemShare::SelectionMode))
#define QDESIGNER_SHARED_EXPORT