summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicslinearlayout.cpp
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@digia.com>2013-11-28 14:04:35 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-05 17:20:35 +0100
commit6c322a917ad57d57f0ee76825eab3e2e008c5bd4 (patch)
tree74732f88c768ed11352d97838a0e3914a0378e28 /src/widgets/graphicsview/qgraphicslinearlayout.cpp
parent434b37323a6feb3210168f70ad59f5ecdaa5a597 (diff)
Add proper abstractions to the grid layout engine.
The abstractions are needed so that they can work with both QGraphicsLayouts and QtQuick.Layouts. Since the plan is to move the engine to QtGui, this means that the engine cannot have any references to anything in the QtWidgets module. As a consequence of that several things had to be done: * The style info object had to be redone with an abstraction layer to get rid of style and widget dependency. (Abstract class is called QAbstractLayoutStyleInfo) * QGridLayoutEngine must be subclassed due to some specializations for QGraphicsLayoutItem, manifested as QGraphicsGridLayoutEngine. * QGridLayoutItem must be subclassed due to some specializations for QGraphicsLayoutItem, manifested as QGraphicsGridLayoutEngineItem. Did also some minor cleanups, reordered arguments so that all styleInfo arguments are last in all function calls This also fixes QTBUG-35099 (bug was spotted during this refactoring) Task-number: QTBUG-35099 Change-Id: If49d40f71870dc8d99d2e145be158e3080b595fa Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicslinearlayout.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicslinearlayout.cpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/widgets/graphicsview/qgraphicslinearlayout.cpp b/src/widgets/graphicsview/qgraphicslinearlayout.cpp
index 00076502ea..f506148ea3 100644
--- a/src/widgets/graphicsview/qgraphicslinearlayout.cpp
+++ b/src/widgets/graphicsview/qgraphicslinearlayout.cpp
@@ -122,7 +122,8 @@
#include "qgraphicslayoutitem.h"
#include "qgraphicslinearlayout.h"
#include "qgraphicswidget.h"
-#include "qgridlayoutengine_p.h"
+#include "qgraphicsgridlayoutengine_p.h"
+#include "qgraphicslayoutstyleinfo_p.h"
#ifdef QT_DEBUG
#include <QtCore/qdebug.h>
#endif
@@ -132,16 +133,20 @@ QT_BEGIN_NAMESPACE
class QGraphicsLinearLayoutPrivate : public QGraphicsLayoutPrivate
{
public:
- QGraphicsLinearLayoutPrivate(Qt::Orientation orientation) : orientation(orientation) { }
+ QGraphicsLinearLayoutPrivate(Qt::Orientation orientation)
+ : orientation(orientation),
+ m_styleInfo(0)
+ { }
void removeGridItem(QGridLayoutItem *gridItem);
- QLayoutStyleInfo styleInfo() const;
+ QGraphicsLayoutStyleInfo *styleInfo() const;
void fixIndex(int *index) const;
int gridRow(int index) const;
int gridColumn(int index) const;
Qt::Orientation orientation;
- QGridLayoutEngine engine;
+ mutable QGraphicsLayoutStyleInfo *m_styleInfo;
+ QGraphicsGridLayoutEngine engine;
};
void QGraphicsLinearLayoutPrivate::removeGridItem(QGridLayoutItem *gridItem)
@@ -172,13 +177,12 @@ int QGraphicsLinearLayoutPrivate::gridColumn(int index) const
return int(qMin(uint(index), uint(engine.columnCount())));
}
-Q_GLOBAL_STATIC(QWidget, globalStyleInfoWidget)
-
-QLayoutStyleInfo QGraphicsLinearLayoutPrivate::styleInfo() const
+QGraphicsLayoutStyleInfo *QGraphicsLinearLayoutPrivate::styleInfo() const
{
- QGraphicsItem *item = parentItem();
- QStyle *style = (item && item->isWidget()) ? static_cast<QGraphicsWidget*>(item)->style() : QApplication::style();
- return QLayoutStyleInfo(style, globalStyleInfoWidget());
+ if (!m_styleInfo)
+ m_styleInfo = new QGraphicsLayoutStyleInfo(this);
+ m_styleInfo->updateChanged(QAbstractLayoutStyleInfo::Unknown);
+ return m_styleInfo;
}
/*!
@@ -281,7 +285,8 @@ void QGraphicsLinearLayout::insertItem(int index, QGraphicsLayoutItem *item)
Q_ASSERT(item);
d->fixIndex(&index);
d->engine.insertRow(index, d->orientation);
- new QGridLayoutItem(&d->engine, item, d->gridRow(index), d->gridColumn(index), 1, 1, 0, index);
+ QGraphicsGridLayoutEngineItem *gridEngineItem = new QGraphicsGridLayoutEngineItem(item, d->gridRow(index), d->gridColumn(index), 1, 1, 0);
+ d->engine.insertItem(gridEngineItem, index);
invalidate();
}
@@ -309,7 +314,7 @@ void QGraphicsLinearLayout::insertStretch(int index, int stretch)
void QGraphicsLinearLayout::removeItem(QGraphicsLayoutItem *item)
{
Q_D(QGraphicsLinearLayout);
- if (QGridLayoutItem *gridItem = d->engine.findLayoutItem(item)) {
+ if (QGraphicsGridLayoutEngineItem *gridItem = d->engine.findLayoutItem(item)) {
item->setParentLayoutItem(0);
d->removeGridItem(gridItem);
delete gridItem;
@@ -330,7 +335,8 @@ void QGraphicsLinearLayout::removeAt(int index)
qWarning("QGraphicsLinearLayout::removeAt: invalid index %d", index);
return;
}
- if (QGridLayoutItem *gridItem = d->engine.itemAt(index)) {
+
+ if (QGraphicsGridLayoutEngineItem *gridItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(index))) {
if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
layoutItem->setParentLayoutItem(0);
d->removeGridItem(gridItem);
@@ -365,7 +371,7 @@ void QGraphicsLinearLayout::setSpacing(qreal spacing)
qreal QGraphicsLinearLayout::spacing() const
{
Q_D(const QGraphicsLinearLayout);
- return d->engine.spacing(d->styleInfo(), d->orientation);
+ return d->engine.spacing(d->orientation, d->styleInfo());
}
/*!
@@ -485,7 +491,7 @@ QGraphicsLayoutItem *QGraphicsLinearLayout::itemAt(int index) const
return 0;
}
QGraphicsLayoutItem *item = 0;
- if (QGridLayoutItem *gridItem = d->engine.itemAt(index))
+ if (QGraphicsGridLayoutEngineItem *gridItem = static_cast<QGraphicsGridLayoutEngineItem *>(d->engine.itemAt(index)))
item = gridItem->layoutItem();
return item;
}
@@ -512,7 +518,7 @@ void QGraphicsLinearLayout::setGeometry(const QRectF &rect)
dump(1);
}
#endif
- d->engine.setGeometries(d->styleInfo(), effectiveRect);
+ d->engine.setGeometries(effectiveRect, d->styleInfo());
#ifdef QT_DEBUG
if (qt_graphicsLayoutDebug()) {
qDebug() << "post dump";
@@ -530,7 +536,7 @@ QSizeF QGraphicsLinearLayout::sizeHint(Qt::SizeHint which, const QSizeF &constra
qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
const QSizeF extraMargins(left + right, top + bottom);
- return d->engine.sizeHint(d->styleInfo(), which , constraint - extraMargins) + extraMargins;
+ return d->engine.sizeHint(which , constraint - extraMargins, d->styleInfo()) + extraMargins;
}
/*!
@@ -540,6 +546,8 @@ void QGraphicsLinearLayout::invalidate()
{
Q_D(QGraphicsLinearLayout);
d->engine.invalidate();
+ if (d->m_styleInfo)
+ d->m_styleInfo->invalidate();
QGraphicsLayout::invalidate();
}