1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QFORMLAYOUT_H
5#define QFORMLAYOUT_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/QLayout>
9
10QT_REQUIRE_CONFIG(formlayout);
11
12QT_BEGIN_NAMESPACE
13
14
15class QFormLayoutPrivate;
16
17class Q_WIDGETS_EXPORT QFormLayout : public QLayout
18{
19 Q_OBJECT
20 Q_DECLARE_PRIVATE(QFormLayout)
21 Q_PROPERTY(FieldGrowthPolicy fieldGrowthPolicy READ fieldGrowthPolicy WRITE setFieldGrowthPolicy
22 RESET resetFieldGrowthPolicy)
23 Q_PROPERTY(RowWrapPolicy rowWrapPolicy READ rowWrapPolicy WRITE setRowWrapPolicy
24 RESET resetRowWrapPolicy)
25 Q_PROPERTY(Qt::Alignment labelAlignment READ labelAlignment WRITE setLabelAlignment
26 RESET resetLabelAlignment)
27 Q_PROPERTY(Qt::Alignment formAlignment READ formAlignment WRITE setFormAlignment
28 RESET resetFormAlignment)
29 Q_PROPERTY(int horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing)
30 Q_PROPERTY(int verticalSpacing READ verticalSpacing WRITE setVerticalSpacing)
31
32public:
33 enum FieldGrowthPolicy {
34 FieldsStayAtSizeHint,
35 ExpandingFieldsGrow,
36 AllNonFixedFieldsGrow
37 };
38 Q_ENUM(FieldGrowthPolicy)
39
40 enum RowWrapPolicy {
41 DontWrapRows,
42 WrapLongRows,
43 WrapAllRows
44 };
45 Q_ENUM(RowWrapPolicy)
46
47 enum ItemRole {
48 LabelRole = 0,
49 FieldRole = 1,
50 SpanningRole = 2
51 };
52 Q_ENUM(ItemRole)
53
54 struct TakeRowResult {
55 QLayoutItem *labelItem;
56 QLayoutItem *fieldItem;
57 };
58
59 explicit QFormLayout(QWidget *parent = nullptr);
60 ~QFormLayout();
61
62 void setFieldGrowthPolicy(FieldGrowthPolicy policy);
63 FieldGrowthPolicy fieldGrowthPolicy() const;
64 void setRowWrapPolicy(RowWrapPolicy policy);
65 RowWrapPolicy rowWrapPolicy() const;
66 void setLabelAlignment(Qt::Alignment alignment);
67 Qt::Alignment labelAlignment() const;
68 void setFormAlignment(Qt::Alignment alignment);
69 Qt::Alignment formAlignment() const;
70
71 void setHorizontalSpacing(int spacing);
72 int horizontalSpacing() const;
73 void setVerticalSpacing(int spacing);
74 int verticalSpacing() const;
75
76 int spacing() const override;
77 void setSpacing(int) override;
78
79 void addRow(QWidget *label, QWidget *field);
80 void addRow(QWidget *label, QLayout *field);
81 void addRow(const QString &labelText, QWidget *field);
82 void addRow(const QString &labelText, QLayout *field);
83 void addRow(QWidget *widget);
84 void addRow(QLayout *layout);
85
86 void insertRow(int row, QWidget *label, QWidget *field);
87 void insertRow(int row, QWidget *label, QLayout *field);
88 void insertRow(int row, const QString &labelText, QWidget *field);
89 void insertRow(int row, const QString &labelText, QLayout *field);
90 void insertRow(int row, QWidget *widget);
91 void insertRow(int row, QLayout *layout);
92
93 void removeRow(int row);
94 void removeRow(QWidget *widget);
95 void removeRow(QLayout *layout);
96
97 TakeRowResult takeRow(int row);
98 TakeRowResult takeRow(QWidget *widget);
99 TakeRowResult takeRow(QLayout *layout);
100
101 void setItem(int row, ItemRole role, QLayoutItem *item);
102 void setWidget(int row, ItemRole role, QWidget *widget);
103 void setLayout(int row, ItemRole role, QLayout *layout);
104
105 void setRowVisible(int row, bool on);
106 void setRowVisible(QWidget *widget, bool on);
107 void setRowVisible(QLayout *layout, bool on);
108
109 bool isRowVisible(int row) const;
110 bool isRowVisible(QWidget *widget) const;
111 bool isRowVisible(QLayout *layout) const;
112
113 QLayoutItem *itemAt(int row, ItemRole role) const;
114 void getItemPosition(int index, int *rowPtr, ItemRole *rolePtr) const;
115 void getWidgetPosition(QWidget *widget, int *rowPtr, ItemRole *rolePtr) const;
116 void getLayoutPosition(QLayout *layout, int *rowPtr, ItemRole *rolePtr) const;
117 QWidget *labelForField(QWidget *field) const;
118 QWidget *labelForField(QLayout *field) const;
119
120 // reimplemented from QLayout
121 void addItem(QLayoutItem *item) override;
122 QLayoutItem *itemAt(int index) const override;
123 QLayoutItem *takeAt(int index) override;
124
125 void setGeometry(const QRect &rect) override;
126 QSize minimumSize() const override;
127 QSize sizeHint() const override;
128 void invalidate() override;
129
130 bool hasHeightForWidth() const override;
131 int heightForWidth(int width) const override;
132 Qt::Orientations expandingDirections() const override;
133 int count() const override;
134
135 int rowCount() const;
136
137#if 0
138 void dump() const;
139#endif
140
141private:
142 void resetFieldGrowthPolicy();
143 void resetRowWrapPolicy();
144 void resetLabelAlignment();
145 void resetFormAlignment();
146};
147
148Q_DECLARE_TYPEINFO(QFormLayout::TakeRowResult, Q_PRIMITIVE_TYPE);
149
150QT_END_NAMESPACE
151
152#endif
153

source code of qtbase/src/widgets/kernel/qformlayout.h