Seamly2D
Code documentation
dialogtool.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file dialogtool.cpp
3  ** @author Douglas S Caskey
4  ** @date Dec 11, 2022
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2022 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 dialogtool.cpp
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date November 15, 2013
30  **
31  ** @copyright
32  ** Copyright (C) 2013 Valentina project.
33  ** This source code is part of the Valentina project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
36  **
37  ** Valentina is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published
39  ** by the Free Software Foundation, either version 3 of the License,
40  ** or (at your option) any later version.
41  **
42  ** Valentina is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "dialogtool.h"
53 
54 #include <limits.h>
55 #include <qiterator.h>
56 #include <qnumeric.h>
57 #include <QCloseEvent>
58 #include <QComboBox>
59 #include <QDoubleSpinBox>
60 #include <QEvent>
61 #include <QHash>
62 #include <QIcon>
63 #include <QKeyEvent>
64 #include <QLabel>
65 #include <QLineEdit>
66 #include <QMapIterator>
67 #include <QMessageLogger>
68 #include <QPalette>
69 #include <QPixmap>
70 #include <QPlainTextEdit>
71 #include <QPushButton>
72 #include <QRegularExpression>
73 #include <QRegularExpressionMatch>
74 #include <QScopedPointer>
75 #include <QSharedPointer>
76 #include <QShowEvent>
77 #include <QSize>
78 #include <QTextCursor>
79 #include <QTimer>
80 #include <QWidget>
81 #include <Qt>
82 #include <QtDebug>
83 #include <new>
84 #include <QBuffer>
85 #include <QFont>
86 
87 #include "../ifc/xml/vdomdocument.h"
88 #include "../qmuparser/qmudef.h"
89 #include "../qmuparser/qmuparsererror.h"
90 #include "../vgeometry/vpointf.h"
91 #include "../vpatterndb/calculator.h"
92 #include "../vpatterndb/vcontainer.h"
93 #include "../vpatterndb/vtranslatevars.h"
94 #include "../vpatterndb/vpiecenode.h"
95 #include "../../tools/vabstracttool.h"
96 #include "../ifc/xml/vabstractpattern.h"
97 #include "../vgeometry/vabstractcurve.h"
98 #include "../vgeometry/vgobject.h"
99 #include "../vmisc/vcommonsettings.h"
100 
101 template <class T> class QSharedPointer;
102 
103 Q_LOGGING_CATEGORY(vDialog, "v.dialog")
104 
105 #define DIALOG_MAX_FORMULA_HEIGHT 64
106 #define DIALOG_MIN_WIDTH 260
107 
108 namespace
109 {
110 //---------------------------------------------------------------------------------------------------------------------
111 quint32 RowId(QListWidget *listWidget, int i)
112 {
113  SCASSERT(listWidget != nullptr);
114 
115  if (i < 0 || i >= listWidget->count())
116  {
117  return NULL_ID;
118  }
119 
120  const QListWidgetItem *rowItem = listWidget->item(i);
121  SCASSERT(rowItem != nullptr);
122  const VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
123  return rowNode.GetId();
124 }
125 }
126 
127 //---------------------------------------------------------------------------------------------------------------------
128 /**
129  * @brief DialogTool create dialog
130  * @param data container with data
131  * @param parent parent widget
132  */
133 DialogTool:: DialogTool(const VContainer *data, const quint32 &toolId, QWidget *parent)
134  : QDialog(parent),
135  data(data),
136  isInitialized(false),
137  flagName(true),
138  flagFormula(true),
139  flagError(true),
140  timerFormula(nullptr),
141  ok_Button(nullptr),
142  apply_Button(nullptr),
143  spinBoxAngle(nullptr),
144  plainTextEditFormula(nullptr),
145  labelResultCalculation(nullptr),
146  labelEditNamePoint(nullptr),
147  labelEditFormula(nullptr),
148  okColor(this->palette().color(QPalette::Active, QPalette::WindowText)),
149  errorColor(Qt::red),
150  associatedTool(nullptr),
151  toolId(toolId),
152  prepare(false),
153  pointName(),
154  number(0),
155  vis(nullptr)
156 {
157  SCASSERT(data != nullptr)
158  timerFormula = new QTimer(this);
159  connect(timerFormula, &QTimer::timeout, this, &DialogTool::EvalFormula);
160 }
161 
162 //---------------------------------------------------------------------------------------------------------------------
164 {
165  emit ToolTip("");
166 
167  if (not vis.isNull())
168  {
169  delete vis;
170  }
171 }
172 
173 //---------------------------------------------------------------------------------------------------------------------
174 void DialogTool::keyPressEvent(QKeyEvent *event)
175 {
176  switch (event->key())
177  {
178  case Qt::Key_Escape:
179  DialogRejected();
180  return; // After reject the dialog will be destroyed, exit imidiately
181  default:
182  break;
183  }
184  QDialog::keyPressEvent ( event );
185 }
186 
187 //---------------------------------------------------------------------------------------------------------------------
188 /**
189  * @brief closeEvent handle when dialog cloded
190  * @param event event
191  */
192 void DialogTool::closeEvent(QCloseEvent *event)
193 {
194  DialogRejected();
195  event->accept();
196 }
197 
198 //---------------------------------------------------------------------------------------------------------------------
199 /**
200  * @brief showEvent handle when window show
201  * @param event event
202  */
203 void DialogTool::showEvent(QShowEvent *event)
204 {
205  QDialog::showEvent( event );
206  if ( event->spontaneous() )
207  {
208  return;
209  }
210  if (isInitialized)
211  {
212  return;
213  }
214  // do your init stuff here
215 
216  setMaximumSize(size());
217  setMinimumSize(size());
218 
219  isInitialized = true;//first show windows are held
221 }
222 
223 //---------------------------------------------------------------------------------------------------------------------
224 void DialogTool::FillComboBoxPiecesList(QComboBox *box, const QVector<quint32> &list)
225 {
226  SCASSERT(box != nullptr)
227  box->blockSignals(true);
228  box->clear();
229  for (int i=0; i < list.size(); ++i)
230  {
231  box->addItem(data->GetPiece(list.at(i)).GetName(), list.at(i));
232  }
233  box->blockSignals(false);
234  box->setCurrentIndex(-1); // Force a user to choose
235 }
236 
237 //---------------------------------------------------------------------------------------------------------------------
238 /**
239  * @brief FillComboBoxPoints fill comboBox list of points
240  * @param box comboBox
241  */
242 void DialogTool::FillComboBoxPoints(QComboBox *box, FillComboBox rule, const quint32 &ch1, const quint32 &ch2) const
243 {
244  FillCombo<VPointF>(box, GOType::Point, rule, ch1, ch2);
245 }
246 
247 //---------------------------------------------------------------------------------------------------------------------
248 void DialogTool::FillComboBoxArcs(QComboBox *box, FillComboBox rule, const quint32 &ch1, const quint32 &ch2) const
249 {
250  FillCombo<VAbstractCurve>(box, GOType::Arc, rule, ch1, ch2);
251 }
252 
253 //---------------------------------------------------------------------------------------------------------------------
254 void DialogTool::FillComboBoxSplines(QComboBox *box) const
255 {
256  SCASSERT(box != nullptr)
257  box->blockSignals(true);
258 
259  const auto objs = data->DataGObjects();
260  QHash<quint32, QSharedPointer<VGObject> >::const_iterator i;
262  for (i = objs->constBegin(); i != objs->constEnd(); ++i)
263  {
264  if (i.key() != toolId)
265  {
266  if (IsSpline(i.value()))
267  {
268  PrepareList<VAbstractCurve>(list, i.key());
269  }
270  }
271  }
272  FillList(box, list);
273 
274  box->blockSignals(false);
275 }
276 
277 //---------------------------------------------------------------------------------------------------------------------
278 void DialogTool::FillComboBoxSplinesPath(QComboBox *box) const
279 {
280  SCASSERT(box != nullptr)
281  box->blockSignals(true);
282 
283  const auto objs = data->DataGObjects();
284  QHash<quint32, QSharedPointer<VGObject> >::const_iterator i;
286  for (i = objs->constBegin(); i != objs->constEnd(); ++i)
287  {
288  if (i.key() != toolId)
289  {
290  if (IsSplinePath(i.value()))
291  {
292  PrepareList<VAbstractCurve>(list, i.key());
293  }
294  }
295  }
296  FillList(box, list);
297 
298  box->blockSignals(false);
299 }
300 
301 //---------------------------------------------------------------------------------------------------------------------
302 void DialogTool::FillComboBoxCurves(QComboBox *box) const
303 {
304  SCASSERT(box != nullptr)
305  const auto objs = data->DataGObjects();
307  QHash<quint32, QSharedPointer<VGObject> >::const_iterator i;
308  for (i = objs->constBegin(); i != objs->constEnd(); ++i)
309  {
310  if (i.key() != toolId)
311  {
312  QSharedPointer<VGObject> obj = i.value();
313  if ((obj->getType() == GOType::Arc
314  || obj->getType() == GOType::EllipticalArc
315  || obj->getType() == GOType::Spline
316  || obj->getType() == GOType::SplinePath
317  || obj->getType() == GOType::CubicBezier
318  || obj->getType() == GOType::CubicBezierPath) && obj->getMode() == Draw::Calculation)
319  {
320  PrepareList<VAbstractCurve>(list, i.key());
321  }
322  }
323  }
324  FillList(box, list);
325 }
326 
327 //---------------------------------------------------------------------------------------------------------------------
328 /**
329  * @brief FillComboBoxTypeLine fill comboBox list of type lines
330  * @param box comboBox
331  */
332 void DialogTool::FillComboBoxTypeLine(QComboBox *box, const QMap<QString, QIcon> &stylesPics) const
333 {
334  SCASSERT(box != nullptr)
335  QMap<QString, QIcon>::const_iterator i = stylesPics.constBegin();
336  while (i != stylesPics.constEnd())
337  {
338  box->addItem(i.value(), "", QVariant(i.key()));
339  ++i;
340  }
341 
342  const int index = box->findData(QVariant(LineTypeSolidLine));
343  if (index != -1)
344  {
345  box->setCurrentIndex(index);
346  }
347 }
348 
349 //---------------------------------------------------------------------------------------------------------------------
350 void DialogTool::FillComboBoxLineColors(QComboBox *box) const
351 {
352  SCASSERT(box != nullptr)
353 
354  box->clear();
355  int size = box->iconSize().height();
356  // On Mac pixmap should be little bit smaller.
357 #if defined(Q_OS_MAC)
358  size -= 2; // Two pixels should be enough.
359 #endif //defined(Q_OS_MAC)
360 
362  QMap<QString, QString>::const_iterator i = map.constBegin();
363  while (i != map.constEnd())
364  {
365  QPixmap pix(size, size);
366  pix.fill(QColor(i.key()));
367  box->addItem(QIcon(pix), i.value(), QVariant(i.key()));
368  ++i;
369  }
370 }
371 
372 //---------------------------------------------------------------------------------------------------------------------
374 {
375  SCASSERT(box != nullptr)
376 
377  box->addItem(tr("First point"), QVariant(static_cast<int>(CrossCirclesPoint::FirstPoint)));
378  box->addItem(tr("Second point"), QVariant(static_cast<int>(CrossCirclesPoint::SecondPoint)));
379 }
380 
381 //---------------------------------------------------------------------------------------------------------------------
383 {
384  SCASSERT(box != nullptr)
385 
386  box->addItem(tr("Highest point"), QVariant(static_cast<int>(VCrossCurvesPoint::HighestPoint)));
387  box->addItem(tr("Lowest point"), QVariant(static_cast<int>(VCrossCurvesPoint::LowestPoint)));
388 }
389 
390 //---------------------------------------------------------------------------------------------------------------------
392 {
393  SCASSERT(box != nullptr)
394 
395  box->addItem(tr("Leftmost point"), QVariant(static_cast<int>(HCrossCurvesPoint::LeftmostPoint)));
396  box->addItem(tr("Rightmost point"), QVariant(static_cast<int>(HCrossCurvesPoint::RightmostPoint)));
397 }
398 
399 //---------------------------------------------------------------------------------------------------------------------
400 QString DialogTool::GetComboBoxCurrentData(const QComboBox *box, const QString &def) const
401 {
402  SCASSERT(box != nullptr)
403  QString value;
404  value = box->currentData().toString();
405 
406  if (value.isEmpty())
407  {
408  value = def;
409  }
410  return value;
411 }
412 
413 //---------------------------------------------------------------------------------------------------------------------
414 /**
415  * @brief ChangeCurrentData select item in combobox by id
416  * @param box combobox
417  * @param value id of item
418  */
419 void DialogTool::ChangeCurrentData(QComboBox *box, const QVariant &value) const
420 {
421  SCASSERT(box != nullptr)
422  const qint32 index = box->findData(value);
423  if (index != -1)
424  {
425  box->blockSignals(true);
426  box->setCurrentIndex(index);
427  box->blockSignals(false);
428  }
429 }
430 
431 //---------------------------------------------------------------------------------------------------------------------
432 void DialogTool::MoveCursorToEnd(QPlainTextEdit *plainTextEdit) const
433 {
434  SCASSERT(plainTextEdit != nullptr)
435  QTextCursor cursor = plainTextEdit->textCursor();
436  cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
437  plainTextEdit->setTextCursor(cursor);
438 }
439 
440 //---------------------------------------------------------------------------------------------------------------------
441 bool DialogTool::eventFilter(QObject *object, QEvent *event)
442 {
443  if (QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(object))
444  {
445  if (event->type() == QEvent::KeyPress)
446  {
447  QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
448  if ((keyEvent->key() == Qt::Key_Enter) || (keyEvent->key() == Qt::Key_Return))
449  {
450  // Ignore Enter key
451  return true;
452  }
453  else if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
454  {
455  if (qApp->Settings()->GetOsSeparator())
456  {
457  plainTextEdit->insertPlainText(QLocale().decimalPoint());
458  }
459  else
460  {
461  plainTextEdit->insertPlainText(QLocale::c().decimalPoint());
462  }
463  return true;
464  }
465  }
466  }
467  else
468  {
469  // pass the event on to the parent class
470  return QDialog::eventFilter(object, event);
471  }
472  return false;// pass the event to the widget
473 }
474 
475 //---------------------------------------------------------------------------------------------------------------------
476 quint32 DialogTool::DNumber(const QString &baseName) const
477 {
478  quint32 num = 0;
479  QString name;
480  do
481  {
482  ++num;
483  name = baseName + QString("_%1").arg(num);
484  } while (not data->IsUnique(name));
485 
486  return num;
487 }
488 
489 //---------------------------------------------------------------------------------------------------------------------
490 int DialogTool::FindNotExcludedNodeDown(QListWidget *listWidget, int candidate)
491 {
492  SCASSERT(listWidget != nullptr);
493 
494  int index = -1;
495  if (candidate < 0 || candidate >= listWidget->count())
496  {
497  return index;
498  }
499 
500  int i = candidate;
501  VPieceNode rowNode;
502  do
503  {
504  const QListWidgetItem *rowItem = listWidget->item(i);
505  SCASSERT(rowItem != nullptr);
506  rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
507 
508  if (not rowNode.isExcluded())
509  {
510  index = i;
511  }
512 
513  ++i;
514  }
515  while (rowNode.isExcluded() && i < listWidget->count());
516 
517  return index;
518 }
519 
520 //---------------------------------------------------------------------------------------------------------------------
521 int DialogTool::FindNotExcludedNodeUp(QListWidget *listWidget, int candidate)
522 {
523  SCASSERT(listWidget != nullptr);
524 
525  int index = -1;
526  if (candidate < 0 || candidate >= listWidget->count())
527  {
528  return index;
529  }
530 
531  int i = candidate;
532  VPieceNode rowNode;
533  do
534  {
535  const QListWidgetItem *rowItem = listWidget->item(i);
536  SCASSERT(rowItem != nullptr);
537  rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
538 
539  if (not rowNode.isExcluded())
540  {
541  index = i;
542  }
543 
544  --i;
545  }
546  while (rowNode.isExcluded() && i > -1);
547 
548  return index;
549 }
550 
551 //---------------------------------------------------------------------------------------------------------------------
552 bool DialogTool::isFirstPointSameAsLast(QListWidget *listWidget)
553 {
554  SCASSERT(listWidget != nullptr);
555  if (listWidget->count() > 1)
556  {
557  const quint32 topId = RowId(listWidget, FindNotExcludedNodeDown(listWidget, 0));
558  const quint32 bottomId = RowId(listWidget, FindNotExcludedNodeUp(listWidget, listWidget->count()-1));
559  return topId == bottomId;
560  }
561  return false;
562 }
563 
564 //---------------------------------------------------------------------------------------------------------------------
565 bool DialogTool::doublePointsExist(QListWidget *listWidget)
566 {
567  SCASSERT(listWidget != nullptr);
568  for (int i=0, sz = listWidget->count()-1; i<sz; ++i)
569  {
570  const int firstIndex = FindNotExcludedNodeDown(listWidget, i);
571  const quint32 firstId = RowId(listWidget, firstIndex);
572  const quint32 secondId = RowId(listWidget, FindNotExcludedNodeDown(listWidget, firstIndex+1));
573 
574  if (firstId == secondId)
575  {
576  return true;
577  }
578  }
579  return false;
580 }
581 
582 //---------------------------------------------------------------------------------------------------------------------
583 bool DialogTool::isEachPointNameUnique(QListWidget *listWidget)
584 {
585  SCASSERT(listWidget != nullptr);
586  QSet<quint32> pointLabels;
587  int countPoints = 0;
588  for (int i=0; i < listWidget->count(); ++i)
589  {
590  const QListWidgetItem *rowItem = listWidget->item(i);
591  SCASSERT(rowItem != nullptr);
592  const VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
593  if (rowNode.GetTypeTool() == Tool::NodePoint)
594  {
595  ++countPoints;
596  pointLabels.insert(rowNode.GetId());
597  }
598  }
599 
600  return countPoints == pointLabels.size();
601 }
602 
603 //---------------------------------------------------------------------------------------------------------------------
605 {
606  const QIcon icon = QIcon::fromTheme("dialog-warning",
607  QIcon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"));
608 
609  const QPixmap pixmap = icon.pixmap(QSize(16, 16));
610  QByteArray byteArray;
611  QBuffer buffer(&byteArray);
612  pixmap.save(&buffer, "PNG");
613  const QString url = QString("<img src=\"data:image/png;base64,") + byteArray.toBase64() + QLatin1String("\"/> ");
614  return url;
615 }
616 
617 //---------------------------------------------------------------------------------------------------------------------
618 QFont DialogTool::NodeFont(bool nodeExcluded)
619 {
620  QFont font = qApp->Settings()->getGuiFont();
621  font.setPointSize(qApp->Settings()->getGuiFontSize());
622  font.setBold(true);
623  font.setStrikeOut(nodeExcluded);
624  return font;
625 }
626 
627 //---------------------------------------------------------------------------------------------------------------------
628 NodeInfo DialogTool::getNodeInfo(const VPieceNode &node, bool showNotch) const
629 {
630  NodeInfo info;
631  const QSharedPointer<VGObject> obj = data->GetGObject(node.GetId());
632  info.name = obj->name();
633  info.icon = "://icon/24x24/spacer.png";
634 
635  if (node.GetTypeTool() != Tool::NodePoint)
636  {
637  int bias = 0;
638  qApp->TrVars()->VariablesToUser(info.name, 0, obj->name(), bias);
639 
640  if (node.GetReverse())
641  {
642  info.icon = "://icon/24x24/reverse.png";
643  }
644  }
645  else if (showNotch && node.isNotch())
646  {
647  switch(node.getNotchType())
648  {
649  case NotchType::TNotch:
650  info.icon = "://icon/24x24/t_notch.png";
651  break;
652  case NotchType::UNotch:
653  info.icon = "://icon/24x24/u_notch.png";
654  break;
656  info.icon = "://icon/24x24/internal_v_notch.png";
657  break;
659  info.icon = "://icon/24x24/external_v_notch.png";
660  break;
661  case NotchType::Castle:
662  info.icon = "://icon/24x24/castle_notch.png";
663  break;
664  case NotchType::Diamond:
665  info.icon = "://icon/24x24/diamond_notch.png";
666  break;
667  case NotchType::Slit:
668  info.icon = "://icon/24x24/slit_notch.png";
669  break;
670  default:
671  break;
672  }
673  }
674 
675  return info;
676 }
677 
678 //---------------------------------------------------------------------------------------------------------------------
679 void DialogTool::newNodeItem(QListWidget *listWidget, const VPieceNode &node, bool nodeExcluded, bool isDuplicate)
680 {
681  SCASSERT(listWidget != nullptr);
682  SCASSERT(node.GetId() > NULL_ID);
683  NodeInfo info;
684  switch (node.GetTypeTool())
685  {
686  case (Tool::NodePoint):
687  case (Tool::NodeArc):
688  case (Tool::NodeElArc):
689  case (Tool::NodeSpline):
690  case (Tool::NodeSplinePath):
691  info = getNodeInfo(node, true);
692  break;
693  default:
694  qDebug()<<"Got wrong tools. Ignore.";
695  return;
696  }
697 
698  bool newNodeAllowed = false;
699 
700  if(listWidget->count() == 0 || isDuplicate || RowId(listWidget, listWidget->count()-1) != node.GetId())
701  {
702  newNodeAllowed = true;
703  }
704 
705  if(newNodeAllowed)
706  {
707  QListWidgetItem *item = new QListWidgetItem(info.name);
708  item->setFont(NodeFont(nodeExcluded ? node.isExcluded() : false));
709  item->setData(Qt::UserRole, QVariant::fromValue(node));
710  item->setIcon(QIcon(info.icon));
711  listWidget->addItem(item);
712  listWidget->setCurrentRow(listWidget->count()-1);
713  }
714 }
715 
716 //---------------------------------------------------------------------------------------------------------------------
718 {
719  SCASSERT(box != nullptr);
720  box->clear();
721 
722  box->addItem(tr("by length"), static_cast<unsigned char>(PieceNodeAngle::ByLength));
723  box->addItem(tr("by points intersetions"), static_cast<unsigned char>(PieceNodeAngle::ByPointsIntersection));
724  box->addItem(tr("by first edge symmetry"), static_cast<unsigned char>(PieceNodeAngle::ByFirstEdgeSymmetry));
725  box->addItem(tr("by second edge symmetry"), static_cast<unsigned char>(PieceNodeAngle::BySecondEdgeSymmetry));
726  box->addItem(tr("by first edge right angle"), static_cast<unsigned char>(PieceNodeAngle::ByFirstEdgeRightAngle));
727  box->addItem(tr("by second edge right angle"), static_cast<unsigned char>(PieceNodeAngle::BySecondEdgeRightAngle));
728 }
729 
730 //---------------------------------------------------------------------------------------------------------------------
732 {
733  return (obj->getType() == GOType::SplinePath || obj->getType() == GOType::CubicBezierPath) &&
734  obj->getMode() == Draw::Calculation;
735 }
736 
737 //---------------------------------------------------------------------------------------------------------------------
738 /**
739  * @brief ValFormulaChanged handle change formula
740  * @param flag flag state of formula
741  * @param edit LineEdit
742  * @param timer timer of formula
743  */
744 void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer, const QString& postfix)
745 {
746  SCASSERT(edit != nullptr)
747  SCASSERT(timer != nullptr)
748  SCASSERT(labelEditFormula != nullptr)
749  SCASSERT(labelResultCalculation != nullptr)
750  if (edit->text().isEmpty())
751  {
752  flag = false;
753  CheckState();
754  ChangeColor(labelEditFormula, Qt::red);
755  if (postfix.isEmpty())
756  {
757  labelResultCalculation->setText(tr("Error"));
758  }
759  else
760  {
761  labelResultCalculation->setText(tr("Error") + " (" + postfix + ")");
762  }
763  labelResultCalculation->setToolTip(tr("Empty field"));
764  return;
765  }
766  timer->start(1000);
767 }
768 //---------------------------------------------------------------------------------------------------------------------
769 void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *timer, const QString& postfix)
770 {
771  SCASSERT(edit != nullptr)
772  SCASSERT(timer != nullptr)
773  SCASSERT(labelEditFormula != nullptr)
774  SCASSERT(labelResultCalculation != nullptr)
775  if (edit->toPlainText().isEmpty())
776  {
777  flag = false;
778  CheckState();
779  ChangeColor(labelEditFormula, Qt::red);
780  if (postfix.isEmpty())
781  {
782  labelResultCalculation->setText(tr("Error"));
783  }
784  else
785  {
786  labelResultCalculation->setText(tr("Error") + " (" + postfix + ")");
787  }
788 
789  labelResultCalculation->setToolTip(tr("Empty field"));
790  return;
791  }
792  timer->setSingleShot(true);
793  timer->start(300);
794 }
795 
796 //---------------------------------------------------------------------------------------------------------------------
797 /**
798  * @brief Eval evaluate formula and show result
799  * @param text expresion that we parse
800  * @param flag flag state of eval formula
801  * @param label label for signal error
802  * @param postfix unit name
803  * @param checkZero true - if formula can't be equal zero
804  */
805 qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QString& postfix, bool checkZero,
806  bool checkLessThanZero)
807 {
808  SCASSERT(label != nullptr)
809  SCASSERT(labelEditFormula != nullptr)
810 
811  qreal result = INT_MIN;//Value can be 0, so use max imposible value
812 
813  if (text.isEmpty())
814  {
815  flag = false;
816  ChangeColor(labelEditFormula, Qt::red);
817  label->setText(tr("Error") + " (" + postfix + ")");
818  label->setToolTip(tr("Empty field"));
819  }
820  else
821  {
822  try
823  {
824  // Replace line return character with spaces for calc if exist
825  QString formula = text;
826  formula.replace("\n", " ");
827  // Translate to internal look.
828  formula = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
829  QScopedPointer<Calculator> cal(new Calculator());
830  result = cal->EvalFormula(data->DataVariables(), formula);
831 
832  if (qIsInf(result) || qIsNaN(result))
833  {
834  flag = false;
835  ChangeColor(labelEditFormula, Qt::red);
836  label->setText(tr("Error") + " (" + postfix + ")");
837  label->setToolTip(tr("Invalid result. Value is infinite or NaN. Please, check your calculations."));
838  }
839  else
840  {
841  //if result equal 0
842  if (checkZero && qFuzzyIsNull(result))
843  {
844  flag = false;
845  ChangeColor(labelEditFormula, Qt::red);
846  label->setText(tr("Error") + " (" + postfix + ")");
847  label->setToolTip(tr("Value can't be 0"));
848  }
849  else if (checkLessThanZero && result < 0)
850  {
851  flag = false;
852  ChangeColor(labelEditFormula, Qt::red);
853  label->setText(tr("Error") + " (" + postfix + ")");
854  label->setToolTip(tr("Value can't be less than 0"));
855  }
856  else
857  {
858  label->setText(qApp->LocaleToString(result) + " " +postfix);
859  flag = true;
861  label->setToolTip(tr("Result Value"));
862  emit ToolTip("");
863  }
864  }
865  }
866  catch (qmu::QmuParserError &e)
867  {
868  label->setText(tr("Error") + " (" + postfix + ")");
869  flag = false;
870  ChangeColor(labelEditFormula, Qt::red);
871  emit ToolTip(tr("Parser error: %1").arg(e.GetMsg()));
872  label->setToolTip(tr("Parser error: %1").arg(e.GetMsg()));
873  qDebug() << "\nMath parser error:\n"
874  << "--------------------------------------\n"
875  << "Message: " << e.GetMsg() << "\n"
876  << "Expression: " << e.GetExpr() << "\n"
877  << "--------------------------------------";
878  }
879  }
880  CheckState(); // Disable Ok and Apply buttons if something wrong.
881  return result;
882 }
883 
884 // Normalizes any number to an arbitrary range
885 // by assuming the range wraps around when going below min or above max
886 qreal DialogTool::normalize( const qreal value, const qreal start, const qreal end )
887 {
888  const qreal range = end - start ; //
889  const qreal offsetValue = value - start ; // value relative to 0
890 
891  return ( offsetValue - ( floor( offsetValue / range ) * range ) ) + start ;
892  // + start to reset back to start of original range
893 }
894 
895 //---------------------------------------------------------------------------------------------------------------------
896 void DialogTool::setCurrentPointId(QComboBox *box, const quint32 &value, FillComboBox rule,
897  const quint32 &ch1, const quint32 &ch2) const
898 {
899  SCASSERT(box != nullptr)
900 
901  box->blockSignals(true);
902 
903  FillComboBoxPoints(box, rule, ch1, ch2);
904  ChangeCurrentData(box, value);
905 
906  box->blockSignals(false);
907 }
908 
909 //---------------------------------------------------------------------------------------------------------------------
910 /**
911  * @brief setCurrentSplineId set current spline id in combobox
912  */
913 void DialogTool::setCurrentSplineId(QComboBox *box, const quint32 &value) const
914 {
915  SCASSERT(box != nullptr)
916  FillComboBoxSplines(box);
917  ChangeCurrentData(box, value);
918 }
919 
920 //---------------------------------------------------------------------------------------------------------------------
921 /**
922  * @brief setCurrentArcId
923  */
924 void DialogTool::setCurrentArcId(QComboBox *box, const quint32 &value, FillComboBox rule,
925  const quint32 &ch1, const quint32 &ch2) const
926 {
927  SCASSERT(box != nullptr)
928  FillComboBoxArcs(box, rule, ch1, ch2);
929  ChangeCurrentData(box, value);
930 }
931 
932 //---------------------------------------------------------------------------------------------------------------------
933 /**
934  * @brief setCurrentSplinePathId set current splinePath id in combobox
935  * @param box combobox
936  * @param value splinePath id
937  */
938 void DialogTool::setCurrentSplinePathId(QComboBox *box, const quint32 &value) const
939 {
940  SCASSERT(box != nullptr)
942  ChangeCurrentData(box, value);
943 }
944 
945 //---------------------------------------------------------------------------------------------------------------------
946 void DialogTool::setCurrentCurveId(QComboBox *box, const quint32 &value) const
947 {
948  SCASSERT(box != nullptr)
949  FillComboBoxCurves(box);
950  ChangeCurrentData(box, value);
951 }
952 
953 //---------------------------------------------------------------------------------------------------------------------
954 /**
955  * @brief getCurrentPointId return current point id stored in combobox
956  * @param box combobox
957  * @return id or 0 if combobox is empty
958  */
959 quint32 DialogTool::getCurrentObjectId(QComboBox *box) const
960 {
961  SCASSERT(box != nullptr)
962  qint32 index = box->currentIndex();
963  if (index != -1)
964  {
965  return qvariant_cast<quint32>(box->itemData(index));
966  }
967  else
968  {
969  return 0;
970  }
971 }
972 
973 //---------------------------------------------------------------------------------------------------------------------
974 bool DialogTool::SetObject(const quint32 &id, QComboBox *box, const QString &toolTip)
975 {
976  SCASSERT(box != nullptr)
977  const qint32 index = box->findData(id);
978  if ( index != -1 )
979  { // -1 for not found
980  box->setCurrentIndex(index);
981  emit ToolTip(toolTip);
982  return true;
983  }
984  else
985  {
986  qWarning()<<"Can't find object by id"<<id;
987  }
988  return false;
989 }
990 
991 //---------------------------------------------------------------------------------------------------------------------
992 void DialogTool::DeployFormula(QPlainTextEdit *formula, QPushButton *buttonGrowLength, int formulaBaseHeight)
993 {
994  SCASSERT(formula != nullptr)
995  SCASSERT(buttonGrowLength != nullptr)
996 
997  const QTextCursor cursor = formula->textCursor();
998 
999  if (formula->height() < DIALOG_MAX_FORMULA_HEIGHT)
1000  {
1001  setMaximumWidth(QWIDGETSIZE_MAX);
1002  formula->setFixedHeight(DIALOG_MAX_FORMULA_HEIGHT);
1003  //Set icon from theme (internal for Windows system)
1004  buttonGrowLength->setIcon(QIcon::fromTheme("go-up",
1005  QIcon(":/icons/win.icon.theme/16x16/actions/go-up.png")));
1006  }
1007  else
1008  {
1009  setMaximumWidth(DIALOG_MIN_WIDTH);
1010  formula->setFixedHeight(formulaBaseHeight);
1011  //Set icon from theme (internal for Windows system)
1012  buttonGrowLength->setIcon(QIcon::fromTheme("go-down",
1013  QIcon(":/icons/win.icon.theme/16x16/actions/go-down.png")));
1014  }
1015 
1016  // I found that after change size of formula field, it was filed for angle formula, field for formula became black.
1017  // This code prevent this.
1018  setUpdatesEnabled(false);
1019  repaint();
1020  setUpdatesEnabled(true);
1021 
1022  formula->setFocus();
1023  formula->setTextCursor(cursor);
1024 }
1025 
1026 //---------------------------------------------------------------------------------------------------------------------
1027 /**
1028  * @brief FillList fill combobox list
1029  * @param box combobox
1030  * @param list list with ids and names
1031  */
1032 void DialogTool::FillList(QComboBox *box, const QMap<QString, quint32> &list) const
1033 {
1034  SCASSERT(box != nullptr)
1035  box->clear();
1036 
1037  QMapIterator<QString, quint32> iter(list);
1038  while (iter.hasNext())
1039  {
1040  iter.next();
1041  box->addItem(iter.key(), iter.value());
1042  }
1043 }
1044 
1045 //---------------------------------------------------------------------------------------------------------------------
1046 template <typename T>
1048 {
1049  const auto obj = data->GeometricObject<T>(id);
1050  SCASSERT(obj != nullptr)
1051 
1052  QString newName = obj->name();
1053  int bias = 0;
1054  if (qApp->TrVars()->VariablesToUser(newName, 0, obj->name(), bias))
1055  {
1056  list[newName] = id;
1057  }
1058  else
1059  {
1060  list[obj->name()] = id;
1061  }
1062 }
1063 
1064 //---------------------------------------------------------------------------------------------------------------------
1066 {
1067  return (obj->getType() == GOType::Spline || obj->getType() == GOType::CubicBezier) &&
1068  obj->getMode() == Draw::Calculation;
1069 }
1070 
1071 //---------------------------------------------------------------------------------------------------------------------
1072 /**
1073  * @brief CheckState enable, when all is correct, or disable, when something wrong, button ok
1074  */
1076 {
1077  SCASSERT(ok_Button != nullptr)
1078  ok_Button->setEnabled(flagFormula && flagName && flagError);
1079  // In case dialog hasn't apply button
1080  if (apply_Button != nullptr)
1081  {
1082  apply_Button->setEnabled(ok_Button->isEnabled());
1083  }
1084 }
1085 
1086 //---------------------------------------------------------------------------------------------------------------------
1087 /**
1088  * @brief ChosenObject gets id and type of selected object. Save right data and ignore wrong.
1089  * @param id id of point or detail
1090  * @param type type of object
1091  */
1092 void DialogTool::ChosenObject(quint32 id, const SceneObject &type)
1093 {
1094  Q_UNUSED(id)
1095  Q_UNUSED(type)
1096 }
1097 
1098 //---------------------------------------------------------------------------------------------------------------------
1099 void DialogTool::SelectedObject(bool selected, quint32 object, quint32 tool)
1100 {
1101  Q_UNUSED(selected)
1102  Q_UNUSED(object)
1103  Q_UNUSED(tool)
1104 }
1105 
1106 //---------------------------------------------------------------------------------------------------------------------
1107 /**
1108  * @brief NamePointChanged check name of point
1109  */
1111 {
1112  SCASSERT(labelEditNamePoint != nullptr)
1113  QLineEdit* edit = qobject_cast<QLineEdit*>(sender());
1114  if (edit)
1115  {
1116  QString name = edit->text();
1117  QRegularExpression rx(NameRegExp());
1118  if (name.isEmpty() || (pointName != name && data->IsUnique(name) == false) ||
1119  rx.match(name).hasMatch() == false)
1120  {
1121  flagName = false;
1122  ChangeColor(labelEditNamePoint, Qt::red);
1123  }
1124  else
1125  {
1126  flagName = true;
1128  }
1129  }
1130  CheckState();
1131 }
1132 
1133 //---------------------------------------------------------------------------------------------------------------------
1134 void DialogTool::ChangeColor(QWidget *widget, const QColor &color)
1135 {
1136  SCASSERT(widget != nullptr)
1137  QPalette palette = widget->palette();
1138  palette.setColor(QPalette::Active, widget->foregroundRole(), color);
1139  widget->setPalette(palette);
1140 }
1141 
1142 //---------------------------------------------------------------------------------------------------------------------
1143 /**
1144  * @brief DialogAccepted save data and emit signal about closed dialog.
1145  */
1147 {
1148  SaveData();
1149  emit DialogClosed(QDialog::Accepted);
1150 }
1151 
1152 //---------------------------------------------------------------------------------------------------------------------
1154 {
1155  SaveData();
1156  emit DialogApplied();
1157 }
1158 
1159 //---------------------------------------------------------------------------------------------------------------------
1160 /**
1161  * @brief DialogRejected emit signal dialog rejected
1162  */
1164 {
1165  emit DialogClosed(QDialog::Rejected);
1166 }
1167 
1168 //---------------------------------------------------------------------------------------------------------------------
1169 /**
1170  * @brief formula check formula
1171  */
1173 {
1174  QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(sender());
1175  if (edit)
1176  {
1178  }
1179 }
1180 //---------------------------------------------------------------------------------------------------------------------
1182 {
1183  QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(sender());
1184  if (edit)
1185  {
1187  }
1188 }
1189 
1190 //---------------------------------------------------------------------------------------------------------------------
1191 /**
1192  * @brief ArrowUp set angle value 90 degree
1193  */
1195 {
1196  SCASSERT(spinBoxAngle != nullptr)
1197  spinBoxAngle->setValue(90);
1198 }
1199 
1200 //---------------------------------------------------------------------------------------------------------------------
1201 /**
1202  * @brief ArrowDown set angle value 270 degree
1203  */
1205 {
1206  SCASSERT(spinBoxAngle != nullptr)
1207  spinBoxAngle->setValue(270);
1208 }
1209 
1210 //---------------------------------------------------------------------------------------------------------------------
1211 /**
1212  * @brief ArrowLeft set angle value 180 degree
1213  */
1215 {
1216  SCASSERT(spinBoxAngle != nullptr)
1217  spinBoxAngle->setValue(180);
1218 }
1219 
1220 //---------------------------------------------------------------------------------------------------------------------
1221 /**
1222  * @brief ArrowRight set angle value 0 degree
1223  */
1225 {
1226  SCASSERT(spinBoxAngle != nullptr)
1227  spinBoxAngle->setValue(0);
1228 }
1229 
1230 //---------------------------------------------------------------------------------------------------------------------
1231 /**
1232  * @brief ArrowLeftUp set angle value 135 degree
1233  */
1235 {
1236  SCASSERT(spinBoxAngle != nullptr)
1237  spinBoxAngle->setValue(135);
1238 }
1239 
1240 //---------------------------------------------------------------------------------------------------------------------
1241 /**
1242  * @brief ArrowLeftDown set angle value 225 degree
1243  */
1245 {
1246  SCASSERT(spinBoxAngle != nullptr)
1247  spinBoxAngle->setValue(225);
1248 }
1249 
1250 //---------------------------------------------------------------------------------------------------------------------
1251 /**
1252  * @brief ArrowRightUp set angle value 45 degree
1253  */
1255 {
1256  SCASSERT(spinBoxAngle != nullptr)
1257  spinBoxAngle->setValue(45);
1258 }
1259 
1260 //---------------------------------------------------------------------------------------------------------------------
1261 /**
1262  * @brief ArrowRightDown set angle value 315 degree
1263  */
1265 {
1266  SCASSERT(spinBoxAngle != nullptr)
1267  spinBoxAngle->setValue(315);
1268 }
1269 
1270 //---------------------------------------------------------------------------------------------------------------------
1271 /**
1272  * @brief EvalFormula evaluate formula
1273  */
1275 {
1276  SCASSERT(plainTextEditFormula != nullptr)
1277  SCASSERT(labelResultCalculation != nullptr)
1278  const QString postfix = UnitsToStr(qApp->patternUnit());//Show unit in dialog lable (cm, mm or inch)
1279  Eval(plainTextEditFormula->toPlainText(), flagFormula, labelResultCalculation, postfix, false);
1280 }
1281 
1282 //---------------------------------------------------------------------------------------------------------------------
1283 // cppcheck-suppress unusedFunction
1284 quint32 DialogTool::GetToolId() const
1285 {
1286  return toolId;
1287 }
1288 
1289 //---------------------------------------------------------------------------------------------------------------------
1290 void DialogTool::SetToolId(const quint32 &value)
1291 {
1292  toolId = value;
1293 }
1294 
1295 //---------------------------------------------------------------------------------------------------------------------
1297 {
1298  return pointName;
1299 }
1300 
1301 //---------------------------------------------------------------------------------------------------------------------
1302 void DialogTool::moveListRowTop(QListWidget *list)
1303 {
1304  SCASSERT(list != nullptr)
1305  const int currentIndex = list->currentRow();
1306  if (QListWidgetItem *currentItem = list->takeItem(currentIndex))
1307  {
1308  list->insertItem(0, currentItem);
1309  list->setCurrentRow(0);
1310  }
1311 }
1312 
1313 //---------------------------------------------------------------------------------------------------------------------
1314 void DialogTool::moveListRowUp(QListWidget *list)
1315 {
1316  SCASSERT(list != nullptr)
1317  int currentIndex = list->currentRow();
1318  if (QListWidgetItem *currentItem = list->takeItem(currentIndex--))
1319  {
1320  if (currentIndex < 0)
1321  {
1322  currentIndex = 0;
1323  }
1324  list->insertItem(currentIndex, currentItem);
1325  list->setCurrentRow(currentIndex);
1326  }
1327 }
1328 
1329 //---------------------------------------------------------------------------------------------------------------------
1330 void DialogTool::moveListRowDown(QListWidget *list)
1331 {
1332  SCASSERT(list != nullptr)
1333  int currentIndex = list->currentRow();
1334  if (QListWidgetItem *currentItem = list->takeItem(currentIndex++))
1335  {
1336  if (currentIndex > list->count())
1337  {
1338  currentIndex = list->count();
1339  }
1340  list->insertItem(currentIndex, currentItem);
1341  list->setCurrentRow(currentIndex);
1342  }
1343 }
1344 
1345 //---------------------------------------------------------------------------------------------------------------------
1346 void DialogTool::moveListRowBottom(QListWidget *list)
1347 {
1348  SCASSERT(list != nullptr)
1349  const int currentIndex = list->currentRow();
1350  if (QListWidgetItem *currentItem = list->takeItem(currentIndex))
1351  {
1352  list->insertItem(list->count(), currentItem);
1353  list->setCurrentRow(list->count()-1);
1354  }
1355 }
1356 
1357 //---------------------------------------------------------------------------------------------------------------------
1358 void DialogTool::ShowDialog(bool click)
1359 {
1360  Q_UNUSED(click)
1361 }
1362 
1363 //---------------------------------------------------------------------------------------------------------------------
1364 void DialogTool::Build(const Tool &type)
1365 {
1366  Q_UNUSED(type)
1367 }
1368 
1369 //---------------------------------------------------------------------------------------------------------------------
1371 {
1372  Q_UNUSED(list);
1373 }
1374 
1375 //---------------------------------------------------------------------------------------------------------------------
1377 {
1378  if (tool != nullptr)
1379  {
1380  associatedTool = tool;
1381  SetToolId(tool->getId());
1382  data = tool->getData();
1383  if (not vis.isNull())
1384  {
1385  vis->setData(data);
1386  }
1387  }
1388  else
1389  {
1390  associatedTool = nullptr;
1391  SetToolId(NULL_ID);
1392  }
1393 }
1394 
1395 //---------------------------------------------------------------------------------------------------------------------
1396 template <typename GObject>
1397 void DialogTool::FillCombo(QComboBox *box, GOType gType, FillComboBox rule, const quint32 &ch1,
1398  const quint32 &ch2) const
1399 {
1400  SCASSERT(box != nullptr)
1401  box->blockSignals(true);
1402 
1404  QHash<quint32, QSharedPointer<VGObject> >::const_iterator i;
1406  for (i = objs->constBegin(); i != objs->constEnd(); ++i)
1407  {
1408  if (rule == FillComboBox::NoChildren)
1409  {
1410  if (i.key() != toolId && i.value()->getIdTool() != toolId && i.key() != ch1 && i.key() != ch2)
1411  {
1412  QSharedPointer<VGObject> obj = i.value();
1413  if (obj->getType() == gType && obj->getMode() == Draw::Calculation)
1414  {
1415  PrepareList<GObject>(list, i.key());
1416  }
1417  }
1418  }
1419  else
1420  {
1421  if (i.key() != toolId && i.value()->getIdTool() != toolId)
1422  {
1423  QSharedPointer<VGObject> obj = i.value();
1424  if (obj->getType() == gType && obj->getMode() == Draw::Calculation)
1425  {
1426  PrepareList<GObject>(list, i.key());
1427  }
1428  }
1429  }
1430  }
1431  FillList(box, list);
1432 
1433  box->blockSignals(false);
1434 }
The Calculator class for calculation formula.
Definition: calculator.h:84
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
quint32 DNumber(const QString &baseName) const
Definition: dialogtool.cpp:476
void ArrowDown()
ArrowDown set angle value 270 degree.
virtual void DialogRejected()
DialogRejected emit signal dialog rejected.
const QColor okColor
Definition: dialogtool.h:219
QDoubleSpinBox * spinBoxAngle
spinBoxAngle spinbox for angle
Definition: dialogtool.h:205
void ArrowLeftUp()
ArrowLeftUp set angle value 135 degree.
qreal normalize(const qreal value, const qreal start, const qreal end)
Definition: dialogtool.cpp:886
void setCurrentArcId(QComboBox *box, const quint32 &value, FillComboBox rule=FillComboBox::NoChildren, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
setCurrentArcId
Definition: dialogtool.cpp:924
static bool isFirstPointSameAsLast(QListWidget *listWidget)
Definition: dialogtool.cpp:552
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.
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
void ArrowLeft()
ArrowLeft set angle value 180 degree.
virtual void ChosenObject(quint32 id, const SceneObject &type)
ChosenObject gets id and type of selected object. Save right data and ignore wrong.
void DialogClosed(int result)
DialogClosed signal dialog closed.
virtual void ShowVisualization()
Definition: dialogtool.h:300
static int FindNotExcludedNodeUp(QListWidget *listWidget, int candidate)
Definition: dialogtool.cpp:521
void ArrowRightDown()
ArrowRightDown set angle value 315 degree.
void NamePointChanged()
NamePointChanged check name of point.
bool flagName
flagName true if name is correct
Definition: dialogtool.h:183
void ArrowUp()
ArrowUp set angle value 90 degree.
void FillComboBoxCrossCirclesPoints(QComboBox *box) const
Definition: dialogtool.cpp:373
void MoveCursorToEnd(QPlainTextEdit *plainTextEdit) const
Definition: dialogtool.cpp:432
QPushButton * ok_Button
ok_Button button ok
Definition: dialogtool.h:199
void FormulaChanged()
formula check formula
void ArrowRight()
ArrowRight set angle value 0 degree.
bool flagFormula
flagFormula true if formula correct
Definition: dialogtool.h:186
void setCurrentSplineId(QComboBox *box, const quint32 &value) const
setCurrentSplineId set current spline id in combobox
Definition: dialogtool.cpp:913
QString pointName
pointName name of point
Definition: dialogtool.h:231
static bool doublePointsExist(QListWidget *listWidget)
Definition: dialogtool.cpp:565
static void moveListRowBottom(QListWidget *list)
qreal Eval(const QString &text, bool &flag, QLabel *label, const QString &postfix, bool checkZero=true, bool checkLessThanZero=false)
Eval evaluate formula and show result.
Definition: dialogtool.cpp:805
void SetAssociatedTool(VAbstractTool *tool)
static void moveListRowDown(QListWidget *list)
NodeInfo getNodeInfo(const VPieceNode &node, bool showNotch=false) const
Definition: dialogtool.cpp:628
void PrepareList(QMap< QString, quint32 > &list, quint32 id) const
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
showEvent handle when window show
Definition: dialogtool.cpp:203
void FillComboBoxSplinesPath(QComboBox *box) const
Definition: dialogtool.cpp:278
virtual void ShowDialog(bool click)
bool IsSpline(const QSharedPointer< VGObject > &obj) const
void newNodeItem(QListWidget *listWidget, const VPieceNode &node, bool nodeExcluded=true, bool isDuplicate=false)
Definition: dialogtool.cpp:679
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
Definition: dialogtool.cpp:192
void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer, const QString &postfix=QString())
ValFormulaChanged handle change formula.
Definition: dialogtool.cpp:744
void FillList(QComboBox *box, const QMap< QString, quint32 > &list) const
FillList fill combobox list.
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 ArrowRightUp()
ArrowRightUp set angle value 45 degree.
void FillComboBoxLineColors(QComboBox *box) const
Definition: dialogtool.cpp:350
QPushButton * apply_Button
apply_Button button apply
Definition: dialogtool.h:202
bool isInitialized
isInitialized true if window is initialized
Definition: dialogtool.h:180
static void moveListRowTop(QListWidget *list)
void FillComboBoxSplines(QComboBox *box) const
Definition: dialogtool.cpp:254
QString getPointName() const
QLabel * labelEditNamePoint
labelEditNamePoint label used when need show wrong name of point
Definition: dialogtool.h:214
quint32 toolId
Definition: dialogtool.h:225
static QFont NodeFont(bool nodeExcluded)
Definition: dialogtool.cpp:618
void FillComboBoxArcs(QComboBox *box, FillComboBox rule=FillComboBox::Whole, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
Definition: dialogtool.cpp:248
QLabel * labelEditFormula
labelEditFormula label used when need show wrong formula
Definition: dialogtool.h:217
void FillComboBoxCurves(QComboBox *box) const
Definition: dialogtool.cpp:302
static int FindNotExcludedNodeDown(QListWidget *listWidget, int candidate)
Definition: dialogtool.cpp:490
void FillCombo(QComboBox *box, GOType gType, FillComboBox rule=FillComboBox::Whole, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
void FillComboBoxVCrossCurvesPoint(QComboBox *box) const
Definition: dialogtool.cpp:382
void setCurrentSplinePathId(QComboBox *box, const quint32 &value) const
setCurrentSplinePathId set current splinePath id in combobox
Definition: dialogtool.cpp:938
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
QPlainTextEdit * plainTextEditFormula
plainTextEditFormula formula
Definition: dialogtool.h:208
QString GetComboBoxCurrentData(const QComboBox *box, const QString &def) const
Definition: dialogtool.cpp:400
virtual void SaveData()
SaveData Put dialog data in local variables.
Definition: dialogtool.h:304
void SetToolId(const quint32 &value)
virtual void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE
Definition: dialogtool.cpp:174
VAbstractTool * associatedTool
associatedTool vdrawtool associated with opened dialog.
Definition: dialogtool.h:224
static bool isEachPointNameUnique(QListWidget *listWidget)
Definition: dialogtool.cpp:583
virtual void Build(const Tool &type)
QLabel * labelResultCalculation
labelResultCalculation label with result of calculation
Definition: dialogtool.h:211
void ArrowLeftDown()
ArrowLeftDown set angle value 225 degree.
void DialogApplied()
DialogApplied emit signal dialog apply changes.
void initializeNodeAngles(QComboBox *box)
Definition: dialogtool.cpp:717
virtual void DialogApply()
DialogApply save data and emit signal DialogApplied.
QTimer * timerFormula
timerFormula timer for check formula
Definition: dialogtool.h:196
virtual bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE
Definition: dialogtool.cpp:441
virtual void EvalFormula()
EvalFormula evaluate formula.
static QString DialogWarningIcon()
Definition: dialogtool.cpp:604
virtual ~DialogTool() Q_DECL_OVERRIDE
Definition: dialogtool.cpp:163
void FillComboBoxHCrossCurvesPoint(QComboBox *box) const
Definition: dialogtool.cpp:391
void setCurrentCurveId(QComboBox *box, const quint32 &value) const
Definition: dialogtool.cpp:946
virtual void SetPiecesList(const QVector< quint32 > &list)
virtual void SelectedObject(bool selected, quint32 object, quint32 tool)
static void moveListRowUp(QListWidget *list)
void FillComboBoxPiecesList(QComboBox *box, const QVector< quint32 > &list)
Definition: dialogtool.cpp:224
QPointer< Visualization > vis
Definition: dialogtool.h:236
void FormulaChangedPlainText()
FormulaChangedPlainText check formula (plain text editor editor)
void FillComboBoxTypeLine(QComboBox *box, const QMap< QString, QIcon > &stylesPics) const
FillComboBoxTypeLine fill comboBox list of type lines.
Definition: dialogtool.cpp:332
DialogTool(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
DialogTool create dialog.
Definition: dialogtool.cpp:133
void ChangeColor(QWidget *widget, const QColor &color)
void DeployFormula(QPlainTextEdit *formula, QPushButton *buttonGrowLength, int formulaBaseHeight)
Definition: dialogtool.cpp:992
quint32 GetToolId() const
quint32 getCurrentObjectId(QComboBox *box) const
getCurrentPointId return current point id stored in combobox
Definition: dialogtool.cpp:959
bool IsSplinePath(const QSharedPointer< VGObject > &obj) const
Definition: dialogtool.cpp:731
QString GetName() const
The VAbstractTool abstract class for all tools.
Definition: vabstracttool.h:80
const VContainer * getData() const
getData return pointer to data container.
static QMap< QString, QString > ColorsList()
quint32 getId() const
getId return object id.
The VContainer class container of all variables.
Definition: vcontainer.h:141
static bool IsUnique(const QString &name)
Definition: vcontainer.cpp:585
const QHash< QString, QSharedPointer< VInternalVariable > > * DataVariables() const
Definition: vcontainer.cpp:718
const QSharedPointer< VGObject > GetGObject(quint32 id) const
GetGObject returns a point by id.
Definition: vcontainer.cpp:150
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
const QHash< quint32, QSharedPointer< VGObject > > * DataGObjects() const
data container with datagObjects return container of gObjects
Definition: vcontainer.cpp:706
VPiece GetPiece(quint32 id) const
Definition: vcontainer.cpp:185
Tool GetTypeTool() const
Definition: vpiecenode.cpp:161
quint32 GetId() const
Definition: vpiecenode.cpp:149
bool isExcluded() const
Definition: vpiecenode.cpp:411
NotchType getNotchType() const
Definition: vpiecenode.cpp:314
bool GetReverse() const
Definition: vpiecenode.cpp:173
bool isNotch() const
Definition: vpiecenode.cpp:287
Error class of the parser.
const QString & GetMsg() const
Returns the message string for this error.
const QString & GetExpr() const
gets the expression related tp this error.
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
Tool
Definition: def.h:161
@ NodeSplinePath
@ NodeSpline
@ NodeElArc
@ NodeArc
@ NodePoint
#define DIALOG_MIN_WIDTH
Definition: dialogtool.cpp:106
#define DIALOG_MAX_FORMULA_HEIGHT
Definition: dialogtool.cpp:105
FillComboBox
Definition: dialogtool.h:101
const QString LineTypeSolidLine
Definition: ifcdef.cpp:159
#define NULL_ID
Definition: ifcdef.h:76
quint32 RowId(QListWidget *listWidget, int i)
Definition: dialogtool.cpp:111
QString NameRegExp()
Definition: qmudef.cpp:281
QString name
Definition: dialogtool.h:89
QString icon
Definition: dialogtool.h:88
#define qApp
Definition: vapplication.h:67
GOType
Definition: vgeometrydef.h:56
@ CubicBezierPath
@ SplinePath
@ EllipticalArc
@ CubicBezier
@ Calculation