79 bool isEmpty()
const {
return item_->isEmpty(); }
86 Qt::Alignment
alignment()
const {
return item_->alignment(); }
91 item_->widget()->sizePolicy().horizontalStretch() : 0; }
93 item_->widget()->sizePolicy().verticalStretch() : 0; }
99 inline int toRow(
int rr)
const {
return torow >= 0 ? torow : rr - 1; }
100 inline int toCol(
int cc)
const {
return tocol >= 0 ? tocol : cc - 1; }
114 void add(
QGridBox*,
int row1,
int row2,
int col1,
int col2);
115 QSize sizeHint(
int hSpacing,
int vSpacing)
const;
116 QSize minimumSize(
int hSpacing,
int vSpacing)
const;
117 QSize maximumSize(
int hSpacing,
int vSpacing)
const;
119 Qt::Orientations expandingDirections(
int hSpacing,
int vSpacing)
const;
121 void distribute(
QRect rect,
int hSpacing,
int vSpacing);
125 { setSize(
qMax(rows, rr),
qMax(cols, cc)); }
127 { expand(r + 1, 0); rStretch[r] = s; setDirty(); }
129 { expand(0, c + 1); cStretch[
c] = s; setDirty(); }
130 inline int rowStretch(
int r)
const {
return rStretch.at(r); }
133 { expand(r + 1, 0); rMinHeights[r] = s; setDirty(); }
135 { expand(0, c + 1); cMinWidths[
c] = s; setDirty(); }
136 inline int rowSpacing(
int r)
const {
return rMinHeights.at(r); }
142 inline void setDirty() { needRecalc =
true; hfw_width = -1; }
143 inline bool isDirty()
const {
return needRecalc; }
144 bool hasHeightForWidth(
int hSpacing,
int vSpacing);
145 int heightForWidth(
int width,
int hSpacing,
int vSpacing);
148 inline void getNextPos(
int &row,
int &col) { row = nextR; col = nextC; }
149 inline int count()
const {
return things.count(); }
150 QRect cellRect(
int row,
int col)
const;
153 if (index < things.count())
154 return things.at(index)->item();
160 if (index < things.count()) {
161 if (
QGridBox *b = things.takeAt(index)) {
176 if (index < things.count()) {
178 int toRow = b->
toRow(rr);
179 int toCol = b->
toCol(cc);
182 *rowSpan = toRow - *row + 1;
183 *columnSpan = toCol - *column +1;
189 void setNextPosAfter(
int r,
int c);
190 void recalcHFW(
int w);
191 void addHfwData(
QGridBox *box,
int width);
195 void setSize(
int rows,
int cols);
198 void setupLayoutData(
int hSpacing,
int vSpacing);
199 void setupHfwLayoutData();
200 void effectiveMargins(
int *
left,
int *top,
int *
right,
int *bottom)
const;
238 int b = bottomMargin;
246 const int n = things.count();
247 for (
int i = 0; i < n; ++i) {
255 if (box->
col <= leftMost) {
256 if (box->
col < leftMost) {
264 if (visualHReversed) {
270 if (box->
row <= topMost) {
271 if (box->
row < topMost) {
284 if (box->
toCol(cc) >= rightMost) {
285 if (box->
toCol(cc) > rightMost) {
287 rightMost = box->
toCol(cc);
293 if (visualHReversed) {
300 if (box->
toRow(rr) >= bottomMost) {
301 if (box->
toRow(rr) > bottomMost) {
303 bottomMost = box->
toRow(rr);
337 horizontalSpacing = -1;
338 verticalSpacing = -1;
343 : rowData(0), colData(0)
354 setSize(nRows, nCols);
360 while (!things.isEmpty())
361 delete things.takeFirst();
367 setupLayoutData(hSpacing, vSpacing);
383 setupHfwLayoutData();
388 for (
int r = 0; r < rr; r++) {
401 setupLayoutData(hSpacing, vSpacing);
405 effectiveMargins(&left, &top, &right, &bottom);
407 int hMargins = left +
right;
408 if (w - hMargins != hfw_width) {
409 qGeomCalc(colData, 0, cc, 0, w - hMargins);
410 recalcHFW(w - hMargins);
412 return hfw_height + top + bottom;
417 (void)heightForWidth(w, hSpacing, vSpacing);
421 effectiveMargins(0, &top, 0, &bottom);
422 return hfw_minheight + top + bottom;
433 for (
int r = 0; r < rr; r++)
434 h += rowData.at(r).*size + rowData.at(r).spacing;
435 for (
int c = 0;
c < cc;
c++)
436 w += colData.at(
c).*size + colData.at(
c).spacing;
448 Qt::Orientations ret;
450 for (
int r = 0; r < rr; r++) {
451 if (rowData.at(r).expansive) {
456 for (
int c = 0;
c < cc;
c++) {
457 if (colData.at(
c).expansive) {
482 if ((
int)rowData.size() < r) {
483 int newR =
qMax(r, rr * 2);
484 rowData.resize(newR);
485 rStretch.resize(newR);
486 rMinHeights.resize(newR);
487 for (
int i = rr; i < newR; i++) {
489 rowData[i].maximumSize = 0;
496 if ((
int)colData.size() <
c) {
497 int newC =
qMax(c, cc * 2);
498 colData.resize(newC);
499 cStretch.resize(newC);
500 cMinWidths.resize(newC);
501 for (
int i = cc; i < newC; i++) {
503 colData[i].maximumSize = 0;
511 if (hfwData && (
int)hfwData->size() < r) {
523 if (col > nextC || (col == nextC && row >= nextR)) {
532 if (row > nextR || (row == nextR && col >= nextC)) {
545 expand(row + 1, col + 1);
550 setNextPosAfter(row, col);
555 if (row2 >= 0 && row2 < row1)
556 qWarning(
"QGridLayout: Multi-cell fromRow greater than toRow");
557 if (col2 >= 0 && col2 < col1)
558 qWarning(
"QGridLayout: Multi-cell fromCol greater than toCol");
559 if (row1 == row2 && col1 == col2) {
560 add(box, row1, col1);
563 expand(row2 + 1, col2 + 1);
575 setNextPosAfter(row2, col2);
587 if (!cStretch.at(box->
col))
597 if (!rStretch.at(box->
row))
609 for (
int i = start; i <=
end; i++) {
625 for (i = start; i <=
end; i++) {
630 if (stretchArray.
at(i) == 0)
649 qGeomCalc(chain, start, end - start + 1, 0, minSize);
651 for (i = start; i <=
end; i++) {
653 int nextPos = (i ==
end) ? minSize : chain.
at(i + 1).
pos;
654 int realSize = nextPos - pos;
663 }
else if (w < minSize) {
664 qGeomCalc(chain, start, end - start + 1, 0, minSize);
665 for (i = start; i <=
end; i++) {
673 qGeomCalc(chain, start, end - start + 1, 0, sizeHint);
674 for (i = start; i <=
end; i++) {
687 return grid[(r * cc) + c];
699 qSwap(numRows, numColumns);
703 if (fixedSpacing < 0) {
708 for (
int c = 0;
c < numColumns; ++
c) {
710 int previousRow = -1;
712 for (
int r = 0; r < numRows; ++r) {
717 if (previousRow != -1 && (!box || previousBox != box)) {
718 int spacing = fixedSpacing;
729 qSwap(controlTypes1, controlTypes2);
733 orientation, 0, q->parentWidget());
736 QGridBox *sibling = vReversed ? previousBox : box;
745 if (spacing > chain.
at(previousRow).
spacing)
746 chain[previousRow].spacing = spacing;
761 #ifndef QT_LAYOUT_DISABLE_CACHING 768 for (i = 0; i < rr; i++) {
769 rowData[i].init(rStretch.at(i), rMinHeights.at(i));
770 rowData[i].maximumSize = rStretch.at(i) ?
QLAYOUTSIZE_MAX : rMinHeights.at(i);
772 for (i = 0; i < cc; i++) {
773 colData[i].init(cStretch.at(i), cMinWidths.at(i));
774 colData[i].maximumSize = cStretch.at(i) ?
QLAYOUTSIZE_MAX : cMinWidths.at(i);
777 int n = things.size();
780 bool has_multi =
false;
793 for (i = 0; i < n; ++i) {
794 QGridBox *
const box = things.at(i);
803 addData(box, sizes[i],
true,
false);
810 addData(box, sizes[i],
false,
true);
816 for (
int r = box->
row; r <= box->toRow(rr); ++r) {
817 for (
int c = box->
col; c <= box->toCol(cc); ++
c) {
832 for (i = 0; i < n; ++i) {
833 QGridBox *
const box = things.at(i);
837 sizes[i].hint.height(), rStretch, box->
vStretch());
840 sizes[i].hint.width(), cStretch, box->
hStretch());
844 for (i = 0; i < rr; i++)
845 rowData[i].expansive = rowData.at(i).expansive || rowData.at(i).stretch > 0;
846 for (i = 0; i < cc; i++)
847 colData[i].expansive = colData.at(i).expansive || colData.at(i).stretch > 0;
849 q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
877 for (
int i = 0; i < rr; i++) {
878 rData[i] = rowData.
at(i);
879 rData[i].minimumSize = rData[i].sizeHint = rMinHeights.
at(i);
882 for (
int pass = 0; pass < 2; ++pass) {
883 for (
int i = 0; i < things.size(); ++i) {
887 int r2 = box->
toRow(rr);
888 int c2 = box->
toCol(cc);
889 int w = colData.at(c2).pos + colData.at(c2).size - colData.at(c1).pos;
913 for (
int i = 0; i < rr; i++)
920 bool visualHReversed = hReversed;
923 visualHReversed = !visualHReversed;
925 setupLayoutData(hSpacing, vSpacing);
928 effectiveMargins(&left, &top, &right, &bottom);
929 r.
adjust(+left, +top, -right, -bottom);
934 recalcHFW(r.
width());
945 && ((r.
right() > rect.right()) != visualHReversed)));
946 int n = things.size();
947 for (i = 0; i < n; ++i) {
948 QGridBox *box = things.at(reverse ? n-i-1 : i);
949 int r2 = box->
toRow(rr);
950 int c2 = box->
toCol(cc);
952 int x = colData.at(box->
col).pos;
954 int x2p = colData.at(c2).pos + colData.at(c2).size;
970 if (row < 0 || row >= rr || col < 0 || col >= cc)
974 if (has_hfw && hfwData)
978 return QRect(colData.at(col).pos, rDataPtr->
at(row).
pos,
979 colData.at(col).size, rDataPtr->
at(row).
size);
1102 int space,
const char *
name)
1106 d->expand(nRows, nCols);
1132 d->expand(nRows, nCols);
1156 d->expand(nRows, nCols);
1177 d->addVertical =
false;
1180 d->addVertical =
true;
1221 if (
d->horizontalSpacing >= 0) {
1222 return d->horizontalSpacing;
1252 if (
d->verticalSpacing >= 0) {
1253 return d->verticalSpacing;
1268 d->horizontalSpacing =
d->verticalSpacing =
spacing;
1294 return d->numRows();
1303 return d->numCols();
1314 d->effectiveMargins(&left, &top, &right, &bottom);
1315 result +=
QSize(left + right, top + bottom);
1327 d->effectiveMargins(&left, &top, &right, &bottom);
1328 result +=
QSize(left + right, top + bottom);
1341 d->effectiveMargins(&left, &top, &right, &bottom);
1342 s +=
QSize(left + right, top + bottom);
1393 bool QGridLayout::findWidget(
QWidget* w,
int *row,
int *column)
1400 d->getItemPosition(index, row, column, &dummy1, &dummy2);
1420 return d->itemAt(index);
1437 int n =
d->things.count();
1438 for (
int i = 0; i < n; ++i) {
1440 if (row >= box->
row && row <= box->toRow(
d->rr)
1441 && column >= box->
col && column <= box->toCol(
d->cc)) {
1454 return d->takeAt(index);
1469 d->getItemPosition(index, row, column, rowSpan, columnSpan);
1479 if (
d->isDirty() || rect !=
geometry()) {
1498 return d->cellRect(row, column);
1511 void QGridLayout::expand(
int nRows,
int nCols)
1514 d->expand(nRows, nCols);
1525 d->getNextPos(r, c);
1544 d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);
1574 if (row < 0 || column < 0) {
1575 qWarning(
"QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d",
1582 addItem(b, row, column, 1, 1, alignment);
1601 int rowSpan,
int columnSpan, Qt::Alignment
alignment)
1606 int toRow = (rowSpan < 0) ? -1 : fromRow + rowSpan - 1;
1607 int toColumn = (columnSpan < 0) ? -1 : fromColumn + columnSpan - 1;
1611 d->add(b, fromRow, toRow, fromColumn, toColumn);
1643 d->add(b, row, column);
1659 int rowSpan,
int columnSpan, Qt::Alignment
alignment)
1666 d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);
1685 d->setRowStretch(row, stretch);
1697 return d->rowStretch(row);
1708 return d->colStretch(column);
1731 d->setColStretch(column, stretch);
1745 d->setRowMinimumHeight(row, minSize);
1757 return d->rowSpacing(row);
1768 d->setColumnMinimumWidth(column, minSize);
1780 return d->colSpacing(column);
1809 if (
d->horReversed()) {
QList< QGridBox * > things
int heightForWidth(int w) const
QSize maximumSize(int hSpacing, int vSpacing) const
QLayoutItem * itemAtPosition(int row, int column) const
Returns the layout item that occupies cell (row, column), or 0 if the cell is empty.
int horizontalSpacing() const
the spacing between widgets that are laid out side by side
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
Qt::Alignment alignment() const
QGridBox(const QLayout *l, QWidget *wid)
Qt::Orientations expandingDirections() const
Reimplemented Function
QPointer< QWidget > widget
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
virtual QRect geometry() const =0
Returns the rectangle covered by this layout item.
char * data()
Returns a pointer to the data stored in the byte array.
static void initEmptyMultiBox(QVector< QLayoutStruct > &chain, int start, int end)
int rowStretch(int r) const
QGridLayout()
Constructs a new grid layout.
QVector< QLayoutStruct > * hfwData
void addLayout(QLayout *, int row, int column, Qt::Alignment=0)
Places the layout at position (row, column) in the grid.
int colSpacing(int c) const
void setReversed(bool r, bool c)
void setupHfwLayoutData()
static C reverse(const C &l)
void addData(QGridBox *b, const QGridLayoutSizeTriple &sizes, bool r, bool c)
QSizePolicy::ControlTypes controlTypes() const
Returns the control type(s) for the layout item.
void setColumnMinimumWidth(int column, int minSize)
Sets the minimum width of column column to minSize pixels.
int left() const
Returns the x-coordinate of the rectangle's left edge.
int width() const
Returns the width of the rectangle.
int minimumHeightForWidth(int width, int hSpacing, int vSpacing)
int count() const
Reimplemented Function
virtual void setGeometry(const QRect &)
Reimplemented Function
long ASN1_INTEGER_get ASN1_INTEGER * a
QGridBox(QLayoutItem *lit)
QVector< QLayoutStruct > colData
void invalidate()
Reimplemented Function
int height() const
Returns the height of the rectangle.
int bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
int rowStretch(int row) const
Returns the stretch factor for row row.
void setHeight(int h)
Sets the height to the given height.
int columnMinimumWidth(int column) const
Returns the column spacing for column column.
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
int rowCount() const
Returns the number of rows in this grid.
void setupLayoutData(int hSpacing, int vSpacing)
Qt::Orientations expandingDirections(int hSpacing, int vSpacing) const
int heightForWidth(int) const
Reimplemented Function
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void add(QGridBox *, int row, int col)
void setParent(QObject *)
Makes the object a child of parent.
void setObjectName(const QString &name)
void setWidth(int w)
Sets the width to the given width.
void setupSpacings(QVector< QLayoutStruct > &chain, QGridBox *grid[], int fixedSpacing, Qt::Orientation orientation)
void setHorizontalSpacing(int spacing)
QLayoutItem * itemAt(int index) const
Reimplemented Function
void setOriginCorner(Qt::Corner)
Sets the grid's origin corner, i.e.
void setAlignment(Qt::Alignment a)
int columnCount() const
Returns the number of columns in this grid.
QLayoutItem * takeAt(int index)
Reimplemented Function
int width() const
Returns the width.
~QGridLayout()
Destroys the grid layout.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
int colStretch(int c) const
void setSize(int rows, int cols)
QLayout()
Constructs a new child QLayout.
bool adoptLayout(QLayout *layout)
virtual int indexOf(QWidget *) const
Searches for widget widget in this layout (not including child layouts).
QSize minimumSize() const
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.
void getNextPos(int &row, int &col)
QSize maximumSize() const
void setRowMinimumHeight(int row, int minSize)
Sets the minimum height of row row to minSize pixels.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
Qt::Corner originCorner() const
Returns the corner that's used for the grid's origin, i.e.
int spacing() const
If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwi...
void effectiveMargins(int *left, int *top, int *right, int *bottom) const
void setVerticalSpacing(int spacing)
void expand(int rows, int cols)
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
QRect alignmentRect(const QRect &) const
Returns the rectangle that should be covered when the geometry of this layout is set to r...
void qSwap(T &value1, T &value2)
QSize minimumSize() const
Reimplemented Function
const T & at(int i) const
Returns the item at index position i in the vector.
QSize findSize(int QLayoutStruct::*, int hSpacing, int vSpacing) const
static QWidget * parentWidget(const QWidget *w)
bool hasHeightForWidth() const
Reimplemented Function
void qGeomCalc(QVector< QLayoutStruct > &chain, int start, int count, int pos, int space, int spacer)
void setNextPosAfter(int r, int c)
int columnStretch(int column) const
Returns the stretch factor for column column.
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
QVector< int > rMinHeights
Qt::Orientations expandingDirections() const
int minimumHeightForWidth(int) const
Reimplemented Function
int top() const
Returns the y-coordinate of the rectangle's top edge.
void * qMemSet(void *dest, int c, size_t n)
void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan)
Q_GUI_EXPORT int qSmartSpacing(const QLayout *layout, QStyle::PixelMetric pm)
#define Q_DECLARE_PUBLIC(Class)
void setColStretch(int c, int s)
int right() const
Returns the x-coordinate of the rectangle's right edge.
void setColumnStretch(int column, int stretch)
Sets the stretch factor of column column to stretch.
int rowSpacing(int r) const
void setGeometry(const QRect &)
Reimplemented Function
int y() const
Returns the y-coordinate of the rectangle's top edge.
void addChildWidget(QWidget *w)
This function is called from addWidget() functions in subclasses to add w as a managed widget of a la...
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned.
int x() const
Returns the x-coordinate of the rectangle's left edge.
QObject * parent() const
Returns a pointer to the parent object.
QSize sizeHint(int hSpacing, int vSpacing) const
void invalidate()
Reimplemented Function
static bool checkWidget(QLayout *l, QWidget *w)
QSize maximumSize() const
Reimplemented Function
The QGridLayout class lays out widgets in a grid.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
QString objectName() const
int height() const
Returns the height.
void setDefaultPositioning(int n, Qt::Orientation orient)
The QRect class defines a rectangle in the plane using integer precision.
QSize sizeHint() const
Reimplemented Function
static QGridBox *& gridAt(QGridBox *grid[], int r, int c, int cc, Qt::Orientation orientation=Qt::Vertical)
Qt::Alignment alignment() const
Returns the alignment of this item.
void setColumnMinimumWidth(int c, int s)
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.
void setRowStretch(int row, int stretch)
Sets the stretch factor of row row to stretch.
void addHfwData(QGridBox *box, int width)
void setRowStretch(int r, int s)
QRect cellRect(int row, int column) const
Returns the geometry of the cell with row row and column column in the grid.
QSize minimumSize(int hSpacing, int vSpacing) const
QVector< QLayoutStruct > rowData
void getItemPosition(int idx, int *row, int *column, int *rowSpan, int *columnSpan)
Returns the position information of the item with the given index.
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QRect geometry() const
Reimplemented Function
QLayout * layout()
Reimplemented Function
static const int QLAYOUTSIZE_MAX
void setRowMinimumHeight(int r, int s)
static const KeyPair *const end
static void qMaxExpCalc(int &max, bool &exp, bool &empty, int boxmax, bool boxexp, bool boxempty)
QRect cellRect(int row, int col) const
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void setGeometry(const QRect &r)
void setSpacing(int spacing)
This function sets both the vertical and horizontal spacing to spacing.
QLayoutItem * takeAt(int index)
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 rowMinimumHeight(int row) const
Returns the minimum width set for row row.
bool hasHeightForWidth(int hSpacing, int vSpacing)
static void distributeMultiBox(QVector< QLayoutStruct > &chain, int start, int end, int minSize, int sizeHint, QVector< int > &stretchArray, int stretch)
void addItem(QLayoutItem *item, int row, int column, int rowSpan=1, int columnSpan=1, Qt::Alignment=0)
Adds item at position row, column, spanning rowSpan rows and columnSpan columns, and aligns it accord...
int heightForWidth(int width, int hSpacing, int vSpacing)
bool hasHeightForWidth() const
int verticalSpacing() const
the spacing between widgets that are laid out on top of each other
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QLayoutItem * itemAt(int index) const
QVector< int > cMinWidths
The QList class is a template class that provides lists.
void distribute(QRect rect, int hSpacing, int vSpacing)