NewEntityIdDialog.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  * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
17  * @date 2021
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #include "NewEntityIdDialog.h"
23 
24 #include <QDialogButtonBox>
25 #include <QGridLayout>
26 #include <QLabel>
27 #include <QLineEdit>
28 #include <QPushButton>
29 #include <QVBoxLayout>
30 
32 
34 
35 
37 {
38 
40  QDialog(parent), coreSegmentID(std::make_unique<armem::MemoryID>(coreSegmentID))
41  {
42  _providerSegmentName = new QLineEdit(this);
43  _entityName = new QLineEdit(this);
44 
45  _buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
46 
47  QLabel* instruction =
48  new QLabel("Enter provider segment name and entity name for new entity:");
49  QFont font = instruction->font();
50  font.setBold(true);
51  instruction->setFont(font);
52 
53 
54  QGridLayout* grid = new QGridLayout();
55  int col = 0;
56 
57  grid->addWidget(new QLabel("Core Segment ID"), 0, col);
58  grid->addWidget(new QLabel(QString::fromStdString(coreSegmentID.str()) + "/"), 1, col);
59  ++col;
60 
61  grid->addWidget(new QLabel("Provider Segment Name"), 0, col);
62  grid->addWidget(_providerSegmentName, 1, col);
63  ++col;
64 
65  grid->addWidget(new QLabel("/"), 1, col);
66  ++col;
67 
68  grid->addWidget(new QLabel("Entity Name"), 0, col);
69  grid->addWidget(_entityName, 1, col);
70  ++col;
71 
72 
73  QVBoxLayout* layout = new QVBoxLayout();
74  setLayout(layout);
75  layout->addWidget(instruction);
76  layout->addLayout(grid);
77  layout->addWidget(_buttonBox);
78 
79 
80  connect(_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
81  connect(_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
82 
83  auto enableOkIfReady = [this]()
84  {
85  _buttonBox->button(QDialogButtonBox::Ok)
86  ->setEnabled(_providerSegmentName->text().size() > 0 and
87  _entityName->text().size() > 0);
88  };
89  connect(_providerSegmentName, &QLineEdit::textChanged, this, enableOkIfReady);
90  connect(_entityName, &QLineEdit::textChanged, this, enableOkIfReady);
91 
92  enableOkIfReady();
93  }
94 
95 
97  {
98  }
99 
100 
101  QString
103  {
104  return _providerSegmentName->text();
105  }
106 
107 
108  QString
110  {
111  return _entityName->text();
112  }
113 
114 
117  {
118  armem::MemoryID id;
119  id.providerSegmentName = providerSegmentName().toStdString();
120  id.entityName = entityName().toStdString();
121  return id;
122  }
123 
126  {
128  ARMARX_CHECK_NOT_NULL(coreSegmentID);
129  entityID.setCoreSegmentID(*coreSegmentID);
130  return entityID;
131  }
132 
133 } // namespace armarx::navigation::qt_plugins::location_graph_editor
armarx::navigation::graph::coreSegmentID
const armem::MemoryID coreSegmentID
Definition: constants.h:30
armarx::armem::MemoryID::setCoreSegmentID
void setCoreSegmentID(const MemoryID &id)
Definition: MemoryID.cpp:361
armarx::navigation::qt_plugins::location_graph_editor::NewEntityIdDialog::NewEntityIdDialog
NewEntityIdDialog(const armem::MemoryID &coreSegmentID, QWidget *parent=nullptr)
Definition: NewEntityIdDialog.cpp:39
armarx::navigation::qt_plugins::location_graph_editor::NewEntityIdDialog::entityID
armem::MemoryID entityID() const
Definition: NewEntityIdDialog.cpp:125
armarx::armem::MemoryID::providerSegmentName
std::string providerSegmentName
Definition: MemoryID.h:52
MemoryID.h
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::armem::MemoryID::str
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
Definition: MemoryID.cpp:102
armarx::navigation::qt_plugins::location_graph_editor::NewEntityIdDialog::providerSegmentName
QString providerSegmentName() const
Definition: NewEntityIdDialog.cpp:102
armarx::navigation::qt_plugins::location_graph_editor::NewEntityIdDialog::entityIDWithoutCoreSegmentID
armem::MemoryID entityIDWithoutCoreSegmentID() const
Definition: NewEntityIdDialog.cpp:116
armarx::armem
Definition: LegacyRobotStateMemoryAdapter.cpp:31
armarx::navigation::qt_plugins::location_graph_editor::NewEntityIdDialog::~NewEntityIdDialog
virtual ~NewEntityIdDialog() override
Definition: NewEntityIdDialog.cpp:96
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::navigation::qt_plugins::location_graph_editor
Definition: GuiGraph.cpp:29
armarx::navigation::qt_plugins::location_graph_editor::NewEntityIdDialog::entityName
QString entityName() const
Definition: NewEntityIdDialog.cpp:109
ExpressionException.h
NewEntityIdDialog.h
std
Definition: Application.h:66
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29