diff options
Diffstat (limited to 'examples/widgets/itemviews/addressbook/tablemodel.h')
-rw-r--r-- | examples/widgets/itemviews/addressbook/tablemodel.h | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/examples/widgets/itemviews/addressbook/tablemodel.h b/examples/widgets/itemviews/addressbook/tablemodel.h index 9a669c508d..1004a35d31 100644 --- a/examples/widgets/itemviews/addressbook/tablemodel.h +++ b/examples/widgets/itemviews/addressbook/tablemodel.h @@ -53,16 +53,37 @@ #include <QAbstractTableModel> #include <QList> -#include <QPair> //! [0] + +struct Contact +{ + QString name; + QString address; + + bool operator==(const Contact &other) const + { + return name == other.name && address == other.address; + } +}; + +inline QDataStream &operator<<(QDataStream &stream, const Contact &contact) +{ + return stream << contact.name << contact.address; +} + +inline QDataStream &operator>>(QDataStream &stream, Contact &contact) +{ + return stream >> contact.name >> contact.address; +} + class TableModel : public QAbstractTableModel { Q_OBJECT public: TableModel(QObject *parent = 0); - TableModel(QList<QPair<QString, QString> > listofPairs, QObject *parent = 0); + TableModel(QList<Contact> contacts, QObject *parent = 0); int rowCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override; @@ -72,10 +93,10 @@ public: bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override; bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) override; - QList<QPair<QString, QString> > getList(); + QList<Contact> getContacts() const; private: - QList<QPair<QString, QString> > listOfPairs; + QList<Contact> contacts; }; //! [0] |