From efc119e2d5c85e2bc98f9d0904ddad223cf7f74e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 17 Nov 2016 22:15:53 +0100 Subject: Contact List: rename AddressModel to ContactModel Change-Id: I2da41a5d108b5da23dc969d30c50138ef7e42cc3 Reviewed-by: J-P Nurmi --- .../quickcontrols2/contactlist/MainForm.ui.qml | 2 +- .../quickcontrols2/contactlist/addressmodel.cpp | 149 --------------------- examples/quickcontrols2/contactlist/addressmodel.h | 94 ------------- .../quickcontrols2/contactlist/contactlist.pro | 4 +- .../quickcontrols2/contactlist/contactmodel.cpp | 149 +++++++++++++++++++++ examples/quickcontrols2/contactlist/contactmodel.h | 94 +++++++++++++ .../contactlist/designer/Backend/AddressModel.qml | 88 ------------ .../contactlist/designer/Backend/ContactModel.qml | 88 ++++++++++++ .../contactlist/designer/Backend/qmldir | 2 +- .../doc/src/qtquickcontrols2-contactlist.qdoc | 8 +- examples/quickcontrols2/contactlist/main.cpp | 4 +- 11 files changed, 341 insertions(+), 341 deletions(-) delete mode 100644 examples/quickcontrols2/contactlist/addressmodel.cpp delete mode 100644 examples/quickcontrols2/contactlist/addressmodel.h create mode 100644 examples/quickcontrols2/contactlist/contactmodel.cpp create mode 100644 examples/quickcontrols2/contactlist/contactmodel.h delete mode 100644 examples/quickcontrols2/contactlist/designer/Backend/AddressModel.qml create mode 100644 examples/quickcontrols2/contactlist/designer/Backend/ContactModel.qml (limited to 'examples/quickcontrols2/contactlist') diff --git a/examples/quickcontrols2/contactlist/MainForm.ui.qml b/examples/quickcontrols2/contactlist/MainForm.ui.qml index 634398bd..3be33c1f 100644 --- a/examples/quickcontrols2/contactlist/MainForm.ui.qml +++ b/examples/quickcontrols2/contactlist/MainForm.ui.qml @@ -96,7 +96,7 @@ Page { } } - model: AddressModel { + model: ContactModel { } ScrollBar.vertical: ScrollBar { diff --git a/examples/quickcontrols2/contactlist/addressmodel.cpp b/examples/quickcontrols2/contactlist/addressmodel.cpp deleted file mode 100644 index f5234b7a..00000000 --- a/examples/quickcontrols2/contactlist/addressmodel.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#include "addressmodel.h" - -AddressModel::AddressModel(QObject *parent ) : QAbstractListModel(parent) -{ - m_data.append({ "Angel Hogan", "Chapel St. 368 ", "Clearwater" , "0311 1823993" }); - m_data.append({ "Felicia Patton", "Annadale Lane 2", "Knoxville" , "0368 1244494" }); - m_data.append({ "Grant Crawford", "Windsor Drive 34", "Riverdale" , "0351 7826892" }); - m_data.append({ "Gretchen Little", "Sunset Drive 348", "Virginia Beach" , "0343 1234991" }); - m_data.append({ "Geoffrey Richards", "University Lane 54", "Trussville" , "0423 2144944" }); - m_data.append({ "Henrietta Chavez", "Via Volto San Luca 3", "Piobesi Torinese" , "0399 2826994" }); - m_data.append({ "Harvey Chandler", "North Squaw Creek 11", "Madisonville" , "0343 1244492" }); - m_data.append({ "Miguel Gomez", "Wild Rose Street 13", "Trussville" , "0343 9826996" }); - m_data.append({ "Norma Rodriguez", " Glen Eagles Street 53", "Buffalo" , "0241 5826596" }); - m_data.append({ "Shelia Ramirez", "East Miller Ave 68", "Pickerington" , "0346 4844556" }); - m_data.append({ "Stephanie Moss", "Piazza Trieste e Trento 77", "Roata Chiusani" , "0363 0510490" }); -} - -int AddressModel::rowCount(const QModelIndex &) const -{ - return m_data.count(); -} - -QVariant AddressModel::data(const QModelIndex &index, int role) const -{ - if (index.row() < rowCount()) - switch (role) { - case FullNameRole: return m_data.at(index.row()).fullName; - case AddressRole: return m_data.at(index.row()).address; - case CityRole: return m_data.at(index.row()).city; - case NumberRole: return m_data.at(index.row()).number; - default: return QVariant(); - } - return QVariant(); -} - -QHash AddressModel::roleNames() const -{ - static QHash roleNames { - { FullNameRole, "fullName" }, - { AddressRole, "address" }, - { CityRole, "city" }, - { NumberRole, "number" } - }; - return roleNames; -} - -void AddressModel::updateContact(int row, - const QString &fullName, - const QString &address, - const QString &city, - const QString &number) -{ - if (row >= 0 && row < rowCount()) { - m_data.replace(row, { fullName, address, city, number }); - dataChanged(index(row, 0), index(row, 0), { FullNameRole, AddressRole, CityRole, NumberRole }); - } else if (row < 0) { - beginInsertRows(QModelIndex(), rowCount() - 1, rowCount() - 1); - m_data.append({fullName, address, city, number}); - endInsertRows(); - dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), { FullNameRole, AddressRole, CityRole, NumberRole }); - } -} - -void AddressModel::removeContact(int row) -{ - if (row >= 0 && row < rowCount()) { - beginRemoveRows(QModelIndex(), row, row); - m_data.removeAt(row); - endRemoveRows(); - } -} - -QString AddressModel::getFullName(int row) const -{ - if (row >= 0 && row < rowCount()) - return m_data.at(row).fullName; - return QString(); -} - -QString AddressModel::getAddress(int row) const -{ - if (row >= 0 && row < rowCount()) - return m_data.at(row).address; - return QString(); -} - -QString AddressModel::getCity(int row) const -{ - if (row >= 0 && row < rowCount()) - return m_data.at(row).city; - return QString(); -} - -QString AddressModel::getNumber(int row) const -{ - if (row >= 0 && row < rowCount()) - return m_data.at(row).number; - return QString(); -} diff --git a/examples/quickcontrols2/contactlist/addressmodel.h b/examples/quickcontrols2/contactlist/addressmodel.h deleted file mode 100644 index f1c92ea2..00000000 --- a/examples/quickcontrols2/contactlist/addressmodel.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#ifndef ADDRESSMODEL_H -#define ADDRESSMODEL_H - -#include - -class AddressModel : public QAbstractListModel -{ - Q_OBJECT - -public: - enum AdressModelRoles { - FullNameRole = Qt::DisplayRole, - AddressRole = Qt::UserRole, - CityRole, - NumberRole - }; - Q_ENUM(AdressModelRoles) - - AddressModel(QObject *parent = nullptr); - - int rowCount(const QModelIndex & = QModelIndex()) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - QHash roleNames() const; - - Q_INVOKABLE QString getFullName(int row) const; - Q_INVOKABLE QString getAddress(int row) const; - Q_INVOKABLE QString getCity(int row) const; - Q_INVOKABLE QString getNumber(int row) const; - - Q_INVOKABLE void updateContact(int row, const QString &fullName, const QString &address, const QString &city, const QString &number); - Q_INVOKABLE void removeContact(int row); - -private: - struct Data { - QString fullName; - QString address; - QString city; - QString number; - }; - - QList m_data; -}; - -#endif // ADDRESSMODEL_H diff --git a/examples/quickcontrols2/contactlist/contactlist.pro b/examples/quickcontrols2/contactlist/contactlist.pro index 418aacab..9025dbde 100644 --- a/examples/quickcontrols2/contactlist/contactlist.pro +++ b/examples/quickcontrols2/contactlist/contactlist.pro @@ -3,11 +3,11 @@ TARGET = contactlist QT += quick HEADERS += \ - addressmodel.h + contactmodel.h SOURCES += \ main.cpp \ - addressmodel.cpp + contactmodel.cpp RESOURCES += \ $$files(*.qml) diff --git a/examples/quickcontrols2/contactlist/contactmodel.cpp b/examples/quickcontrols2/contactlist/contactmodel.cpp new file mode 100644 index 00000000..3ffaed8c --- /dev/null +++ b/examples/quickcontrols2/contactlist/contactmodel.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples 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$ +** +****************************************************************************/ + +#include "contactmodel.h" + +ContactModel::ContactModel(QObject *parent ) : QAbstractListModel(parent) +{ + m_contacts.append({ "Angel Hogan", "Chapel St. 368 ", "Clearwater" , "0311 1823993" }); + m_contacts.append({ "Felicia Patton", "Annadale Lane 2", "Knoxville" , "0368 1244494" }); + m_contacts.append({ "Grant Crawford", "Windsor Drive 34", "Riverdale" , "0351 7826892" }); + m_contacts.append({ "Gretchen Little", "Sunset Drive 348", "Virginia Beach" , "0343 1234991" }); + m_contacts.append({ "Geoffrey Richards", "University Lane 54", "Trussville" , "0423 2144944" }); + m_contacts.append({ "Henrietta Chavez", "Via Volto San Luca 3", "Piobesi Torinese" , "0399 2826994" }); + m_contacts.append({ "Harvey Chandler", "North Squaw Creek 11", "Madisonville" , "0343 1244492" }); + m_contacts.append({ "Miguel Gomez", "Wild Rose Street 13", "Trussville" , "0343 9826996" }); + m_contacts.append({ "Norma Rodriguez", " Glen Eagles Street 53", "Buffalo" , "0241 5826596" }); + m_contacts.append({ "Shelia Ramirez", "East Miller Ave 68", "Pickerington" , "0346 4844556" }); + m_contacts.append({ "Stephanie Moss", "Piazza Trieste e Trento 77", "Roata Chiusani" , "0363 0510490" }); +} + +int ContactModel::rowCount(const QModelIndex &) const +{ + return m_contacts.count(); +} + +QVariant ContactModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < rowCount()) + switch (role) { + case FullNameRole: return m_contacts.at(index.row()).fullName; + case AddressRole: return m_contacts.at(index.row()).address; + case CityRole: return m_contacts.at(index.row()).city; + case NumberRole: return m_contacts.at(index.row()).number; + default: return QVariant(); + } + return QVariant(); +} + +QHash ContactModel::roleNames() const +{ + static QHash roleNames { + { FullNameRole, "fullName" }, + { AddressRole, "address" }, + { CityRole, "city" }, + { NumberRole, "number" } + }; + return roleNames; +} + +void ContactModel::updateContact(int row, + const QString &fullName, + const QString &address, + const QString &city, + const QString &number) +{ + if (row >= 0 && row < rowCount()) { + m_contacts.replace(row, { fullName, address, city, number }); + dataChanged(index(row, 0), index(row, 0), { FullNameRole, AddressRole, CityRole, NumberRole }); + } else if (row < 0) { + beginInsertRows(QModelIndex(), rowCount() - 1, rowCount() - 1); + m_contacts.append({fullName, address, city, number}); + endInsertRows(); + dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), { FullNameRole, AddressRole, CityRole, NumberRole }); + } +} + +void ContactModel::removeContact(int row) +{ + if (row >= 0 && row < rowCount()) { + beginRemoveRows(QModelIndex(), row, row); + m_contacts.removeAt(row); + endRemoveRows(); + } +} + +QString ContactModel::getFullName(int row) const +{ + if (row >= 0 && row < rowCount()) + return m_contacts.at(row).fullName; + return QString(); +} + +QString ContactModel::getAddress(int row) const +{ + if (row >= 0 && row < rowCount()) + return m_contacts.at(row).address; + return QString(); +} + +QString ContactModel::getCity(int row) const +{ + if (row >= 0 && row < rowCount()) + return m_contacts.at(row).city; + return QString(); +} + +QString ContactModel::getNumber(int row) const +{ + if (row >= 0 && row < rowCount()) + return m_contacts.at(row).number; + return QString(); +} diff --git a/examples/quickcontrols2/contactlist/contactmodel.h b/examples/quickcontrols2/contactlist/contactmodel.h new file mode 100644 index 00000000..2776905f --- /dev/null +++ b/examples/quickcontrols2/contactlist/contactmodel.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples 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$ +** +****************************************************************************/ + +#ifndef CONTACTMODEL_H +#define CONTACTMODEL_H + +#include + +class ContactModel : public QAbstractListModel +{ + Q_OBJECT + +public: + enum ContactRole { + FullNameRole = Qt::DisplayRole, + AddressRole = Qt::UserRole, + CityRole, + NumberRole + }; + Q_ENUM(ContactRole) + + ContactModel(QObject *parent = nullptr); + + int rowCount(const QModelIndex & = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QHash roleNames() const; + + Q_INVOKABLE QString getFullName(int row) const; + Q_INVOKABLE QString getAddress(int row) const; + Q_INVOKABLE QString getCity(int row) const; + Q_INVOKABLE QString getNumber(int row) const; + + Q_INVOKABLE void updateContact(int row, const QString &fullName, const QString &address, const QString &city, const QString &number); + Q_INVOKABLE void removeContact(int row); + +private: + struct Contact { + QString fullName; + QString address; + QString city; + QString number; + }; + + QList m_contacts; +}; + +#endif // CONTACTMODEL_H diff --git a/examples/quickcontrols2/contactlist/designer/Backend/AddressModel.qml b/examples/quickcontrols2/contactlist/designer/Backend/AddressModel.qml deleted file mode 100644 index b9570934..00000000 --- a/examples/quickcontrols2/contactlist/designer/Backend/AddressModel.qml +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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.6 - -ListModel { - ListElement { - address: "Chapel St. 368" - city: "Knoxville" - number: "0311 1823993" - fullName: "Angel Hogan" - } - - ListElement { - address: "Annadale Lane 2" - city: "Clearwater" - number: "0368 1244494" - fullName: "Felicia Patton" - } - - ListElement { - address: "Windsor Drive 34" - city: "Riverdale" - number: "0368 1244494" - fullName: "Grant Crawford" - } - - ListElement { - address: "Sunset Drive 348" - city: "Virginia Beach" - number: "0351 7826892" - fullName: "Gretchen Little" - } - - ListElement { - address: "University Lane 54" - city: "Trussville" - number: "0399 2826994" - fullName: "Geoffrey Richards" - } -} diff --git a/examples/quickcontrols2/contactlist/designer/Backend/ContactModel.qml b/examples/quickcontrols2/contactlist/designer/Backend/ContactModel.qml new file mode 100644 index 00000000..b9570934 --- /dev/null +++ b/examples/quickcontrols2/contactlist/designer/Backend/ContactModel.qml @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples 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.6 + +ListModel { + ListElement { + address: "Chapel St. 368" + city: "Knoxville" + number: "0311 1823993" + fullName: "Angel Hogan" + } + + ListElement { + address: "Annadale Lane 2" + city: "Clearwater" + number: "0368 1244494" + fullName: "Felicia Patton" + } + + ListElement { + address: "Windsor Drive 34" + city: "Riverdale" + number: "0368 1244494" + fullName: "Grant Crawford" + } + + ListElement { + address: "Sunset Drive 348" + city: "Virginia Beach" + number: "0351 7826892" + fullName: "Gretchen Little" + } + + ListElement { + address: "University Lane 54" + city: "Trussville" + number: "0399 2826994" + fullName: "Geoffrey Richards" + } +} diff --git a/examples/quickcontrols2/contactlist/designer/Backend/qmldir b/examples/quickcontrols2/contactlist/designer/Backend/qmldir index 45552843..8e2037d4 100644 --- a/examples/quickcontrols2/contactlist/designer/Backend/qmldir +++ b/examples/quickcontrols2/contactlist/designer/Backend/qmldir @@ -1,2 +1,2 @@ module Backend -AddressModel 1.0 AddressModel.qml +ContactModel 1.0 ContactModel.qml diff --git a/examples/quickcontrols2/contactlist/doc/src/qtquickcontrols2-contactlist.qdoc b/examples/quickcontrols2/contactlist/doc/src/qtquickcontrols2-contactlist.qdoc index 93ef569d..a6a25b49 100644 --- a/examples/quickcontrols2/contactlist/doc/src/qtquickcontrols2-contactlist.qdoc +++ b/examples/quickcontrols2/contactlist/doc/src/qtquickcontrols2-contactlist.qdoc @@ -43,27 +43,27 @@ The contact list application allows the user to add, edit, and remove contacts. The actual implementation is done in C++ and exposed as a QAbstractListModel. - The AdressModel C++ class is registered under a namespace and later + The ContactModel C++ class is registered under a namespace and later imported and instantiated by \e MainForm.ui.qml. For more information about registering C++ classes as QML types, see \l {Defining QML Types from C++}. \code #include ... - qmlRegisterType("Backend", 1, 0, "AdressModel"); + qmlRegisterType("Backend", 1, 0, "ContactModel"); ... \endcode \section1 Designer Support - In the designer subdirectory, we create a plugin that replaces the AdressModel + In the designer subdirectory, we create a plugin that replaces the ContactModel in Qt Quick Designer. For this to work we add the following line to \e contactlist.pro. \code QML_DESIGNER_IMPORT_PATH=$$PWD/designer \endcode - Because Qt Quick Designer cannot instantiate the AdressModel C++ class, we define + Because Qt Quick Designer cannot instantiate the ContactModel C++ class, we define a mockup using a ListModel. This ensures that the ListView using the model shows something in Qt Quick Designer. diff --git a/examples/quickcontrols2/contactlist/main.cpp b/examples/quickcontrols2/contactlist/main.cpp index 268a750a..ccad6ff3 100644 --- a/examples/quickcontrols2/contactlist/main.cpp +++ b/examples/quickcontrols2/contactlist/main.cpp @@ -51,13 +51,13 @@ #include #include -#include "addressmodel.h" +#include "contactmodel.h" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterType("Backend", 1, 0, "AddressModel"); + qmlRegisterType("Backend", 1, 0, "ContactModel"); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/contactlist.qml"))); -- cgit v1.2.3