Fix setting role names for Qt4 (Inspired by QtGrilo fixes).
authorMohammed Sameer <msameer@foolab.org>
Sat, 27 Jul 2013 22:00:03 +0000 (01:00 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sat, 27 Jul 2013 22:00:03 +0000 (01:00 +0300)
declarative/imageresolutionmodel.cpp
declarative/imageresolutionmodel.h
declarative/videoresolutionmodel.cpp
declarative/videoresolutionmodel.h
src/postcapturemodel.cpp
src/postcapturemodel.h

index 16778f4..2d9ad14 100644 (file)
 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<int, QByteArray> 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<int, QByteArray> ImageResolutionModel::roleNames() const {
   return m_roles;
 }
+
+void ImageResolutionModel::setRoleNames(const QHash<int, QByteArray>& roles) {
+  m_roles = roles;
+}
+#endif
index 294c89f..dcc7b8b 100644 (file)
@@ -56,8 +56,6 @@ public:
   QString aspectRatio() const;
   void setAspectRatio(const QString& aspectRatio);
 
-  QHash<int, QByteArray> roleNames() const;
-
 signals:
   void aspectRatioChanged();
 
@@ -68,7 +66,11 @@ private:
 
   QList<QtCamImageResolution> m_resolutions;
 
+#if defined(QT5)
+  QHash<int, QByteArray> roleNames() const;
+  void setRoleNames(const QHash<int, QByteArray>& roles);
   QHash<int, QByteArray> m_roles;
+#endif
 };
 
 #endif /* IMAGE_RESOLUTION_MODEL_H */
index 60ba7bf..9741bb2 100644 (file)
 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<int, QByteArray> 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<int, QByteArray> VideoResolutionModel::roleNames() const {
   return m_roles;
 }
+
+void VideoResolutionModel::setRoleNames(const QHash<int, QByteArray>& roles) {
+  m_roles = roles;
+}
+#endif
index 77bd1bf..9d25967 100644 (file)
@@ -56,8 +56,6 @@ public:
   QString aspectRatio() const;
   void setAspectRatio(const QString& aspectRatio);
 
-  QHash<int, QByteArray> roleNames() const;
-
 signals:
   void aspectRatioChanged();
 
@@ -68,7 +66,11 @@ private:
 
   QList<QtCamVideoResolution> m_resolutions;
 
+#if defined(QT5)
+  QHash<int, QByteArray> roleNames() const;
+  void setRoleNames(const QHash<int, QByteArray>& roles);
   QHash<int, QByteArray> m_roles;
+#endif
 };
 
 #endif /* VIDEO_RESOLUTION_MODEL_H */
index 54e7c31..fc639c9 100644 (file)
@@ -79,6 +79,11 @@ PostCaptureModel::PostCaptureModel(QObject *parent) :
 
   qDBusRegisterMetaType<Quad>();
   qDBusRegisterMetaType<QList<Quad> >();
+
+  QHash<int, QByteArray> roles;
+  roles.insert(Item, "item");
+
+  setRoleNames(roles);
 }
 
 PostCaptureModel::~PostCaptureModel() {
@@ -88,12 +93,6 @@ PostCaptureModel::~PostCaptureModel() {
   delete m_connection; m_connection = 0;
 }
 
-QHash<int, QByteArray> PostCaptureModel::roleNames() const {
-  QHash<int, QByteArray> 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<Quad>&
   }
 }
 
+#if defined(QT5)
+QHash<int, QByteArray> PostCaptureModel::roleNames() const {
+  return m_roles;
+}
+
+void PostCaptureModel::setRoleNames(const QHash<int, QByteArray>& roles) {
+  m_roles = roles;
+}
+#endif
+
 PostCaptureModelItem::PostCaptureModelItem(const QSparqlResultRow& row, QObject *parent) :
   QObject(parent) {
 
index 69f5130..c5e0ce1 100644 (file)
@@ -56,8 +56,6 @@ public:
   QString model() const;
   void setModel(const QString& model);
 
-  QHash<int, QByteArray> roleNames() const;
-
 signals:
   void error(const QString& msg);
 
@@ -85,6 +83,12 @@ private:
   QHash<int, PostCaptureModelItem *> m_hash;
 
   bool m_connected;
+
+#if defined(QT5)
+  QHash<int, QByteArray> roleNames() const;
+  void setRoleNames(const QHash<int, QByteArray>& roles);
+  QHash<int, QByteArray> m_roles;
+#endif
 };
 
 class PostCaptureModelItem : public QObject {