diff options
author | Jędrzej Nowacki <jedrzej.nowacki@digia.com> | 2013-11-28 15:11:02 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-29 10:34:51 +0100 |
commit | 1d03f4793dd342f2aaba46f7a6334ab5c8825492 (patch) | |
tree | d56e3b3d6a940a0818edbb80ecccc0e50a8baf50 /examples | |
parent | 9690909d91208d8b1c35b5e32e46375b0a38907c (diff) | |
download | qtenginio-1d03f4793dd342f2aaba46f7a6334ab5c8825492.tar.gz |
Remove redundant code from image gallery example
Change-Id: If6f2c1b9473e94654d95879b5445d987176a7668
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/widgets/image-gallery-cpp/imagemodel.cpp | 23 | ||||
-rw-r--r-- | examples/widgets/image-gallery-cpp/imagemodel.h | 8 |
2 files changed, 4 insertions, 27 deletions
diff --git a/examples/widgets/image-gallery-cpp/imagemodel.cpp b/examples/widgets/image-gallery-cpp/imagemodel.cpp index 3d574ad..68bc813 100644 --- a/examples/widgets/image-gallery-cpp/imagemodel.cpp +++ b/examples/widgets/image-gallery-cpp/imagemodel.cpp @@ -49,8 +49,7 @@ ImageModel::ImageModel(QObject *parent) : EnginioModel(parent) { - connect(this, SIGNAL(modelReset()), - this, SLOT(reset())); + connect(this, SIGNAL(modelReset()), this, SLOT(reset())); connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(updateRows(QModelIndex,int,int))); @@ -82,7 +81,7 @@ void ImageModel::updateRows(const QModelIndex &, int start, int end) void ImageModel::imageChanged(const QString &id) { for (int row = 0; row < rowCount(); ++row) { - if (data(index(row), Id) == id) { + if (data(index(row), Enginio::IdRole).toString() == id) { QModelIndex changedIndex = index(row); emit dataChanged(changedIndex, changedIndex); } @@ -99,17 +98,9 @@ void ImageModel::onDataChanged(const QModelIndex &topLeft, const QModelIndex &bo QVariant ImageModel::data(const QModelIndex &index, int role) const { - if (!index.isValid() || index.parent().isValid() - || index.row() < 0 || index.row() >= rowCount()) - return QVariant(); - - QJsonObject rowData = EnginioModel::data(index).value<QJsonValue>().toObject(); - switch (role) { - case Id: { - return rowData.value("id").toString(); - } case Qt::DecorationRole: { + QJsonObject rowData = EnginioModel::data(index).value<QJsonValue>().toObject(); QString id = rowData.value("id").toString(); if (m_images.contains(id)) return m_images.value(id)->thumbnail(); @@ -118,15 +109,9 @@ QVariant ImageModel::data(const QModelIndex &index, int role) const case Qt::SizeHintRole: { return QVariant(QSize(100, 100)); } - case FileName: - return rowData.value("file").toObject().value("fileName").toString(); - case FileSize: - return QString::number(rowData.value("file").toObject().value("fileSize").toDouble()); - case CreationTime: - return QDateTime::fromString(rowData.value("file").toObject().value("createdAt").toString(), Qt::ISODate); } - return QVariant(); + return EnginioModel::data(index, role); } Qt::ItemFlags ImageModel::flags(const QModelIndex &index) const diff --git a/examples/widgets/image-gallery-cpp/imagemodel.h b/examples/widgets/image-gallery-cpp/imagemodel.h index 4a50400..89125c9 100644 --- a/examples/widgets/image-gallery-cpp/imagemodel.h +++ b/examples/widgets/image-gallery-cpp/imagemodel.h @@ -51,14 +51,6 @@ public: QVariant data(const QModelIndex &index, int role) const; - enum Role { - Id = Qt::UserRole + 1, - Image, - FileName, - FileSize, - CreationTime - }; - virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; public slots: |