settings.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, Dirk Thomas, TU Darmstadt
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials provided
14  * with the distribution.
15  * * Neither the name of the TU Darmstadt nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <qt_gui_cpp/settings.h>
34 
35 #include <stdexcept>
36 
37 namespace qt_gui_cpp {
38 
39 Settings::Settings(QObject* obj)
40  : proxy_(obj)
41 {}
42 
43 Settings Settings::getSettings(const QString& prefix)
44 {
45  Settings settings(proxy_.proxiedObject());
46  bool rc = proxy_.invokeMethodWithReturn("get_settings", Q_RETURN_ARG(Settings, settings), Q_ARG(QString, prefix));
47  if (!rc) throw std::runtime_error("Settings::get_settings() invoke method failed");
48  return settings;
49 }
50 
51 QStringList Settings::allKeys() const
52 {
53  QStringList list;
54  bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("all_keys", Q_RETURN_ARG(QStringList, list));
55  if (!rc) throw std::runtime_error("Settings::all_keys() invoke method failed");
56  return list;
57 }
58 
59 QStringList Settings::childGroups() const
60 {
61  QStringList list;
62  bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("child_groups", Q_RETURN_ARG(QStringList, list));
63  if (!rc) throw std::runtime_error("Settings::child_groups() invoke method failed");
64  return list;
65 }
66 
67 QStringList Settings::childKeys() const
68 {
69  QStringList list;
70  bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("child_keys", Q_RETURN_ARG(QStringList, list));
71  if (!rc) throw std::runtime_error("Settings::child_keys() invoke method failed");
72  return list;
73 }
74 
75 bool Settings::contains(const QString& key) const
76 {
77  bool flag = false;
78  bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("contains", Q_RETURN_ARG(bool, flag), Q_ARG(QString, key));
79  if (!rc) throw std::runtime_error("Settings::contains() invoke method failed");
80  return flag;
81 }
82 
83 void Settings::remove(const QString& key)
84 {
85  bool rc = proxy_.invokeMethod("remove", Q_ARG(QString, key));
86  if (!rc) throw std::runtime_error("Settings::remove() invoke method failed");
87 }
88 
89 void Settings::setValue(const QString& key, const QVariant& value)
90 {
91  bool rc = proxy_.invokeMethod("set_value", Q_ARG(QString, key), Q_ARG(QVariant, value));
92  if (!rc) throw std::runtime_error("Settings::set_value() invoke method failed");
93 }
94 
95 QVariant Settings::value(const QString& key, const QVariant& defaultValue) const
96 {
97  QVariant val;
98  bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("value", Q_RETURN_ARG(QVariant, val), Q_ARG(QString, key), Q_ARG(QVariant, defaultValue));
99  if (!rc) throw std::runtime_error("Settings::value() invoke method failed");
100  return val;
101 }
102 
103 } // namespace
bool invokeMethodWithReturn(const char *member, QGenericReturnArgument ret=QGenericReturnArgument(0, 0), QGenericArgument val0=QGenericArgument(), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Settings(QObject *obj)
Definition: settings.cpp:39
Settings getSettings(const QString &prefix)
Definition: settings.cpp:43
bool invokeMethod(const char *member, QGenericArgument val0=QGenericArgument(), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
GenericProxy proxy_
Definition: settings.h:86
void setValue(const QString &key, const QVariant &value)
Definition: settings.cpp:89
QStringList childKeys() const
Definition: settings.cpp:67
QStringList childGroups() const
Definition: settings.cpp:59
bool contains(const QString &key) const
Definition: settings.cpp:75
void remove(const QString &key)
Definition: settings.cpp:83
QStringList allKeys() const
Definition: settings.cpp:51
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: settings.cpp:95


qt_gui_cpp
Author(s): Dirk Thomas
autogenerated on Fri Jun 24 2022 02:42:39