File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 9
9
10
10
11
11
12
+
12
13
class QgsSettings : QObject
13
14
{
14
15
%Docstring
@@ -220,6 +221,7 @@ An optional Section argument can be used to get a value from a specific Section.
220
221
sipIsErr = !sipRes;
221
222
%End
222
223
224
+
223
225
bool contains( const QString &key, const QgsSettings::Section section = QgsSettings::NoSection ) const;
224
226
%Docstring
225
227
Returns true if there exists a setting called key; returns false otherwise.
Original file line number Diff line number Diff line change 18
18
#define QGSSETTINGS_H
19
19
20
20
#include < QSettings>
21
+ #include < QMetaEnum>
22
+
21
23
#include " qgis_core.h"
22
24
#include " qgis.h"
23
25
@@ -216,6 +218,30 @@ class CORE_EXPORT QgsSettings : public QObject
216
218
% End
217
219
#endif
218
220
221
+ #ifndef SIP_RUN
222
+
223
+ /* *
224
+ * Return the setting value for a setting defined on an enum.
225
+ * This forces the output to be a valid and existing entry of the enum.
226
+ * \note The enum needs to be declared with Q_ENUM
227
+ */
228
+ template <class T >
229
+ T enumSettingValue ( const QString &key, const T &defaultValue,
230
+ const Section section = NoSection ) const
231
+ {
232
+ T v = static_cast <T>( value ( key, static_cast <int >( defaultValue ), section ).toInt () );
233
+ QMetaEnum metaEnum = QMetaEnum::fromType<T>();
234
+ if ( metaEnum.isValid () )
235
+ {
236
+ if ( !metaEnum.valueToKey ( static_cast <int >( v ) ) )
237
+ {
238
+ v = defaultValue;
239
+ }
240
+ }
241
+ return v;
242
+ }
243
+ #endif
244
+
219
245
/* *
220
246
* Returns true if there exists a setting called key; returns false otherwise.
221
247
* If a group is set using beginGroup(), key is taken to be relative to that group.
You can’t perform that action at this time.
0 commit comments