valentina/tools/vabstracttool.cpp

130 lines
4.6 KiB
C++
Raw Normal View History

2013-08-20 12:26:02 +02:00
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
2013-08-20 12:26:02 +02:00
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
2013-07-25 20:39:51 +02:00
#include "vabstracttool.h"
2013-07-29 14:55:40 +02:00
#include <QDebug>
#pragma GCC diagnostic pop
2013-07-25 20:39:51 +02:00
2013-08-28 10:55:11 +02:00
VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, QObject *parent):
2013-08-20 12:26:02 +02:00
VDataTool(data, parent), doc(doc), id(id), ignoreContextMenuEvent(false), nameActivDraw(QString()),
2013-08-28 10:55:11 +02:00
baseColor(Qt::black), currentColor(Qt::black), mode(mode){
2013-07-25 20:39:51 +02:00
this->doc = doc;
this->id = id;
nameActivDraw = doc->GetNameActivDraw();
ignoreContextMenuEvent = false;//don't ignore context menu events;
connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VAbstractTool::ChangedActivDraw);
connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VAbstractTool::ChangedNameDraw);
connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange);
2013-07-25 20:39:51 +02:00
connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile);
2013-07-29 14:55:40 +02:00
connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree);
2013-08-15 22:39:00 +02:00
connect(this->doc, &VDomDocument::ShowTool, this, &VAbstractTool::ShowTool);
2013-07-25 20:39:51 +02:00
}
void VAbstractTool::ChangedNameDraw(const QString oldName, const QString newName){
if(nameActivDraw == oldName){
nameActivDraw = newName;
}
}
void VAbstractTool::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){
ignoreContextMenuEvent = false;
} else {
ignoreContextMenuEvent = true;
}
}
2013-08-15 22:39:00 +02:00
void VAbstractTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
Q_UNUSED(id);
Q_UNUSED(color);
Q_UNUSED(enable);
}
2013-07-25 20:39:51 +02:00
void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, const qint64 &value){
QDomAttr domAttr = doc->createAttribute(name);
domAttr.setValue(QString().setNum(value));
domElement.setAttributeNode(domAttr);
}
void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, const qint32 &value){
QDomAttr domAttr = doc->createAttribute(name);
domAttr.setValue(QString().setNum(value));
domElement.setAttributeNode(domAttr);
}
void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, const qreal &value){
QDomAttr domAttr = doc->createAttribute(name);
domAttr.setValue(QString().setNum(value));
domElement.setAttributeNode(domAttr);
}
void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, const QString &value){
QDomAttr domAttr = doc->createAttribute(name);
domAttr.setValue(value);
domElement.setAttributeNode(domAttr);
}
VAbstractTool::~VAbstractTool(){
}
2013-08-28 10:55:11 +02:00
void VAbstractTool::AddToDraw(const QDomElement &domElement){
2013-07-29 14:55:40 +02:00
QDomElement calcElement;
2013-08-28 10:55:11 +02:00
if(mode == Draw::Modeling){
bool ok = doc->GetActivModelingElement(calcElement);
if(ok){
2013-08-15 22:39:00 +02:00
calcElement.appendChild(domElement);
2013-08-28 10:55:11 +02:00
}
} else {
bool ok = doc->GetActivCalculationElement(calcElement);
if(ok){
qint64 id = doc->getCursor();
if(id <= 0){
calcElement.appendChild(domElement);
2013-08-15 22:39:00 +02:00
} else {
2013-08-28 10:55:11 +02:00
QDomElement refElement = doc->elementById(QString().setNum(doc->getCursor()));
if(refElement.isElement()){
calcElement.insertAfter(domElement,refElement);
doc->setCursor(0);
} else {
qCritical()<<"Не можу знайти елемент після якого потрібно вставляти."<< Q_FUNC_INFO;
}
2013-08-15 22:39:00 +02:00
}
2013-08-28 10:55:11 +02:00
} else {
qCritical()<<"Не можу знайти тег калькуляції."<< Q_FUNC_INFO;
2013-08-15 22:39:00 +02:00
}
2013-07-29 14:55:40 +02:00
}
2013-08-15 22:39:00 +02:00
emit toolhaveChange();
2013-07-29 14:55:40 +02:00
}
const VContainer *VAbstractTool::getData()const{
return &data;
}
void VAbstractTool::setDialog(){
}
2013-08-15 22:39:00 +02:00
void VAbstractTool::AddRecord(const qint64 id, Tools::Enum toolType, VDomDocument *doc){
qint64 cursor = doc->getCursor();
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()));
}
}
2013-08-28 10:55:11 +02:00
void VAbstractTool::ignoreContextMenu(bool enable){
ignoreContextMenuEvent = enable;
}