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 
25 
27 
28 #include <QDialog>
29 
30 #include <functional>
31 #include <map>
32 
33 class QLineEdit;
34 class QVBoxLayout;
35 
36 namespace Ui
37 {
38  class SimpleConfigDialog;
39 }
40 
41 namespace armarx
42 {
43  class IceProxyFinderBase;
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  */
85  public QDialog,
86  virtual public armarx::ManagedIceObject
87  {
88  Q_OBJECT
89  public:
90  struct EntryData
91  {
92  std::string name;
93  std::string description;
94  std::string mask;
95  };
96 
97  /**
98  * @brief ctor
99  * @param parent the dialog's parent
100  */
101  explicit SimpleConfigDialog(QWidget* parent = nullptr);
102 
103  template<class...ProxyTypes>
104  void addProxyFinder(const std::vector<EntryData>& entryData)
105  {
106  SimpleConfigDialogAdder<ProxyTypes...>().addEntries(*this, 0, entryData);
107  }
108 
109  template<class ProxyType>
110  void addProxyFinder(const EntryData& entryData)
111  {
112  SimpleConfigDialogAdder<ProxyType>().addEntries(*this, 0, {entryData});
113  }
114 
115  template<class ProxyType>
116  void addProxyFinder(const std::string& name,
117  const std::string& description,
118  const std::string& mask)
119  {
120  addProxyFinder<ProxyType>({name, description, mask});
121  }
122 
123  /**
124  * @brief dtor
125  */
126  ~SimpleConfigDialog() override;
127 
128  std::string getProxyName(const std::string& entryName) const;
129 
130  std::string getProxyName(const std::string& entryName, const std::string& def) const;
131 
132  bool hasProxyName(const std::string& entryName) const;
133 
134  QVBoxLayout* getLayout();
135 
136  void addLineEdit(const std::string& name,
137  const std::string& label,
138  const std::string& defaultValue = "");
139 
140  std::string getLineEditText(const std::string& entryName)const;
141  bool hasLineEdit(const std::string& entryName) const;
142 
143  std::string get(const std::string& entryName) const;
144 
145  std::string get(const std::string& entryName, const std::string& def) const;
146  private:
147 
148  struct SimpleConfigDialogAdderBase
149  {
150  virtual ~SimpleConfigDialogAdderBase() = default;
151  virtual armarx::IceProxyFinderBase* createIceProxyFinder(SimpleConfigDialog* d)
152  {
153  return nullptr;
154  }
155 
156  void implAddEntries(SimpleConfigDialog& d, std::size_t index, const std::vector<EntryData>& entryData);
157  };
158 
159  template<class...ProxyTs>
161  {
162  void addEntries(SimpleConfigDialog&, std::size_t, const std::vector<EntryData>&)
163  {
164  }
165  };
166 
167  template<class ProxyT, class...ProxyTs>
168  struct SimpleConfigDialogAdder<ProxyT, ProxyTs...> : SimpleConfigDialogAdderBase
169  {
170  IceProxyFinderBase* createIceProxyFinder(SimpleConfigDialog* d) override
171  {
172  return new armarx::IceProxyFinder<ProxyT>(d);
173  }
174  void addEntries(SimpleConfigDialog& d, std::size_t index, const std::vector<EntryData>& entryData)
175  {
176  this->implAddEntries(d, index, entryData);
177  SimpleConfigDialogAdder<ProxyTs...>().addEntries(d, index + 1, entryData);
178  }
179  };
180 
181  template<class...ProxyTs> friend struct SimpleConfigDialogAdder;
182 
183  struct EntryCallbacks
184  {
185  std::function<std::string()> proxyName;
186  std::function<void(const IceManagerPtr&)> setIceManager;
187  };
188 
189  std::map<std::string, EntryCallbacks> entries;
190  std::map<std::string, QLineEdit*> lineEdits;
191  /**
192  * @brief The internal ui.
193  */
194  Ui::SimpleConfigDialog* ui;
195  /**
196  * @brief The used uuid.
197  */
198  std::string uuid;
199 
200  protected:
201  /**
202  * @brief Initializes the proxy finder
203  */
204  void onInitComponent() override;
205  /**
206  * @brief noop
207  */
208  void onConnectComponent() override {}
209  /**
210  * @brief Returns the dialog's default name.
211  * @return The dialog's default name.
212  */
213  std::string getDefaultName() const override;
214  };
215 }
armarx::SimpleConfigDialog::SimpleConfigDialogAdder
friend struct SimpleConfigDialogAdder
Definition: SimpleConfigDialog.h:181
armarx::SimpleConfigDialog::addProxyFinder
void addProxyFinder(const std::string &name, const std::string &description, const std::string &mask)
Definition: SimpleConfigDialog.h:116
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::SimpleConfigDialog::EntryData::mask
std::string mask
Definition: SimpleConfigDialog.h:94
armarx::IceProxyFinderBase
The IceProxyFinderBase class provides a convenient way to query online proxies in the ice network,...
Definition: IceProxyFinder.h:53
armarx::SimpleConfigDialog::onConnectComponent
void onConnectComponent() override
noop
Definition: SimpleConfigDialog.h:208
armarx::SimpleConfigDialog::SimpleConfigDialog
SimpleConfigDialog(QWidget *parent=nullptr)
ctor
Definition: SimpleConfigDialog.cpp:36
armarx::SimpleConfigDialog::EntryData
Definition: SimpleConfigDialog.h:90
armarx::SimpleConfigDialog::EntryData::name
std::string name
Definition: SimpleConfigDialog.h:92
armarx::SimpleConfigDialog::hasProxyName
bool hasProxyName(const std::string &entryName) const
Definition: SimpleConfigDialog.cpp:59
armarx::SimpleConfigDialog::onInitComponent
void onInitComponent() override
Initializes the proxy finder.
Definition: SimpleConfigDialog.cpp:64
armarx::SimpleConfigDialog::hasLineEdit
bool hasLineEdit(const std::string &entryName) const
Definition: SimpleConfigDialog.cpp:100
armarx::SimpleConfigDialog::get
std::string get(const std::string &entryName) const
Definition: SimpleConfigDialog.cpp:105
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
ManagedIceObject.h
IceProxyFinder.h
armarx::SimpleConfigDialog::getLineEditText
std::string getLineEditText(const std::string &entryName) const
Definition: SimpleConfigDialog.cpp:95
armarx::SimpleConfigDialog::addProxyFinder
void addProxyFinder(const EntryData &entryData)
Definition: SimpleConfigDialog.h:110
armarx::SimpleConfigDialog::addProxyFinder
void addProxyFinder(const std::vector< EntryData > &entryData)
Definition: SimpleConfigDialog.h:104
armarx::SimpleConfigDialog::addLineEdit
void addLineEdit(const std::string &name, const std::string &label, const std::string &defaultValue="")
Definition: SimpleConfigDialog.cpp:84
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
armarx::SimpleConfigDialog::getDefaultName
std::string getDefaultName() const override
Returns the dialog's default name.
Definition: SimpleConfigDialog.cpp:73
IceUtil::Handle< IceManager >
armarx::IceProxyFinder< ProxyT >
armarx::SimpleConfigDialog::getLayout
QVBoxLayout * getLayout()
Definition: SimpleConfigDialog.cpp:79
armarx::SimpleConfigDialog::getProxyName
std::string getProxyName(const std::string &entryName) const
Definition: SimpleConfigDialog.cpp:49
armarx::SimpleConfigDialog::EntryData::description
std::string description
Definition: SimpleConfigDialog.h:93
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::SimpleConfigDialog::~SimpleConfigDialog
~SimpleConfigDialog() override
dtor
Definition: SimpleConfigDialog.cpp:44
armarx::SimpleConfigDialog
A config-dialog containing one (or multiple) proxy finders.
Definition: SimpleConfigDialog.h:84