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"
67 #include <QCloseEvent>
78 , ui(new
Ui::DialogHistory)
81 , cursorToolRecordRow(0)
85 setWindowFlags(Qt::Window);
86 setWindowFlags((windowFlags() | Qt::WindowStaysOnTopHint) & ~Qt::WindowContextHelpButtonHint);
88 ui->find_LineEdit->installEventFilter(
this);
90 qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
92 ok_Button = ui->buttonBox->button(QDialogButtonBox::Ok);
93 connect(ok_Button, &QPushButton::clicked,
this, &DialogHistory::DialogAccepted);
96 connect(ui->tableWidget, &QTableWidget::cellClicked,
this, &DialogHistory::cellClicked);
99 connect(ui->find_LineEdit, &QLineEdit::textEdited,
this, &DialogHistory::findText);
100 connect(
this, &DialogHistory::ShowHistoryTool, doc, [doc](quint32
id,
bool enable)
109 DialogHistory::~DialogHistory()
118 void DialogHistory::DialogAccepted()
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);
132 void DialogHistory::cellClicked(
int row,
int column)
136 QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0);
137 item->setIcon(QIcon());
139 item = ui->tableWidget->item(row, 0);
141 item->setIcon(QIcon(
"://icon/32x32/put_after.png"));
142 const quint32
id = qvariant_cast<quint32>(item->data(Qt::UserRole));
143 doc->blockSignals(
true);
145 doc->blockSignals(
false);
149 QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0);
150 quint32
id = qvariant_cast<quint32>(item->data(Qt::UserRole));
151 emit ShowHistoryTool(
id,
false);
153 cursorToolRecordRow = row;
154 item = ui->tableWidget->item(cursorToolRecordRow, 0);
155 id = qvariant_cast<quint32>(item->data(Qt::UserRole));
156 emit ShowHistoryTool(
id,
true);
165 void DialogHistory::ChangedCursor(quint32
id)
167 for (qint32 i = 0; i< ui->tableWidget->rowCount(); ++i)
169 QTableWidgetItem *item = ui->tableWidget->item(i, 0);
170 quint32 rId = qvariant_cast<quint32>(item->data(Qt::UserRole));
173 QTableWidgetItem *oldCursorItem = ui->tableWidget->item(cursorRow, 0);
174 oldCursorItem->setIcon(QIcon());
176 item->setIcon(QIcon(
"://icon/32x32/put_after.png"));
185 void DialogHistory::updateHistory()
195 void DialogHistory::FillTable()
197 ui->tableWidget->clear();
199 qint32 currentRow = -1;
201 ui->tableWidget->setRowCount(history.size());
203 for (qint32 i = 0; i< history.size(); ++i)
206 const QString historyRecord = Record(tool);
207 if (not historyRecord.isEmpty())
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);
219 QTableWidgetItem *item =
new QTableWidgetItem(historyRecord);
220 item->setFlags(item->flags() ^ Qt::ItemIsEditable);
221 ui->tableWidget->setItem(currentRow, 1, item);
226 ui->tableWidget->setRowCount(count);
229 cursorRow = CursorRow();
230 QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0);
232 item->setIcon(QIcon(":
235 ui->tableWidget->resizeRowsToContents();
236 ui->tableWidget->verticalHeader()->setDefaultSectionSize(20);
242 QT_WARNING_DISABLE_GCC("-Wswitch-default")
248 QString DialogHistory::Record(const
VToolRecord &tool)
253 const QDomElement domElem = doc->
elementById(tool.getId());
254 if (domElem.isElement() ==
false)
256 qDebug()<<
"Can't find element by id"<<Q_FUNC_INFO;
261 switch ( tool.getTypeTool() )
275 return tr(
"%1 - Base point").arg(PointName(tool.getId()));
277 return tr(
"%1_%2 - Line from point %1 to point %2")
279 .arg(PointName(tool.getId()));
281 return tr(
"%1_%2 - Line from point %1 to point %2")
285 return tr(
"%3 - Point along line %1_%2")
288 .arg(PointName(tool.getId()));
290 return tr(
"%1 - Point of shoulder").arg(PointName(tool.getId()));
292 return tr(
"%3 - normal to line %1_%2")
295 .arg(PointName(tool.getId()));
297 return tr(
"%4 - bisector of angle %1_%2_%3")
301 .arg(PointName(tool.getId()));
303 return tr(
"%5 - intersection of lines %1_%2 and %3_%4")
308 .arg(PointName(tool.getId()));
313 return spl->NameForHistory(tr("Curve"));
315 case
Tool::CubicBezier:
319 return spl->NameForHistory(tr("Cubic bezier curve"));
325 return arc->NameForHistory(tr("Arc"));
327 case
Tool::ArcWithLength:
331 return tr("%1 with length %2")
332 .arg(arc->NameForHistory(tr("Arc")))
333 .arg(arc->GetLength());
335 case
Tool::SplinePath:
339 return
splPath->NameForHistory(tr("Spline path"));
341 case
Tool::CubicBezierPath:
345 return
splPath->NameForHistory(tr("Cubic bezier curve path"));
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)))
352 .arg(PointName(tool.getId()));
354 return tr("Point of perpendicular from point %1 to line %2_%3")
356 .arg(PointName(AttrUInt(domElem,
AttrP1Line)))
357 .arg(PointName(AttrUInt(domElem,
AttrP2Line)));
359 return tr("Triangle: axis %1_%2, points %3 and %4")
360 .arg(PointName(AttrUInt(domElem,
AttrAxisP1)))
361 .arg(PointName(AttrUInt(domElem,
AttrAxisP2)))
364 case
Tool::PointOfIntersection:
365 return tr("%1 - point of intersection %2 and %3")
366 .arg(PointName(tool.getId()))
373 return tr("%1 - cut %2")
374 .arg(PointName(tool.getId()))
375 .arg(arc->NameForHistory(tr("arc")));
377 case
Tool::CutSpline:
382 return tr("%1 - cut %2")
383 .arg(PointName(tool.getId()))
384 .arg(spl->NameForHistory(tr("curve")));
386 case
Tool::CutSplinePath:
392 return tr("%1 - cut %2")
393 .arg(PointName(tool.getId()))
394 .arg(
splPath->NameForHistory(tr("curve path")));
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)))
402 case
Tool::CurveIntersectAxis:
403 return tr("%1 - point of intersection curve and axis through point %2")
404 .arg(PointName(tool.getId()))
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:
425 return tr("%1 with length %2")
426 .arg(elArc->NameForHistory(tr("Elliptical arc")))
427 .arg(elArc->GetLength());
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)),
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()));
443 return tr("Move objects, rotate around point %1. Suffix '%2'")
444 .arg(PointName(AttrUInt(domElem,
AttrCenter)),
445 doc->GetParametrString(domElem,
AttrSuffix, QString()));
452 case
Tool::NodeElArc:
453 case
Tool::NodePoint:
454 case
Tool::NodeSpline:
455 case
Tool::NodeSplinePath:
457 case
Tool::InternalPath:
458 case
Tool::AnchorPoint:
459 case
Tool::InsertNodes:
465 qDebug()<<e.ErrorMessage()<<Q_FUNC_INFO;
468 qDebug()<<
"Can't create history record for the tool.";
478 void DialogHistory::InitialTable()
480 ui->tableWidget->setSortingEnabled(
false);
481 ui->tableWidget->setHorizontalHeaderItem(0,
new QTableWidgetItem(
" "));
482 ui->tableWidget->setHorizontalHeaderItem(1,
new QTableWidgetItem(tr(
"Tool")));
489 void DialogHistory::ShowPoint()
492 if (history->size()>0)
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);
511 QString DialogHistory::PointName(quint32 pointId)
517 quint32 DialogHistory::AttrUInt(
const QDomElement &domElement,
const QString &name)
527 void DialogHistory::closeEvent(QCloseEvent *event)
529 QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0);
530 quint32
id = qvariant_cast<quint32>(item->data(Qt::UserRole));
531 emit ShowHistoryTool(
id,
false);
536 void DialogHistory::changeEvent(QEvent *event)
538 if (event->type() == QEvent::LanguageChange)
541 ui->retranslateUi(
this);
546 QDialog::changeEvent(event);
550 bool DialogHistory::eventFilter(QObject *
object, QEvent *event)
552 if (QLineEdit *textEdit = qobject_cast<QLineEdit *>(
object))
554 if (event->type() == QEvent::KeyPress)
556 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(event);
557 if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
559 if (
qApp->Settings()->GetOsSeparator())
561 textEdit->insert(QLocale().decimalPoint());
565 textEdit->insert(QLocale::c().decimalPoint());
580 void DialogHistory::RetranslateUi()
582 qint32 currentRow = cursorRow;
585 QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0);
587 item->setIcon(QIcon(""));
589 cursorRow = currentRow;
590 cellClicked(cursorRow, 0);
594 int DialogHistory::CursorRow()
const
599 return ui->tableWidget->rowCount()-1;
602 for (
int i = 0; i < ui->tableWidget->rowCount(); ++i)
604 QTableWidgetItem *item = ui->tableWidget->item(i, 0);
605 const quint32
id = qvariant_cast<quint32>(item->data(Qt::UserRole));
611 return ui->tableWidget->rowCount()-1;
614 void DialogHistory::findText(
const QString &text)
624 for (
int i = 0; i < items.count(); ++i)
626 items.at(i)->setBackground(QColor(
"skyblue"));
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.
The VContainer class container of all variables.
const QSharedPointer< T > GeometricObject(const quint32 &id) const
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.
The VPointF class keep data of point.
The VSplinePath class keep information about splinePath.
VSpline class that implements the spline.
const QString AttrBasePoint
const QString AttrSecondPoint
const QString AttrFirstPoint
const QString AttrP1Line1
const QString AttrThirdPoint
const QString AttrP2Line2
const QString AttrP1Line2
const QString AttrP2Line1