summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview/qgridlayoutengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/graphicsview/qgridlayoutengine.cpp')
-rw-r--r--src/gui/graphicsview/qgridlayoutengine.cpp46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp
index ee09da5..b2b4551 100644
--- a/src/gui/graphicsview/qgridlayoutengine.cpp
+++ b/src/gui/graphicsview/qgridlayoutengine.cpp
@@ -275,7 +275,7 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
if (hasIgnoreFlag) {
factors[i] = (stretch < 0) ? 1.0 : 0.0;
} else {
- factors[i] = (stretch < 0) ? sizes[i] : 0.0;
+ factors[i] = (stretch < 0) ? sizes[i] : 0.0;
}
} else if (stretch == sumStretches) {
factors[i] = 1.0;
@@ -461,7 +461,7 @@ void QGridLayoutRowData::dump(int indent) const
QGridLayoutItem::QGridLayoutItem(QGridLayoutEngine *engine, QGraphicsLayoutItem *layoutItem,
int row, int column, int rowSpan, int columnSpan,
- Qt::Alignment alignment)
+ Qt::Alignment alignment, int itemAtIndex)
: q_engine(engine), q_layoutItem(layoutItem), q_alignment(alignment)
{
q_firstRows[Hor] = column;
@@ -471,7 +471,7 @@ QGridLayoutItem::QGridLayoutItem(QGridLayoutEngine *engine, QGraphicsLayoutItem
q_stretches[Hor] = -1;
q_stretches[Ver] = -1;
- q_engine->addItem(this);
+ q_engine->insertItem(this, itemAtIndex);
}
int QGridLayoutItem::firstRow(Qt::Orientation orientation) const
@@ -615,7 +615,7 @@ QRectF QGridLayoutItem::geometryWithin(qreal x, qreal y, qreal width, qreal heig
QSizeF size = effectiveMaxSize().boundedTo(QSizeF(cellWidth, cellHeight));
width = size.width();
height = size.height();
-
+
Qt::Alignment align = q_engine->effectiveAlignment(this);
switch (align & Qt::AlignHorizontal_Mask) {
case Qt::AlignHCenter:
@@ -717,7 +717,7 @@ void QGridLayoutItem::dump(int indent) const
void QGridLayoutRowInfo::insertOrRemoveRows(int row, int delta)
{
count += delta;
-
+
insertOrRemoveItems(stretches, row, delta);
insertOrRemoveItems(spacings, row, delta);
insertOrRemoveItems(alignments, row, delta);
@@ -937,11 +937,20 @@ Qt::Alignment QGridLayoutEngine::effectiveAlignment(const QGridLayoutItem *layou
return align;
}
-void QGridLayoutEngine::addItem(QGridLayoutItem *item)
+/*!
+ \internal
+ The \a index is only used by QGraphicsLinearLayout to ensure that itemAt() reflects the order
+ of visual arrangement. Strictly speaking it does not have to, but most people expect it to.
+ (And if it didn't we would have to add itemArrangedAt(int index) or something..)
+ */
+void QGridLayoutEngine::insertItem(QGridLayoutItem *item, int index)
{
maybeExpandGrid(item->lastRow(), item->lastColumn());
- q_items.append(item);
+ if (index == -1)
+ q_items.append(item);
+ else
+ q_items.insert(index, item);
for (int i = item->firstRow(); i <= item->lastRow(); ++i) {
for (int j = item->firstColumn(); j <= item->lastColumn(); ++j) {
@@ -952,6 +961,11 @@ void QGridLayoutEngine::addItem(QGridLayoutItem *item)
}
}
+void QGridLayoutEngine::addItem(QGridLayoutItem *item)
+{
+ insertItem(item, -1);
+}
+
void QGridLayoutEngine::removeItem(QGridLayoutItem *item)
{
Q_ASSERT(q_items.contains(item));
@@ -1076,7 +1090,7 @@ QSizeF QGridLayoutEngine::sizeHint(const QLayoutStyleInfo &styleInfo, Qt::SizeHi
break;
}
return QSizeF();
-}
+}
QSizePolicy::ControlTypes QGridLayoutEngine::controlTypes(LayoutSide side) const
{
@@ -1131,9 +1145,9 @@ void QGridLayoutEngine::dump(int indent) const
QString message = QLatin1String("[ ");
for (int column = 0; column < internalGridColumnCount(); ++column) {
message += QString::number(q_items.indexOf(itemAt(row, column))).rightJustified(3);
- message += QLatin1String(" ");
+ message += QLatin1Char(' ');
}
- message += QLatin1String("]");
+ message += QLatin1Char(']');
qDebug("%*s %s", indent, "", qPrintable(message));
}
@@ -1150,16 +1164,16 @@ void QGridLayoutEngine::dump(int indent) const
q_rowData.dump(indent + 2);
qDebug("%*s Geometries output", indent, "");
+ QVector<qreal> *cellPos = &q_yy;
for (int pass = 0; pass < 2; ++pass) {
- QVector<qreal> &cellPos = q_yy;
QString message;
- for (i = 0; i < cellPos.count(); ++i) {
+ for (i = 0; i < cellPos->count(); ++i) {
message += QLatin1String((message.isEmpty() ? "[" : ", "));
- message += QString::number(cellPos.at(i));
+ message += QString::number(cellPos->at(i));
}
- message += QLatin1String("]");
+ message += QLatin1Char(']');
qDebug("%*s %s %s", indent, "", (pass == 0 ? "rows:" : "columns:"), qPrintable(message));
- cellPos = q_xx;
+ cellPos = &q_xx;
}
}
#endif
@@ -1538,5 +1552,5 @@ void QGridLayoutEngine::ensureGeometries(const QLayoutStyleInfo &styleInfo,
}
QT_END_NAMESPACE
-
+
#endif //QT_NO_GRAPHICSVIEW