1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QFORMLAYOUT_H
41#define QFORMLAYOUT_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtWidgets/QLayout>
45
46QT_REQUIRE_CONFIG(formlayout);
47
48QT_BEGIN_NAMESPACE
49
50
51class QFormLayoutPrivate;
52
53class Q_WIDGETS_EXPORT QFormLayout : public QLayout
54{
55 Q_OBJECT
56 Q_DECLARE_PRIVATE(QFormLayout)
57 Q_PROPERTY(FieldGrowthPolicy fieldGrowthPolicy READ fieldGrowthPolicy WRITE setFieldGrowthPolicy RESET resetFieldGrowthPolicy)
58 Q_PROPERTY(RowWrapPolicy rowWrapPolicy READ rowWrapPolicy WRITE setRowWrapPolicy RESET resetRowWrapPolicy)
59 Q_PROPERTY(Qt::Alignment labelAlignment READ labelAlignment WRITE setLabelAlignment RESET resetLabelAlignment)
60 Q_PROPERTY(Qt::Alignment formAlignment READ formAlignment WRITE setFormAlignment RESET resetFormAlignment)
61 Q_PROPERTY(int horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing)
62 Q_PROPERTY(int verticalSpacing READ verticalSpacing WRITE setVerticalSpacing)
63
64public:
65 enum FieldGrowthPolicy {
66 FieldsStayAtSizeHint,
67 ExpandingFieldsGrow,
68 AllNonFixedFieldsGrow
69 };
70 Q_ENUM(FieldGrowthPolicy)
71
72 enum RowWrapPolicy {
73 DontWrapRows,
74 WrapLongRows,
75 WrapAllRows
76 };
77 Q_ENUM(RowWrapPolicy)
78
79 enum ItemRole {
80 LabelRole = 0,
81 FieldRole = 1,
82 SpanningRole = 2
83 };
84 Q_ENUM(ItemRole)
85
86 struct TakeRowResult {
87 QLayoutItem *labelItem;
88 QLayoutItem *fieldItem;
89 };
90
91 explicit QFormLayout(QWidget *parent = nullptr);
92 ~QFormLayout();
93
94 void setFieldGrowthPolicy(FieldGrowthPolicy policy);
95 FieldGrowthPolicy fieldGrowthPolicy() const;
96 void setRowWrapPolicy(RowWrapPolicy policy);
97 RowWrapPolicy rowWrapPolicy() const;
98 void setLabelAlignment(Qt::Alignment alignment);
99 Qt::Alignment labelAlignment() const;
100 void setFormAlignment(Qt::Alignment alignment);
101 Qt::Alignment formAlignment() const;
102
103 void setHorizontalSpacing(int spacing);
104 int horizontalSpacing() const;
105 void setVerticalSpacing(int spacing);
106 int verticalSpacing() const;
107
108 int spacing() const;
109 void setSpacing(int);
110
111 void addRow(QWidget *label, QWidget *field);
112 void addRow(QWidget *label, QLayout *field);
113 void addRow(const QString &labelText, QWidget *field);
114 void addRow(const QString &labelText, QLayout *field);
115 void addRow(QWidget *widget);
116 void addRow(QLayout *layout);
117
118 void insertRow(int row, QWidget *label, QWidget *field);
119 void insertRow(int row, QWidget *label, QLayout *field);
120 void insertRow(int row, const QString &labelText, QWidget *field);
121 void insertRow(int row, const QString &labelText, QLayout *field);
122 void insertRow(int row, QWidget *widget);
123 void insertRow(int row, QLayout *layout);
124
125 void removeRow(int row);
126 void removeRow(QWidget *widget);
127 void removeRow(QLayout *layout);
128
129 TakeRowResult takeRow(int row);
130 TakeRowResult takeRow(QWidget *widget);
131 TakeRowResult takeRow(QLayout *layout);
132
133 void setItem(int row, ItemRole role, QLayoutItem *item);
134 void setWidget(int row, ItemRole role, QWidget *widget);
135 void setLayout(int row, ItemRole role, QLayout *layout);
136
137 QLayoutItem *itemAt(int row, ItemRole role) const;
138 void getItemPosition(int index, int *rowPtr, ItemRole *rolePtr) const;
139 void getWidgetPosition(QWidget *widget, int *rowPtr, ItemRole *rolePtr) const;
140 void getLayoutPosition(QLayout *layout, int *rowPtr, ItemRole *rolePtr) const;
141 QWidget *labelForField(QWidget *field) const;
142 QWidget *labelForField(QLayout *field) const;
143
144 // reimplemented from QLayout
145 void addItem(QLayoutItem *item) override;
146 QLayoutItem *itemAt(int index) const override;
147 QLayoutItem *takeAt(int index) override;
148
149 void setGeometry(const QRect &rect) override;
150 QSize minimumSize() const override;
151 QSize sizeHint() const override;
152 void invalidate() override;
153
154 bool hasHeightForWidth() const override;
155 int heightForWidth(int width) const override;
156 Qt::Orientations expandingDirections() const override;
157 int count() const override;
158
159 int rowCount() const;
160
161#if 0
162 void dump() const;
163#endif
164
165private:
166 void resetFieldGrowthPolicy();
167 void resetRowWrapPolicy();
168 void resetLabelAlignment();
169 void resetFormAlignment();
170};
171
172Q_DECLARE_TYPEINFO(QFormLayout::TakeRowResult, Q_PRIMITIVE_TYPE);
173
174QT_END_NAMESPACE
175
176#endif
177