Add contextsubscriber-1.0 to PKGCONFIG
[harmattan/cameraplus] / declarative / imageresolutionmodel.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include "imageresolutionmodel.h"
22 #include "qtcamimagesettings.h"
23 #include <QDebug>
24
25 ImageResolutionModel::ImageResolutionModel(QtCamImageSettings *settings, QObject *parent) :
26   QAbstractListModel(parent), m_settings(settings) {
27
28   QHash<int, QByteArray> roles;
29   roles[IdRole] = "resolutionId";
30   roles[NameRole] = "resolutionName";
31   roles[CaptureRole] = "captureResolution";
32   roles[PreviewRole] = "previewResolution";
33   roles[FpsRole] = "frameRate";
34   roles[NightFpsRole] = "nightFrameRate";
35   roles[MegaPixelsRole] = "megaPixels";
36   roles[AspectRatioRole] = "resolutionAspectRatio";
37
38   setRoleNames(roles);
39
40   m_resolutions = m_settings->resolutions(m_aspectRatio);
41 }
42
43 ImageResolutionModel::~ImageResolutionModel() {
44   m_settings = 0;
45 }
46
47 int ImageResolutionModel::rowCount(const QModelIndex& parent) const {
48   if (!parent.isValid()) {
49     return m_resolutions.size();
50   }
51
52   return 0;
53 }
54
55 QVariant ImageResolutionModel::data(const QModelIndex& index, int role) const {
56   if (index.row() < 0 || index.row() >= m_resolutions.size()) {
57     return QVariant();
58   }
59
60   const QtCamImageResolution& res = m_resolutions[index.row()];
61
62   switch (role) {
63   case IdRole:
64     return res.id();
65
66   case NameRole:
67     return res.name();
68
69   case CaptureRole:
70     return res.captureResolution();
71
72   case PreviewRole:
73     return res.previewResolution();
74
75   case FpsRole:
76     return res.frameRate();
77
78   case NightFpsRole:
79     return res.nightFrameRate();
80
81   case MegaPixelsRole:
82     return res.megaPixels();
83
84   case AspectRatioRole:
85     return res.aspectRatio();
86
87   default:
88     return QVariant();
89   }
90 }
91
92 QString ImageResolutionModel::aspectRatio() const {
93   return m_aspectRatio;
94 }
95
96 void ImageResolutionModel::setAspectRatio(const QString& aspectRatio) {
97   if (aspectRatio != m_aspectRatio) {
98
99     m_aspectRatio = aspectRatio;
100
101     beginResetModel();
102
103     m_resolutions = m_settings->resolutions(m_aspectRatio);
104
105     endResetModel();
106
107     emit aspectRatioChanged();
108   }
109 }