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