Seamly2D
Code documentation
dialogline.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 * @file dialogline.cpp
3 ** @author Douglas S Caskey
4 ** @date 30 Apr, 2023
5 **
6 ** @brief
7 ** @copyright
8 ** This source code is part of the Seamly2D project, a pattern making
9 ** program to create and model patterns of clothing.
10 ** Copyright (C) 2017-2023 Seamly2D project
11 ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
12 **
13 ** Seamly2D is free software: you can redistribute it and/or modify
14 ** it under the terms of the GNU General Public License as published by
15 ** the Free Software Foundation, either version 3 of the License, or
16 ** (at your option) any later version.
17 **
18 ** Seamly2D is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
22 **
23 ** You should have received a copy of the GNU General Public License
24 ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
25 **
26 *************************************************************************/
27 
28 /************************************************************************
29  **
30  ** @file dialogline.cpp
31  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
32  ** @date November 15, 2013
33  **
34  ** @brief
35  ** @copyright
36  ** This source code is part of the Valentine project, a pattern making
37  ** program, whose allow create and modeling patterns of clothing.
38  ** Copyright (C) 2013-2015 Seamly2D project
39  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
40  **
41  ** Seamly2D is free software: you can redistribute it and/or modify
42  ** it under the terms of the GNU General Public License as published by
43  ** the Free Software Foundation, either version 3 of the License, or
44  ** (at your option) any later version.
45  **
46  ** Seamly2D is distributed in the hope that it will be useful,
47  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
48  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49  ** GNU General Public License for more details.
50  **
51  ** You should have received a copy of the GNU General Public License
52  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
53  **
54  *************************************************************************/
55 
56 #include "dialogline.h"
57 
58 #include <QColor>
59 #include <QComboBox>
60 #include <QIcon>
61 #include <QLabel>
62 #include <QMap>
63 #include <QPointer>
64 #include <QVariant>
65 
66 #include "../../visualization/visualization.h"
67 #include "../../visualization/line/vistoolline.h"
68 #include "../ifc/ifcdef.h"
70 #include "ui_dialogline.h"
71 
72 //---------------------------------------------------------------------------------------------------------------------
73 /**
74  * @brief DialogLine create dialog
75  * @param data container with data
76  * @param parent parent widget
77  */
78 DialogLine::DialogLine(const VContainer *data, const quint32 &toolId, QWidget *parent)
79  : DialogTool(data, toolId, parent)
80  , ui(new Ui::DialogLine)
81 {
82  ui->setupUi(this);
83  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
85 
86 
87  FillComboBoxPoints(ui->comboBoxFirstPoint);
88  FillComboBoxPoints(ui->comboBoxSecondPoint);
89 
90  int index = ui->lineType_ComboBox->findData(LineTypeNone);
91  if (index != -1)
92  {
93  ui->lineType_ComboBox->removeItem(index);
94  }
95 
96  index = ui->lineColor_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineColor());
97  if (index != -1)
98  {
99  ui->lineColor_ComboBox->setCurrentIndex(index);
100  }
101 
102  index = ui->lineWeight_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineWeight());
103  if (index != -1)
104  {
105  ui->lineWeight_ComboBox->setCurrentIndex(index);
106  }
107 
108  index = ui->lineType_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineType());
109  if (index != -1)
110  {
111  ui->lineType_ComboBox->setCurrentIndex(index);
112  }
113 
114  number = 0;
115 
116  connect(ui->comboBoxFirstPoint, &QComboBox::currentTextChanged, this, &DialogLine::PointNameChanged);
117  connect(ui->comboBoxSecondPoint, &QComboBox::currentTextChanged, this, &DialogLine::PointNameChanged);
118 
119  vis = new VisToolLine(data);
120 }
121 
122 //---------------------------------------------------------------------------------------------------------------------
124 {
125  delete ui;
126 }
127 
128 //---------------------------------------------------------------------------------------------------------------------
129 /**
130  * @brief setSecondPoint set id second point
131  * @param value id
132  */
133 void DialogLine::setSecondPoint(const quint32 &value)
134 {
135  setCurrentPointId(ui->comboBoxSecondPoint, value);
136 
137  VisToolLine *line = qobject_cast<VisToolLine *>(vis);
138  SCASSERT(line != nullptr)
139  line->setPoint2Id(value);
140 }
141 
142 //---------------------------------------------------------------------------------------------------------------------
143 /**
144  * @brief setLineName set the name of the line
145  * @param value id
146  */
148 {
149  ui->name_LineEdit->setText(tr("Line_") + ui->comboBoxFirstPoint->currentText() +
150  "_" + ui->comboBoxSecondPoint->currentText());
151 }
152 
153 //---------------------------------------------------------------------------------------------------------------------
154 /**
155  * @brief getLineType return type of line
156  * @return type
157  */
158 QString DialogLine::getLineType() const
159 {
160  return GetComboBoxCurrentData(ui->lineType_ComboBox, LineTypeSolidLine);
161 }
162 
163 //---------------------------------------------------------------------------------------------------------------------
164 /**
165  * @brief setLineType set type of line
166  * @param value type
167  */
168 void DialogLine::setLineType(const QString &value)
169 {
170  ChangeCurrentData(ui->lineType_ComboBox, value);
171  vis->setLineStyle(lineTypeToPenStyle(value));
172 }
173 
174 //---------------------------------------------------------------------------------------------------------------------
175 /**
176  * @brief getLineWeight return weight of the lines
177  * @return type
178  */
180 {
181  return GetComboBoxCurrentData(ui->lineWeight_ComboBox, "0.35");
182 }
183 
184 //---------------------------------------------------------------------------------------------------------------------
185 /**
186  * @brief setLineWeight set weight of the lines
187  * @param value type
188  */
189 void DialogLine::setLineWeight(const QString &value)
190 {
191  ChangeCurrentData(ui->lineWeight_ComboBox, value);
192  vis->setLineWeight(value);
193 }
194 
195 //---------------------------------------------------------------------------------------------------------------------
197 {
198  return GetComboBoxCurrentData(ui->lineColor_ComboBox, ColorBlack);
199 }
200 
201 //---------------------------------------------------------------------------------------------------------------------
202 void DialogLine::setLineColor(const QString &value)
203 {
204  ChangeCurrentData(ui->lineColor_ComboBox, value);
205 }
206 
207 //---------------------------------------------------------------------------------------------------------------------
208 /**
209  * @brief setFirstPoint set id first point
210  * @param value id
211  */
212 void DialogLine::setFirstPoint(const quint32 &value)
213 {
214  setCurrentPointId(ui->comboBoxFirstPoint, value);
215 
216  VisToolLine *line = qobject_cast<VisToolLine *>(vis);
217  SCASSERT(line != nullptr)
218  line->setObject1Id(value);
219 }
220 
221 //---------------------------------------------------------------------------------------------------------------------
223 {
224  QColor color = okColor;
225  if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint))
226  {
227  flagError = false;
228  color = errorColor;
229  }
230  else
231  {
232  flagError = true;
233  color = okColor;
234  }
235 
236  ui->name_LineEdit->setText(tr("Line_") + ui->comboBoxFirstPoint->currentText() +
237  "_" + ui->comboBoxSecondPoint->currentText());
238 
239  ChangeColor(ui->labelFirstPoint, color);
240  ChangeColor(ui->labelSecondPoint, color);
241  CheckState();
242 }
243 
244 //---------------------------------------------------------------------------------------------------------------------
246 {
247  AddVisualization<VisToolLine>();
248 }
249 
250 //---------------------------------------------------------------------------------------------------------------------
252 {
253  VisToolLine *line = qobject_cast<VisToolLine *>(vis);
254  SCASSERT(line != nullptr)
255 
256  line->setObject1Id(getFirstPoint());
257  line->setPoint2Id(getSecondPoint());
259  line->setLineWeight(getLineWeight());
260  line->RefreshGeometry();
261 }
262 
263 //---------------------------------------------------------------------------------------------------------------------
264 /**
265  * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
266  * @param id id of point or detail
267  * @param type type of object
268  */
269 void DialogLine::ChosenObject(quint32 id, const SceneObject &type)
270 {
271  if (prepare == false)// After first choose we ignore all objects
272  {
273  if (type == SceneObject::Point)
274  {
275  switch (number)
276  {
277  case 0:
278  if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point")))
279  {
280  number++;
281  vis->VisualMode(id);
282  }
283  break;
284  case 1:
285  if (getCurrentObjectId(ui->comboBoxFirstPoint) != id)
286  {
287  if (SetObject(id, ui->comboBoxSecondPoint, ""))
288  {
289  if (flagError)
290  {
291  number = 0;
292  prepare = true;
293  DialogAccepted();
294  }
295  }
296  }
297  break;
298  default:
299  break;
300  }
301  }
302  }
303 }
304 
305 //---------------------------------------------------------------------------------------------------------------------
306 /**
307  * @brief getFirstPoint return id first point
308  * @return id
309  */
311 {
312  return qvariant_cast<quint32>(ui->comboBoxFirstPoint->currentData());
313 }
314 
315 //---------------------------------------------------------------------------------------------------------------------
316 /**
317  * @brief getSecondPoint return id second point
318  * @return id
319  */
321 {
322  return qvariant_cast<quint32>(ui->comboBoxSecondPoint->currentData());
323 }
The DialogLine class dialog for ToolLine. Help create line and edit option.
Definition: dialogline.h:68
virtual void ShowVisualization() Q_DECL_OVERRIDE
Definition: dialogline.cpp:245
virtual void PointNameChanged() Q_DECL_OVERRIDE
Definition: dialogline.cpp:222
virtual ~DialogLine() Q_DECL_OVERRIDE
Definition: dialogline.cpp:123
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
Definition: dialogline.cpp:251
QString getLineWeight() const
getLineWeight return weight of the lines
Definition: dialogline.cpp:179
void setFirstPoint(const quint32 &value)
setFirstPoint set id first point
Definition: dialogline.cpp:212
DialogLine(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
DialogLine create dialog.
Definition: dialogline.cpp:78
QString getLineColor() const
Definition: dialogline.cpp:196
quint32 getFirstPoint() const
getFirstPoint return id first point
Definition: dialogline.cpp:310
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE
ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
Definition: dialogline.cpp:269
QString getLineType() const
getLineType return type of line
Definition: dialogline.cpp:158
void setLineName()
setLineName set the name of the line
Definition: dialogline.cpp:147
void setLineType(const QString &value)
setLineType set type of line
Definition: dialogline.cpp:168
Ui::DialogLine * ui
ui keeps information about user interface
Definition: dialogline.h:106
void setLineWeight(const QString &value)
setLineWeight set weight of the lines
Definition: dialogline.cpp:189
void setLineColor(const QString &value)
Definition: dialogline.cpp:202
void setSecondPoint(const quint32 &value)
setSecondPoint set id second point
Definition: dialogline.cpp:133
quint32 getSecondPoint() const
getSecondPoint return id second point
Definition: dialogline.cpp:320
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
void setCurrentPointId(QComboBox *box, const quint32 &value, FillComboBox rule=FillComboBox::NoChildren, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
Definition: dialogtool.cpp:896
void ChangeCurrentData(QComboBox *box, const QVariant &value) const
ChangeCurrentData select item in combobox by id.
Definition: dialogtool.cpp:419
const QColor okColor
Definition: dialogtool.h:219
virtual void CheckState()
CheckState enable, when all is correct, or disable, when something wrong, button ok.
void FillComboBoxPoints(QComboBox *box, FillComboBox rule=FillComboBox::Whole, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
FillComboBoxPoints fill comboBox list of points.
Definition: dialogtool.cpp:242
const QColor errorColor
Definition: dialogtool.h:220
qint32 number
number number of handled objects
Definition: dialogtool.h:234
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip)
Definition: dialogtool.cpp:974
virtual void DialogAccepted()
DialogAccepted save data and emit signal about closed dialog.
void initializeOkCancelApply(T *ui)
initializeOkCancelApply initialize OK / Cancel and Apply buttons
Definition: dialogtool.h:365
bool flagError
flagError use this flag if for you do not enought
Definition: dialogtool.h:193
const VContainer * data
data container with data
Definition: dialogtool.h:177
QString GetComboBoxCurrentData(const QComboBox *box, const QString &def) const
Definition: dialogtool.cpp:400
bool prepare
prepare show if we prepare. Show dialog after finish working with visual part of tool
Definition: dialogtool.h:228
QPointer< Visualization > vis
Definition: dialogtool.h:236
void ChangeColor(QWidget *widget, const QColor &color)
quint32 getCurrentObjectId(QComboBox *box) const
getCurrentPointId return current point id stored in combobox
Definition: dialogtool.cpp:959
The VContainer class container of all variables.
Definition: vcontainer.h:141
void setPoint2Id(const quint32 &value)
Definition: vistoolline.cpp:93
virtual void RefreshGeometry() Q_DECL_OVERRIDE
Definition: vistoolline.cpp:76
void setLineWeight(const QString &value)
void setObject1Id(const quint32 &value)
void setLineStyle(const Qt::PenStyle &value)
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
const QString LineTypeSolidLine
Definition: ifcdef.cpp:159
const QString ColorBlack
Definition: ifcdef.cpp:373
const QString LineTypeNone
Definition: ifcdef.cpp:158
Qt::PenStyle lineTypeToPenStyle(const QString &lineType)
LineStyle return pen style for current line style.
Definition: ifcdef.cpp:183
#define qApp
Definition: vapplication.h:67