2013-07-28 00:18:06 +02:00
|
|
|
#include "vtoolalongline.h"
|
|
|
|
#include "../container/calculator.h"
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula,
|
|
|
|
const qint64 &firstPointId, const qint64 &secondPointId,
|
|
|
|
const QString &typeLine, Tool::Enum typeCreation,
|
2013-07-31 13:34:39 +02:00
|
|
|
QGraphicsItem *parent):
|
|
|
|
VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent){
|
2013-07-28 00:18:06 +02:00
|
|
|
this->secondPointId = secondPointId;
|
|
|
|
|
2013-07-31 13:34:39 +02:00
|
|
|
if(typeCreation == Tool::FromGui){
|
|
|
|
AddToFile();
|
2013-07-28 00:18:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolAlongLine::FullUpdateFromFile(){
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
|
|
|
typeLine = domElement.attribute("typeLine", "");
|
|
|
|
formula = domElement.attribute("length", "");
|
2013-07-31 13:34:39 +02:00
|
|
|
basePointId = domElement.attribute("firstPoint", "").toLongLong();
|
2013-07-28 00:18:06 +02:00
|
|
|
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
|
|
|
|
}
|
2013-07-31 13:34:39 +02:00
|
|
|
RefreshGeometry();
|
2013-07-30 20:46:40 +02:00
|
|
|
}
|
|
|
|
|
2013-07-28 00:18:06 +02:00
|
|
|
void VToolAlongLine::FullUpdateFromGui(int result){
|
|
|
|
if(result == QDialog::Accepted){
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
|
|
|
domElement.setAttribute("name", dialogAlongLine->getPointName());
|
|
|
|
domElement.setAttribute("typeLine", dialogAlongLine->getTypeLine());
|
|
|
|
domElement.setAttribute("length", dialogAlongLine->getFormula());
|
|
|
|
domElement.setAttribute("firstPoint", QString().setNum(dialogAlongLine->getFirstPointId()));
|
|
|
|
domElement.setAttribute("secondPoint", QString().setNum(dialogAlongLine->getSecondPointId()));
|
|
|
|
emit FullUpdateTree();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
dialogAlongLine.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
|
|
|
|
if(!ignoreContextMenuEvent){
|
|
|
|
QMenu menu;
|
|
|
|
QAction *actionOption = menu.addAction("Властивості");
|
|
|
|
QAction *selectedAction = menu.exec(event->screenPos());
|
|
|
|
if(selectedAction == actionOption){
|
|
|
|
dialogAlongLine = QSharedPointer<DialogAlongLine>(new DialogAlongLine(VAbstractTool::data));
|
|
|
|
|
|
|
|
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
|
|
|
|
dialogAlongLine.data(), &DialogAlongLine::ChoosedPoint);
|
|
|
|
connect(dialogAlongLine.data(), &DialogAlongLine::DialogClosed, this,
|
|
|
|
&VToolAlongLine::FullUpdateFromGui);
|
|
|
|
connect(doc, &VDomDocument::FullUpdateFromFile, dialogAlongLine.data(),
|
|
|
|
&DialogAlongLine::UpdateList);
|
|
|
|
|
|
|
|
VPointF p = VAbstractTool::data->GetPoint(id);
|
|
|
|
|
|
|
|
dialogAlongLine->setTypeLine(typeLine);
|
|
|
|
dialogAlongLine->setFormula(formula);
|
2013-07-31 13:34:39 +02:00
|
|
|
dialogAlongLine->setFirstPointId(basePointId);
|
2013-07-28 00:18:06 +02:00
|
|
|
dialogAlongLine->setSecondPointId(secondPointId);
|
|
|
|
dialogAlongLine->setPointName(p.name());
|
|
|
|
|
|
|
|
dialogAlongLine->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolAlongLine::AddToFile(){
|
|
|
|
VPointF point = VAbstractTool::data->GetPoint(id);
|
|
|
|
QDomElement domElement = doc->createElement("point");
|
|
|
|
|
|
|
|
AddAttribute(domElement, "id", id);
|
|
|
|
AddAttribute(domElement, "type", "alongLine");
|
|
|
|
AddAttribute(domElement, "name", point.name());
|
|
|
|
AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4);
|
|
|
|
AddAttribute(domElement, "my", point.my()/PrintDPI*25.4);
|
|
|
|
|
|
|
|
AddAttribute(domElement, "typeLine", typeLine);
|
|
|
|
AddAttribute(domElement, "length", formula);
|
2013-07-31 13:34:39 +02:00
|
|
|
AddAttribute(domElement, "firstPoint", basePointId);
|
2013-07-28 00:18:06 +02:00
|
|
|
AddAttribute(domElement, "secondPoint", secondPointId);
|
|
|
|
|
2013-07-29 14:55:40 +02:00
|
|
|
AddToCalculation(domElement);
|
2013-07-28 00:18:06 +02:00
|
|
|
}
|