summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview/qgridlayoutengine.cpp
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-08-27 07:30:32 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-08-27 08:24:08 (GMT)
commit574fcf93bd5420a7e668466259de5c89b485fef2 (patch)
treeefc70f16e85fe94e3618818f64ab90c1700d5884 /src/gui/graphicsview/qgridlayoutengine.cpp
parent35dbf37c70cd27494e9463b7b75c83ad7a671f1e (diff)
downloadQt-574fcf93bd5420a7e668466259de5c89b485fef2.zip
Qt-574fcf93bd5420a7e668466259de5c89b485fef2.tar.gz
Qt-574fcf93bd5420a7e668466259de5c89b485fef2.tar.bz2
Make sure itemAt() reflects the visual order.
This means it should respect the order that was defined with insertItem() and addItem(). Note that this is not strictly necessary (as now explicitly written in the docs for QGraphicsLayout::itemAt()), but commit 2ec56d158dc140f68efb45e2e0613f0e4026ddf6 broke the order and for people that relied on this that commit caused a regression. In addition, after commit 2ec56d158dc140f68efb45e2e0613f0e4026ddf6 it was not longer possible to query the "item at visual index". Thus, instead of adding another function (like QGGL::itemAt(int,int)) we make sure that itemAt() also returns the "item at visual index".
Diffstat (limited to 'src/gui/graphicsview/qgridlayoutengine.cpp')
-rw-r--r--src/gui/graphicsview/qgridlayoutengine.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp
index 5ad6ac9..beb9cb0 100644
--- a/src/gui/graphicsview/qgridlayoutengine.cpp
+++ b/src/gui/graphicsview/qgridlayoutengine.cpp
@@ -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
@@ -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));