From f9343d91286d83a721186a78eb0296702ca4bc12 Mon Sep 17 00:00:00 2001 From: Mohammed Sameer Date: Sun, 28 Jul 2013 01:00:03 +0300 Subject: [PATCH] Fix setting role names for Qt4 (Inspired by QtGrilo fixes). --- declarative/imageresolutionmodel.cpp | 25 +++++++++++++++++-------- declarative/imageresolutionmodel.h | 6 ++++-- declarative/videoresolutionmodel.cpp | 25 +++++++++++++++++-------- declarative/videoresolutionmodel.h | 6 ++++-- src/postcapturemodel.cpp | 21 +++++++++++++++------ src/postcapturemodel.h | 8 ++++++-- 6 files changed, 63 insertions(+), 28 deletions(-) diff --git a/declarative/imageresolutionmodel.cpp b/declarative/imageresolutionmodel.cpp index 16778f4..2d9ad14 100644 --- a/declarative/imageresolutionmodel.cpp +++ b/declarative/imageresolutionmodel.cpp @@ -25,14 +25,17 @@ ImageResolutionModel::ImageResolutionModel(QtCamImageSettings *settings, QObject *parent) : QAbstractListModel(parent), m_settings(settings) { - m_roles[IdRole] = "resolutionId"; - m_roles[NameRole] = "resolutionName"; - m_roles[CaptureRole] = "captureResolution"; - m_roles[PreviewRole] = "previewResolution"; - m_roles[FpsRole] = "frameRate"; - m_roles[NightFpsRole] = "nightFrameRate"; - m_roles[MegaPixelsRole] = "megaPixels"; - m_roles[AspectRatioRole] = "resolutionAspectRatio"; + QHash roles; + roles[IdRole] = "resolutionId"; + roles[NameRole] = "resolutionName"; + roles[CaptureRole] = "captureResolution"; + roles[PreviewRole] = "previewResolution"; + roles[FpsRole] = "frameRate"; + roles[NightFpsRole] = "nightFrameRate"; + roles[MegaPixelsRole] = "megaPixels"; + roles[AspectRatioRole] = "resolutionAspectRatio"; + + setRoleNames(roles); m_resolutions = m_settings->resolutions(m_aspectRatio); } @@ -105,6 +108,12 @@ void ImageResolutionModel::setAspectRatio(const QString& aspectRatio) { } } +#if defined(QT5) QHash ImageResolutionModel::roleNames() const { return m_roles; } + +void ImageResolutionModel::setRoleNames(const QHash& roles) { + m_roles = roles; +} +#endif diff --git a/declarative/imageresolutionmodel.h b/declarative/imageresolutionmodel.h index 294c89f..dcc7b8b 100644 --- a/declarative/imageresolutionmodel.h +++ b/declarative/imageresolutionmodel.h @@ -56,8 +56,6 @@ public: QString aspectRatio() const; void setAspectRatio(const QString& aspectRatio); - QHash roleNames() const; - signals: void aspectRatioChanged(); @@ -68,7 +66,11 @@ private: QList m_resolutions; +#if defined(QT5) + QHash roleNames() const; + void setRoleNames(const QHash& roles); QHash m_roles; +#endif }; #endif /* IMAGE_RESOLUTION_MODEL_H */ diff --git a/declarative/videoresolutionmodel.cpp b/declarative/videoresolutionmodel.cpp index 60ba7bf..9741bb2 100644 --- a/declarative/videoresolutionmodel.cpp +++ b/declarative/videoresolutionmodel.cpp @@ -25,14 +25,17 @@ VideoResolutionModel::VideoResolutionModel(QtCamVideoSettings *settings, QObject *parent) : QAbstractListModel(parent), m_settings(settings) { - m_roles[IdRole] = "resolutionId"; - m_roles[NameRole] = "resolutionName"; - m_roles[CaptureRole] = "captureResolution"; - m_roles[PreviewRole] = "previewResolution"; - m_roles[FpsRole] = "frameRate"; - m_roles[NightFpsRole] = "nightFrameRate"; - m_roles[ResolutionRole] = "resolution"; - m_roles[AspectRatioRole] = "resolutionAspectRatio"; + QHash roles; + roles[IdRole] = "resolutionId"; + roles[NameRole] = "resolutionName"; + roles[CaptureRole] = "captureResolution"; + roles[PreviewRole] = "previewResolution"; + roles[FpsRole] = "frameRate"; + roles[NightFpsRole] = "nightFrameRate"; + roles[ResolutionRole] = "resolution"; + roles[AspectRatioRole] = "resolutionAspectRatio"; + + setRoleNames(roles); m_resolutions = m_settings->resolutions(m_aspectRatio); } @@ -105,6 +108,12 @@ void VideoResolutionModel::setAspectRatio(const QString& aspectRatio) { } } +#if defined(QT5) QHash VideoResolutionModel::roleNames() const { return m_roles; } + +void VideoResolutionModel::setRoleNames(const QHash& roles) { + m_roles = roles; +} +#endif diff --git a/declarative/videoresolutionmodel.h b/declarative/videoresolutionmodel.h index 77bd1bf..9d25967 100644 --- a/declarative/videoresolutionmodel.h +++ b/declarative/videoresolutionmodel.h @@ -56,8 +56,6 @@ public: QString aspectRatio() const; void setAspectRatio(const QString& aspectRatio); - QHash roleNames() const; - signals: void aspectRatioChanged(); @@ -68,7 +66,11 @@ private: QList m_resolutions; +#if defined(QT5) + QHash roleNames() const; + void setRoleNames(const QHash& roles); QHash m_roles; +#endif }; #endif /* VIDEO_RESOLUTION_MODEL_H */ diff --git a/src/postcapturemodel.cpp b/src/postcapturemodel.cpp index 54e7c31..fc639c9 100644 --- a/src/postcapturemodel.cpp +++ b/src/postcapturemodel.cpp @@ -79,6 +79,11 @@ PostCaptureModel::PostCaptureModel(QObject *parent) : qDBusRegisterMetaType(); qDBusRegisterMetaType >(); + + QHash roles; + roles.insert(Item, "item"); + + setRoleNames(roles); } PostCaptureModel::~PostCaptureModel() { @@ -88,12 +93,6 @@ PostCaptureModel::~PostCaptureModel() { delete m_connection; m_connection = 0; } -QHash PostCaptureModel::roleNames() const { - QHash roles; - roles.insert(Item, "item"); - return roles; -} - void PostCaptureModel::reload() { delete m_connection; m_connection = 0; @@ -281,6 +280,16 @@ void PostCaptureModel::graphUpdated(const QString& className, const QList& } } +#if defined(QT5) +QHash PostCaptureModel::roleNames() const { + return m_roles; +} + +void PostCaptureModel::setRoleNames(const QHash& roles) { + m_roles = roles; +} +#endif + PostCaptureModelItem::PostCaptureModelItem(const QSparqlResultRow& row, QObject *parent) : QObject(parent) { diff --git a/src/postcapturemodel.h b/src/postcapturemodel.h index 69f5130..c5e0ce1 100644 --- a/src/postcapturemodel.h +++ b/src/postcapturemodel.h @@ -56,8 +56,6 @@ public: QString model() const; void setModel(const QString& model); - QHash roleNames() const; - signals: void error(const QString& msg); @@ -85,6 +83,12 @@ private: QHash m_hash; bool m_connected; + +#if defined(QT5) + QHash roleNames() const; + void setRoleNames(const QHash& roles); + QHash m_roles; +#endif }; class PostCaptureModelItem : public QObject { -- 2.25.1