2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vabstracttool.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-07-25 20:39:51 +02:00
|
|
|
#include "vabstracttool.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
#include "../xml/vpattern.h"
|
2014-04-17 19:18:26 +02:00
|
|
|
#include <QGraphicsView>
|
2014-06-14 08:37:25 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include "../undocommands/deltool.h"
|
|
|
|
#include "../widgets/vapplication.h"
|
2013-07-25 20:39:51 +02:00
|
|
|
|
2013-10-29 18:46:58 +01:00
|
|
|
const QString VAbstractTool::AttrType = QStringLiteral("type");
|
|
|
|
const QString VAbstractTool::AttrMx = QStringLiteral("mx");
|
|
|
|
const QString VAbstractTool::AttrMy = QStringLiteral("my");
|
|
|
|
const QString VAbstractTool::AttrName = QStringLiteral("name");
|
|
|
|
const QString VAbstractTool::AttrX = QStringLiteral("x");
|
|
|
|
const QString VAbstractTool::AttrY = QStringLiteral("y");
|
|
|
|
const QString VAbstractTool::AttrTypeLine = QStringLiteral("typeLine");
|
|
|
|
const QString VAbstractTool::AttrLength = QStringLiteral("length");
|
|
|
|
const QString VAbstractTool::AttrBasePoint = QStringLiteral("basePoint");
|
|
|
|
const QString VAbstractTool::AttrFirstPoint = QStringLiteral("firstPoint");
|
2013-10-29 14:45:07 +01:00
|
|
|
const QString VAbstractTool::AttrSecondPoint = QStringLiteral("secondPoint");
|
2013-10-29 18:46:58 +01:00
|
|
|
const QString VAbstractTool::AttrThirdPoint = QStringLiteral("thirdPoint");
|
|
|
|
const QString VAbstractTool::AttrCenter = QStringLiteral("center");
|
|
|
|
const QString VAbstractTool::AttrRadius = QStringLiteral("radius");
|
|
|
|
const QString VAbstractTool::AttrAngle = QStringLiteral("angle");
|
|
|
|
const QString VAbstractTool::AttrAngle1 = QStringLiteral("angle1");
|
|
|
|
const QString VAbstractTool::AttrAngle2 = QStringLiteral("angle2");
|
|
|
|
const QString VAbstractTool::AttrP1Line = QStringLiteral("p1Line");
|
|
|
|
const QString VAbstractTool::AttrP2Line = QStringLiteral("p2Line");
|
|
|
|
const QString VAbstractTool::AttrP1Line1 = QStringLiteral("p1Line1");
|
|
|
|
const QString VAbstractTool::AttrP2Line1 = QStringLiteral("p2Line1");
|
|
|
|
const QString VAbstractTool::AttrP1Line2 = QStringLiteral("p1Line2");
|
|
|
|
const QString VAbstractTool::AttrP2Line2 = QStringLiteral("p2Line2");
|
|
|
|
const QString VAbstractTool::AttrPShoulder = QStringLiteral("pShoulder");
|
|
|
|
const QString VAbstractTool::AttrPoint1 = QStringLiteral("point1");
|
|
|
|
const QString VAbstractTool::AttrPoint4 = QStringLiteral("point4");
|
|
|
|
const QString VAbstractTool::AttrKAsm1 = QStringLiteral("kAsm1");
|
|
|
|
const QString VAbstractTool::AttrKAsm2 = QStringLiteral("kAsm2");
|
|
|
|
const QString VAbstractTool::AttrKCurve = QStringLiteral("kCurve");
|
|
|
|
const QString VAbstractTool::AttrPathPoint = QStringLiteral("pathPoint");
|
|
|
|
const QString VAbstractTool::AttrPSpline = QStringLiteral("pSpline");
|
|
|
|
const QString VAbstractTool::AttrAxisP1 = QStringLiteral("axisP1");
|
|
|
|
const QString VAbstractTool::AttrAxisP2 = QStringLiteral("axisP2");
|
2014-02-25 19:03:17 +01:00
|
|
|
|
|
|
|
const QString VAbstractTool::TypeLineNone = QStringLiteral("none");
|
|
|
|
const QString VAbstractTool::TypeLineLine = QStringLiteral("hair");
|
2014-01-29 13:47:43 +01:00
|
|
|
const QString VAbstractTool::TypeLineDashLine = QStringLiteral("dashLine");
|
|
|
|
const QString VAbstractTool::TypeLineDotLine = QStringLiteral("dotLine");
|
|
|
|
const QString VAbstractTool::TypeLineDashDotLine = QStringLiteral("dashDotLine");
|
|
|
|
const QString VAbstractTool::TypeLineDashDotDotLine = QStringLiteral("dashDotDotLine");
|
2013-10-29 14:45:07 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief VAbstractTool container.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with data.
|
|
|
|
* @param id object id in container.
|
|
|
|
* @param parent parent object.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent)
|
2014-01-29 13:47:43 +01:00
|
|
|
:VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black), typeLine(TypeLineLine)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(doc != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
connect(this, &VAbstractTool::toolhaveChange, this->doc, &VPattern::haveLiteChange);
|
|
|
|
connect(this->doc, &VPattern::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile);
|
2014-06-11 15:24:51 +02:00
|
|
|
connect(this, &VAbstractTool::LiteUpdateTree, this->doc, &VPattern::LiteParseTree);
|
2013-08-15 22:39:00 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view.
|
|
|
|
* @param sc scene.
|
|
|
|
* @param view view.
|
|
|
|
*/
|
2014-01-15 10:20:46 +01:00
|
|
|
void VAbstractTool::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view)
|
|
|
|
{
|
|
|
|
QRectF rect = sc->itemsBoundingRect();
|
|
|
|
|
|
|
|
QRect rec0 = view->rect();
|
|
|
|
rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2);
|
|
|
|
|
|
|
|
QTransform t = view->transform();
|
|
|
|
|
|
|
|
QRectF rec1;
|
2014-01-27 17:01:24 +01:00
|
|
|
if (t.m11() < 1)
|
2014-01-15 10:20:46 +01:00
|
|
|
{
|
2014-01-29 10:18:26 +01:00
|
|
|
qreal width = rec0.width()/t.m11();
|
|
|
|
qreal height = rec0.height()/t.m22();
|
|
|
|
rec1 = QRect(0, 0, static_cast<qint32>(width), static_cast<qint32>(height));
|
2014-01-15 10:20:46 +01:00
|
|
|
|
|
|
|
rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y());
|
|
|
|
QPolygonF polygone = view->mapToScene(rec1.toRect());
|
|
|
|
rec1 = polygone.boundingRect();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rec1 = rec0;
|
|
|
|
}
|
|
|
|
rec1 = rec1.united(rect.toRect());
|
|
|
|
sc->setSceneRect(rec1);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief LineIntersectRect find point intersection line and rect.
|
|
|
|
* @param rec rect.
|
|
|
|
* @param line line.
|
|
|
|
* @return point intersection.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
QPointF VAbstractTool::LineIntersectRect(QRectF rec, QLineF line)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
qreal x1, y1, x2, y2;
|
|
|
|
rec.getCoords(&x1, &y1, &x2, &y2);
|
|
|
|
QPointF point;
|
2013-11-04 21:35:15 +01:00
|
|
|
QLineF::IntersectType type = line.intersect(QLineF(QPointF(x1, y1), QPointF(x1, y2)), &point);
|
|
|
|
if ( type == QLineF::BoundedIntersection )
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
return point;
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
type = line.intersect(QLineF(QPointF(x1, y1), QPointF(x2, y1)), &point);
|
|
|
|
if ( type == QLineF::BoundedIntersection )
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
return point;
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
type = line.intersect(QLineF(QPointF(x1, y2), QPointF(x2, y2)), &point);
|
|
|
|
if ( type == QLineF::BoundedIntersection )
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
return point;
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
type = line.intersect(QLineF(QPointF(x2, y1), QPointF(x2, y2)), &point);
|
|
|
|
if ( type == QLineF::BoundedIntersection )
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
return point;
|
|
|
|
}
|
2013-10-29 14:45:07 +01:00
|
|
|
Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "There is no point of intersection.");
|
2013-09-10 14:29:06 +02:00
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief LineIntersectCircle find point intersection line and circle.
|
|
|
|
* @param center arc center.
|
|
|
|
* @param radius arc radius.
|
|
|
|
* @param line line
|
|
|
|
* @param p1 first intersection point.
|
|
|
|
* @param p2 second intersection point.
|
|
|
|
* @return 0 - intersection doesn't exist, 1 - one intersection point, 2 - two intersection points.
|
|
|
|
*/
|
2013-11-06 22:11:12 +01:00
|
|
|
qint32 VAbstractTool::LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1,
|
|
|
|
QPointF &p2)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-21 15:21:40 +01:00
|
|
|
//coefficient for equation of segment
|
2013-10-18 12:03:01 +02:00
|
|
|
qreal a = 0, b = 0, c = 0;
|
|
|
|
LineCoefficients(line, &a, &b, &c);
|
2013-12-21 15:21:40 +01:00
|
|
|
// projection center of circle on to line
|
2013-09-10 14:29:06 +02:00
|
|
|
QPointF p = ClosestPoint (line, center);
|
2013-12-21 15:21:40 +01:00
|
|
|
// how many solutions?
|
2013-09-10 14:29:06 +02:00
|
|
|
qint32 flag = 0;
|
|
|
|
qreal d = QLineF (center, p).length();
|
2014-01-29 10:18:26 +01:00
|
|
|
if (qFuzzyCompare(d, radius))
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
flag = 1;
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (radius > d)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
flag = 2;
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
return 0;
|
2013-08-15 22:39:00 +02:00
|
|
|
}
|
2013-07-29 14:55:40 +02:00
|
|
|
}
|
2013-12-21 15:21:40 +01:00
|
|
|
// find distance from projection to points of intersection
|
2013-09-10 14:29:06 +02:00
|
|
|
qreal k = sqrt (radius * radius - d * d);
|
|
|
|
qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length();
|
2013-12-21 15:21:40 +01:00
|
|
|
// add to projection a vectors aimed to points of intersection
|
2013-09-10 14:29:06 +02:00
|
|
|
p1 = addVector (p, QPointF (0, 0), QPointF (- b, a), k / t);
|
|
|
|
p2 = addVector (p, QPointF (0, 0), QPointF (b, - a), k / t);
|
|
|
|
return flag;
|
2013-07-29 14:55:40 +02:00
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief ClosestPoint find point projection of point onto line.
|
|
|
|
* @param line line.
|
|
|
|
* @return point on line or extended line if origin size too small.
|
|
|
|
*/
|
2014-01-29 10:18:26 +01:00
|
|
|
QPointF VAbstractTool::ClosestPoint(const QLineF &line, const QPointF &point)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-01-29 10:18:26 +01:00
|
|
|
qreal a = 0, b = 0, c = 0;
|
|
|
|
LineCoefficients(line, &a, &b, &c);
|
|
|
|
qreal x = point.x() + a;
|
|
|
|
qreal y = b + point.y();
|
|
|
|
QLineF lin (point, QPointF(x, y));
|
|
|
|
QPointF p;
|
|
|
|
QLineF::IntersectType intersect = line.intersect(lin, &p);
|
|
|
|
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-01-29 10:18:26 +01:00
|
|
|
return p;
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-29 10:18:26 +01:00
|
|
|
return QPointF();
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-06 22:11:12 +01:00
|
|
|
QPointF VAbstractTool::addVector(const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
return QPointF (p.x() + (p2.x() - p1.x()) * k, p.y() + (p2.y() - p1.y()) * k);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
2013-08-15 22:39:00 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief DeleteTool full delete object form scene and file.
|
|
|
|
* @param tool tool
|
|
|
|
*/
|
2014-01-03 16:13:43 +01:00
|
|
|
void VAbstractTool::DeleteTool(QGraphicsItem *tool)
|
|
|
|
{
|
2014-06-14 08:37:25 +02:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("Confirm the deletion."));
|
|
|
|
msgBox.setInformativeText(tr("Do you really want delete?"));
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
msgBox.setIcon(QMessageBox::Question);
|
|
|
|
if (msgBox.exec() == QMessageBox::Cancel)
|
2014-01-03 16:13:43 +01:00
|
|
|
{
|
2014-06-14 08:37:25 +02:00
|
|
|
return;
|
2014-01-03 16:13:43 +01:00
|
|
|
}
|
2014-06-14 08:37:25 +02:00
|
|
|
|
|
|
|
DelTool *delTool = new DelTool(doc, id);
|
|
|
|
connect(delTool, &DelTool::NeedFullParsing, doc, &VPattern::NeedFullParsing);
|
|
|
|
qApp->getUndoStack()->push(delTool);
|
2014-01-03 16:13:43 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief LineStyle return pen style for current line style.
|
|
|
|
* @return pen style.
|
|
|
|
*/
|
2014-01-29 13:47:43 +01:00
|
|
|
Qt::PenStyle VAbstractTool::LineStyle()
|
|
|
|
{
|
|
|
|
QStringList styles = Styles();
|
2014-02-26 10:51:37 +01:00
|
|
|
switch (styles.indexOf(typeLine))
|
2014-01-29 13:47:43 +01:00
|
|
|
{
|
2014-02-26 10:51:37 +01:00
|
|
|
case 0: // TypeLineNone
|
2014-01-29 13:47:43 +01:00
|
|
|
return Qt::NoPen;
|
|
|
|
break;
|
2014-02-26 10:51:37 +01:00
|
|
|
case 1: // TypeLineLine
|
2014-01-29 13:47:43 +01:00
|
|
|
return Qt::SolidLine;
|
|
|
|
break;
|
2014-02-26 10:51:37 +01:00
|
|
|
case 2: // TypeLineDashLine
|
2014-01-29 13:47:43 +01:00
|
|
|
return Qt::DashLine;
|
|
|
|
break;
|
2014-02-26 10:51:37 +01:00
|
|
|
case 3: // TypeLineDotLine
|
2014-01-29 13:47:43 +01:00
|
|
|
return Qt::DotLine;
|
|
|
|
break;
|
2014-02-26 10:51:37 +01:00
|
|
|
case 4: // TypeLineDashDotLine
|
2014-01-29 13:47:43 +01:00
|
|
|
return Qt::DashDotLine;
|
|
|
|
break;
|
2014-02-26 10:51:37 +01:00
|
|
|
case 5: // TypeLineDashDotDotLine
|
2014-01-29 13:47:43 +01:00
|
|
|
return Qt::DashDotDotLine;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return Qt::SolidLine;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief LineCoefficients coefficient for equation of segment. Segment equestion ax+by+c=0.
|
|
|
|
* @param line line
|
|
|
|
* @param a a value
|
|
|
|
* @param b b value
|
|
|
|
* @param c c value
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VAbstractTool::LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c)
|
|
|
|
{
|
2013-12-21 15:21:40 +01:00
|
|
|
//coefficient for equation of segment
|
2013-11-06 22:11:12 +01:00
|
|
|
QPointF p1 = line.p1();
|
|
|
|
*a = line.p2().y() - p1.y();
|
|
|
|
*b = p1.x() - line.p2().x();
|
|
|
|
*c = - *a * p1.x() - *b * p1.y();
|
2013-10-18 12:03:01 +02:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief Styles return list of all line styles.
|
|
|
|
* @return list of all line styles.
|
|
|
|
*/
|
2014-01-29 13:47:43 +01:00
|
|
|
const QStringList VAbstractTool::Styles()
|
|
|
|
{
|
|
|
|
//Keep synchronize with DialogTool lineStyles list!!!
|
2014-05-30 11:52:19 +02:00
|
|
|
QStringList styles{TypeLineNone, TypeLineLine, TypeLineDashLine, TypeLineDotLine, TypeLineDashDotLine,
|
|
|
|
TypeLineDashDotDotLine};
|
2014-01-29 13:47:43 +01:00
|
|
|
return styles;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief AddRecord add record about tool in history.
|
|
|
|
* @param id object id in container
|
|
|
|
* @param toolType tool type
|
|
|
|
* @param doc dom document container
|
|
|
|
*/
|
2014-06-12 09:22:29 +02:00
|
|
|
void VAbstractTool::AddRecord(const quint32 id, const Tool &toolType, VPattern *doc)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 cursor = doc->getCursor();
|
2014-01-02 16:50:01 +01:00
|
|
|
QVector<VToolRecord> *history = doc->getHistory();
|
|
|
|
if (cursor <= 0)
|
|
|
|
{
|
|
|
|
history->append(VToolRecord(id, toolType, doc->GetNameActivDraw()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qint32 index = 0;
|
|
|
|
for (qint32 i = 0; i<history->size(); ++i)
|
|
|
|
{
|
|
|
|
VToolRecord rec = history->at(i);
|
|
|
|
if (rec.getId() == cursor)
|
|
|
|
{
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
history->insert(index+1, VToolRecord(id, toolType, doc->GetNameActivDraw()));
|
|
|
|
}
|
|
|
|
}
|