25 |
25 |
26 #include <QObject> |
26 #include <QObject> |
27 #include <QString> |
27 #include <QString> |
28 #include <QVariant> |
28 #include <QVariant> |
29 |
29 |
|
30 #include "cxeerror.h" |
30 #include "cxenamespace.h" |
31 #include "cxenamespace.h" |
31 #include "cxeerror.h" |
32 #include "cxeexception.h" |
32 |
33 |
33 |
34 /*! |
34 // forward declaration |
|
35 class CxeSettingsModel; |
|
36 |
|
37 |
|
38 |
|
39 /* |
|
40 * Class to access all kind of Camera Settings |
35 * Class to access all kind of Camera Settings |
|
36 * |
|
37 * There are templated get() and set() methods for accessing and modifying settings. |
|
38 * Supported types are int, qreal, QString, QVariantMap and enums. |
|
39 * |
|
40 * It is possible to monitor changes in settings, either by connecting to settingValueChanged() signal |
|
41 * or registering a slot as listener to a specific setting using listenForSetting(). With the latter |
|
42 * method you will only be notified of the change in the requested setting, as opposed to the settingValueChanged() |
|
43 * which will be emitted for any setting change. |
41 */ |
44 */ |
42 class CxeSettings : public QObject |
45 class CxeSettings : public QObject |
43 { |
46 { |
44 |
47 |
45 Q_OBJECT |
48 Q_OBJECT |
46 |
49 |
47 public: |
50 public: |
48 |
|
49 /* |
|
50 * returns the current integer setting value for the given key |
|
51 */ |
|
52 virtual CxeError::Id get(const QString &key, int &value) const = 0; |
|
53 |
51 |
54 /* |
|
55 * returns the current real setting value for the given key |
|
56 */ |
|
57 virtual CxeError::Id get(const QString &key, qreal &value) const = 0; |
|
58 |
52 |
59 /* |
53 /*! |
60 * returns the current string setting value for the given key |
54 * Returns value of external setting item which is not owned by camera |
61 */ |
55 */ |
62 virtual CxeError::Id get(const QString &key, QString &stringValue) const = 0; |
56 virtual void get(long int uid, |
63 |
57 unsigned long int key, |
64 /* |
58 Cxe::SettingKeyType type, |
65 * Returns value of external setting item which is not owned by camera |
59 QVariant &value) const = 0; |
66 */ |
60 |
67 virtual void get(long int uid, |
61 /*! |
68 unsigned long int key, |
62 * Get a value of a certain setting. Template method that can be used |
69 Cxe::SettingKeyType type, |
63 * with any enumeration (well actually, anything that can be cast to from int), |
70 QVariant &value) const = 0; |
64 * int, QString and QVariantMap. Will throw CxeException in case of error. |
71 |
65 * |
72 /** |
66 * An example: |
73 * Get a value of a certain setting. A convenience method with a template |
67 * \code |
74 * parameter to be used with enumerations. |
68 * try { |
75 * |
69 * Cxe::Whitebalance wb = settings.get<Cxe::Whitebalance>(CxeSettingIds::WHITE_BALANCE); |
76 * An example: |
70 * catch (CxeException &e) { |
77 * \code |
71 * CX_DEBUG(("Error getting white balance")); |
78 * Cxe::Whitebalance wb = Cxe::WhitebalanceAutomatic; |
72 * } |
79 * if (settings.get<Cxe::Whitebalance>(CxeSettingIds::WHITE_BALANCE, wb)) { |
73 * \endcode |
80 * CX_DEBUG(("Error getting white balance - using default")); |
74 * @param settingId Setting key |
81 * } |
75 * @return Setting value |
82 * \endcode |
76 */ |
83 * @param settingId Setting key |
77 template<typename T> |
84 * @param value Reference to a variable where to put the setting value |
78 inline T get(const QString &key) const { |
85 * @return Error code |
79 QVariant v; |
86 */ |
80 getValue(key, v); |
87 template<typename T> |
81 return (T)v.value<int>(); |
88 inline CxeError::Id get(const QString &key, T &value) const { |
82 } |
89 int intValue = value; // This will not compile if T cannot be converted to an int |
83 |
90 CxeError::Id err = get(key, intValue); |
84 /*! |
91 value = static_cast<T>(intValue); // Convert to enum |
85 * Same as above but with default value in case of error. No exceptions are thrown. |
92 return err; |
86 * |
|
87 *An example: |
|
88 * \code |
|
89 * |
|
90 * Cxe::Whitebalance wb = settings.get<Cxe::Whitebalance>(CxeSettingIds::WHITE_BALANCE, Cxe::WhitebalanceAutomatic); |
|
91 * |
|
92 * \endcode |
|
93 * @param key Setting key |
|
94 * @param defaultValue Default value returned in case of error |
|
95 * @return Value of the setting |
|
96 */ |
|
97 template<typename T> |
|
98 inline T get(const QString &key, const T &defaultValue) const { |
|
99 try { |
|
100 return get<T>(key); |
|
101 } catch (CxeException &e) { |
|
102 return defaultValue; |
93 } |
103 } |
94 |
104 } |
95 /* |
|
96 * Set new values for the given key |
|
97 */ |
|
98 virtual CxeError::Id set(const QString &key, int newValue) = 0; |
|
99 |
105 |
100 /* |
|
101 * Set new values for the given key |
|
102 */ |
|
103 virtual CxeError::Id set(const QString &key, qreal newValue) = 0; |
|
104 |
106 |
105 /* |
|
106 * Set new values for the given key |
|
107 */ |
|
108 virtual CxeError::Id set(const QString &key, const QString &newValue) = 0; |
|
109 |
107 |
110 /* |
108 /*! |
111 * Resets only virtual settings( persistent settings ) |
109 * Set a value of a certain setting. Template method that can be used |
112 */ |
110 * with any enumeration (well actually, anything that can be cast to from int), |
113 virtual void reset() = 0; |
111 * int, QString and QVariantMap. |
114 |
112 * |
115 signals: |
113 * An example: |
116 /* |
114 * \code |
117 * to notify engine and ui components for a change in a setting value |
115 * try { |
118 */ |
116 * Cxe::Whitebalance wb = Cxe::WhiteBalanceAutomatic; |
119 void settingValueChanged(const QString &key, QVariant newValue); |
117 * settings.get<Cxe::Whitebalance>(CxeSettingIds::WHITE_BALANCE, wb); |
|
118 * catch (CxeException &e) { |
|
119 * CX_DEBUG(("Error setting white balance")); |
|
120 * } |
|
121 * \endcode |
|
122 * @param settingId Setting key |
|
123 * @param value Setting value |
|
124 */ |
|
125 template<typename T> |
|
126 inline void set(const QString &key, const T &value) { |
|
127 QVariant v; |
|
128 v.setValue((int)value); |
|
129 setValue(key, v); |
|
130 } |
120 |
131 |
121 /* |
132 /*! |
122 * to notify engine and ui components for a change in a setting value |
133 * Resets settings to default values. |
123 */ |
134 */ |
124 void settingValueChanged(long int uid, unsigned long int key, QVariant value); |
135 virtual void reset() = 0; |
125 |
136 |
126 /* |
137 /*! |
127 * to update engine and ui components of new image scene |
138 * Get value of variation setting. |
128 */ |
139 */ |
129 void sceneChanged(CxeScene &scene); |
140 virtual CxeError::Id getVariationValue(const QString &key, QVariant &value) = 0; |
130 |
141 |
131 protected: |
142 /*! |
132 CxeSettings() {} |
143 * Add listener for changes in one setting. When the value of the setting changes, the given |
133 |
144 * slot is invoked on given object. |
134 private: |
145 * |
135 Q_DISABLE_COPY( CxeSettings ) |
146 * @param settingKey Setting to listen to |
|
147 * @param target Object that the slot will be invoked for |
|
148 * @param slot Slot that will be invoked. The slot can have either of these two signatures: |
|
149 * slotName(const QVariant&) only new value of setting is passed as parameter |
|
150 * slotName(const QString&, const QVariant&) both setting key and new value are passed as parameter |
|
151 * @return boolean to indicate success |
|
152 */ |
|
153 virtual bool listenForSetting(const QString &settingKey, QObject *target, const char *slot) = 0; |
|
154 |
|
155 protected: |
|
156 /*! |
|
157 * returns the setting as QVariant |
|
158 */ |
|
159 virtual void getValue(const QString &key, QVariant &value) const = 0; |
|
160 |
|
161 /*! |
|
162 * Set new value for the given key |
|
163 */ |
|
164 virtual void setValue(const QString &key, const QVariant &newValue) = 0; |
|
165 |
|
166 signals: |
|
167 |
|
168 /*! |
|
169 * to notify engine and ui components for a change in a setting value |
|
170 */ |
|
171 void settingValueChanged(const QString &key, QVariant newValue); |
|
172 |
|
173 /*! |
|
174 * to notify engine and ui components for a change in a setting value |
|
175 */ |
|
176 void settingValueChanged(long int uid, unsigned long int key, QVariant value); |
|
177 |
|
178 protected: |
|
179 CxeSettings() {} |
|
180 |
|
181 private: |
|
182 Q_DISABLE_COPY( CxeSettings ) |
136 }; |
183 }; |
|
184 |
|
185 // include set/get function specializations |
|
186 #include "cxesettings.inl" |
137 |
187 |
138 #endif /*CXESETTINGS_H_*/ |
188 #endif /*CXESETTINGS_H_*/ |
139 |
189 |
140 // end of file |
190 // end of file |