Seamly2D
Code documentation
dialoghistory.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file dialoghistory.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date November 15, 2013
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D 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 Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "dialoghistory.h"
53 #include "ui_dialoghistory.h"
54 #include "../vgeometry/varc.h"
55 #include "../vgeometry/vellipticalarc.h"
56 #include "../vgeometry/vcubicbezier.h"
57 #include "../vgeometry/vsplinepath.h"
58 #include "../vgeometry/vcubicbezierpath.h"
59 #include "../vgeometry/vpointf.h"
60 #include "../vtools/tools/vabstracttool.h"
61 #include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h"
62 #include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h"
63 #include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h"
64 #include "../xml/vpattern.h"
65 #include "../vmisc/diagnostic.h"
66 #include <QDebug>
67 #include <QCloseEvent>
68 
69 //---------------------------------------------------------------------------------------------------------------------
70 /**
71  * @brief DialogHistory create dialog
72  * @param data container with data
73  * @param doc dom document container
74  * @param parent parent widget
75  */
76 DialogHistory::DialogHistory(VContainer *data, VPattern *doc, QWidget *parent)
77  : DialogTool(data, 0, parent)
78  , ui(new Ui::DialogHistory)
79  , doc(doc)
80  , cursorRow(0)
81  , cursorToolRecordRow(0)
82 {
83  ui->setupUi(this);
84 
85  setWindowFlags(Qt::Window);
86  setWindowFlags((windowFlags() | Qt::WindowStaysOnTopHint) & ~Qt::WindowContextHelpButtonHint);
87 
88  ui->find_LineEdit->installEventFilter(this);
89 
90  qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
91 
92  ok_Button = ui->buttonBox->button(QDialogButtonBox::Ok);
93  connect(ok_Button, &QPushButton::clicked, this, &DialogHistory::DialogAccepted);
94  FillTable();
95  InitialTable();
96  connect(ui->tableWidget, &QTableWidget::cellClicked, this, &DialogHistory::cellClicked);
97  connect(doc, &VPattern::ChangedCursor, this, &DialogHistory::ChangedCursor);
98  connect(doc, &VPattern::patternChanged, this, &DialogHistory::updateHistory);
99  connect(ui->find_LineEdit, &QLineEdit::textEdited, this, &DialogHistory::findText);
100  connect(this, &DialogHistory::ShowHistoryTool, doc, [doc](quint32 id, bool enable)
101  {
102  emit doc->ShowTool(id, enable);
103  });
104 
105  ShowPoint();
106 }
107 
108 //---------------------------------------------------------------------------------------------------------------------
109 DialogHistory::~DialogHistory()
110 {
111  delete ui;
112 }
113 
114 //---------------------------------------------------------------------------------------------------------------------
115 /**
116  * @brief DialogAccepted save data and emit signal about closed dialog.
117  */
118 void DialogHistory::DialogAccepted()
119 {
120  QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0);
121  quint32 id = qvariant_cast<quint32>(item->data(Qt::UserRole));
122  emit ShowHistoryTool(id, false);
123  emit DialogClosed(QDialog::Accepted);
124 }
125 
126 //---------------------------------------------------------------------------------------------------------------------
127 /**
128  * @brief cellClicked changed history record
129  * @param row number row in table
130  * @param column number column in table
131  */
132 void DialogHistory::cellClicked(int row, int column)
133 {
134  if (column == 0)
135  {
136  QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0);
137  item->setIcon(QIcon());
138 
139  item = ui->tableWidget->item(row, 0);
140  cursorRow = row;
141  item->setIcon(QIcon("://icon/32x32/put_after.png"));
142  const quint32 id = qvariant_cast<quint32>(item->data(Qt::UserRole));
143  doc->blockSignals(true);
144  row == ui->tableWidget->rowCount()-1 ? doc->setCursor(0) : doc->setCursor(id);
145  doc->blockSignals(false);
146  }
147  else
148  {
149  QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0);
150  quint32 id = qvariant_cast<quint32>(item->data(Qt::UserRole));
151  emit ShowHistoryTool(id, false);
152 
153  cursorToolRecordRow = row;
154  item = ui->tableWidget->item(cursorToolRecordRow, 0);
155  id = qvariant_cast<quint32>(item->data(Qt::UserRole));
156  emit ShowHistoryTool(id, true);
157  }
158 }
159 
160 //---------------------------------------------------------------------------------------------------------------------
161 /**
162  * @brief ChangedCursor changed cursor of input. Cursor show after which record we will insert new object
163  * @param id id of object
164  */
165 void DialogHistory::ChangedCursor(quint32 id)
166 {
167  for (qint32 i = 0; i< ui->tableWidget->rowCount(); ++i)
168  {
169  QTableWidgetItem *item = ui->tableWidget->item(i, 0);
170  quint32 rId = qvariant_cast<quint32>(item->data(Qt::UserRole));
171  if (rId == id)
172  {
173  QTableWidgetItem *oldCursorItem = ui->tableWidget->item(cursorRow, 0);
174  oldCursorItem->setIcon(QIcon());
175  cursorRow = i;
176  item->setIcon(QIcon("://icon/32x32/put_after.png"));
177  }
178  }
179 }
180 
181 //---------------------------------------------------------------------------------------------------------------------
182 /**
183  * @brief updateHistory update history table
184  */
185 void DialogHistory::updateHistory()
186 {
187  FillTable();
188  InitialTable();
189 }
190 
191 //---------------------------------------------------------------------------------------------------------------------
192 /**
193  * @brief FillTable fill table
194  */
195 void DialogHistory::FillTable()
196 {
197  ui->tableWidget->clear();
198  QVector<VToolRecord> history = doc->getBlockHistory();
199  qint32 currentRow = -1;
200  qint32 count = 0;
201  ui->tableWidget->setRowCount(history.size());//Set Row count to number of Tool history records
202 
203  for (qint32 i = 0; i< history.size(); ++i)
204  {
205  const VToolRecord tool = history.at(i);
206  const QString historyRecord = Record(tool);
207  if (not historyRecord.isEmpty())
208  {
209  currentRow++;
210 
211  {
212  QTableWidgetItem *item = new QTableWidgetItem(QString());
213  item->setTextAlignment(Qt::AlignHCenter);
214  item->setData(Qt::UserRole, tool.getId());
215  item->setFlags(item->flags() ^ Qt::ItemIsEditable);
216  ui->tableWidget->setItem(currentRow, 0, item);//1st column is ID to lookup Tool history description
217  }
218 
219  QTableWidgetItem *item = new QTableWidgetItem(historyRecord);
220  item->setFlags(item->flags() ^ Qt::ItemIsEditable);
221  ui->tableWidget->setItem(currentRow, 1, item);//2nd column is Tool history description
222  ++count;
223 
224  }
225  }
226  ui->tableWidget->setRowCount(count);//Current history records count
227  if (count>0)
228  {
229  cursorRow = CursorRow();
230  QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0);
231  SCASSERT(item != nullptr)
232  item->setIcon(QIcon("://icon/32x32/put_after.png"));//place curved arrow in 1st column of most recent history record
233  }
234  //ui->tableWidget->resizeColumnsToContents();//doesn't work, maybe sets column size to header size
235  ui->tableWidget->resizeRowsToContents();//works, sets row count to current number of history records
236  ui->tableWidget->verticalHeader()->setDefaultSectionSize(20);//works,sets all row heights to 20px
237 
238 }
239 
240 //---------------------------------------------------------------------------------------------------------------------
241 QT_WARNING_PUSH
242 QT_WARNING_DISABLE_GCC("-Wswitch-default")
243 /**
244  * @brief Record return description for record
245  * @param tool record data
246  * @return description
247  */
248 QString DialogHistory::Record(const VToolRecord &tool)
249 {
250  // This check helps to find missed tools in the switch
251  Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used in history.");
252 
253  const QDomElement domElem = doc->elementById(tool.getId());
254  if (domElem.isElement() == false)
255  {
256  qDebug()<<"Can't find element by id"<<Q_FUNC_INFO;
257  return QString();
258  }
259  try
260  {
261  switch ( tool.getTypeTool() )
262  {
263  case Tool::Arrow:
264  case Tool::SinglePoint:
265  case Tool::DoublePoint:
266  case Tool::LinePoint:
268  case Tool::Cut:
269  case Tool::Midpoint:// Same as Tool::AlongLine, but tool will never has such type
270  case Tool::ArcIntersectAxis:// Same as Tool::CurveIntersectAxis, but tool will never has such type
272  Q_UNREACHABLE(); //-V501
273  break;
274  case Tool::BasePoint:
275  return tr("%1 - Base point").arg(PointName(tool.getId()));
276  case Tool::EndLine:
277  return tr("%1_%2 - Line from point %1 to point %2")
278  .arg(PointName(AttrUInt(domElem, AttrBasePoint)))
279  .arg(PointName(tool.getId()));
280  case Tool::Line:
281  return tr("%1_%2 - Line from point %1 to point %2")
282  .arg(PointName(AttrUInt(domElem, AttrFirstPoint)))
283  .arg(PointName(AttrUInt(domElem, AttrSecondPoint)));
284  case Tool::AlongLine:
285  return tr("%3 - Point along line %1_%2")
286  .arg(PointName(AttrUInt(domElem, AttrFirstPoint)))
287  .arg(PointName(AttrUInt(domElem, AttrSecondPoint)))
288  .arg(PointName(tool.getId()));
289  case Tool::ShoulderPoint:
290  return tr("%1 - Point of shoulder").arg(PointName(tool.getId()));
291  case Tool::Normal:
292  return tr("%3 - normal to line %1_%2")
293  .arg(PointName(AttrUInt(domElem, AttrFirstPoint)))
294  .arg(PointName(AttrUInt(domElem, AttrSecondPoint)))
295  .arg(PointName(tool.getId()));
296  case Tool::Bisector:
297  return tr("%4 - bisector of angle %1_%2_%3")
298  .arg(PointName(AttrUInt(domElem, AttrFirstPoint)))
299  .arg(PointName(AttrUInt(domElem, AttrSecondPoint)))
300  .arg(PointName(AttrUInt(domElem, AttrThirdPoint)))
301  .arg(PointName(tool.getId()));
302  case Tool::LineIntersect:
303  return tr("%5 - intersection of lines %1_%2 and %3_%4")
304  .arg(PointName(AttrUInt(domElem, AttrP1Line1)))
305  .arg(PointName(AttrUInt(domElem, AttrP2Line1)))
306  .arg(PointName(AttrUInt(domElem, AttrP1Line2)))
307  .arg(PointName(AttrUInt(domElem, AttrP2Line2)))
308  .arg(PointName(tool.getId()));
309  case Tool::Spline:
310  {
311  const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(tool.getId());
312  SCASSERT(not spl.isNull())
313  return spl->NameForHistory(tr("Curve"));
314  }
315  case Tool::CubicBezier:
316  {
317  const QSharedPointer<VCubicBezier> spl = data->GeometricObject<VCubicBezier>(tool.getId());
318  SCASSERT(not spl.isNull())
319  return spl->NameForHistory(tr("Cubic bezier curve"));
320  }
321  case Tool::Arc:
322  {
323  const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId());
324  SCASSERT(not arc.isNull())
325  return arc->NameForHistory(tr("Arc"));
326  }
327  case Tool::ArcWithLength:
328  {
329  const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId());
330  SCASSERT(not arc.isNull())
331  return tr("%1 with length %2")
332  .arg(arc->NameForHistory(tr("Arc")))
333  .arg(arc->GetLength());
334  }
335  case Tool::SplinePath:
336  {
337  const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(tool.getId());
338  SCASSERT(not splPath.isNull())
339  return splPath->NameForHistory(tr("Spline path"));
340  }
341  case Tool::CubicBezierPath:
342  {
344  SCASSERT(not splPath.isNull())
345  return splPath->NameForHistory(tr("Cubic bezier curve path"));
346  }
347  case Tool::PointOfContact:
348  return tr("%4 - point of contact of arc with the center in point %1 and line %2_%3")
349  .arg(PointName(AttrUInt(domElem, AttrCenter)))
350  .arg(PointName(AttrUInt(domElem, AttrFirstPoint)))
351  .arg(PointName(AttrUInt(domElem, AttrSecondPoint)))
352  .arg(PointName(tool.getId()));
353  case Tool::Height:
354  return tr("Point of perpendicular from point %1 to line %2_%3")
355  .arg(PointName(AttrUInt(domElem, AttrBasePoint)))
356  .arg(PointName(AttrUInt(domElem, AttrP1Line)))
357  .arg(PointName(AttrUInt(domElem, AttrP2Line)));
358  case Tool::Triangle:
359  return tr("Triangle: axis %1_%2, points %3 and %4")
360  .arg(PointName(AttrUInt(domElem, AttrAxisP1)))
361  .arg(PointName(AttrUInt(domElem, AttrAxisP2)))
362  .arg(PointName(AttrUInt(domElem, AttrFirstPoint)))
363  .arg(PointName(AttrUInt(domElem, AttrSecondPoint)));
364  case Tool::PointOfIntersection:
365  return tr("%1 - point of intersection %2 and %3")
366  .arg(PointName(tool.getId()))
367  .arg(PointName(AttrUInt(domElem, AttrFirstPoint)))
368  .arg(PointName(AttrUInt(domElem, AttrSecondPoint)));
369  case Tool::CutArc:
370  {
371  const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(AttrUInt(domElem, AttrArc));
372  SCASSERT(not arc.isNull())
373  return tr("%1 - cut %2")
374  .arg(PointName(tool.getId()))
375  .arg(arc->NameForHistory(tr("arc")));
376  }
377  case Tool::CutSpline:
378  {
379  const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline);
381  SCASSERT(not spl.isNull())
382  return tr("%1 - cut %2")
383  .arg(PointName(tool.getId()))
384  .arg(spl->NameForHistory(tr("curve")));
385  }
386  case Tool::CutSplinePath:
387  {
388  const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath);
390  data->GeometricObject<VAbstractCubicBezierPath>(splinePathId);
391  SCASSERT(not splPath.isNull())
392  return tr("%1 - cut %2")
393  .arg(PointName(tool.getId()))
394  .arg(splPath->NameForHistory(tr("curve path")));
395  }
396  case Tool::LineIntersectAxis:
397  return tr("%1 - point of intersection line %2_%3 and axis through point %4")
398  .arg(PointName(tool.getId()))
399  .arg(PointName(AttrUInt(domElem, AttrP1Line)))
400  .arg(PointName(AttrUInt(domElem, AttrP2Line)))
401  .arg(PointName(AttrUInt(domElem, AttrBasePoint)));
402  case Tool::CurveIntersectAxis:
403  return tr("%1 - point of intersection curve and axis through point %2")
404  .arg(PointName(tool.getId()))
405  .arg(PointName(AttrUInt(domElem, AttrBasePoint)));
406  case Tool::PointOfIntersectionArcs:
407  return tr("%1 - point of arcs intersection").arg(PointName(tool.getId()));
408  case Tool::PointOfIntersectionCircles:
409  return tr("%1 - point of circles intersection").arg(PointName(tool.getId()));
410  case Tool::PointOfIntersectionCurves:
411  return tr("%1 - point of curves intersection").arg(PointName(tool.getId()));
412  case Tool::PointFromCircleAndTangent:
413  return tr("%1 - point from circle and tangent").arg(PointName(tool.getId()));
414  case Tool::PointFromArcAndTangent:
415  return tr("%1 - point from arc and tangent").arg(PointName(tool.getId()));
416  case Tool::TrueDarts:
417  return tr("Correction the dart %1_%2_%3")
418  .arg(PointName(AttrUInt(domElem, AttrDartP1)))
419  .arg(PointName(AttrUInt(domElem, AttrDartP2)))
420  .arg(PointName(AttrUInt(domElem, AttrDartP2)));
421  case Tool::EllipticalArc:
422  {
423  const QSharedPointer<VEllipticalArc> elArc = data->GeometricObject<VEllipticalArc>(tool.getId());
424  SCASSERT(not elArc.isNull())
425  return tr("%1 with length %2")
426  .arg(elArc->NameForHistory(tr("Elliptical arc")))
427  .arg(elArc->GetLength());
428  }
429  case Tool::Rotation:
430  return tr("Rotate objects around point %1. Suffix '%2'")
431  .arg(PointName(AttrUInt(domElem, AttrCenter)),
432  doc->GetParametrString(domElem, AttrSuffix, QString()));
433  case Tool::MirrorByLine:
434  return tr("Mirror by line %1_%2. Suffix '%3'")
435  .arg(PointName(AttrUInt(domElem, AttrP1Line)),
436  PointName(AttrUInt(domElem, AttrP2Line)),
437  doc->GetParametrString(domElem, AttrSuffix, QString()));
438  case Tool::MirrorByAxis:
439  return tr("Mirror by axis through %1 point. Suffix '%2'")
440  .arg(PointName(AttrUInt(domElem, AttrCenter)),
441  doc->GetParametrString(domElem, AttrSuffix, QString()));
442  case Tool::Move:
443  return tr("Move objects, rotate around point %1. Suffix '%2'")
444  .arg(PointName(AttrUInt(domElem, AttrCenter)),
445  doc->GetParametrString(domElem, AttrSuffix, QString()));
446 
447  //Because "history" not only show history of pattern, but help restore current data for each pattern's
448  //piece, we need add record about details and nodes, but don't show them.
449  case Tool::Piece:
450  case Tool::Union:
451  case Tool::NodeArc:
452  case Tool::NodeElArc:
453  case Tool::NodePoint:
454  case Tool::NodeSpline:
455  case Tool::NodeSplinePath:
456  case Tool::Group:
457  case Tool::InternalPath:
458  case Tool::AnchorPoint:
459  case Tool::InsertNodes:
460  return QString();
461  }
462  }
463  catch (const VExceptionBadId &e)
464  {
465  qDebug()<<e.ErrorMessage()<<Q_FUNC_INFO;
466  return QString();
467  }
468  qDebug()<<"Can't create history record for the tool.";
469  return QString();
470 }
471 
473 
474 //---------------------------------------------------------------------------------------------------------------------
475 /**
476  * @brief InitialTable set initial option of table
477  */
478 void DialogHistory::InitialTable()
479 {
480  ui->tableWidget->setSortingEnabled(false);
481  ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(" "));
482  ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Tool")));
483 }
484 
485 //---------------------------------------------------------------------------------------------------------------------
486 /**
487  * @brief ShowPoint show selected point
488  */
489 void DialogHistory::ShowPoint()
490 {
491  const QVector<VToolRecord> *history = doc->getHistory();
492  if (history->size()>0)
493  {
494  QTableWidgetItem *item = ui->tableWidget->item(0, 1);
495  item->setSelected(true);
496  cursorToolRecordRow = 0;
497  item = ui->tableWidget->item(0, 0);
498  quint32 id = qvariant_cast<quint32>(item->data(Qt::UserRole));
499  emit ShowHistoryTool(id, true);
500  }
501 }
502 
503 //---------------------------------------------------------------------------------------------------------------------
504 /**
505  * @brief DialogHistory::PointName return point name by id.
506  *
507  * Refacoring what hide ugly string getting point name by id.
508  * @param pointId point if in data.
509  * @return point name.
510  */
511 QString DialogHistory::PointName(quint32 pointId)
512 {
513  return data->GeometricObject<VPointF>(pointId)->name();
514 }
515 
516 //---------------------------------------------------------------------------------------------------------------------
517 quint32 DialogHistory::AttrUInt(const QDomElement &domElement, const QString &name)
518 {
519  return doc->GetParametrUInt(domElement, name, "0");
520 }
521 
522 //---------------------------------------------------------------------------------------------------------------------
523 /**
524  * @brief closeEvent handle when windows is closing
525  * @param event event
526  */
527 void DialogHistory::closeEvent(QCloseEvent *event)
528 {
529  QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0);
530  quint32 id = qvariant_cast<quint32>(item->data(Qt::UserRole));
531  emit ShowHistoryTool(id, false);
532  DialogTool::closeEvent(event);
533 }
534 
535 //---------------------------------------------------------------------------------------------------------------------
536 void DialogHistory::changeEvent(QEvent *event)
537 {
538  if (event->type() == QEvent::LanguageChange)
539  {
540  // retranslate designer form (single inheritance approach)
541  ui->retranslateUi(this);
542  RetranslateUi();
543  }
544 
545  // remember to call base class implementation
546  QDialog::changeEvent(event);
547 }
548 
549 //---------------------------------------------------------------------------------------------------------------------
550 bool DialogHistory::eventFilter(QObject *object, QEvent *event)
551 {
552  if (QLineEdit *textEdit = qobject_cast<QLineEdit *>(object))
553  {
554  if (event->type() == QEvent::KeyPress)
555  {
556  QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
557  if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
558  {
559  if (qApp->Settings()->GetOsSeparator())
560  {
561  textEdit->insert(QLocale().decimalPoint());
562  }
563  else
564  {
565  textEdit->insert(QLocale::c().decimalPoint());
566  }
567  return true;
568  }
569  }
570  }
571  else
572  {
573  // pass the event on to the parent class
574  return DialogTool::eventFilter(object, event);
575  }
576  return false;// pass the event to the widget
577 }
578 
579 //---------------------------------------------------------------------------------------------------------------------
580 void DialogHistory::RetranslateUi()
581 {
582  qint32 currentRow = cursorRow;
583  updateHistory();
584 
585  QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0);
586  SCASSERT(item != nullptr)
587  item->setIcon(QIcon(""));
588 
589  cursorRow = currentRow;
590  cellClicked(cursorRow, 0);
591 }
592 
593 //---------------------------------------------------------------------------------------------------------------------
594 int DialogHistory::CursorRow() const
595 {
596  const quint32 cursor = doc->getCursor();
597  if (cursor == 0)
598  {
599  return ui->tableWidget->rowCount()-1;
600  }
601 
602  for (int i = 0; i < ui->tableWidget->rowCount(); ++i)
603  {
604  QTableWidgetItem *item = ui->tableWidget->item(i, 0);
605  const quint32 id = qvariant_cast<quint32>(item->data(Qt::UserRole));
606  if (cursor == id)
607  {
608  return i;
609  }
610  }
611  return ui->tableWidget->rowCount()-1;
612 }
613 
614 void DialogHistory::findText(const QString &text)
615 {
616  updateHistory();
617  if (text.isEmpty())
618  {
619  return;
620  }
621 
622  QList<QTableWidgetItem *> items = ui->tableWidget->findItems(text, Qt::MatchContains);
623 
624  for (int i = 0; i < items.count(); ++i)
625  {
626  items.at(i)->setBackground(QColor("skyblue"));
627  }
628 }
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
Definition: dialogtool.cpp:192
virtual bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE
Definition: dialogtool.cpp:441
void ChangedCursor(quint32 id)
ChangedCursor change cursor position.
void ShowTool(quint32 id, bool enable)
ShowTool highlight tool.
void patternChanged(bool saved)
patternChanged emit if we have unsaved change.
QVector< VToolRecord > getBlockHistory() const
void setCursor(const quint32 &value)
quint32 getCursor() const
QVector< VToolRecord > * getHistory()
getHistory return list with list of history records.
VArc class for anticlockwise arc.
Definition: varc.h:74
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
QDomElement elementById(quint32 id, const QString &tagName=QString())
static quint32 GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue)
Returns the long long value of the given attribute. RENAME: GetParameterLongLong?
The VExceptionBadId class for exception bad id.
The VPattern class working with pattern file.
Definition: vpattern.h:68
The VPointF class keep data of point.
Definition: vpointf.h:75
The VSplinePath class keep information about splinePath.
Definition: vsplinepath.h:72
VSpline class that implements the spline.
Definition: vspline.h:75
static const QString AttrSplinePath
static const QString AttrSpline
The VToolRecord class record about tool in history.
Definition: vtoolrecord.h:64
quint32 getId() const
getId return tool id.
Definition: vtoolrecord.h:94
#define SCASSERT(cond)
Definition: def.h:317
Tool
Definition: def.h:161
@ AlongLine
@ EndLine
@ SinglePoint
@ ShoulderPoint
@ Spline
@ Bisector
@ LineIntersect
@ LinePoint
@ BasePoint
@ Midpoint
@ ArcIntersectAxis
@ Normal
@ DoublePoint
@ AbstractSpline
@ LAST_ONE_DO_NOT_USE
const QString AttrBasePoint
Definition: ifcdef.cpp:95
const QString splPath
Definition: ifcdef.cpp:419
const QString AttrSecondPoint
Definition: ifcdef.cpp:97
const QString AttrFirstPoint
Definition: ifcdef.cpp:96
const QString AttrP1Line1
Definition: ifcdef.cpp:110
const QString AttrP1Line
Definition: ifcdef.cpp:108
const QString AttrP2Line
Definition: ifcdef.cpp:109
const QString AttrDartP2
Definition: ifcdef.cpp:86
const QString AttrAxisP2
Definition: ifcdef.cpp:126
const QString AttrDartP1
Definition: ifcdef.cpp:85
const QString AttrThirdPoint
Definition: ifcdef.cpp:98
const QString AttrAxisP1
Definition: ifcdef.cpp:125
const QString AttrP2Line2
Definition: ifcdef.cpp:113
const QString AttrP1Line2
Definition: ifcdef.cpp:112
const QString AttrSuffix
Definition: ifcdef.cpp:147
const QString AttrP2Line1
Definition: ifcdef.cpp:111
const QString AttrArc
Definition: ifcdef.cpp:146
const QString AttrCenter
Definition: ifcdef.cpp:99
#define qApp
Definition: vapplication.h:67