RenameGroupDialog.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 ArmarX::
17* @author Valerij Wittenbeck (valerij.wittenbeck at student dot kit dot edu
18* @date 2015
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "RenameGroupDialog.h"
24
25#include <QFileDialog>
26#include <QTimer>
27#include <QtGui>
28
31
33#include <ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/ui_RenameGroupDialog.h>
34
35namespace armarx
36{
37
39 const StateTreeModelPtr& treeModel,
40 const StatechartGroupPtr& group,
41 const GroupRenamerPtr& groupRenamer,
42 QWidget* parent) :
43 QDialog(parent),
44 ui(new Ui::RenameGroupDialog),
45 group(group),
46 groupRenamer(groupRenamer),
47 validGroupName("([a-zA-Z][a-zA-Z0-9]*)"),
48 colorGreen(QColor::fromRgb(120, 255, 120)),
49 colorRed(QColor::fromRgb(255, 120, 120)),
50 colorYellow(QColor::fromRgb(255, 200, 0)),
51 saveAll(false)
52 {
53 ui->setupUi(this);
54 setOkButtonsEnabled(false);
55 ui->editOldName->setText(group->getName());
56 ui->editOldName->setReadOnly(true);
57 // ui->editOldName->setEnabled(false);
58
59 ui->editNewName->setValidator(new QRegExpValidator(validGroupName, this));
60
61 connect(ui->btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
62 connect(
63 ui->btnSaveAndProceed, SIGNAL(clicked()), this, SLOT(saveAllProceedButtonClicked()));
64 connect(ui->btnDontSaveAndProceed, SIGNAL(clicked()), this, SLOT(accept()));
65 connect(ui->editNewName, SIGNAL(textChanged(QString)), this, SLOT(verifyNewName(QString)));
66
67 for (const StateTreeNodePtr& c : rootNode->getChildren())
68 {
69 if (!c->isGroup())
70 {
71 continue;
72 }
73
74 auto childGroup = c->getGroup();
75 allGroups.push_back(childGroup);
76
77 QVector<statechartmodel::StatePtr> allGroupStates = childGroup->getAllStates(false);
78 auto dependencies = GroupCloner::GetGroupsFromStates(treeModel, allGroupStates);
79 bool isDependent = std::find_if(dependencies.constBegin(),
80 dependencies.constEnd(),
81 [&](const StatechartGroupPtr& g) {
82 return g->getGroupPath() == group->getGroupPath();
83 }) != dependencies.constEnd();
84
85 if (isDependent && childGroup->getGroupPath() != group->getGroupPath())
86 {
87 dependantGroups.push_back(childGroup);
88 }
89 }
90
91 ui->groupsWidget->setRowCount(dependantGroups.size() + 1);
92 ui->groupsWidget->setColumnCount(1);
93 ui->groupsWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
94 ui->groupsWidget->setHorizontalHeaderLabels({"Affected Groups"});
95
96 QTableWidgetItem* groupItem = new QTableWidgetItem(group->getName());
97 groupItem->setFlags(groupItem->flags() ^ Qt::ItemIsEditable);
98 ui->groupsWidget->setItem(0, 0, groupItem);
99
100 for (int i = 0; i < dependantGroups.size(); ++i)
101 {
102 QTableWidgetItem* item = new QTableWidgetItem(dependantGroups[i]->getName());
103 item->setFlags(item->flags() ^ Qt::ItemIsEditable);
104 ui->groupsWidget->setItem(i + 1, 0, item);
105 }
106 }
107
108 void
109 RenameGroupDialog::setOkButtonsEnabled(bool enabled)
110 {
111 ui->btnDontSaveAndProceed->setEnabled(enabled);
112 ui->btnSaveAndProceed->setEnabled(enabled);
113 }
114
116 {
117 delete ui;
118 }
119
122 {
123 return group;
124 }
125
128 {
129 return groupRenamer;
130 }
131
132 bool
134 {
135 return saveAll;
136 }
137
138 QVector<StatechartGroupPtr>
140 {
141 return dependantGroups;
142 }
143
144 QVector<StatechartGroupPtr>
146 {
147 return allGroups;
148 }
149
150 QString
152 {
153 return ui->editNewName->text();
154 }
155
156 void
158 {
159 saveAll = true;
160 accept();
161 }
162
163 void
165 {
166 bool inUse = false;
167
168 for (const auto& g : allGroups)
169 {
170 if (newName == g->getName())
171 {
172 inUse = true;
173 break;
174 }
175 }
176
177 QColor colorToUse;
178
179 if (inUse)
180 {
181 ui->labelNewNameError->setText("Name already in use");
182 colorToUse = colorRed;
183 setOkButtonsEnabled(false);
184 }
185 else
186 {
187 ui->labelNewNameError->setText("Valid name");
188 colorToUse = colorGreen;
189 setOkButtonsEnabled(true);
190 }
191
192 QPalette p(ui->labelNewNameError->palette());
193 p.setColor(ui->labelNewNameError->backgroundRole(), colorToUse);
194 ui->labelNewNameError->setPalette(p);
195 }
196
197} // namespace armarx
constexpr T c
static QVector< StatechartGroupPtr > GetGroupsFromStates(const StateTreeModelPtr &treeModel, const QVector< statechartmodel::StatePtr > &states)
RenameGroupDialog(const StateTreeNodePtr &rootNode, const StateTreeModelPtr &treeModel, const StatechartGroupPtr &group, const GroupRenamerPtr &groupRenamer, QWidget *parent=0)
void verifyNewName(QString newName)
QVector< StatechartGroupPtr > getAllGroups() const
StatechartGroupPtr getGroup() const
QVector< StatechartGroupPtr > getDependantGroups() const
GroupRenamerPtr getGroupRenamer() const
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< StatechartGroup > StatechartGroupPtr
std::shared_ptr< StateTreeModel > StateTreeModelPtr
std::shared_ptr< StateTreeNode > StateTreeNodePtr
std::shared_ptr< GroupRenamer > GroupRenamerPtr