diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-11-17 22:15:53 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-11-17 21:54:39 +0000 |
commit | efc119e2d5c85e2bc98f9d0904ddad223cf7f74e (patch) | |
tree | 8c5f20a57f0944666a0ca7f1a856fb3ed0928270 /examples/quickcontrols2 | |
parent | 0779dc2ad0a7e087de71eadf64423e9610d3cc0a (diff) |
Contact List: rename AddressModel to ContactModel
Change-Id: I2da41a5d108b5da23dc969d30c50138ef7e42cc3
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'examples/quickcontrols2')
-rw-r--r-- | examples/quickcontrols2/contactlist/MainForm.ui.qml | 2 | ||||
-rw-r--r-- | examples/quickcontrols2/contactlist/contactlist.pro | 4 | ||||
-rw-r--r-- | examples/quickcontrols2/contactlist/contactmodel.cpp (renamed from examples/quickcontrols2/contactlist/addressmodel.cpp) | 68 | ||||
-rw-r--r-- | examples/quickcontrols2/contactlist/contactmodel.h (renamed from examples/quickcontrols2/contactlist/addressmodel.h) | 18 | ||||
-rw-r--r-- | examples/quickcontrols2/contactlist/designer/Backend/ContactModel.qml (renamed from examples/quickcontrols2/contactlist/designer/Backend/AddressModel.qml) | 0 | ||||
-rw-r--r-- | examples/quickcontrols2/contactlist/designer/Backend/qmldir | 2 | ||||
-rw-r--r-- | examples/quickcontrols2/contactlist/doc/src/qtquickcontrols2-contactlist.qdoc | 8 | ||||
-rw-r--r-- | examples/quickcontrols2/contactlist/main.cpp | 4 |
8 files changed, 53 insertions, 53 deletions
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/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/addressmodel.cpp b/examples/quickcontrols2/contactlist/contactmodel.cpp index f5234b7a..3ffaed8c 100644 --- a/examples/quickcontrols2/contactlist/addressmodel.cpp +++ b/examples/quickcontrols2/contactlist/contactmodel.cpp @@ -48,42 +48,42 @@ ** ****************************************************************************/ -#include "addressmodel.h" +#include "contactmodel.h" -AddressModel::AddressModel(QObject *parent ) : QAbstractListModel(parent) +ContactModel::ContactModel(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" }); + 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 AddressModel::rowCount(const QModelIndex &) const +int ContactModel::rowCount(const QModelIndex &) const { - return m_data.count(); + return m_contacts.count(); } -QVariant AddressModel::data(const QModelIndex &index, int role) const +QVariant ContactModel::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; + 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<int, QByteArray> AddressModel::roleNames() const +QHash<int, QByteArray> ContactModel::roleNames() const { static QHash<int, QByteArray> roleNames { { FullNameRole, "fullName" }, @@ -94,56 +94,56 @@ QHash<int, QByteArray> AddressModel::roleNames() const return roleNames; } -void AddressModel::updateContact(int row, +void ContactModel::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 }); + 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_data.append({fullName, address, city, number}); + m_contacts.append({fullName, address, city, number}); endInsertRows(); dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), { FullNameRole, AddressRole, CityRole, NumberRole }); } } -void AddressModel::removeContact(int row) +void ContactModel::removeContact(int row) { if (row >= 0 && row < rowCount()) { beginRemoveRows(QModelIndex(), row, row); - m_data.removeAt(row); + m_contacts.removeAt(row); endRemoveRows(); } } -QString AddressModel::getFullName(int row) const +QString ContactModel::getFullName(int row) const { if (row >= 0 && row < rowCount()) - return m_data.at(row).fullName; + return m_contacts.at(row).fullName; return QString(); } -QString AddressModel::getAddress(int row) const +QString ContactModel::getAddress(int row) const { if (row >= 0 && row < rowCount()) - return m_data.at(row).address; + return m_contacts.at(row).address; return QString(); } -QString AddressModel::getCity(int row) const +QString ContactModel::getCity(int row) const { if (row >= 0 && row < rowCount()) - return m_data.at(row).city; + return m_contacts.at(row).city; return QString(); } -QString AddressModel::getNumber(int row) const +QString ContactModel::getNumber(int row) const { if (row >= 0 && row < rowCount()) - return m_data.at(row).number; + return m_contacts.at(row).number; return QString(); } diff --git a/examples/quickcontrols2/contactlist/addressmodel.h b/examples/quickcontrols2/contactlist/contactmodel.h index f1c92ea2..2776905f 100644 --- a/examples/quickcontrols2/contactlist/addressmodel.h +++ b/examples/quickcontrols2/contactlist/contactmodel.h @@ -48,25 +48,25 @@ ** ****************************************************************************/ -#ifndef ADDRESSMODEL_H -#define ADDRESSMODEL_H +#ifndef CONTACTMODEL_H +#define CONTACTMODEL_H #include <QAbstractListModel> -class AddressModel : public QAbstractListModel +class ContactModel : public QAbstractListModel { Q_OBJECT public: - enum AdressModelRoles { + enum ContactRole { FullNameRole = Qt::DisplayRole, AddressRole = Qt::UserRole, CityRole, NumberRole }; - Q_ENUM(AdressModelRoles) + Q_ENUM(ContactRole) - AddressModel(QObject *parent = nullptr); + ContactModel(QObject *parent = nullptr); int rowCount(const QModelIndex & = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; @@ -81,14 +81,14 @@ public: Q_INVOKABLE void removeContact(int row); private: - struct Data { + struct Contact { QString fullName; QString address; QString city; QString number; }; - QList<Data> m_data; + QList<Contact> m_contacts; }; -#endif // ADDRESSMODEL_H +#endif // CONTACTMODEL_H diff --git a/examples/quickcontrols2/contactlist/designer/Backend/AddressModel.qml b/examples/quickcontrols2/contactlist/designer/Backend/ContactModel.qml index b9570934..b9570934 100644 --- a/examples/quickcontrols2/contactlist/designer/Backend/AddressModel.qml +++ b/examples/quickcontrols2/contactlist/designer/Backend/ContactModel.qml 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 <QtQml/qqml.h> ... - qmlRegisterType<AdressModel>("Backend", 1, 0, "AdressModel"); + qmlRegisterType<ContactModel>("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 <QGuiApplication> #include <QQmlApplicationEngine> -#include "addressmodel.h" +#include "contactmodel.h" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterType<AddressModel>("Backend", 1, 0, "AddressModel"); + qmlRegisterType<ContactModel>("Backend", 1, 0, "ContactModel"); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/contactlist.qml"))); |