diff options
author | Jan Arve Saether <jan-arve.saether@digia.com> | 2013-11-28 14:04:35 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-05 17:20:35 +0100 |
commit | 6c322a917ad57d57f0ee76825eab3e2e008c5bd4 (patch) | |
tree | 74732f88c768ed11352d97838a0e3914a0378e28 /src/widgets/graphicsview/qgraphicsgridlayout.cpp | |
parent | 434b37323a6feb3210168f70ad59f5ecdaa5a597 (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/qgraphicsgridlayout.cpp')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsgridlayout.cpp | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/src/widgets/graphicsview/qgraphicsgridlayout.cpp b/src/widgets/graphicsview/qgraphicsgridlayout.cpp index 6d9dd98839..59f3d891f2 100644 --- a/src/widgets/graphicsview/qgraphicsgridlayout.cpp +++ b/src/widgets/graphicsview/qgraphicsgridlayout.cpp @@ -89,30 +89,35 @@ #include "qgraphicslayoutitem.h" #include "qgraphicsgridlayout.h" #include "qgraphicswidget.h" -#include "qgridlayoutengine_p.h" -#include <QtCore/qdebug.h> +#include "qgraphicsgridlayoutengine_p.h" +#include "qgraphicslayoutstyleinfo_p.h" +#ifdef QT_DEBUG +# include <QtCore/qdebug.h> +#endif QT_BEGIN_NAMESPACE class QGraphicsGridLayoutPrivate : public QGraphicsLayoutPrivate { public: - QGraphicsGridLayoutPrivate() { } - QLayoutStyleInfo styleInfo() const; + QGraphicsGridLayoutPrivate(): m_styleInfo(0) { } + QGraphicsLayoutStyleInfo *styleInfo() const; + + mutable QGraphicsLayoutStyleInfo *m_styleInfo; + QGraphicsGridLayoutEngine engine; - QGridLayoutEngine engine; #ifdef QT_DEBUG void dump(int indent) const; #endif }; -Q_GLOBAL_STATIC(QWidget, globalStyleInfoWidget); -QLayoutStyleInfo QGraphicsGridLayoutPrivate::styleInfo() const +QGraphicsLayoutStyleInfo *QGraphicsGridLayoutPrivate::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; } /*! @@ -172,7 +177,8 @@ void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column d->addChildLayoutItem(item); - new QGridLayoutItem(&d->engine, item, row, column, rowSpan, columnSpan, alignment); + QGraphicsGridLayoutEngineItem *gridEngineItem = new QGraphicsGridLayoutEngineItem(item, row, column, rowSpan, columnSpan, alignment); + d->engine.insertItem(gridEngineItem, -1); invalidate(); } @@ -199,7 +205,7 @@ void QGraphicsGridLayout::setHorizontalSpacing(qreal spacing) qreal QGraphicsGridLayout::horizontalSpacing() const { Q_D(const QGraphicsGridLayout); - return d->engine.spacing(d->styleInfo(), Qt::Horizontal); + return d->engine.spacing(Qt::Horizontal, d->styleInfo()); } /*! @@ -218,7 +224,7 @@ void QGraphicsGridLayout::setVerticalSpacing(qreal spacing) qreal QGraphicsGridLayout::verticalSpacing() const { Q_D(const QGraphicsGridLayout); - return d->engine.spacing(d->styleInfo(), Qt::Vertical); + return d->engine.spacing(Qt::Vertical, d->styleInfo()); } /*! @@ -535,8 +541,8 @@ QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int row, int column) const qWarning("QGraphicsGridLayout::itemAt: invalid row, column %d, %d", row, column); return 0; } - if (QGridLayoutItem *item = d->engine.itemAt(row, column)) - return item->layoutItem(); + if (QGraphicsGridLayoutEngineItem *engineItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(row, column))) + return engineItem->layoutItem(); return 0; } @@ -561,8 +567,8 @@ QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int index) const return 0; } QGraphicsLayoutItem *item = 0; - if (QGridLayoutItem *gridItem = d->engine.itemAt(index)) - item = gridItem->layoutItem(); + if (QGraphicsGridLayoutEngineItem *engineItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(index))) + item = engineItem->layoutItem(); return item; } @@ -579,7 +585,8 @@ void QGraphicsGridLayout::removeAt(int index) qWarning("QGraphicsGridLayout::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->engine.removeItem(gridItem); @@ -619,6 +626,8 @@ void QGraphicsGridLayout::invalidate() { Q_D(QGraphicsGridLayout); d->engine.invalidate(); + if (d->m_styleInfo) + d->m_styleInfo->invalidate(); QGraphicsLayout::invalidate(); } @@ -646,7 +655,7 @@ void QGraphicsGridLayout::setGeometry(const QRectF &rect) if (visualDir == Qt::RightToLeft) qSwap(left, right); effectiveRect.adjust(+left, +top, -right, -bottom); - d->engine.setGeometries(d->styleInfo(), effectiveRect); + d->engine.setGeometries(effectiveRect, d->styleInfo()); #ifdef QT_DEBUG if (qt_graphicsLayoutDebug()) { static int counter = 0; @@ -666,7 +675,7 @@ QSizeF QGraphicsGridLayout::sizeHint(Qt::SizeHint which, const QSizeF &constrain 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; } |