209QQuickGridLayoutBase::QQuickGridLayoutBase(QQuickGridLayoutBasePrivate &dd,
210 Qt::Orientation orientation,
212 : QQuickLayout(dd, parent)
214 Q_D(QQuickGridLayoutBase);
215 d->orientation = orientation;
216 d->styleInfo =
new QQuickLayoutStyleInfo;
286void QQuickGridLayoutBase::setStretchFactor(QQuickItem *item,
int stretchFactor, Qt::Orientation orient)
288 Q_D(QQuickGridLayoutBase);
289 d->engine.setStretchFactor(item, stretchFactor, orient);
302void QQuickGridLayoutBase::componentComplete()
304 qCDebug(lcQuickLayouts) <<
"QQuickGridLayoutBase::componentComplete()" <<
this << parent();
305 QQuickLayout::componentComplete();
308
309
310
311
312
313
314
315
316
318 ensureLayoutItemsUpdated(QQuickLayout::ApplySizeHints);
320 QQuickItem *par = parentItem();
321 if (qobject_cast<QQuickLayout*>(par))
323 rearrange(QSizeF(width(), height()));
324 qCDebug(lcQuickLayouts) <<
"QQuickGridLayoutBase::componentComplete(). COMPLETED" <<
this << parent();
359void QQuickGridLayoutBase::invalidate(QQuickItem *childItem)
361 Q_D(QQuickGridLayoutBase);
364 qCDebug(lcQuickLayouts) <<
"QQuickGridLayoutBase::invalidate()" <<
this <<
", invalidated:" << invalidated();
366 if (d->m_rearranging) {
367 if (!d->m_invalidateAfterRearrange.contains(childItem))
368 d->m_invalidateAfterRearrange << childItem;
371 if (QQuickGridLayoutItem *layoutItem = d->engine.findLayoutItem(childItem)) {
372 layoutItem->invalidate();
377 d->engine.invalidate();
379 qCDebug(lcQuickLayouts) <<
"calling QQuickLayout::invalidate();";
380 QQuickLayout::invalidate();
382 if (
auto *parentLayout = qobject_cast<QQuickLayout *>(parentItem()))
383 parentLayout->invalidate(
this);
384 qCDebug(lcQuickLayouts) <<
"QQuickGridLayoutBase::invalidate() LEAVING" <<
this;
442void QQuickGridLayoutBase::rearrange(
const QSizeF &size)
444 Q_D(QQuickGridLayoutBase);
445 if (!isReady() || !size.isValid())
448 qCDebug(lcQuickLayouts) <<
"QQuickGridLayoutBase::rearrange" << d->m_recurRearrangeCounter <<
this;
449 const auto refCounter = qScopeGuard([&d] {
450 --(d->m_recurRearrangeCounter);
452 if (d->m_recurRearrangeCounter++ == 2) {
456 <<
"Qt Quick Layouts: Detected recursive rearrange. Aborting after two iterations.";
462 ensureLayoutItemsUpdated(QQuickLayout::ApplySizeHints | QQuickLayout::Recursive);
464 d->m_rearranging =
true;
465 qCDebug(lcQuickLayouts) << objectName() <<
"QQuickGridLayoutBase::rearrange()" << size;
466 Qt::LayoutDirection visualDir = effectiveLayoutDirection();
467 d->engine.setVisualDirection(visualDir);
470
471
472
473
474
478 QQuickLayout::rearrange(size);
479 d->engine.setGeometries(QRectF(QPointF(0,0), size), d->styleInfo);
480 d->m_rearranging =
false;
482 for (
auto childItem : std::as_const(d->m_invalidateAfterRearrange))
483 invalidate(childItem);
484 d->m_invalidateAfterRearrange.clear();
688void QQuickGridLayout::insertLayoutItems()
690 Q_D(QQuickGridLayout);
692 int nextCellPos[2] = {0,0};
693 int &nextColumn = nextCellPos[0];
694 int &nextRow = nextCellPos[1];
696 const QSize gridSize(columns(), rows());
697 const int flowOrientation = flow();
698 int &flowColumn = nextCellPos[flowOrientation];
699 int &flowRow = nextCellPos[1 - flowOrientation];
700 int flowBound = (flowOrientation == QQuickGridLayout::LeftToRight) ? columns() : rows();
703 flowBound = std::numeric_limits<
int>::max();
705 const auto items = childItems();
706 for (QQuickItem *child : items) {
709 if (shouldIgnoreItem(child))
711 QQuickLayoutAttached *info = attachedLayoutObject(child,
false);
713 Qt::Alignment alignment;
719 int &columnSpan = span[0];
720 int &rowSpan = span[1];
723 if (info->isRowSet() || info->isColumnSet()) {
732 if (gridSize.height() >= 0 && row >= gridSize.height()) {
733 qmlWarning(child) << QString::fromLatin1(
"Layout: row (%1) should be less than the number of rows (%2)").arg(info->row()).arg(rows());
738 if (gridSize.width() >= 0 && info->column() >= gridSize.width()) {
739 qmlWarning(child) << QString::fromLatin1(
"Layout: column (%1) should be less than the number of columns (%2)").arg(info->column()).arg(columns());
741 column = info->column();
744 rowSpan = info->rowSpan();
745 columnSpan = info->columnSpan();
746 if (columnSpan < 1) {
747 qmlWarning(child) <<
"Layout: invalid column span: " << columnSpan;
750 }
else if (rowSpan < 1) {
751 qmlWarning(child) <<
"Layout: invalid row span: " << rowSpan;
754 alignment = info->alignment();
755 hStretch = info->horizontalStretchFactor();
756 if (hStretch >= 0 && !info->fillWidth())
757 qmlWarning(child) <<
"horizontalStretchFactor requires fillWidth to also be set to true";
758 vStretch = info->verticalStretchFactor();
759 if (vStretch >= 0 && !info->fillHeight())
760 qmlWarning(child) <<
"verticalStretchFactor requires fillHeight to also be set to true";
763 Q_ASSERT(columnSpan >= 1);
764 Q_ASSERT(rowSpan >= 1);
765 const int sp = span[flowOrientation];
774 if (row < 0 || column < 0) {
776
777
778
779
780
781
782
783
784
785
786
787 bool cellAcceptsItem;
790 cellAcceptsItem = (flowColumn + sp) <= flowBound;
793 for (
int rs = 0; cellAcceptsItem && rs < rowSpan; ++rs) {
794 for (
int cs = 0; cellAcceptsItem && cs < columnSpan; ++cs) {
795 if (d->engine.itemAt(nextRow + rs, nextColumn + cs)) {
796 cellAcceptsItem =
false;
803 if (flowColumn == flowBound) {
811 QQuickGridLayoutItem *layoutItem =
new QQuickGridLayoutItem(child, row, column, rowSpan, columnSpan, alignment);
813 layoutItem->setStretchFactor(hStretch, Qt::Horizontal);
815 layoutItem->setStretchFactor(vStretch, Qt::Vertical);
817 d->engine.insertItem(layoutItem, -1);
889void QQuickLinearLayout::setUniformCellSizes(
bool uniformCellSizes)
891 Q_D(QQuickLinearLayout);
892 Q_ASSERT(d->engine.uniformCellWidths() == d->engine.uniformCellHeights());
893 if (d->engine.uniformCellHeights() == uniformCellSizes)
895 d->engine.setUniformCellWidths(uniformCellSizes);
896 d->engine.setUniformCellHeights(uniformCellSizes);
898 emit uniformCellSizesChanged();
932void QQuickLinearLayout::insertLayoutItems()
934 Q_D(QQuickLinearLayout);
935 const auto items = childItems();
936 for (QQuickItem *child : items) {
941 if (shouldIgnoreItem(child))
943 QQuickLayoutAttached *info = attachedLayoutObject(child,
false);
945 Qt::Alignment alignment;
948 bool fillWidth =
false;
949 bool fillHeight =
false;
951 alignment = info->alignment();
952 hStretch = info->horizontalStretchFactor();
953 vStretch = info->verticalStretchFactor();
954 fillWidth = info->fillWidth();
955 fillHeight = info->fillHeight();
958 const int index = d->engine.rowCount(d->orientation);
959 d->engine.insertRow(index, d->orientation);
962 int gridColumn = index;
963 if (d->orientation == Qt::Vertical)
964 qSwap(gridRow, gridColumn);
965 QQuickGridLayoutItem *layoutItem =
new QQuickGridLayoutItem(child, gridRow, gridColumn, 1, 1, alignment);
969 qmlWarning(child) <<
"horizontalStretchFactor requires fillWidth to also be set to true";
970 layoutItem->setStretchFactor(hStretch, Qt::Horizontal);
974 qmlWarning(child) <<
"verticalStretchFactor requires fillHeight to also be set to true";
975 layoutItem->setStretchFactor(vStretch, Qt::Vertical);
977 d->engine.insertItem(layoutItem, index);