SimpleConfigDialog.cpp
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#include "SimpleConfigDialog.h"
23
24#include <QDialog>
25#include <QHBoxLayout>
26#include <QLabel>
27#include <QLineEdit>
28
29#include <IceUtil/UUID.h>
30
32
33#include <ArmarXGui/libraries/SimpleConfigDialog/ui_SimpleConfigDialog.h>
34
36 QDialog(parent), ui(new Ui::SimpleConfigDialog), uuid{IceUtil::generateUUID()}
37{
38 ui->setupUi(this);
39}
40
45
46std::string
47armarx::SimpleConfigDialog::getProxyName(const std::string& entryName) const
48{
49 return entries.at(entryName).proxyName();
50}
51
52std::string
53armarx::SimpleConfigDialog::getProxyName(const std::string& entryName, const std::string& def) const
54{
55 return hasProxyName(entryName) ? getProxyName(entryName) : def;
56}
57
58bool
59armarx::SimpleConfigDialog::hasProxyName(const std::string& entryName) const
60{
61 return entries.count(entryName);
62}
63
64void
66{
67 auto manager = getIceManager();
68 for (auto& entry : entries)
69 {
70 entry.second.setIceManager(manager);
71 }
72}
73
74std::string
76{
77 return "SimpleConfigDialog" + uuid;
78}
79
80QVBoxLayout*
82{
83 return ui->verticalLayout;
84}
85
86void
88 const std::string& label,
89 const std::string& defaultValue)
90{
91 ARMARX_CHECK_EXPRESSION(!lineEdits.count(name));
92 QHBoxLayout* horizontalLayout = new QHBoxLayout;
93 horizontalLayout->addWidget(new QLabel{QString::fromStdString(label)});
94 lineEdits[name] = new QLineEdit;
95 lineEdits.at(name)->setText(QString::fromStdString(defaultValue));
96 horizontalLayout->addWidget(lineEdits.at(name));
97 getLayout()->addLayout(horizontalLayout);
98}
99
100std::string
101armarx::SimpleConfigDialog::getLineEditText(const std::string& entryName) const
102{
103 return lineEdits.at(entryName)->text().toStdString();
104}
105
106bool
107armarx::SimpleConfigDialog::hasLineEdit(const std::string& entryName) const
108{
109 return lineEdits.count(entryName);
110}
111
112std::string
113armarx::SimpleConfigDialog::get(const std::string& entryName) const
114{
115 const auto hasprx = hasProxyName(entryName);
116 const auto hasedt = hasLineEdit(entryName);
117 ARMARX_CHECK_EXPRESSION(hasprx != hasedt)
118 << VAROUT(entryName) << ' ' << VAROUT(hasprx) << ' ' << VAROUT(hasedt);
119 return hasprx ? getProxyName(entryName) : getLineEditText(entryName);
120}
121
122std::string
123armarx::SimpleConfigDialog::get(const std::string& entryName, const std::string& def) const
124{
125 const auto hasprx = hasProxyName(entryName);
126 const auto hasedt = hasLineEdit(entryName);
127 ARMARX_CHECK_EXPRESSION(!(hasprx && hasedt))
128 << VAROUT(entryName) << ' ' << VAROUT(hasprx) << ' ' << VAROUT(hasedt);
129 return hasprx ? getProxyName(entryName) : (hasedt ? getLineEditText(entryName) : def);
130}
131
132void
133armarx::SimpleConfigDialog::SimpleConfigDialogAdderBase::implAddEntries(
135 std::size_t index,
136 const std::vector<armarx::SimpleConfigDialog::EntryData>& entryData)
137{
138 auto& entry = entryData.at(index);
139 QHBoxLayout* horizontalLayout = new QHBoxLayout;
140
141 horizontalLayout->addWidget(new QLabel{QString::fromStdString(entry.description)});
142
143 armarx::IceProxyFinderBase* finder = createIceProxyFinder(&d);
144 finder->setSearchMask(QString::fromStdString(entry.mask));
145 horizontalLayout->addWidget(finder);
146
147 d.entries[entry.name] = {[finder]
148 { return finder->getSelectedProxyName().trimmed().toStdString(); },
149 [finder](const IceManagerPtr& m) { finder->setIceManager(m); }};
150
151 d.getLayout()->addLayout(horizontalLayout);
152}
uint8_t index
#define VAROUT(x)
The IceProxyFinderBase class provides a convenient way to query online proxies in the ice network,...
void setIceManager(IceManagerPtr icemanager, bool fetchProxies=true)
void setSearchMask(const QString &searchMask)
QString getSelectedProxyName() const
IceManagerPtr getIceManager() const
Returns the IceManager.
A config-dialog containing one (or multiple) proxy finders.
void onInitComponent() override
Initializes the proxy finder.
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
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.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
ArmarX Headers.
IceUtil::Handle< IceManager > IceManagerPtr
IceManager smart pointer.
Definition ArmarXFwd.h:39