Seamly2D
Code documentation
editgroup_dialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file editgroup_dialog.cpp
3  ** @author Douglas S Caskey
4  ** @date Mar 1, 2023
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2023 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25 /************************************************************************
26  **
27  ** @file dialog_editgroup.cpp
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 4 4, 2016
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentina project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2016 Valentina project
36  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
37  **
38  ** Valentina is free software: you can redistribute it and/or modify
39  ** it under the terms of the GNU General Public License as published by
40  ** the Free Software Foundation, either version 3 of the License, or
41  ** (at your option) any later version.
42  **
43  ** Valentina is distributed in the hope that it will be useful,
44  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  ** GNU General Public License for more details.
47  **
48  ** You should have received a copy of the GNU General Public License
49  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
50  **
51  *************************************************************************/
52 
53 #include "editgroup_dialog.h"
54 #include "ui_editgroup_dialog.h"
55 
56 #include <QLineEdit>
57 #include <QStringList>
58 #include <QInputDialog>
59 #include <QComboBox>
60 
61 #include "dialogtool.h"
62 #include "../ifc/ifcdef.h"
63 #include "../ifc/xml/vabstractpattern.h"
64 #include "../vmisc/logging.h"
65 #include "../vmisc/vabstractapplication.h"
66 #include "../vpatterndb/vcontainer.h"
67 #include "../vtools/undocommands/addgroup.h"
68 #include "../vwidgets/color_combobox.h"
69 #include "../vwidgets/linetype_combobox.h"
70 #include "../vwidgets/lineweight_combobox.h"
71 
72 Q_LOGGING_CATEGORY(EditGroupDialogLog, "editGroupDialogLog")
73 
74 //---------------------------------------------------------------------------------------------------------------------
75 EditGroupDialog::EditGroupDialog(const VContainer *data, const quint32 &toolId, QWidget *parent)
76  : DialogTool(data, toolId, parent)
77  , ui(new Ui::EditGroupDialog)
78  , m_doc(qApp->getCurrentDocument())
79  , m_groupData()
80  , m_oldGroupName()
81 {
82  ui->setupUi(this);
83  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
84  setWindowIcon(QIcon(":/icon/32x32/edit.png"));
85  ui->groupColor_ComboBox->removeItem(ui->groupColor_ComboBox->findData(ColorByGroup)); //remove color "BY Group" item
86  ui->groupLineType_ComboBox->removeItem(ui->groupLineType_ComboBox->findData(LineTypeByGroup)); //remove linetype "BY Group" item
87  ui->groupLineType_ComboBox->removeItem(ui->groupLineType_ComboBox->findData(LineTypeNone)); //remove linetype "No Pen" item
88  ui->groupLineWeight_ComboBox->removeItem(ui->groupLineWeight_ComboBox->findData(LineWeightByGroup)); //remove lineweight "BY Group" item
89  m_oldGroupName = ui->groupName_LineEdit->text();
90 
91  initializeOkCancel(ui);
93  connect(ui->groupName_LineEdit, &QLineEdit::textChanged, this, &EditGroupDialog::nameChanged);
94 }
95 
96 //---------------------------------------------------------------------------------------------------------------------
98 {
99  delete ui;
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
103 void EditGroupDialog::setName(const QString &name)
104 {
105  ui->groupName_LineEdit->setText(name);
106 }
107 
108 //---------------------------------------------------------------------------------------------------------------------
110 {
111  return ui->groupName_LineEdit->text();
112 }
113 
114 //---------------------------------------------------------------------------------------------------------------------
115 void EditGroupDialog::ShowDialog(bool click)
116 {
117  if (not click)
118  {
119  if (m_groupData.isEmpty())
120  {
121  return;
122  }
123 
124  //setName(tr("New group"));
125 
126  setModal(true);
127  emit ToolTip("");
128  show();
129  }
130 }
131 
132 //---------------------------------------------------------------------------------------------------------------------
133 void EditGroupDialog::SelectedObject(bool selected, quint32 object, quint32 tool)
134 {
135  if (selected)
136  {
137  m_groupData.insert(object, tool);
138  }
139  else
140  {
141  m_groupData.remove(object);
142  }
143 }
144 
145 //---------------------------------------------------------------------------------------------------------------------
147 {
148  ui->groupName_LineEdit->text().isEmpty() ? flagName = false : flagName = true;
149  CheckState();
150 }
151 
152 //---------------------------------------------------------------------------------------------------------------------
154 {
155  return m_groupData;
156 }
157 
158 //---------------------------------------------------------------------------------------------------------------------
160 {
161  return GetComboBoxCurrentData(ui->groupColor_ComboBox, ColorBlack);
162 }
163 
164 //---------------------------------------------------------------------------------------------------------------------
165 void EditGroupDialog::setColor(const QString &color)
166 {
167  ChangeCurrentData(ui->groupColor_ComboBox, color);
168 }
169 
170 //---------------------------------------------------------------------------------------------------------------------
172 {
173  return GetComboBoxCurrentData(ui->groupLineType_ComboBox, LineTypeSolidLine);
174 }
175 
176 //---------------------------------------------------------------------------------------------------------------------
177 void EditGroupDialog::setLineType(const QString &type)
178 {
179  ChangeCurrentData(ui->groupLineType_ComboBox, type);
180 }
181 
182 //---------------------------------------------------------------------------------------------------------------------
184 {
185  return GetComboBoxCurrentData(ui->groupLineWeight_ComboBox, "0.35");
186 }
187 
188 //---------------------------------------------------------------------------------------------------------------------
189 void EditGroupDialog::setLineWeight(const QString &weight)
190 {
191  ChangeCurrentData(ui->groupLineWeight_ComboBox, weight);
192 }
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
void ChangeCurrentData(QComboBox *box, const QVariant &value) const
ChangeCurrentData select item in combobox by id.
Definition: dialogtool.cpp:419
void ToolTip(const QString &toolTip)
ToolTip emit tooltipe for tool.
virtual void CheckState()
CheckState enable, when all is correct, or disable, when something wrong, button ok.
bool flagName
flagName true if name is correct
Definition: dialogtool.h:183
QString GetComboBoxCurrentData(const QComboBox *box, const QString &def) const
Definition: dialogtool.cpp:400
QString getLineType() const
QString getColor() const
Ui::EditGroupDialog * ui
Definition: dialoggroup.h:92
void setLineType(const QString &type)
QMap< quint32, quint32 > getGroupData() const
QMap< quint32, quint32 > m_groupData
virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE
void setLineWeight(const QString &weight)
void setName(const QString &name)
void setColor(const QString &color)
QString getLineWeight() const
virtual void ShowDialog(bool click) Q_DECL_OVERRIDE
Definition: dialoggroup.cpp:93
QString getName() const
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QString LineTypeByGroup
Definition: ifcdef.cpp:370
const QString LineTypeSolidLine
Definition: ifcdef.cpp:159
const QString ColorBlack
Definition: ifcdef.cpp:373
const QString LineTypeNone
Definition: ifcdef.cpp:158
const QString ColorByGroup
Definition: ifcdef.cpp:371
const QString LineWeightByGroup
Definition: ifcdef.cpp:369
#define qApp
Definition: vapplication.h:67