From 1f2be87eb9093e2287b1a8f87985c50074597117 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 30 Aug 2018 15:48:05 +0200 Subject: Fix revisioning of QQuickMouseEvent::flags Change-Id: If8f8a2f889eba1287664988519a68ee9acf259c6 Reviewed-by: Shawn Rutledge --- src/quick/items/qquickevents_p_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h index 3623dcdf3a..5c95a12e9a 100644 --- a/src/quick/items/qquickevents_p_p.h +++ b/src/quick/items/qquickevents_p_p.h @@ -134,7 +134,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickMouseEvent : public QObject Q_PROPERTY(bool wasHeld READ wasHeld CONSTANT) Q_PROPERTY(bool isClick READ isClick CONSTANT) Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) - Q_REVISION(11) Q_PROPERTY(int flags READ flags CONSTANT) + Q_PROPERTY(int flags READ flags CONSTANT REVISION 11) public: QQuickMouseEvent() -- cgit v1.2.3 From 5b32b7071725e00cad36e9ee97bcd6e886a254b4 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 29 Aug 2018 15:59:45 +0200 Subject: QQuickTableView: allow negative margins Currently TableView will hang when using negative margins. This patch will fix this so that negative margins will work as expected. An alternative implementations would be to only allow positive margins, but from an implementation point of view, there is really no reason to add such a restriction. Change-Id: Iea89212eb9d7f9d467955e27c70d9b7583a80d2e Reviewed-by: Shawn Rutledge --- src/quick/items/qquicktableview.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index a1a5520239..5bc9b48e14 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -252,28 +252,30 @@ void QQuickTableViewPrivate::enforceTableAtOrigin() bool layoutNeeded = false; const qreal flickMargin = 50; - if (loadedTable.x() == 0 && loadedTableOuterRect.x() != tableMargins.left()) { + if (loadedTable.x() == 0 && loadedTableOuterRect.x() > tableMargins.left()) { // The table is at the beginning, but not at the edge of the // content view. So move the table to origo. loadedTableOuterRect.moveLeft(tableMargins.left()); layoutNeeded = true; - } else if (loadedTableOuterRect.x() < 0) { + } else if (loadedTableOuterRect.x() < tableMargins.left()) { // The table is outside the beginning of the content view. Move // the whole table inside, and make some room for flicking. - loadedTableOuterRect.moveLeft(tableMargins.left() + loadedTable.x() == 0 ? 0 : flickMargin); + loadedTableOuterRect.moveLeft(qFuzzyIsNull(tableMargins.left() + loadedTable.x()) ? 0 : flickMargin); layoutNeeded = true; } - if (loadedTable.y() == 0 && loadedTableOuterRect.y() != tableMargins.top()) { + if (loadedTable.y() == 0 && loadedTableOuterRect.y() > tableMargins.top()) { loadedTableOuterRect.moveTop(tableMargins.top()); layoutNeeded = true; - } else if (loadedTableOuterRect.y() < 0) { - loadedTableOuterRect.moveTop(tableMargins.top() + loadedTable.y() == 0 ? 0 : flickMargin); + } else if (loadedTableOuterRect.y() < tableMargins.top()) { + loadedTableOuterRect.moveTop(qFuzzyIsNull(tableMargins.top() + loadedTable.y()) ? 0 : flickMargin); layoutNeeded = true; } - if (layoutNeeded) + if (layoutNeeded) { + qCDebug(lcTableViewDelegateLifecycle); relayoutTableItems(); + } } void QQuickTableViewPrivate::syncLoadedTableRectFromLoadedTable() -- cgit v1.2.3 From 2dac7983b0cceb23682ae2f14cc0a612888461e2 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Fri, 17 Aug 2018 12:55:19 +0200 Subject: Doc: Document TableView qml type Change-Id: Ic6722a3cae6b3b6a3933206f14e0b6f6613609d8 Reviewed-by: Paul Wicking Reviewed-by: Venugopal Shivashankar Reviewed-by: Richard Moe Gustavsen --- .../snippets/qml/tableview/reusabledelegate.qml | 82 +++++ .../doc/snippets/qml/tableview/tablemodel.cpp | 103 ++++++ .../doc/snippets/qml/tableview/tablemodel.qml | 71 +++++ .../snippets/qml/tableview/tableviewwithheader.qml | 64 ++++ .../qml/tableview/tableviewwithprovider.qml | 69 ++++ src/quick/items/qquicktableview.cpp | 353 +++++++++++++++++++++ 6 files changed, 742 insertions(+) create mode 100644 src/quick/doc/snippets/qml/tableview/reusabledelegate.qml create mode 100644 src/quick/doc/snippets/qml/tableview/tablemodel.cpp create mode 100644 src/quick/doc/snippets/qml/tableview/tablemodel.qml create mode 100644 src/quick/doc/snippets/qml/tableview/tableviewwithheader.qml create mode 100644 src/quick/doc/snippets/qml/tableview/tableviewwithprovider.qml (limited to 'src/quick') diff --git a/src/quick/doc/snippets/qml/tableview/reusabledelegate.qml b/src/quick/doc/snippets/qml/tableview/reusabledelegate.qml new file mode 100644 index 0000000000..4a49e809cc --- /dev/null +++ b/src/quick/doc/snippets/qml/tableview/reusabledelegate.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 + +//![0] +Component { + id: tableViewDelegate + Rectangle { + implicitWidth: 100 + implicitHeight: 50 + + TableView.onPooled: rotationAnimation.pause() + TableView.onReused: rotationAnimation.resume() + + Rectangle { + id: rect + anchors.centerIn: parent + width: 40 + height: 5 + color: "green" + + RotationAnimation { + id: rotationAnimation + target: rect + duration: (Math.random() * 2000) + 200 + from: 0 + to: 359 + running: true + loops: Animation.Infinite + } + } + } +} +//![0] diff --git a/src/quick/doc/snippets/qml/tableview/tablemodel.cpp b/src/quick/doc/snippets/qml/tableview/tablemodel.cpp new file mode 100644 index 0000000000..ea9f76f131 --- /dev/null +++ b/src/quick/doc/snippets/qml/tableview/tablemodel.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** + ** + ** Copyright (C) 2018 The Qt Company Ltd. + ** Contact: https://www.qt.io/licensing/ + ** + ** This file is part of the documentation of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:BSD$ + ** Commercial License Usage + ** Licensees holding valid commercial Qt licenses may use this file in + ** accordance with the commercial license agreement provided with the + ** Software or, alternatively, in accordance with the terms contained in + ** a written agreement between you and The Qt Company. For licensing terms + ** and conditions see https://www.qt.io/terms-conditions. For further + ** information use the contact form at https://www.qt.io/contact-us. + ** + ** BSD License Usage + ** Alternatively, you may use this file under the terms of the BSD license + ** as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of The Qt Company Ltd nor the names of its + ** contributors may be used to endorse or promote products derived + ** from this software without specific prior written permission. + ** + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +//![0] +#include +#include +#include + +class TableModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + + int rowCount(const QModelIndex & = QModelIndex()) const override + { + return 200; + } + + int columnCount(const QModelIndex & = QModelIndex()) const override + { + return 200; + } + + QVariant data(const QModelIndex &index, int role) const override + { + switch (role) { + case Qt::DisplayRole: + return QString("%1, %2").arg(index.column()).arg(index.row()); + default: + break; + } + + return QVariant(); + } + + QHash roleNames() const override + { + return { {Qt::DisplayRole, "display"} }; + } +}; + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + qmlRegisterType("TableModel", 0, 1, "TableModel"); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} + +#include "main.moc" +//![0] diff --git a/src/quick/doc/snippets/qml/tableview/tablemodel.qml b/src/quick/doc/snippets/qml/tableview/tablemodel.qml new file mode 100644 index 0000000000..8a8ec94958 --- /dev/null +++ b/src/quick/doc/snippets/qml/tableview/tablemodel.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//![0] +import QtQuick 2.12 +import TableModel 0.1 + +TableView { + anchors.fill: parent + columnSpacing: 1 + rowSpacing: 1 + clip: true + + model: TableModel {} + + delegate: Rectangle { + implicitWidth: 100 + implicitHeight: 50 + Text { + text: display + } + } +} +//![0] diff --git a/src/quick/doc/snippets/qml/tableview/tableviewwithheader.qml b/src/quick/doc/snippets/qml/tableview/tableviewwithheader.qml new file mode 100644 index 0000000000..2214328ee7 --- /dev/null +++ b/src/quick/doc/snippets/qml/tableview/tableviewwithheader.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 + +//![0] +TableView { + id: tableView + + topMargin: header.implicitHeight + + Text { + id: header + text: "A table header" + } +} +//![0] diff --git a/src/quick/doc/snippets/qml/tableview/tableviewwithprovider.qml b/src/quick/doc/snippets/qml/tableview/tableviewwithprovider.qml new file mode 100644 index 0000000000..028b12ca6c --- /dev/null +++ b/src/quick/doc/snippets/qml/tableview/tableviewwithprovider.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 + +//![0] +TableView { + id: tableView + + property var columnWidths: [100, 50, 80, 150] + columnWidthProvider: function (column) { return columnWidths[column] } + + Timer { + running: true + interval: 2000 + onTriggered: { + tableView.columnWidths[2] = 150 + tableView.forceLayout(); + } + } +} +//![0] diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 5bc9b48e14..2e594df8dd 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -51,6 +51,359 @@ #include #include +/*! + \qmltype TableView + \instantiates QQuickTableView + \inqmlmodule QtQuick + \ingroup qtquick-views + \inherits Flickable + \brief Provides a table view of items provided by the model. + + A TableView has a \l model that defines the data to be displayed, and a + \l delegate that defines how the data should be displayed. + + TableView inherits \l Flickable. This means that while the model can have + any number of rows and columns, only a subsection of the table is usually + visible inside the viewport. As soon as you flick, new rows and columns + enter the viewport, while old ones exit and are removed from the viewport. + The rows and columns that move out are reused for building the rows and columns + that move into the viewport. As such, the TableView support models of any + size without affecting performance. + + A TableView displays data from models created from built-in QML types + such as ListModel and XmlListModel, which populates the first column only + in a TableView. To create models with multiple columns, create a model in + C++ that inherits QAbstractItemModel, and expose it to QML. + + \section1 Example Usage + + The following example shows how to create a model from C++ with multiple + columns: + + \snippet qml/tableview/tablemodel.cpp 0 + + And then how to use it from QML: + + \snippet qml/tableview/tablemodel.qml 0 + + \section1 Reusing items + + TableView recycles delegate items by default, instead of instantiating from + the \l delegate whenever new rows and columns are flicked into view. This + can give a huge performance boost, depending on the complexity of the + delegate. + + When an item is flicked out, it moves to the \e{reuse pool}, which is an + internal cache of unused items. When this happens, the \l TableView::pooled + signal is emitted to inform the item about it. Likewise, when the item is + moved back from the pool, the \l TableView::reused signal is emitted. + + Any item properties that come from the model are updated when the + item is reused. This includes \c index, \c row, and \c column, but also + any model roles. + + \note Avoid storing any state inside a delegate. If you do, reset it + manually on receiving the \l TableView::reused signal. + + If an item has timers or animations, consider pausing them on receiving + the \l TableView::pooled signal. That way you avoid using the CPU resources + for items that are not visible. Likewise, if an item has resources that + cannot be reused, they could be freed up. + + If you don't want to reuse items or if the \l delegate cannot support it, + you can set the \l reuseItems property to \c false. + + \note While an item is in the pool, it might still be alive and respond + to connected signals and bindings. + + The following example shows a delegate that animates a spinning rectangle. When + it is pooled, the animation is temporarily paused: + + \snippet qml/tableview/reusabledelegate.qml 0 + + \section1 Row heights and column widths + + When a new column is flicked into view, TableView will determine its width + by calling the \l columnWidthProvider function. TableView itself will never + store row height or column width, as it's designed to support large models + containing any number of rows and columns. Instead, it will ask the + application whenever it needs to know. + + TableView uses the largest \c implicitWidth among the items as the column + width, unless the \l columnWidthProvider property is explicitly set. Once + the column width is found, all other items in the same column are resized + to this width, even if new items that are flicked in later have larger + \c implicitWidth. Setting an explicit \l width on an item is ignored and + overwritten. + + \note The calculated width of a column is discarded when it is flicked out + of the viewport, and is recalculated if the column is flicked back in. The + calculation is always based on the items that are visible when the column + is flicked in. This means that it can end up different each time, depending + on which row you're at when the column enters. You should therefore have the + same \c implicitWidth for all items in a column, or set + \l columnWidthProvider. The same logic applies for the row height + calculation. + + If you change the values that a \l rowHeightProvider or a + \l columnWidthProvider return for rows and columns inside the viewport, you + must call \l forceLayout. This informs TableView that it needs to use the + provider functions again to recalculate and update the layout. + + \note The size of a row or column should be a whole number to avoid + sub-pixel alignment of items. + + The following example shows how to set a simple \c columnWidthProvider + together with a timer that modifies the values the function returns. When + the array is modified, \l forceLayout is called to let the changes + take effect: + + \snippet qml/tableview/tableviewwithprovider.qml 0 + + \section1 Overlays and underlays + + Tableview inherits \l Flickable. And when new items are instantiated from the + delegate, it will parent them to the \l{Flickable::}{contentItem} + with a \c z value equal to \c 1. You can add your own items inside the + Tableview, as child items of the Flickable. By controlling their \c z + value, you can make them be on top of or underneath the table items. + + Here is an example that shows how to add some text on top of the table, that + moves together with the table as you flick: + + \snippet qml/tableview/tableviewwithheader.qml 0 +*/ + +/*! + \qmlproperty int QtQuick::TableView::rows + + This property holds the number of rows in the table. This is + equal to the number of rows in the model. + + This property is read only. +*/ + +/*! + \qmlproperty int QtQuick::TableView::columns + + This property holds the number of columns in the table. This is + equal to the number of columns in the model. If the model is + a list, columns will be 1. + + This property is read only. +*/ + +/*! + \qmlproperty real QtQuick::TableView::rowSpacing + + This property holds the spacing between the rows. + + The default value is 0. +*/ + +/*! + \qmlproperty real QtQuick::TableView::columnSpacing + + This property holds the spacing between the columns. + + The default value is 0. +*/ + +/*! + \qmlproperty real QtQuick::TableView::topMargin + + This property holds the margin between the top of the table and + the top of the content view. + + The default value is 0. +*/ + +/*! + \qmlproperty real QtQuick::TableView::bottomMargin + + This property holds the margin between the bottom of the table and + the bottom of the content view. + + The default value is 0. +*/ + +/*! + \qmlproperty real QtQuick::TableView::leftMargin + + This property holds the margin between the left side of the table and + the left side of the content view. + + The default value is 0. +*/ + +/*! + \qmlproperty real QtQuick::TableView::rightMargin + + This property holds the margin between the right side of the table and + the right side of the content view. + + The default value is 0. +*/ + +/*! + \qmlproperty var QtQuick::TableView::rowHeightProvider + + This property can hold a function that returns the row height for each row + in the model. When assigned, it will be called whenever TableView needs to + know the height of a specific row. The function takes one argument, \c row, + for which the TableView needs to know the height. + + \note The height of a row must always be greater than \c 0. + + \sa columnWidthProvider, {Row heights and column widths} +*/ + +/*! + \qmlproperty var QtQuick::TableView::columnWidthProvider + + This property can hold a function that returns the column width for each + column in the model. When assigned, it is called whenever TableView needs + to know the width of a specific column. The function takes one argument, + \c column, for which the TableView needs to know the width. + + \note The width of a column must always be greater than \c 0. + + \sa rowHeightProvider, {Row heights and column widths} +*/ + +/*! + \qmlproperty model QtQuick::TableView::model + This property holds the model that provides data for the table. + + The model provides the set of data that is used to create the items + in the view. Models can be created directly in QML using \l ListModel, + \l XmlListModel or \l VisualItemModel, or provided by a custom C++ model + class. If it is a C++ model, it must be a subclass of \l QAbstractItemModel + or a simple list. + + \sa {qml-data-models}{Data Models} +*/ + +/*! + \qmlproperty Component QtQuick::TableView::delegate + + The delegate provides a template defining each cell item instantiated by the + view. The model index is exposed as an accessible \c index property. The same + applies to \c row and \c column. Properties of the model are also available + depending upon the type of \l {qml-data-models}{Data Model}. + + A delegate should specify its size using \l implicitWidth and \l implicitHeight. + The TableView lays out the items based on that information. Explicit \l width or + \l height settings are ignored and overwritten. + + \note Delegates are instantiated as needed and may be destroyed at any time. + They are also reused if the \l reuseItems property is set to \c true. You + should therefore avoid storing state information in the delegates. + + \sa {Row heights and column widths}, {Reusing items} +*/ + +/*! + \qmlproperty bool QtQuick::TableView::reuseItems + + This property holds whether or not items instantiated from the \l delegate + should be reused. If set to \c false, any currently pooled items + are destroyed. + + \sa {Reusing items}, TableView::pooled, TableView::reused +*/ + +/*! + \qmlproperty real QtQuick::TableView::contentWidth + + This property holds the width of the \l contentView, which is also + the width of the table (including margins). As a TableView cannot + always know the exact width of the table without loading all columns + in the model, the \c contentWidth is usually an estimated width based on + the columns it has seen so far. This estimate is recalculated whenever + new columns are flicked into view, which means that the content width + can change dynamically. + + If you know up front what the width of the table will be, assign a value + to \c contentWidth explicitly, to avoid unnecessary calculations and + updates to the TableView. + + \sa contentHeight +*/ + +/*! + \qmlproperty real QtQuick::TableView::contentHeight + + This property holds the height of the \l contentView, which is also + the height of the table (including margins). As a TableView cannot + always know the exact height of the table without loading all rows + in the model, the \c contentHeight is usually an estimated height + based on the rows it has seen so far. This estimate is recalculated + whenever new rows are flicked into view, which means that the content height + can change dynamically. + + If you know up front what the height of the table will be, assign a + value to \c contentHeight explicitly, to avoid unnecessary calculations and + updates to the TableView. + + \sa contentWidth +*/ + +/*! + \qmlmethod real QtQuick::TableView::forceLayout + + Responding to changes in the model are batched so that they are handled + only once per frame. This means the TableView delays showing any changes + while a script is being run. The same is also true when changing + properties such as \l rowSpacing or \l leftMargin. + + This method forces the TableView to immediately update the layout so + that any recent changes take effect. + + Calling this function re-evaluates the size and position of each visible + row and column. This is needed if the functions assigned to + \l rowHeightProvider or \l columnWidthProvider return different values than + what is already assigned. +*/ + +/*! + \qmlattachedproperty TableView QtQuick::TableView::view + + This attached property holds the view that manages the delegate instance. + It is attached to each instance of the delegate. +*/ + +/*! + \qmlattachedsignal QtQuick::TableView::pooled + + This signal is emitted after an item has been added to the reuse + pool. You can use it to pause ongoing timers or animations inside + the item, or free up resources that cannot be reused. + + This signal is emitted only if the \l reuseItems property is \c true. + + \sa {Reusing items}, reuseItems, reused +*/ + +/*! + \qmlattachedsignal QtQuick::TableView::reused + + This signal is emitted after an item has been reused. At this point, the + item has been taken out of the pool and placed inside the content view, + and the model properties such as index, row, and column have been updated. + + Other properties that are not provided by the model does not change when an item + is reused. You should avoid storing any state inside a delegate, but if you do, + manually reset that state on receiving this signal. + + This signal is emitted when the item is reused, and not the first time the + item is created. + + This signal is emitted only if the \l reuseItems property is \c true. + + \sa {Reusing items}, reuseItems, pooled +*/ + QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcTableViewDelegateLifecycle, "qt.quick.tableview.lifecycle") -- cgit v1.2.3 From eb6201b2af725d64e5e92f19a512b1ff23ceba51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 4 Jun 2018 11:33:45 +0200 Subject: WebAssembly for QtDeclarative This is the squashed diff from wip/webassembly to 5.12. Done-with: Lorn Potter Change-Id: Ieef34accefef38018a66d3c39bfacb825af4bea6 Reviewed-by: Lorn Potter --- src/quick/scenegraph/qsgdefaultrendercontext.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/quick') diff --git a/src/quick/scenegraph/qsgdefaultrendercontext.cpp b/src/quick/scenegraph/qsgdefaultrendercontext.cpp index 22e97a2dc9..73b79c6300 100644 --- a/src/quick/scenegraph/qsgdefaultrendercontext.cpp +++ b/src/quick/scenegraph/qsgdefaultrendercontext.cpp @@ -325,7 +325,8 @@ bool QSGDefaultRenderContext::separateIndexBuffer() const // lifetime. An attempt to bind a buffer object to the other // target will generate an INVALID_OPERATION error, and the // current binding will remain untouched. - static const bool isWebGL = qGuiApp->platformName().compare(QLatin1String("webgl")) == 0; + static const bool isWebGL = (qGuiApp->platformName().compare(QLatin1String("webgl")) == 0 + || qGuiApp->platformName().compare(QLatin1String("wasm")) == 0); return isWebGL; } -- cgit v1.2.3 From a7472867f407f1226d82aa7bce4cd4d6f9bd652f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 2 Jul 2018 22:27:11 +0200 Subject: Make QtDeclarative work for the no-thread config Force use of the basic render loop, adapt qqmlthread and qqmltypeloader to work on a single thread. Disable components and features that require worker threads: qmldb_server, worker script, shapes, folderlistmodel, threaded render loop, software renderer. Done-with: Lorn Potter Change-Id: I77d965947f684f8b7d19284b5decd893395316cb Reviewed-by: Lorn Potter --- src/quick/configure.json | 2 +- src/quick/items/qquickrendercontrol.cpp | 2 ++ src/quick/scenegraph/adaptations/adaptations.pri | 2 +- src/quick/scenegraph/qsgcontextplugin.cpp | 2 ++ src/quick/scenegraph/qsgrenderloop.cpp | 2 ++ src/quick/scenegraph/scenegraph.pri | 9 +++++++-- 6 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/quick') diff --git a/src/quick/configure.json b/src/quick/configure.json index 9ec3531ef4..9d7bafcb3b 100644 --- a/src/quick/configure.json +++ b/src/quick/configure.json @@ -129,7 +129,7 @@ "label": "Path support", "purpose": "Provides Path elements.", "section": "Qt Quick", - "condition": "features.quick-shadereffect", + "condition": "features.thread && features.quick-shadereffect", "output": [ "privateFeature" ] diff --git a/src/quick/items/qquickrendercontrol.cpp b/src/quick/items/qquickrendercontrol.cpp index 86a64cdeeb..ec74660d96 100644 --- a/src/quick/items/qquickrendercontrol.cpp +++ b/src/quick/items/qquickrendercontrol.cpp @@ -391,6 +391,7 @@ QImage QQuickRenderControl::grab() grabContent.setDevicePixelRatio(d->window->effectiveDevicePixelRatio()); } #endif +#if QT_CONFIG(thread) } else if (d->window->rendererInterface()->graphicsApi() == QSGRendererInterface::Software) { QQuickWindowPrivate *cd = QQuickWindowPrivate::get(d->window); cd->polishItems(); @@ -408,6 +409,7 @@ QImage QQuickRenderControl::grab() render(); softwareRenderer->setCurrentPaintDevice(prevDev); } +#endif } else { qWarning("QQuickRenderControl: grabs are not supported with the current Qt Quick backend"); } diff --git a/src/quick/scenegraph/adaptations/adaptations.pri b/src/quick/scenegraph/adaptations/adaptations.pri index 40fa739e15..bfd7095718 100644 --- a/src/quick/scenegraph/adaptations/adaptations.pri +++ b/src/quick/scenegraph/adaptations/adaptations.pri @@ -1 +1 @@ -include(software/software.pri) +qtConfig(thread): include(software/software.pri) diff --git a/src/quick/scenegraph/qsgcontextplugin.cpp b/src/quick/scenegraph/qsgcontextplugin.cpp index 66add51c55..4f8b1cf332 100644 --- a/src/quick/scenegraph/qsgcontextplugin.cpp +++ b/src/quick/scenegraph/qsgcontextplugin.cpp @@ -89,8 +89,10 @@ struct QSGAdaptationBackendData QSGAdaptationBackendData::QSGAdaptationBackendData() : flags(nullptr) { +#if QT_CONFIG(thread) // Fill in the table with the built-in adaptations. builtIns.append(new QSGSoftwareAdaptation); +#endif } QSGAdaptationBackendData::~QSGAdaptationBackendData() diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp index 2eaed497ef..79bfe95e90 100644 --- a/src/quick/scenegraph/qsgrenderloop.cpp +++ b/src/quick/scenegraph/qsgrenderloop.cpp @@ -221,10 +221,12 @@ QSGRenderLoop *QSGRenderLoop::instance() } switch (loopType) { +#if QT_CONFIG(thread) case ThreadedRenderLoop: qCDebug(QSG_LOG_INFO, "threaded render loop"); s_instance = new QSGThreadedRenderLoop(); break; +#endif case WindowsRenderLoop: qCDebug(QSG_LOG_INFO, "windows render loop"); s_instance = new QSGWindowsRenderLoop(); diff --git a/src/quick/scenegraph/scenegraph.pri b/src/quick/scenegraph/scenegraph.pri index f08e8b7863..ddd7fb7f4c 100644 --- a/src/quick/scenegraph/scenegraph.pri +++ b/src/quick/scenegraph/scenegraph.pri @@ -115,7 +115,6 @@ qtConfig(opengl(es1|es2)?) { $$PWD/util/qsgdefaultimagenode.cpp \ $$PWD/util/qsgdefaultninepatchnode.cpp \ $$PWD/qsgdefaultlayer.cpp \ - $$PWD/qsgthreadedrenderloop.cpp \ $$PWD/qsgwindowsrenderloop.cpp HEADERS += \ $$PWD/qsgdefaultglyphnode_p.h \ @@ -132,9 +131,15 @@ qtConfig(opengl(es1|es2)?) { $$PWD/util/qsgdefaultimagenode_p.h \ $$PWD/util/qsgdefaultninepatchnode_p.h \ $$PWD/qsgdefaultlayer_p.h \ - $$PWD/qsgthreadedrenderloop_p.h \ $$PWD/qsgwindowsrenderloop_p.h + qtConfig(thread) { + SOURCES += \ + $$PWD/qsgthreadedrenderloop.cpp + HEADERS += \ + $$PWD/qsgthreadedrenderloop_p.h + } + qtConfig(quick-sprite) { SOURCES += \ $$PWD/qsgdefaultspritenode.cpp -- cgit v1.2.3 From 044b6b64334019b98704445d797d6695730a2a4d Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 3 Sep 2018 10:35:11 +0200 Subject: Fix no-opengl build Change-Id: I4b02c4ea380ca18bd62509676cec2608b923c268 Reviewed-by: Eirik Aavitsland --- src/quick/scenegraph/util/qsgtexturereader.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/quick') diff --git a/src/quick/scenegraph/util/qsgtexturereader.cpp b/src/quick/scenegraph/util/qsgtexturereader.cpp index 27ba119f63..5e12ca4035 100644 --- a/src/quick/scenegraph/util/qsgtexturereader.cpp +++ b/src/quick/scenegraph/util/qsgtexturereader.cpp @@ -38,9 +38,12 @@ ****************************************************************************/ #include "qsgtexturereader_p.h" -#include #include +#if QT_CONFIG(opengl) +#include +#endif + QT_BEGIN_NAMESPACE QSGTextureReader::QSGTextureReader(QIODevice *device, const QString &fileName) -- cgit v1.2.3 From 64d0880c6bbf4dd39f35d818e456e23a14c97058 Mon Sep 17 00:00:00 2001 From: Venugopal Shivashankar Date: Thu, 30 Aug 2018 14:38:36 +0200 Subject: Doc: Add the youtube tutorial video MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The \youtube macro embeds the video within the online docs and the thumbnail JPG is used for the offline version. Change-Id: Ic26fb8b517b50e3a8be2b80b1627823fdbd37909 Reviewed-by: Paul Wicking Reviewed-by: Topi Reiniƶ --- src/quick/doc/images/9BcAYDlpuT8.jpg | Bin 0 -> 8788 bytes src/quick/doc/qtquick.qdocconf | 4 ++++ src/quick/doc/src/concepts/modelviewsdata/cppmodels.qdoc | 7 ++++--- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/quick/doc/images/9BcAYDlpuT8.jpg (limited to 'src/quick') diff --git a/src/quick/doc/images/9BcAYDlpuT8.jpg b/src/quick/doc/images/9BcAYDlpuT8.jpg new file mode 100644 index 0000000000..0a69ab0034 Binary files /dev/null and b/src/quick/doc/images/9BcAYDlpuT8.jpg differ diff --git a/src/quick/doc/qtquick.qdocconf b/src/quick/doc/qtquick.qdocconf index ad5e47002d..34ec66bf1d 100644 --- a/src/quick/doc/qtquick.qdocconf +++ b/src/quick/doc/qtquick.qdocconf @@ -89,3 +89,7 @@ navigation.qmltypespage = "Qt Quick QML Types" # \svgcolor {#ffdead} macro.svgcolor.HTML = "
" + +# youtube video thumbnails that show up in offline and online docs +HTML.extraimages += images/9BcAYDlpuT8.jpg +qhp.QtQuick.extraFiles += images/9BcAYDlpuT8.jpg diff --git a/src/quick/doc/src/concepts/modelviewsdata/cppmodels.qdoc b/src/quick/doc/src/concepts/modelviewsdata/cppmodels.qdoc index 2705ca5e34..e8265b92d2 100644 --- a/src/quick/doc/src/concepts/modelviewsdata/cppmodels.qdoc +++ b/src/quick/doc/src/concepts/modelviewsdata/cppmodels.qdoc @@ -41,9 +41,10 @@ QObjectList or a \l QAbstractItemModel. The first three are useful for exposing simpler datasets, while QAbstractItemModel provides a more flexible solution for more complex models. -For a video tutorial that takes you through the whole process of exposing a C++ -model to QML, see the -\l {https://youtu.be/9BcAYDlpuT8}{Using C++ Models in QML Tutorial}. +Here is a video tutorial that takes you through the whole process of exposing a C++ +model to QML: + +\youtube 9BcAYDlpuT8 \section2 QStringList-based Model -- cgit v1.2.3