diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2019-04-09 11:40:10 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2019-04-24 11:40:06 +0000 |
commit | 2821172d514469f99301c3592eec941db9ebc438 (patch) | |
tree | 4bb0244cb73328325629bcadb6d44f9dc10d7b46 /src/quick | |
parent | 4d098132421fe75492d61d270569c2d8a7acbdde (diff) |
Doc: improve Example Usage section of TableView
- Make two sub-sections: C++ and QML
- Add a TableModel example to the QML section
Change-Id: Ib391b4c0a78e11f5130944b6ac99e20a5982a453
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Venugopal Shivashankar <Venugopal.Shivashankar@qt.io>
Diffstat (limited to 'src/quick')
-rw-r--r-- | src/quick/doc/snippets/qml/tableview/cpp-tablemodel.cpp (renamed from src/quick/doc/snippets/qml/tableview/tablemodel.cpp) | 0 | ||||
-rw-r--r-- | src/quick/doc/snippets/qml/tableview/cpp-tablemodel.qml (renamed from src/quick/doc/snippets/qml/tableview/tablemodel.qml) | 0 | ||||
-rw-r--r-- | src/quick/doc/snippets/qml/tableview/qml-tablemodel.qml | 92 | ||||
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 13 |
4 files changed, 103 insertions, 2 deletions
diff --git a/src/quick/doc/snippets/qml/tableview/tablemodel.cpp b/src/quick/doc/snippets/qml/tableview/cpp-tablemodel.cpp index ea9f76f131..ea9f76f131 100644 --- a/src/quick/doc/snippets/qml/tableview/tablemodel.cpp +++ b/src/quick/doc/snippets/qml/tableview/cpp-tablemodel.cpp diff --git a/src/quick/doc/snippets/qml/tableview/tablemodel.qml b/src/quick/doc/snippets/qml/tableview/cpp-tablemodel.qml index 8a8ec94958..8a8ec94958 100644 --- a/src/quick/doc/snippets/qml/tableview/tablemodel.qml +++ b/src/quick/doc/snippets/qml/tableview/cpp-tablemodel.qml diff --git a/src/quick/doc/snippets/qml/tableview/qml-tablemodel.qml b/src/quick/doc/snippets/qml/tableview/qml-tablemodel.qml new file mode 100644 index 0000000000..a01a2a628a --- /dev/null +++ b/src/quick/doc/snippets/qml/tableview/qml-tablemodel.qml @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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.14 +import Qt.labs.qmlmodels 1.0 + +TableView { + anchors.fill: parent + columnSpacing: 1 + rowSpacing: 1 + clip: true + + model: TableModel { + TableModelColumn { display: "name" } + TableModelColumn { display: "color" } + + rows: [ + { + "name": "cat", + "color": "black" + }, + { + "name": "dog", + "color": "brown" + }, + { + "name": "bird", + "color": "white" + } + ] + } + + delegate: Rectangle { + implicitWidth: 100 + implicitHeight: 50 + border.width: 1 + + Text { + text: display + anchors.centerIn: parent + } + } +} +//![0] diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index fc7516ec66..5437b54b78 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -76,14 +76,23 @@ \section1 Example Usage + \section2 C++ Models + The following example shows how to create a model from C++ with multiple columns: - \snippet qml/tableview/tablemodel.cpp 0 + \snippet qml/tableview/cpp-tablemodel.cpp 0 And then how to use it from QML: - \snippet qml/tableview/tablemodel.qml 0 + \snippet qml/tableview/cpp-tablemodel.qml 0 + + \section2 QML Models + + For prototyping and displaying very simple data (from a web API, for + example), \l TableModel can be used: + + \snippet qml/tableview/qml-tablemodel.qml 0 \section1 Reusing items |