SimpleConfigDialog.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXGui::ArmarXObjects::SimpleConfigDialog
17 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18 * @date 2016
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22#pragma once
23
24#include <functional>
25#include <map>
26
27#include <QDialog>
28
30
32
33class QLineEdit;
34class QVBoxLayout;
35
36namespace Ui
37{
38 class SimpleConfigDialog;
39}
40
41namespace armarx
42{
44
45 /**
46 * @class SimpleConfigDialog
47 * @ingroup ArmarXGui
48 * @brief A config-dialog containing one (or multiple) proxy finders.
49 *
50 * To use it in your gui:
51 * Include
52 * \code{.cpp}
53 * #include <ArmarXGui/libraries/SimpleConfigDialog/SimpleConfigDialog.h>
54 * \endcode
55 * and link against SimpleConfigDialog from ArmarXGui
56 *
57 * Add this member to your WidgetController
58 * \code{.cpp}
59 * QPointer<SimpleConfigDialog> dialog;
60 * \endcode
61 *
62 * Override the function
63 * \code{.cpp}
64 * virtual QPointer<QDialog> getConfigDialog(QWidget *parent) override
65 * {
66 * if (!dialog)
67 * {
68 * dialog = new SimpleConfigDialog(parent);
69 * dialog->addProxyFinder<ProxyType1>({"Accessname1", "Description text 1", "SearchMask1"});
70 * dialog->addProxyFinder<ProxyType2>({"Accessname2", "Description text 2", "SearchMask2"});
71 * dialog->getLayout()->addWidget(new QLabel{"i am a label"};
72 * //or add multiple at once
73 * dialog->addProxyFinder<ProxyType3,ProxyType4>({{"Accessname3", "Description text 3", "SearchMask3"}, {"Accessname4", "Description text 4", "SearchMask4"}});
74 * }
75 * return qobject_cast<SimpleConfigDialog*>(dialog);
76 * }
77 * \endcode
78 *
79 * Where you want to access the proxy names:
80 * \code{.cpp}
81 * dialog->getProxyName("Accessname1");
82 * \endcode
83 */
84 class SimpleConfigDialog : public QDialog, virtual public armarx::ManagedIceObject
85 {
86 Q_OBJECT
87 public:
88 struct EntryData
89 {
90 std::string name;
91 std::string description;
92 std::string mask;
93 };
94
95 /**
96 * @brief ctor
97 * @param parent the dialog's parent
98 */
99 explicit SimpleConfigDialog(QWidget* parent = nullptr);
100
101 template <class... ProxyTypes>
102 void
103 addProxyFinder(const std::vector<EntryData>& entryData)
104 {
105 SimpleConfigDialogAdder<ProxyTypes...>().addEntries(*this, 0, entryData);
106 }
107
108 template <class ProxyType>
109 void
110 addProxyFinder(const EntryData& entryData)
111 {
112 SimpleConfigDialogAdder<ProxyType>().addEntries(*this, 0, {entryData});
113 }
114
115 template <class ProxyType>
116 void
117 addProxyFinder(const std::string& name,
118 const std::string& description,
119 const std::string& mask)
120 {
121 addProxyFinder<ProxyType>({name, description, mask});
122 }
123
124 /**
125 * @brief dtor
126 */
127 ~SimpleConfigDialog() override;
128
129 std::string getProxyName(const std::string& entryName) const;
130
131 std::string getProxyName(const std::string& entryName, const std::string& def) const;
132
133 bool hasProxyName(const std::string& entryName) const;
134
135 QVBoxLayout* getLayout();
136
137 void addLineEdit(const std::string& name,
138 const std::string& label,
139 const std::string& defaultValue = "");
140
141 std::string getLineEditText(const std::string& entryName) const;
142 bool hasLineEdit(const std::string& entryName) const;
143
144 std::string get(const std::string& entryName) const;
145
146 std::string get(const std::string& entryName, const std::string& def) const;
147
148 private:
149 struct SimpleConfigDialogAdderBase
150 {
151 virtual ~SimpleConfigDialogAdderBase() = default;
152
154 createIceProxyFinder(SimpleConfigDialog* d)
155 {
156 return nullptr;
157 }
158
159 void implAddEntries(SimpleConfigDialog& d,
160 std::size_t index,
161 const std::vector<EntryData>& entryData);
162 };
163
164 template <class... ProxyTs>
165 struct SimpleConfigDialogAdder
166 {
167 void
168 addEntries(SimpleConfigDialog&, std::size_t, const std::vector<EntryData>&)
169 {
170 }
171 };
172
173 template <class ProxyT, class... ProxyTs>
174 struct SimpleConfigDialogAdder<ProxyT, ProxyTs...> : SimpleConfigDialogAdderBase
175 {
176 IceProxyFinderBase*
177 createIceProxyFinder(SimpleConfigDialog* d) override
178 {
179 return new armarx::IceProxyFinder<ProxyT>(d);
180 }
181
182 void
183 addEntries(SimpleConfigDialog& d,
184 std::size_t index,
185 const std::vector<EntryData>& entryData)
186 {
187 this->implAddEntries(d, index, entryData);
188 SimpleConfigDialogAdder<ProxyTs...>().addEntries(d, index + 1, entryData);
189 }
190 };
191
192 template <class... ProxyTs>
193 friend struct SimpleConfigDialogAdder;
194
195 struct EntryCallbacks
196 {
197 std::function<std::string()> proxyName;
198 std::function<void(const IceManagerPtr&)> setIceManager;
199 };
200
201 std::map<std::string, EntryCallbacks> entries;
202 std::map<std::string, QLineEdit*> lineEdits;
203 /**
204 * @brief The internal ui.
205 */
206 Ui::SimpleConfigDialog* ui;
207 /**
208 * @brief The used uuid.
209 */
210 std::string uuid;
211
212 protected:
213 /**
214 * @brief Initializes the proxy finder
215 */
216 void onInitComponent() override;
217
218 /**
219 * @brief noop
220 */
221 void
223 {
224 }
225
226 /**
227 * @brief Returns the dialog's default name.
228 * @return The dialog's default name.
229 */
230 std::string getDefaultName() const override;
231 };
232} // namespace armarx
uint8_t index
The IceProxyFinderBase class provides a convenient way to query online proxies in the ice network,...
The ManagedIceObject is the base class for all ArmarX objects.
A config-dialog containing one (or multiple) proxy finders.
void onInitComponent() override
Initializes the proxy finder.
void addProxyFinder(const std::vector< EntryData > &entryData)
void addProxyFinder(const std::string &name, const std::string &description, const std::string &mask)
bool hasProxyName(const std::string &entryName) const
SimpleConfigDialog(QWidget *parent=nullptr)
ctor
std::string getProxyName(const std::string &entryName) const
std::string get(const std::string &entryName) const
void addProxyFinder(const EntryData &entryData)
void onConnectComponent() override
noop
bool hasLineEdit(const std::string &entryName) const
void addLineEdit(const std::string &name, const std::string &label, const std::string &defaultValue="")
std::string getLineEditText(const std::string &entryName) const
std::string getDefaultName() const override
Returns the dialog's default name.
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< IceManager > IceManagerPtr
IceManager smart pointer.
Definition ArmarXFwd.h:39