From 158fe2a0c551f7aaeaa07bdbb0096bee0ade0fdf Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Tue, 28 May 2013 10:09:03 +0200 Subject: Change default layout spacing to 5, and make it depend on DPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I6f34ace6a24ce918cdd417bbfcd2fe8126aa321b Reviewed-by: Jens Bache-Wiig Reviewed-by: Jan Arve Sæther --- src/layouts/qquicklinearlayout.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/layouts/qquicklinearlayout.cpp') diff --git a/src/layouts/qquicklinearlayout.cpp b/src/layouts/qquicklinearlayout.cpp index 541e4aca..b9a8e224 100644 --- a/src/layouts/qquicklinearlayout.cpp +++ b/src/layouts/qquicklinearlayout.cpp @@ -143,8 +143,15 @@ QT_BEGIN_NAMESPACE -static const qreal q_declarativeLayoutDefaultSpacing = 4.0; - +static qreal quickLayoutDefaultSpacing() +{ + qreal spacing = 5.0; +#ifndef Q_OS_MAC + // On mac the DPI is always 72 so we should not scale it + spacing = qRound(spacing * (qreal(qt_defaultDpiX()) / 96.0)); +#endif + return spacing; +} QQuickGridLayoutBase::QQuickGridLayoutBase(QQuickGridLayoutBasePrivate &dd, Qt::Orientation orientation, @@ -412,9 +419,10 @@ QQuickGridLayout::QQuickGridLayout(QQuickItem *parent /* = 0*/) : QQuickGridLayoutBase(*new QQuickGridLayoutPrivate, Qt::Horizontal, parent) { Q_D(QQuickGridLayout); - d->columnSpacing = q_declarativeLayoutDefaultSpacing; - d->rowSpacing = q_declarativeLayoutDefaultSpacing; - d->engine.setSpacing(q_declarativeLayoutDefaultSpacing, Qt::Horizontal | Qt::Vertical); + const qreal defaultSpacing = quickLayoutDefaultSpacing(); + d->columnSpacing = defaultSpacing; + d->rowSpacing = defaultSpacing; + d->engine.setSpacing(defaultSpacing, Qt::Horizontal | Qt::Vertical); } /*! @@ -672,7 +680,7 @@ QQuickLinearLayout::QQuickLinearLayout(Qt::Orientation orientation, : QQuickGridLayoutBase(*new QQuickLinearLayoutPrivate, orientation, parent) { Q_D(QQuickLinearLayout); - d->spacing = q_declarativeLayoutDefaultSpacing; + d->spacing = quickLayoutDefaultSpacing(); d->engine.setSpacing(d->spacing, Qt::Horizontal | Qt::Vertical); } -- cgit v1.2.1 From cf6f7de3f03d52174f3dfa57031159caa4e7be31 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Wed, 29 May 2013 15:34:48 +0200 Subject: Do not crash when deleting a layout onItemVisibleChanged() was in some cases called after the dtor of QQuickGridLayoutBase was called. After having called the dtor of QQuickGridLayoutBase it would continue to call the dtors of its base classes until it entered the dtor of QQuickItem. In QQuickItem it would call setParentItem(0) on all its child items. This caused the item to become visible again, thus it would emit visibleChanged() and finally invoke QQuickGridLayoutBase::onItemVisibleChanged() which lead to the crash (while trying to call the virtual invalidate()) The fix is to do an early return if we know that the layout is in the destruction phase. isReady() will return only true *after* the component is completed, and before the component is destructing. Task-number: QTBUG-31276 Change-Id: I191e348278e3d052c109bffb92a1ccd9326859bd Reviewed-by: Jens Bache-Wiig --- src/layouts/qquicklinearlayout.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/layouts/qquicklinearlayout.cpp') diff --git a/src/layouts/qquicklinearlayout.cpp b/src/layouts/qquicklinearlayout.cpp index b9a8e224..13b582f9 100644 --- a/src/layouts/qquicklinearlayout.cpp +++ b/src/layouts/qquicklinearlayout.cpp @@ -184,12 +184,18 @@ QSizeF QQuickGridLayoutBase::sizeHint(Qt::SizeHint whichSizeHint) const return d->engine.sizeHint(whichSizeHint, QSizeF()); } +QQuickGridLayoutBase::~QQuickGridLayoutBase() +{ + d_func()->m_isReady = false; +} + void QQuickGridLayoutBase::componentComplete() { Q_D(QQuickGridLayoutBase); quickLayoutDebug() << objectName() << "QQuickGridLayoutBase::componentComplete()" << parent(); d->m_disableRearrange = true; QQuickLayout::componentComplete(); // will call our geometryChange(), (where isComponentComplete() == true) + d->m_isReady = true; d->m_disableRearrange = false; updateLayoutItems(); @@ -235,7 +241,7 @@ void QQuickGridLayoutBase::componentComplete() void QQuickGridLayoutBase::invalidate(QQuickItem *childItem) { Q_D(QQuickGridLayoutBase); - if (!isComponentComplete()) + if (!isReady()) return; quickLayoutDebug() << "QQuickGridLayoutBase::invalidate()"; @@ -274,7 +280,7 @@ void QQuickGridLayoutBase::invalidate(QQuickItem *childItem) void QQuickGridLayoutBase::updateLayoutItems() { Q_D(QQuickGridLayoutBase); - if (!isComponentComplete() || !isVisible()) + if (!isReady() || !isVisible()) return; quickLayoutDebug() << "QQuickGridLayoutBase::updateLayoutItems"; d->engine.deleteItems(); @@ -294,7 +300,7 @@ void QQuickGridLayoutBase::itemChange(ItemChange change, const ItemChangeData &v QObject::connect(item, SIGNAL(implicitWidthChanged()), this, SLOT(onItemImplicitSizeChanged())); QObject::connect(item, SIGNAL(implicitHeightChanged()), this, SLOT(onItemImplicitSizeChanged())); - if (isComponentComplete() && isVisible()) + if (isReady() && isVisible()) updateLayoutItems(); } else if (change == ItemChildRemovedChange) { quickLayoutDebug() << "ItemChildRemovedChange"; @@ -303,7 +309,7 @@ void QQuickGridLayoutBase::itemChange(ItemChange change, const ItemChangeData &v QObject::disconnect(item, SIGNAL(visibleChanged()), this, SLOT(onItemVisibleChanged())); QObject::disconnect(item, SIGNAL(implicitWidthChanged()), this, SLOT(onItemImplicitSizeChanged())); QObject::disconnect(item, SIGNAL(implicitHeightChanged()), this, SLOT(onItemImplicitSizeChanged())); - if (isComponentComplete() && isVisible()) + if (isReady() && isVisible()) updateLayoutItems(); } @@ -314,7 +320,7 @@ void QQuickGridLayoutBase::geometryChanged(const QRectF &newGeometry, const QRec { Q_D(QQuickGridLayoutBase); QQuickLayout::geometryChanged(newGeometry, oldGeometry); - if (d->m_disableRearrange || !isComponentComplete() || !newGeometry.isValid()) + if (d->m_disableRearrange || !isReady() || !newGeometry.isValid()) return; quickLayoutDebug() << "QQuickGridLayoutBase::geometryChanged" << newGeometry << oldGeometry; rearrange(newGeometry.size()); @@ -328,6 +334,11 @@ void QQuickGridLayoutBase::removeGridItem(QGridLayoutItem *gridItem) d->engine.removeRows(index, 1, d->orientation); } +bool QQuickGridLayoutBase::isReady() const +{ + return d_func()->m_isReady; +} + void QQuickGridLayoutBase::removeLayoutItem(QQuickItem *item) { Q_D(QQuickGridLayoutBase); @@ -341,7 +352,7 @@ void QQuickGridLayoutBase::removeLayoutItem(QQuickItem *item) void QQuickGridLayoutBase::onItemVisibleChanged() { - if (!isComponentComplete()) + if (!isReady()) return; quickLayoutDebug() << "QQuickGridLayoutBase::onItemVisibleChanged"; updateLayoutItems(); @@ -349,6 +360,8 @@ void QQuickGridLayoutBase::onItemVisibleChanged() void QQuickGridLayoutBase::onItemDestroyed() { + if (!isReady()) + return; Q_D(QQuickGridLayoutBase); quickLayoutDebug() << "QQuickGridLayoutBase::onItemDestroyed"; QQuickItem *inDestruction = static_cast(sender()); @@ -361,6 +374,8 @@ void QQuickGridLayoutBase::onItemDestroyed() void QQuickGridLayoutBase::onItemImplicitSizeChanged() { + if (!isReady()) + return; QQuickItem *item = static_cast(sender()); Q_ASSERT(item); invalidate(item); @@ -369,7 +384,7 @@ void QQuickGridLayoutBase::onItemImplicitSizeChanged() void QQuickGridLayoutBase::rearrange(const QSizeF &size) { Q_D(QQuickGridLayoutBase); - if (!isComponentComplete()) + if (!isReady()) return; quickLayoutDebug() << objectName() << "QQuickGridLayoutBase::rearrange()" << size; -- cgit v1.2.1 From c5d39cb125a0fe1080e32a2cade0975d4f99832f Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Fri, 24 May 2013 16:49:59 +0200 Subject: Several improvements to documentation * List all applicable attached properties for each layout * Move the stuff that describes min,pref and max sizes from GridLayout to the Layout docs. * Document that all layouts \inherits Item. (Even if they don't directly inherit, this is consistent with how the positioners are documented) * Add some links to Row, Column and Grid where appropriate * Use \qmlattachedproperty instead of \qmlproperty for the attached properties. (Again, consistent with how the Positioners attached properties are documented) * Change POSITIVE_INFINITE to the correct POSITIVE_INFINITY Change-Id: Ia9272faa479b48a97300b031402c0380ca113d7b Reviewed-by: Caroline Chao Reviewed-by: Jerome Pasion --- src/layouts/qquicklinearlayout.cpp | 68 ++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 21 deletions(-) (limited to 'src/layouts/qquicklinearlayout.cpp') diff --git a/src/layouts/qquicklinearlayout.cpp b/src/layouts/qquicklinearlayout.cpp index 13b582f9..7c48248b 100644 --- a/src/layouts/qquicklinearlayout.cpp +++ b/src/layouts/qquicklinearlayout.cpp @@ -48,33 +48,63 @@ /*! \qmltype RowLayout \instantiates QQuickRowLayout + \inherits Item \inqmlmodule QtQuick.Layouts 1.0 \ingroup layouts \brief Identical to \l GridLayout, but having only one row. It is available as a convenience for developers, as it offers a cleaner API. + Items in a RowLayout support these attached properties: + \list + \li \l{Layout::minimumWidth}{Layout.minimumWidth} + \li \l{Layout::minimumHeight}{Layout.minimumHeight} + \li \l{Layout::preferredWidth}{Layout.preferredWidth} + \li \l{Layout::preferredHeight}{Layout.preferredHeight} + \li \l{Layout::maximumWidth}{Layout.maximumWidth} + \li \l{Layout::maximumHeight}{Layout.maximumHeight} + \li \l{Layout::fillWidth}{Layout.fillWidth} + \li \l{Layout::fillHeight}{Layout.fillHeight} + \li \l{Layout::alignment}{Layout.alignment} + \endlist \sa ColumnLayout \sa GridLayout + \sa Row */ /*! \qmltype ColumnLayout \instantiates QQuickColumnLayout + \inherits Item \inqmlmodule QtQuick.Layouts 1.0 \ingroup layouts \brief Identical to \l GridLayout, but having only one column. It is available as a convenience for developers, as it offers a cleaner API. + Items in a ColumnLayout support these attached properties: + \list + \li \l{Layout::minimumWidth}{Layout.minimumWidth} + \li \l{Layout::minimumHeight}{Layout.minimumHeight} + \li \l{Layout::preferredWidth}{Layout.preferredWidth} + \li \l{Layout::preferredHeight}{Layout.preferredHeight} + \li \l{Layout::maximumWidth}{Layout.maximumWidth} + \li \l{Layout::maximumHeight}{Layout.maximumHeight} + \li \l{Layout::fillWidth}{Layout.fillWidth} + \li \l{Layout::fillHeight}{Layout.fillHeight} + \li \l{Layout::alignment}{Layout.alignment} + \endlist + \sa RowLayout \sa GridLayout + \sa Column */ /*! \qmltype GridLayout \instantiates QQuickGridLayout + \inherits Item \inqmlmodule QtQuick.Layouts 1.0 \ingroup layouts \brief Provides a way of dynamically arranging items in a grid. @@ -112,31 +142,27 @@ specify the row span or column span by setting the \l{Layout::rowSpan}{Layout.rowSpan} or \l{Layout::columnSpan}{Layout.columnSpan} properties. - When the layout is resized, items may grow or shrink. Due to this, items have a - \l{Layout::minimumWidth}{minimum size}, \l{Layout::preferredWidth}{preferred size} and a - \l{Layout::maximumWidth}{maximum size}. - Preferred size may come from one of several sources. It can be specified with the - \l{Layout::preferredWidth}{Layout.preferredWidth} and - \l{Layout::preferredHeight}{Layout.preferredHeight} properties. If these properties are not - specified, it will use the items' \l{Item::implicitWidth}{implicitWidth} or - \l{Item::implicitHeight}{implicitHeight} as the preferred size. - Finally, if neither of these properties are set, it will use the \l{Item::width}{width} and - \l{Item::height}{height} properties of the item. Note that is provided only as a final - fallback. If you want to override the preferred size, you should use - \l{Layout::preferredWidth}{Layout.preferredWidth} or - \l{Layout::preferredHeight}{Layout.preferredHeight}. - - The \l{Layout::fillWidth}{Layout.fillWidth} and \l{Layout::fillHeight}{Layout.fillHeight} can - either be \c true or \c false. If it is \c false, the items size will be fixed to its preferred - size. Otherwise, it will grow or shrink between its minimum and maximum size. - - \note It is not recommended to have bindings to the width and height properties of items in a - GridLayout, since this would conflict with the goal of the GridLayout. + Items in a GridLayout support these attached properties: + \list + \li \l{Layout::row}{Layout.row} + \li \l{Layout::column}{Layout.column} + \li \l{Layout::rowSpan}{Layout.rowSpan} + \li \l{Layout::columnSpan}{Layout.columnSpan} + \li \l{Layout::minimumWidth}{Layout.minimumWidth} + \li \l{Layout::minimumHeight}{Layout.minimumHeight} + \li \l{Layout::preferredWidth}{Layout.preferredWidth} + \li \l{Layout::preferredHeight}{Layout.preferredHeight} + \li \l{Layout::maximumWidth}{Layout.maximumWidth} + \li \l{Layout::maximumHeight}{Layout.maximumHeight} + \li \l{Layout::fillWidth}{Layout.fillWidth} + \li \l{Layout::fillHeight}{Layout.fillHeight} + \li \l{Layout::alignment}{Layout.alignment} + \endlist \sa RowLayout \sa ColumnLayout - + \sa Grid */ -- cgit v1.2.1 From 3b10c17e34bd6da6278600f57a0ecafe5eb58431 Mon Sep 17 00:00:00 2001 From: Caroline Chao Date: Mon, 10 Jun 2013 09:38:28 +0200 Subject: Move doc from the index to the overview page Cleanup the links. And doc fix in TableViewStyle.qml Change-Id: Id61fcff49af79f35f68696900142bb200ae18042 Reviewed-by: Jens Bache-Wiig Reviewed-by: Nico Vertriest --- src/layouts/qquicklinearlayout.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/layouts/qquicklinearlayout.cpp') diff --git a/src/layouts/qquicklinearlayout.cpp b/src/layouts/qquicklinearlayout.cpp index 7c48248b..931bfed5 100644 --- a/src/layouts/qquicklinearlayout.cpp +++ b/src/layouts/qquicklinearlayout.cpp @@ -67,6 +67,8 @@ \li \l{Layout::fillHeight}{Layout.fillHeight} \li \l{Layout::alignment}{Layout.alignment} \endlist + + Read more about attached properties \l{QML Object Attributes}{here}. \sa ColumnLayout \sa GridLayout \sa Row @@ -95,6 +97,8 @@ \li \l{Layout::alignment}{Layout.alignment} \endlist + Read more about attached properties \l{QML Object Attributes}{here}. + \sa RowLayout \sa GridLayout \sa Column @@ -160,6 +164,8 @@ \li \l{Layout::alignment}{Layout.alignment} \endlist + Read more about attached properties \l{QML Object Attributes}{here}. + \sa RowLayout \sa ColumnLayout \sa Grid -- cgit v1.2.1