57 template <
class T,
int NumColumns>
58 class FixedColumnMatrix {
62 FixedColumnMatrix() { }
64 void clear() { m_storage.clear(); }
66 const T &operator()(
int r,
int c)
const {
return m_storage[r * NumColumns +
c]; }
67 T &operator()(
int r,
int c) {
return m_storage[r * NumColumns +
c]; }
69 int rowCount()
const {
return m_storage.size() / NumColumns; }
70 void addRow(
const T &value);
71 void insertRow(
int r,
const T &value);
72 void removeRow(
int r);
74 bool find(
const T &value,
int *rowPtr,
int *colPtr)
const ;
75 int count(
const T &value)
const {
return m_storage.count(value); }
78 const Storage &storage()
const {
return m_storage; }
80 static void storageIndexToPosition(
int idx,
int *rowPtr,
int *colPtr);
86 template <
class T,
int NumColumns>
87 void FixedColumnMatrix<T, NumColumns>::addRow(
const T &value)
89 for (
int i = 0; i < NumColumns; ++i)
90 m_storage.append(value);
93 template <
class T,
int NumColumns>
94 void FixedColumnMatrix<T, NumColumns>::insertRow(
int r,
const T &value)
98 m_storage.insert(it, NumColumns, value);
101 template <
class T,
int NumColumns>
102 void FixedColumnMatrix<T, NumColumns>::removeRow(
int r)
104 m_storage.remove(r * NumColumns, NumColumns);
107 template <
class T,
int NumColumns>
108 bool FixedColumnMatrix<T, NumColumns>::find(
const T &value,
int *rowPtr,
int *colPtr)
const 110 const int idx = m_storage.indexOf(value);
113 storageIndexToPosition(idx, rowPtr, colPtr);
117 template <
class T,
int NumColumns>
118 void FixedColumnMatrix<T, NumColumns>::storageIndexToPosition(
int idx,
int *rowPtr,
int *colPtr)
120 *rowPtr = idx / NumColumns;
121 *colPtr = idx % NumColumns;
147 QSizePolicy::ControlTypes
controlTypes()
const {
return item->controlTypes(); }
183 typedef FixedColumnMatrix<QFormLayoutItem *, ColumnCount>
ItemMatrix;
188 int insertRow(
int row);
189 void insertRows(
int row,
int count);
198 void setupVerticalLayoutData(
int width);
199 void setupHorizontalLayoutData(
int width);
205 return (hfw_width == width) || (width == sh_width && hfw_sh_height >= 0);
208 void recalcHFW(
int w);
209 void setupHfwLayoutData();
239 void calcSizeHints();
252 : fieldGrowthPolicy(DefaultFieldGrowthPolicy),
253 rowWrapPolicy(DefaultRowWrapPolicy), has_hfw(false), dirty(true), sizesDirty(true),
254 expandVertical(0), expandHorizontal(0), labelAlignment(0), formAlignment(0),
255 layoutWidth(-1), hfw_width(-1), hfw_sh_height(-1), min_width(-1),
256 sh_width(-1), thresh_width(
QLAYOUTSIZE_MAX), hSpacing(-1), vSpacing(-1)
266 | ((alignment & Qt::AlignLeft) ? Qt::AlignRight : 0));
276 return m.storage().indexOf(item);
296 item->
vSpace = userVSpacing;
319 bool expandH =
false;
320 bool expandV =
false;
328 int userVSpacing = q->verticalSpacing();
329 int userHSpacing = wrapAllRows ? 0 : q->horizontalSpacing();
331 int maxMinLblWidth = 0;
332 int maxMinFldWidth = 0;
333 int maxMinIfldWidth = 0;
335 int maxShLblWidth = 0;
336 int maxShFldWidth = 0;
337 int maxShIfldWidth = 0;
339 for (
int i = 0; i < rr; ++i) {
344 if (!label && !field)
373 if ((userHSpacing < 0 || userVSpacing < 0) && style) {
374 QSizePolicy::ControlTypes lbltypes =
376 QSizePolicy::ControlTypes fldtypes =
380 if (userVSpacing < 0) {
386 QSizePolicy::ControlTypes lbltoptypes =
388 QSizePolicy::ControlTypes fldtoptypes =
399 QSizePolicy::ControlTypes lbltoptypes =
401 QSizePolicy::ControlTypes fldtoptypes =
429 if (userHSpacing < 0 && !wrapAllRows && (label || !field->
fullRow) && field)
462 }
else if (dontWrapRows) {
464 sh_width =
qMax(maxShLblWidth + maxShFldWidth, maxShIfldWidth);
465 min_width =
qMax(maxMinLblWidth + maxMinFldWidth, maxMinIfldWidth);
469 sh_width =
qMax(maxShLblWidth + maxShFldWidth, maxShIfldWidth);
529 for (i = 0; i < rr; ++i) {
607 int spacing = userVSpacing;
615 if (style && prevItem1) {
616 QSizePolicy::ControlTypes itemtypes =
628 spacing =
qMax(spacing, spacing2);
669 bool addTopBottomStretch =
true;
676 int userVSpacing = q->verticalSpacing();
678 if (userVSpacing < 0) {
692 for (
int i = 0; i < rr; ++i) {
704 bool prevRowSplit =
false;
706 for (
int i = 0; i < rr; ++i) {
711 if (!label && !field)
732 if (wrapAllRows || splitSideBySide) {
737 vLayouts[vidx - 1].spacing =
spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, label, 0, prevItem1, prevItem2);
739 label->vLayoutIndex = vidx;
740 label->sideBySide =
false;
746 addTopBottomStretch =
false;
755 vLayouts[vidx - 1].spacing =
spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, field, 0, prevItem1, prevItem2);
757 field->vLayoutIndex = vidx;
758 field->sideBySide =
false;
764 addTopBottomStretch =
false;
769 prevRowSplit = splitSideBySide;
777 bool expanding =
false;
806 addTopBottomStretch =
false;
809 vLayouts[vidx - 1].spacing =
spacingHelper(q->parentWidget(), style, userVSpacing, prevRowSplit, label, field, prevItem1, prevItem2);
819 prevRowSplit =
false;
824 if (addTopBottomStretch) {
855 int fieldMaxWidth = 0;
860 for (
int i = 0; i < rr; ++i) {
865 if (!label && !field)
907 int leftMargin, topMargin, rightMargin, bottomMargin;
908 q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
914 int h = topMargin + bottomMargin;
915 int mh = topMargin + bottomMargin;
918 int w =
sh_width + leftMargin + rightMargin;
919 int mw =
min_width + leftMargin + rightMargin;
956 qWarning(
"QFormLayoutPrivate::setItem: Invalid cell (%d, %d)", row, column);
964 qWarning(
"QFormLayoutPrivate::setItem: Cell (%d, %d) already occupied", row, column);
979 if (q->adoptLayout(layout))
988 q->addChildWidget(widget);
1190 d->m_things.clear();
1192 d->m_matrix.clear();
1282 row =
d->insertRow(row);
1297 row =
d->insertRow(row);
1319 label =
new QLabel(labelText);
1320 #ifndef QT_NO_SHORTCUT 1360 row =
d->insertRow(row);
1384 row =
d->insertRow(row);
1396 int row =
d->insertRow(
d->m_matrix.rowCount());
1407 return d->m_things.count();
1417 return formItem->item;
1429 if (storageIndex == -1) {
1430 qWarning(
"QFormLayout::takeAt: Invalid index %d", index);
1435 QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col);
1440 d->m_things.removeAt(index);
1441 d->m_matrix(row, col) = 0;
1468 Qt::Orientations o = 0;
1496 int leftMargin, topMargin, rightMargin, bottomMargin;
1499 int targetWidth = width - leftMargin - rightMargin;
1501 if (!
d->haveHfwCached(targetWidth)) {
1507 if (targetWidth ==
d->sh_width)
1508 return d->hfw_sh_height + topMargin + bottomMargin;
1510 return d->hfw_height + topMargin + bottomMargin;
1521 int leftMargin, topMargin, rightMargin, bottomMargin;
1523 cr.
adjust(+leftMargin, +topMargin, -rightMargin, -bottomMargin);
1526 d->setupVerticalLayoutData(cr.
width());
1527 d->setupHorizontalLayoutData(cr.
width());
1528 if (hfw && (!
d->haveHfwCached(cr.
width()) ||
d->hfwLayouts.size() !=
d->vLayoutCount))
1529 d->recalcHFW(cr.
width());
1532 d->arrangeWidgets(
d->hfwLayouts, cr);
1535 d->arrangeWidgets(
d->vLayouts, cr);
1547 if (!
d->prefSize.isValid()) {
1561 if (!
d->minSize.isValid()) {
1575 d->sizesDirty =
true;
1578 d->formMaxWidth = -1;
1581 d->layoutWidth = -1;
1582 d->hfw_sh_height = -1;
1594 return d->m_matrix.rowCount();
1606 if (
uint(row) >=
uint(
d->m_matrix.rowCount()))
1638 if (storageIndex != -1)
1639 QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col);
1643 if (rolePtr && col != -1) {
1644 const bool spanning = col == 1 &&
d->m_matrix(row, col)->fullRow;
1664 if (
itemAt(index) == layout)
1702 return label->widget();
1721 return label->widget();
1750 d->fieldGrowthPolicy = policy;
1758 if (
d->fieldGrowthPolicy == DefaultFieldGrowthPolicy) {
1786 d->rowWrapPolicy = policy;
1794 if (
d->rowWrapPolicy == DefaultRowWrapPolicy) {
1819 if (
d->labelAlignment != alignment) {
1828 if (!
d->labelAlignment) {
1831 return d->labelAlignment;
1852 if (
d->formAlignment != alignment) {
1861 if (!
d->formAlignment) {
1864 return d->formAlignment;
1884 if (spacing !=
d->hSpacing) {
1893 if (
d->hSpacing >= 0) {
1916 if (spacing !=
d->vSpacing) {
1925 if (
d->vSpacing >= 0) {
1966 const int rr = m_matrix.rowCount();
1972 int delta = rect.
width() - formMaxWidth;
1979 for (i = 0; i < rr; ++i) {
1992 height =
qMin(height,
1998 int x = leftOffset + rect.
x() + label->
layoutPos;
2017 sz = sz.boundedTo(field->
maxSize);
2040 d->insertRows(rowCnt, row - rowCnt + 1);
2041 d->setWidget(row, role, widget);
2060 d->insertRows(rowCnt, row - rowCnt + 1);
2061 d->setLayout(row, role, layout);
2082 d->insertRows(rowCnt, row - rowCnt + 1);
2083 d->setItem(row, role, item);
2113 d->formAlignment = 0;
2123 d->labelAlignment = 0;
2130 for (
int i = 0; i <
rowCount(); ++i) {
2131 for (
int j = 0; j < 2; ++j) {
2132 qDebug(
"m_matrix(%d, %d) = %p", i, j,
d->m_matrix(i, j));
2135 for (
int i = 0; i <
d->m_things.count(); ++i)
2136 qDebug(
"m_things[%d] = %p", i,
d->m_things.at(i));
static Qt::LayoutDirection layoutDirection()
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
QPointer< QWidget > widget
#define it(className, varName)
void init(int stretchFactor=0, int minSize=0)
static void clear(QVariant::Private *d)
virtual Qt::Orientations expandingDirections() const =0
Returns whether this layout item can make use of more space than sizeHint().
int width() const
Returns the width of the rectangle.
virtual void setGeometry(const QRect &)
Reimplemented Function
static QStyle * style()
Returns the application's style object.
void invalidate()
Reimplemented Function
int height() const
Returns the height of the rectangle.
virtual QSize minimumSize() const =0
Implemented in subclasses to return the minimum size of this item.
The QString class provides a Unicode character string.
virtual bool hasHeightForWidth() const
Returns true if this layout's preferred height depends on its width; otherwise returns false...
The QVector class is a template class that provides a dynamic array.
bool empty() const
This function is provided for STL compatibility.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void resize(int size)
Sets the size of the vector to size.
void setParent(QObject *)
Makes the object a child of parent.
void setWidth(int w)
Sets the width to the given width.
Q_CORE_EXPORT void qDebug(const char *,...)
int width() const
Returns the width.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
virtual int indexOf(QWidget *) const
Searches for widget widget in this layout (not including child layouts).
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
The QLayout class is the base class of geometry managers.
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Q_CORE_EXPORT void qWarning(const char *,...)
int verticalStretch() const
const T & at(int i) const
Returns the item at index position i in the vector.
static QWidget * parentWidget(const QWidget *w)
void qGeomCalc(QVector< QLayoutStruct > &chain, int start, int count, int pos, int space, int spacer)
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
T * iterator
The QVector::iterator typedef provides an STL-style non-const iterator for QVector and QStack...
int top() const
Returns the y-coordinate of the rectangle's top edge.
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
Q_GUI_EXPORT int qSmartSpacing(const QLayout *layout, QStyle::PixelMetric pm)
#define Q_DECLARE_PUBLIC(Class)
void setBuddy(QWidget *)
Sets this label's buddy to buddy.
int y() const
Returns the y-coordinate of the rectangle's top edge.
virtual QSize sizeHint() const =0
Implemented in subclasses to return the preferred size of this item.
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned.
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
int x() const
Returns the x-coordinate of the rectangle's left edge.
QObject * parent() const
Returns a pointer to the parent object.
virtual QSize maximumSize() const =0
Implemented in subclasses to return the maximum size of this item.
The QPoint class defines a point in the plane using integer precision.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
int & rheight()
Returns a reference to the height.
QString objectName() const
int height() const
Returns the height.
The QRect class defines a rectangle in the plane using integer precision.
static QtFontStyle::Key getStyle(char **tokens)
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
The QLabel widget provides a text or image display.
Qt::Alignment alignment() const
Returns the alignment of this item.
static QString dump(const QByteArray &)
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
The QSize class defines the size of a two-dimensional object using integer point precision.
QRect geometry() const
Reimplemented Function
QLayout * layout()
Reimplemented Function
static const int QLAYOUTSIZE_MAX
#define qPrintable(string)
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
int combinedLayoutSpacing(QSizePolicy::ControlTypes controls1, QSizePolicy::ControlTypes controls2, Qt::Orientation orientation, QStyleOption *option=0, QWidget *widget=0) const
Returns the spacing that should be used between controls1 and controls2 in a layout.
int & rwidth()
Returns a reference to the width.
The QList class is a template class that provides lists.