Add class VDataTool. Change in class VPointF.

This commit is contained in:
dismine 2013-08-13 19:48:36 +03:00
parent 309f190921
commit 67dd88145c
76 changed files with 1647 additions and 1456 deletions

View File

@ -13,7 +13,6 @@ TEMPLATE = app
SOURCES += main.cpp\ SOURCES += main.cpp\
mainwindow.cpp \ mainwindow.cpp \
widgets/vmaingraphicsscene.cpp \
dialogs/dialogsinglepoint.cpp \ dialogs/dialogsinglepoint.cpp \
widgets/vgraphicssimpletextitem.cpp \ widgets/vgraphicssimpletextitem.cpp \
xml/vdomdocument.cpp \ xml/vdomdocument.cpp \
@ -54,7 +53,10 @@ SOURCES += main.cpp\
geometry/vsplinepoint.cpp \ geometry/vsplinepoint.cpp \
geometry/vsplinepath.cpp \ geometry/vsplinepath.cpp \
tools/vtoolsplinepath.cpp \ tools/vtoolsplinepath.cpp \
dialogs/dialogsplinepath.cpp dialogs/dialogsplinepath.cpp \
widgets/vmaingraphicsscene.cpp \
widgets/vmaingraphicsview.cpp \
tools/vdatatool.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
widgets/vmaingraphicsscene.h \ widgets/vmaingraphicsscene.h \
@ -99,7 +101,9 @@ HEADERS += mainwindow.h \
geometry/vsplinepoint.h \ geometry/vsplinepoint.h \
geometry/vsplinepath.h \ geometry/vsplinepath.h \
tools/vtoolsplinepath.h \ tools/vtoolsplinepath.h \
dialogs/dialogsplinepath.h dialogs/dialogsplinepath.h \
widgets/vmaingraphicsview.h \
tools/vdatatool.h
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
dialogs/dialogsinglepoint.ui \ dialogs/dialogsinglepoint.ui \
@ -121,7 +125,9 @@ RESOURCES += \
CONFIG(debug, debug|release){ CONFIG(debug, debug|release){
# Debug # Debug
QMAKE_CXXFLAGS += -O0 -Wall -Wextra -pedantic -std=c++0x QMAKE_CXXFLAGS += -O0 -isystem "/usr/include/qt5" -Wall -Wextra -pedantic -Weffc++ -Woverloaded-virtual \
-Wctor-dtor-privacy -Wnon-virtual-dtor -Wold-style-cast -Wconversion -Wsign-conversion \
-Winit-self -Wunreachable-code -std=c++0x
}else{ }else{
# Release # Release
QMAKE_CXXFLAGS += -O1 -std=c++0x QMAKE_CXXFLAGS += -O1 -std=c++0x

View File

@ -7,42 +7,54 @@ VContainer::VContainer(){
_id = 0; _id = 0;
SetSize(500); SetSize(500);
SetGrowth(1760); SetGrowth(1760);
CreateManTableIGroup ();
} }
VPointF VContainer::GetPoint(qint64 id) const{ template <typename key, typename val>
if(points.contains(id)){ val VContainer::GetObject(const QMap<key,val> &obj, key id)const{
return points.value(id); if(obj.contains(id)){
return obj.value(id);
} else { } else {
qCritical()<<"Не можу знайти id = "<<id<<" в таблиці."; qCritical()<<"Не можу знайти key = "<<id<<" в таблиці.";
throw"Не можу знайти точку за id."; throw"Не можу знайти об'єкт за ключем.";
} }
return VPointF(); }
VPointF VContainer::GetPoint(qint64 id) const{
return GetObject(points, id);
} }
VStandartTableCell VContainer::GetStandartTableCell(const QString &name) const{ VStandartTableCell VContainer::GetStandartTableCell(const QString &name) const{
if(standartTable.contains(name)){ Q_ASSERT(!name.isEmpty());
return standartTable.value(name); return GetObject(standartTable, name);
} else {
qCritical()<<"Не можу знайти змінну за імям = "<<name<<" в таблиці.";
throw"Не можу знайти змінну в стандартній таблиці вимірів за ім'ям.";
}
return VStandartTableCell();
} }
VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const{ VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const{
if(incrementTable.contains(name)){ Q_ASSERT(!name.isEmpty());
return incrementTable.value(name); return GetObject(incrementTable, name);
} else {
qCritical()<<"Не можу знайти змінну за імям = "<<name<<" в таблиці.";
throw"Не можу знайти змінну в таблиці прибавок за ім'ям.";
}
return VIncrementTableRow();
} }
qint64 VContainer::AddPoint(const VPointF& point){ qreal VContainer::GetLine(const QString &name) const{
qint64 id = getNextId(); Q_ASSERT(!name.isEmpty());
points[id] = point; return GetObject(lengthLines, name);
return id; }
qint32 VContainer::GetLineArc(const QString &name) const{
Q_ASSERT(!name.isEmpty());
return GetObject(lineArcs, name);
}
VSpline VContainer::GetSpline(qint64 id) const{
return GetObject(splines, id);
}
VArc VContainer::GetArc(qint64 id) const{
return GetObject(arcs, id);
}
VSplinePath VContainer::GetSplinePath(qint64 id) const{
return GetObject(splinePaths, id);
} }
void VContainer::AddStandartTableCell(const QString& name, const VStandartTableCell& cell){ void VContainer::AddStandartTableCell(const QString& name, const VStandartTableCell& cell){
@ -62,36 +74,36 @@ qint64 VContainer::getNextId(){
return _id; return _id;
} }
void VContainer::UpdateId(qint64 newId){
if(newId > _id){
_id = newId;
}
}
void VContainer::RemoveIncrementTableRow(const QString& name){ void VContainer::RemoveIncrementTableRow(const QString& name){
incrementTable.remove(name); incrementTable.remove(name);
} }
void VContainer::UpdatePoint(qint64 id, const VPointF& point){ template <typename val>
points[id] = point; void VContainer::UpdateObject(QMap<qint64, val> &obj, const qint64 &id, const val& point){
if(id > _id){ obj[id] = point;
_id = id; UpdateId(id);
} }
void VContainer::UpdatePoint(qint64 id, const VPointF& point){
UpdateObject(points, id, point);
} }
void VContainer::UpdateSpline(qint64 id, const VSpline &spl){ void VContainer::UpdateSpline(qint64 id, const VSpline &spl){
splines[id] = spl; UpdateObject(splines, id, spl);
if(id > _id){
_id = id;
}
} }
void VContainer::UpdateSplinePath(qint64 id, const VSplinePath &splPath){ void VContainer::UpdateSplinePath(qint64 id, const VSplinePath &splPath){
splinePaths[id] = splPath; UpdateObject(splinePaths, id, splPath);
if(id > _id){
_id = id;
}
} }
void VContainer::UpdateArc(qint64 id, const VArc &arc){ void VContainer::UpdateArc(qint64 id, const VArc &arc){
arcs[id] = arc; UpdateObject(arcs, id, arc);
if(id > _id){
_id = id;
}
} }
void VContainer::UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell){ void VContainer::UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell){
@ -102,6 +114,25 @@ void VContainer::UpdateIncrementTableRow(const QString& name, const VIncrementTa
incrementTable[name] = cell; incrementTable[name] = cell;
} }
void VContainer::AddLengthSpline(const QString &name, const qreal &value){
Q_ASSERT(!name.isEmpty());
lengthSplines[name] = value;
}
void VContainer::AddLengthArc(const qint64 &center, const qint64 &id){
AddLengthArc(GetNameArc(center, id), GetArc(id).GetLength());
}
void VContainer::AddLengthArc(const QString &name, const qreal &value){
Q_ASSERT(!name.isEmpty());
lengthArcs[name] = value;
}
void VContainer::AddLineArc(const QString &name, const qint32 &value){
Q_ASSERT(!name.isEmpty());
lineArcs[name] = value;
}
qreal VContainer::GetValueStandartTableCell(const QString& name) const{ qreal VContainer::GetValueStandartTableCell(const QString& name) const{
VStandartTableCell cell = GetStandartTableCell(name); VStandartTableCell cell = GetStandartTableCell(name);
qreal k_size = ( ( qreal ) (size()/10) - 50.0 ) / 2; qreal k_size = ( ( qreal ) (size()/10) - 50.0 ) / 2;
@ -128,6 +159,7 @@ void VContainer::Clear(){
arcs.clear(); arcs.clear();
lengthArcs.clear(); lengthArcs.clear();
lineArcs.clear(); lineArcs.clear();
CreateManTableIGroup ();
} }
void VContainer::ClearIncrementTable(){ void VContainer::ClearIncrementTable(){
@ -232,29 +264,46 @@ const QMap<QString, qreal> *VContainer::DataLengthSplines() const{
return &lengthSplines; return &lengthSplines;
} }
const QMap<QString, qreal> *VContainer::DataLengthArcs() const{
return &lengthArcs;
}
const QMap<QString, qreal> *VContainer::DataLineArcs() const{
return &lineArcs;
}
const QMap<qint64, VSplinePath> *VContainer::DataSplinePaths() const{
return &splinePaths;
}
void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId){ void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId){
QString nameLine = GetNameLine(firstPointId, secondPointId); QString nameLine = GetNameLine(firstPointId, secondPointId);
VPointF firstPoint = GetPoint(firstPointId); VPointF firstPoint = GetPoint(firstPointId);
VPointF secondPoint = GetPoint(secondPointId); VPointF secondPoint = GetPoint(secondPointId);
AddLengthLine(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length()); AddLengthLine(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length()/PrintDPI*25.4);
}
template <typename key, typename val>
qint64 VContainer::AddObject(QMap<key, val> &obj, const val& value){
qint64 id = getNextId();
obj[id] = value;
return id;
}
qint64 VContainer::AddPoint(const VPointF& point){
return AddObject(points, point);
} }
qint64 VContainer::AddSpline(const VSpline &spl){ qint64 VContainer::AddSpline(const VSpline &spl){
qint64 id = getNextId(); return AddObject(splines, spl);
splines[id] = spl;
return id;
} }
qint64 VContainer::AddSplinePath(const VSplinePath &splPath){ qint64 VContainer::AddSplinePath(const VSplinePath &splPath){
qint64 id = getNextId(); return AddObject(splinePaths, splPath);
splinePaths[id] = splPath;
return id;
} }
qint64 VContainer::AddArc(const VArc &arc){ qint64 VContainer::AddArc(const VArc &arc){
qint64 id = getNextId(); return AddObject(arcs, arc);
arcs[id] = arc;
return id;
} }
QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const{ QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const{
@ -307,86 +356,60 @@ void VContainer::AddLengthSpline(const qint64 &firstPointId, const qint64 &secon
AddLengthSpline(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length()); AddLengthSpline(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length());
} }
void VContainer::AddLengthSpline(const QString &name, const qreal &value){ void VContainer::CreateManTableIGroup (){
Q_ASSERT(!name.isEmpty()); AddStandartTableCell("Pkor", VStandartTableCell(84, 0, 3));
lengthSplines[name] = value; AddStandartTableCell("Pkor", VStandartTableCell(84, 0, 3));
} AddStandartTableCell("Vtos", VStandartTableCell(1450, 2, 51));
AddStandartTableCell("Vtosh", VStandartTableCell(1506, 2, 54));
void VContainer::AddLengthArc(const qint64 &center, const qint64 &id){ AddStandartTableCell("Vpt", VStandartTableCell(1438, 3, 52));
AddLengthArc(GetNameArc(center, id), GetArc(id).GetLength()); AddStandartTableCell("Vst", VStandartTableCell(1257, -1, 49));
} AddStandartTableCell("Vlt", VStandartTableCell(1102, 0, 43));
AddStandartTableCell("Vk", VStandartTableCell(503, 0, 22));
void VContainer::AddLengthArc(const QString &name, const qreal &value){ AddStandartTableCell("Vsht", VStandartTableCell(1522, 2, 54));
Q_ASSERT(!name.isEmpty()); AddStandartTableCell("Vzy", VStandartTableCell(1328, 0, 49));
lengthArcs[name] = value; AddStandartTableCell("Vlop", VStandartTableCell(1320, 0, 49));
} AddStandartTableCell("Vps", VStandartTableCell(811, -1, 36));
AddStandartTableCell("Osh", VStandartTableCell(404,8, 2));
void VContainer::AddLineArc(const QString &name, const qint32 &value){ AddStandartTableCell("OgI", VStandartTableCell(1034, 36, 4));
Q_ASSERT(!name.isEmpty()); AddStandartTableCell("OgII", VStandartTableCell(1044, 38, 2));
lineArcs[name] = value; AddStandartTableCell("OgIII", VStandartTableCell(1000, 40, 0));
} AddStandartTableCell("Ot", VStandartTableCell(780, 40, 0));
AddStandartTableCell("Ob", VStandartTableCell(984, 30, 10));
qreal VContainer::GetLine(const QString &name) const{ AddStandartTableCell("ObI", VStandartTableCell(964, 24, 12));
Q_ASSERT(!name.isEmpty()); AddStandartTableCell("Obed", VStandartTableCell(566, 18, 6));
if(lengthLines.contains(name)){ AddStandartTableCell("Ok", VStandartTableCell(386, 8, 8));
return lengthLines.value(name); AddStandartTableCell("Oi", VStandartTableCell(380, 8, 6));
} else { AddStandartTableCell("Osch", VStandartTableCell(234, 4, 4));
qCritical()<<"Не можу знайти лінію за імям = "<<name<<" в таблиці."; AddStandartTableCell("Os", VStandartTableCell(350, 2, 8));
throw"Не можу знайти лінію в таблиці."; AddStandartTableCell("Dsb", VStandartTableCell(1120, 0, 44));
} AddStandartTableCell("Dsp", VStandartTableCell(1110, 0, 43));
return 0; AddStandartTableCell("Dn", VStandartTableCell(826, -3, 37));
} AddStandartTableCell("Dps", VStandartTableCell(316, 4, 7));
AddStandartTableCell("Dpob", VStandartTableCell(783, 14, 15));
qint32 VContainer::GetLineArc(const QString &name) const{ AddStandartTableCell("Ds", VStandartTableCell(260, 1, 6));
Q_ASSERT(!name.isEmpty()); AddStandartTableCell("Op", VStandartTableCell(316, 12, 0));
if(lineArcs.contains(name)){ AddStandartTableCell("Ozap", VStandartTableCell(180, 4, 0));
return lineArcs.value(name); AddStandartTableCell("Pkis", VStandartTableCell(250, 4, 0));
} else { AddStandartTableCell("SHp", VStandartTableCell(160, 1, 4));
qCritical()<<"Не можу знайти кут за імям = "<<name<<" в таблиці."; AddStandartTableCell("Dlych", VStandartTableCell(500, 2, 15));
throw"Не можу знайти кут в таблиці."; AddStandartTableCell("Dzap", VStandartTableCell(768, 2, 24));
} AddStandartTableCell("DIIIp", VStandartTableCell(970, 2, 29));
return 0; AddStandartTableCell("Vprp", VStandartTableCell(214, 3, 3));
} AddStandartTableCell("Vg", VStandartTableCell(262, 8, 3));
AddStandartTableCell("Dtp", VStandartTableCell(460, 7, 9));
VSpline VContainer::GetSpline(qint64 id) const{ AddStandartTableCell("Dp", VStandartTableCell(355, 5, 5));
if(splines.contains(id)){ AddStandartTableCell("Vprz", VStandartTableCell(208, 3, 5));
return splines.value(id); AddStandartTableCell("Dts", VStandartTableCell(438, 2, 10));
} else { AddStandartTableCell("DtsI", VStandartTableCell(469, 2, 10));
qCritical()<<"Не можу знайти id = "<<id<<" в таблиці."; AddStandartTableCell("Dvcht", VStandartTableCell(929, 9, 19));
throw"Не можу знайти сплайн за id."; AddStandartTableCell("SHg", VStandartTableCell(370, 14, 4));
} AddStandartTableCell("Cg", VStandartTableCell(224, 6, 0));
return VSpline(); AddStandartTableCell("SHs", VStandartTableCell(416, 10, 2));
} AddStandartTableCell("dpzr", VStandartTableCell(121, 6, 0));
AddStandartTableCell("Ogol", VStandartTableCell(576, 4, 4));
VArc VContainer::GetArc(qint64 id) const{ AddStandartTableCell("Ssh1", VStandartTableCell(205, 5, 0));
if(arcs.contains(id)){ AddStandartTableCell("St", VStandartTableCell(410, 20, 0));
return arcs.value(id); AddStandartTableCell("Drzap", VStandartTableCell(594, 3, 19));
} else { AddStandartTableCell("DbII", VStandartTableCell(1020, 0, 44));
qCritical()<<"Не можу знайти id = "<<id<<" в таблиці."; AddStandartTableCell("Sb", VStandartTableCell(504, 15, 4));
throw"Не можу знайти дугу за id.";
}
return VArc();
}
VSplinePath VContainer::GetSplinePath(qint64 id) const{
if(splinePaths.contains(id)){
return splinePaths.value(id);
} else {
qCritical()<<"Не можу знайти id = "<<id<<" в таблиці.";
throw"Не можу знайти дугу за id.";
}
return VSplinePath();
}
const QMap<QString, qreal> *VContainer::DataLengthArcs() const{
return &lengthArcs;
}
const QMap<QString, qreal> *VContainer::DataLineArcs() const{
return &lineArcs;
}
const QMap<qint64, VSplinePath> *VContainer::DataSplinePaths() const{
return &splinePaths;
} }

View File

@ -1,11 +1,13 @@
#ifndef VCONTAINER_H #ifndef VCONTAINER_H
#define VCONTAINER_H #define VCONTAINER_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QMap> #include <QMap>
#include <QTableWidget> #include <QTableWidget>
#include "vpointf.h" #include "vpointf.h"
#include "vstandarttablecell.h" #include "vstandarttablecell.h"
#include "vincrementtablerow.h" #include "vincrementtablerow.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "../geometry/vspline.h" #include "../geometry/vspline.h"
#include "../geometry/varc.h" #include "../geometry/varc.h"
#include "../geometry/vsplinepath.h" #include "../geometry/vsplinepath.h"
@ -85,6 +87,7 @@ public:
const QMap<QString, qreal> *DataLengthArcs() const; const QMap<QString, qreal> *DataLengthArcs() const;
const QMap<QString, qreal> *DataLineArcs() const; const QMap<QString, qreal> *DataLineArcs() const;
const QMap<qint64, VSplinePath> *DataSplinePaths() const; const QMap<qint64, VSplinePath> *DataSplinePaths() const;
void UpdateId(qint64 newId);
private: private:
qint64 _id; qint64 _id;
QMap<QString, qint32> base; QMap<QString, qint32> base;
@ -98,6 +101,10 @@ private:
QMap<qint64, VArc> arcs; QMap<qint64, VArc> arcs;
QMap<QString, qreal> lengthArcs; QMap<QString, qreal> lengthArcs;
QMap<qint64, VSplinePath> splinePaths; QMap<qint64, VSplinePath> splinePaths;
template <typename key, typename val> val GetObject(const QMap<key,val> &obj, key id) const;
template <typename val> void UpdateObject(QMap<qint64, val> &obj, const qint64 &id, const val& point);
template <typename key, typename val> qint64 AddObject(QMap<key, val> &obj, const val& value);
void CreateManTableIGroup ();
}; };
#endif // VCONTAINER_H #endif // VCONTAINER_H

View File

@ -8,7 +8,7 @@ VIncrementTableRow::VIncrementTableRow(){
this->description = QString(); this->description = QString();
} }
VIncrementTableRow::VIncrementTableRow(qint64 id, qint32 base, qreal ksize, qreal kgrowth, VIncrementTableRow::VIncrementTableRow(qint64 id, qreal base, qreal ksize, qreal kgrowth,
QString description){ QString description){
this->id = id; this->id = id;
this->base = base; this->base = base;
@ -41,11 +41,11 @@ void VIncrementTableRow::setKsize(const qreal &value){
ksize = value; ksize = value;
} }
qint32 VIncrementTableRow::getBase() const{ qreal VIncrementTableRow::getBase() const{
return base; return base;
} }
void VIncrementTableRow::setBase(const qint32 &value){ void VIncrementTableRow::setBase(const qreal &value){
base = value; base = value;
} }

View File

@ -7,13 +7,13 @@ class VIncrementTableRow
{ {
public: public:
VIncrementTableRow(); VIncrementTableRow();
VIncrementTableRow(qint64 id, qint32 base, qreal ksize, qreal kgrowth, VIncrementTableRow(qint64 id, qreal base, qreal ksize, qreal kgrowth,
QString description = QString()); QString description = QString());
qint64 getId() const; qint64 getId() const;
void setId(const qint64 &value); void setId(const qint64 &value);
qint32 getBase() const; qreal getBase() const;
void setBase(const qint32 &value); void setBase(const qreal &value);
qreal getKsize() const; qreal getKsize() const;
void setKsize(const qreal &value); void setKsize(const qreal &value);
@ -26,7 +26,7 @@ public:
private: private:
qint64 id; qint64 id;
qint32 base; qreal base;
qreal ksize; qreal ksize;
qreal kgrowth; qreal kgrowth;
QString description; QString description;

View File

@ -1,20 +1,29 @@
#include "vpointf.h" #include "vpointf.h"
VPointF::VPointF():QPointF(){ VPointF::VPointF(){
_mx = 0; _mx = 0;
_my = 0; _my = 0;
this->_x = 0;
this->_y = 0;
} }
VPointF::VPointF ( const VPointF & point ):QPointF(point){ VPointF::VPointF ( const VPointF & point ){
_name = point.name(); _name = point.name();
_mx = point.mx(); _mx = point.mx();
_my = point.my(); _my = point.my();
this->_x = point.x();
this->_y = point.y();
} }
VPointF::VPointF (qreal x, qreal y , QString name, qreal mx, qreal my):QPointF(x, y){ VPointF::VPointF (qreal x, qreal y , QString name, qreal mx, qreal my){
_name = name; _name = name;
_mx = mx; _mx = mx;
_my = my; _my = my;
this->_x = x;
this->_y = y;
}
VPointF::~VPointF(){
} }
QString VPointF::name() const{ QString VPointF::name() const{
@ -42,5 +51,21 @@ void VPointF::setMy(qreal my){
} }
QPointF VPointF::toQPointF()const{ QPointF VPointF::toQPointF()const{
return QPointF(this->x(), this->y()); return QPointF(_x, _y);
}
qreal VPointF::y() const{
return _y;
}
void VPointF::setY(const qreal &value){
_y = value;
}
qreal VPointF::x() const{
return _x;
}
void VPointF::setX(const qreal &value){
_x = value;
} }

View File

@ -1,15 +1,18 @@
#ifndef VPOINTF_H #ifndef VPOINTF_H
#define VPOINTF_H #define VPOINTF_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QPointF> #include <QPointF>
#include <QString> #include <QString>
#pragma GCC diagnostic warning "-Weffc++"
class VPointF : public QPointF class VPointF
{ {
public: public:
VPointF(); VPointF();
VPointF (const VPointF &point ); VPointF (const VPointF &point );
VPointF ( qreal x, qreal y, QString name, qreal mx, qreal my ); VPointF ( qreal x, qreal y, QString name, qreal mx, qreal my );
~VPointF();
QString name() const; QString name() const;
qreal mx() const; qreal mx() const;
qreal my() const; qreal my() const;
@ -17,10 +20,17 @@ public:
void setMx(qreal mx); void setMx(qreal mx);
void setMy(qreal my); void setMy(qreal my);
QPointF toQPointF()const; QPointF toQPointF()const;
qreal x() const;
void setX(const qreal &value);
qreal y() const;
void setY(const qreal &value);
private: private:
QString _name; QString _name;
qreal _mx; qreal _mx;
qreal _my; qreal _my;
qreal _x;
qreal _y;
}; };
#endif // VPOINTF_H #endif // VPOINTF_H

View File

@ -72,10 +72,8 @@ void DialogAlongLine::DialogAccepted(){
pointName = ui->lineEditNamePoint->text(); pointName = ui->lineEditNamePoint->text();
typeLine = GetTypeLine(ui->comboBoxLineType); typeLine = GetTypeLine(ui->comboBoxLineType);
formula = ui->lineEditFormula->text(); formula = ui->lineEditFormula->text();
qint32 index = ui->comboBoxFirstPoint->currentIndex(); firstPointId = getCurrentPointId(ui->comboBoxFirstPoint);
firstPointId = qvariant_cast<qint64>(ui->comboBoxFirstPoint->itemData(index)); secondPointId = getCurrentPointId(ui->comboBoxSecondPoint);
index = ui->comboBoxSecondPoint->currentIndex();
secondPointId = qvariant_cast<qint64>(ui->comboBoxSecondPoint->itemData(index));
emit DialogClosed(QDialog::Accepted); emit DialogClosed(QDialog::Accepted);
} }
@ -83,18 +81,16 @@ qint64 DialogAlongLine::getSecondPointId() const{
return secondPointId; return secondPointId;
} }
void DialogAlongLine::setSecondPointId(const qint64 &value){ void DialogAlongLine::setSecondPointId(const qint64 &value, const qint64 &id){
secondPointId = value; setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id);
ChangeCurrentData(ui->comboBoxSecondPoint, value);
} }
qint64 DialogAlongLine::getFirstPointId() const{ qint64 DialogAlongLine::getFirstPointId() const{
return firstPointId; return firstPointId;
} }
void DialogAlongLine::setFirstPointId(const qint64 &value){ void DialogAlongLine::setFirstPointId(const qint64 &value, const qint64 &id){
firstPointId = value; setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id);
ChangeCurrentData(ui->comboBoxFirstPoint, value);
} }
QString DialogAlongLine::getFormula() const{ QString DialogAlongLine::getFormula() const{

View File

@ -23,9 +23,9 @@ public:
QString getFormula() const; QString getFormula() const;
void setFormula(const QString &value); void setFormula(const QString &value);
qint64 getFirstPointId() const; qint64 getFirstPointId() const;
void setFirstPointId(const qint64 &value); void setFirstPointId(const qint64 &value, const qint64 &id);
qint64 getSecondPointId() const; qint64 getSecondPointId() const;
void setSecondPointId(const qint64 &value); void setSecondPointId(const qint64 &value, const qint64 &id);
public slots: public slots:
virtual void ChoosedObject(qint64 id, Scene::Type type); virtual void ChoosedObject(qint64 id, Scene::Type type);
virtual void DialogAccepted(); virtual void DialogAccepted();

View File

@ -60,7 +60,7 @@ qint64 DialogArc::GetCenter() const{
return center; return center;
} }
void DialogArc::GetCenter(const qint64 &value){ void DialogArc::SetCenter(const qint64 &value){
center = value; center = value;
ChangeCurrentData(ui->comboBoxBasePoint, center); ChangeCurrentData(ui->comboBoxBasePoint, center);
} }
@ -69,7 +69,7 @@ QString DialogArc::GetF2() const{
return f2; return f2;
} }
void DialogArc::GetF2(const QString &value){ void DialogArc::SetF2(const QString &value){
f2 = value; f2 = value;
ui->lineEditF2->setText(f2); ui->lineEditF2->setText(f2);
} }
@ -78,7 +78,7 @@ QString DialogArc::GetF1() const{
return f1; return f1;
} }
void DialogArc::GetF1(const QString &value){ void DialogArc::SetF1(const QString &value){
f1 = value; f1 = value;
ui->lineEditF1->setText(f1); ui->lineEditF1->setText(f1);
} }
@ -87,7 +87,7 @@ QString DialogArc::GetRadius() const{
return radius; return radius;
} }
void DialogArc::GetRadius(const QString &value){ void DialogArc::SetRadius(const QString &value){
radius = value; radius = value;
ui->lineEditRadius->setText(radius); ui->lineEditRadius->setText(radius);
} }
@ -108,8 +108,7 @@ void DialogArc::DialogAccepted(){
radius = ui->lineEditRadius->text(); radius = ui->lineEditRadius->text();
f1 = ui->lineEditF1->text(); f1 = ui->lineEditF1->text();
f2 = ui->lineEditF2->text(); f2 = ui->lineEditF2->text();
qint32 index = ui->comboBoxBasePoint->currentIndex(); center = getCurrentPointId(ui->comboBoxBasePoint);
center = qvariant_cast<qint64>(ui->comboBoxBasePoint->itemData(index));
emit DialogClosed(QDialog::Accepted); emit DialogClosed(QDialog::Accepted);
} }

View File

@ -15,16 +15,16 @@ public:
explicit DialogArc(const VContainer *data, QWidget *parent = 0); explicit DialogArc(const VContainer *data, QWidget *parent = 0);
~DialogArc(); ~DialogArc();
qint64 GetCenter() const; qint64 GetCenter() const;
void GetCenter(const qint64 &value); void SetCenter(const qint64 &value);
QString GetRadius() const; QString GetRadius() const;
void GetRadius(const QString &value); void SetRadius(const QString &value);
QString GetF1() const; QString GetF1() const;
void GetF1(const QString &value); void SetF1(const QString &value);
QString GetF2() const; QString GetF2() const;
void GetF2(const QString &value); void SetF2(const QString &value);
public slots: public slots:
virtual void ChoosedObject(qint64 id, Scene::Type type); virtual void ChoosedObject(qint64 id, Scene::Type type);

View File

@ -107,38 +107,32 @@ qint64 DialogBisector::getFirstPointId() const{
return firstPointId; return firstPointId;
} }
void DialogBisector::setFirstPointId(const qint64 &value){ void DialogBisector::setFirstPointId(const qint64 &value, const qint64 &id){
firstPointId = value; setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id);
ChangeCurrentData(ui->comboBoxFirstPoint, value);
} }
qint64 DialogBisector::getSecondPointId() const{ qint64 DialogBisector::getSecondPointId() const{
return secondPointId; return secondPointId;
} }
void DialogBisector::setSecondPointId(const qint64 &value){ void DialogBisector::setSecondPointId(const qint64 &value, const qint64 &id){
secondPointId = value; setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id);
ChangeCurrentData(ui->comboBoxSecondPoint, value);
} }
qint64 DialogBisector::getThirdPointId() const{ qint64 DialogBisector::getThirdPointId() const{
return thirdPointId; return thirdPointId;
} }
void DialogBisector::setThirdPointId(const qint64 &value){ void DialogBisector::setThirdPointId(const qint64 &value, const qint64 &id){
thirdPointId = value; setCurrentPointId(ui->comboBoxThirdPoint, thirdPointId, value, id);
ChangeCurrentData(ui->comboBoxThirdPoint, value);
} }
void DialogBisector::DialogAccepted(){ void DialogBisector::DialogAccepted(){
pointName = ui->lineEditNamePoint->text(); pointName = ui->lineEditNamePoint->text();
typeLine = GetTypeLine(ui->comboBoxLineType); typeLine = GetTypeLine(ui->comboBoxLineType);
formula = ui->lineEditFormula->text(); formula = ui->lineEditFormula->text();
qint32 index = ui->comboBoxFirstPoint->currentIndex(); firstPointId = getCurrentPointId(ui->comboBoxFirstPoint);
firstPointId = qvariant_cast<qint64>(ui->comboBoxFirstPoint->itemData(index)); secondPointId = getCurrentPointId(ui->comboBoxSecondPoint);
index = ui->comboBoxSecondPoint->currentIndex(); thirdPointId = getCurrentPointId(ui->comboBoxThirdPoint);
secondPointId = qvariant_cast<qint64>(ui->comboBoxSecondPoint->itemData(index));
index = ui->comboBoxThirdPoint->currentIndex();
thirdPointId = qvariant_cast<qint64>(ui->comboBoxThirdPoint->itemData(index));
emit DialogClosed(QDialog::Accepted); emit DialogClosed(QDialog::Accepted);
} }

View File

@ -28,11 +28,11 @@ public:
QString getFormula() const; QString getFormula() const;
void setFormula(const QString &value); void setFormula(const QString &value);
qint64 getFirstPointId() const; qint64 getFirstPointId() const;
void setFirstPointId(const qint64 &value); void setFirstPointId(const qint64 &value, const qint64 &id);
qint64 getSecondPointId() const; qint64 getSecondPointId() const;
void setSecondPointId(const qint64 &value); void setSecondPointId(const qint64 &value, const qint64 &id);
qint64 getThirdPointId() const; qint64 getThirdPointId() const;
void setThirdPointId(const qint64 &value); void setThirdPointId(const qint64 &value, const qint64 &id);
public slots: public slots:
virtual void ChoosedObject(qint64 id, Scene::Type type); virtual void ChoosedObject(qint64 id, Scene::Type type);
virtual void DialogAccepted(); virtual void DialogAccepted();

View File

@ -107,9 +107,8 @@ qint64 DialogEndLine::getBasePointId() const{
return basePointId; return basePointId;
} }
void DialogEndLine::setBasePointId(const qint64 &value){ void DialogEndLine::setBasePointId(const qint64 &value, const qint64 &id){
basePointId = value; setCurrentPointId(ui->comboBoxBasePoint, basePointId, value, id);
ChangeCurrentData(ui->comboBoxBasePoint, value);
} }
void DialogEndLine::DialogAccepted(){ void DialogEndLine::DialogAccepted(){
@ -117,8 +116,7 @@ void DialogEndLine::DialogAccepted(){
typeLine = GetTypeLine(ui->comboBoxLineType); typeLine = GetTypeLine(ui->comboBoxLineType);
formula = ui->lineEditFormula->text(); formula = ui->lineEditFormula->text();
angle = ui->spinBoxAngle->value(); angle = ui->spinBoxAngle->value();
qint32 index = ui->comboBoxBasePoint->currentIndex(); basePointId = getCurrentPointId(ui->comboBoxBasePoint);
basePointId = qvariant_cast<qint64>(ui->comboBoxBasePoint->itemData(index));
emit DialogClosed(QDialog::Accepted); emit DialogClosed(QDialog::Accepted);
} }

View File

@ -29,7 +29,7 @@ public:
qint32 getAngle() const; qint32 getAngle() const;
void setAngle(const qint32 &value); void setAngle(const qint32 &value);
qint64 getBasePointId() const; qint64 getBasePointId() const;
void setBasePointId(const qint64 &value); void setBasePointId(const qint64 &value, const qint64 &id);
public slots: public slots:
virtual void ChoosedObject(qint64 id, Scene::Type type); virtual void ChoosedObject(qint64 id, Scene::Type type);
virtual void DialogAccepted(); virtual void DialogAccepted();

View File

@ -15,9 +15,8 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget
InitialStandartTable(); InitialStandartTable();
InitialIncrementTable(); InitialIncrementTable();
InitialLinesTable(); InitialLinesTable();
SpinBoxDelegate *delegate = new SpinBoxDelegate(ui->tableWidgetIncrement);
DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement);
ui->tableWidgetIncrement->setItemDelegateForColumn(2, delegate); ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);
ui->tableWidgetIncrement->setItemDelegateForColumn(3, doubleDelegate); ui->tableWidgetIncrement->setItemDelegateForColumn(3, doubleDelegate);
ui->tableWidgetIncrement->setItemDelegateForColumn(4, doubleDelegate); ui->tableWidgetIncrement->setItemDelegateForColumn(4, doubleDelegate);
FillStandartTable(); FillStandartTable();
@ -72,6 +71,9 @@ void DialogIncrements::FillStandartTable(){
item->setTextAlignment(Qt::AlignHCenter); item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetStandart->setItem(currentRow, 5, item); ui->tableWidgetStandart->setItem(currentRow, 5, item);
} }
ui->tableWidgetStandart->resizeColumnsToContents();
ui->tableWidgetStandart->resizeRowsToContents();
ui->tableWidgetStandart->verticalHeader()->setDefaultSectionSize(20);
} }
void DialogIncrements::FillIncrementTable(){ void DialogIncrements::FillIncrementTable(){
@ -117,6 +119,9 @@ void DialogIncrements::FillIncrementTable(){
if(ui->tableWidgetIncrement->rowCount()>0){ if(ui->tableWidgetIncrement->rowCount()>0){
ui->toolButtonRemove->setEnabled(true); ui->toolButtonRemove->setEnabled(true);
} }
ui->tableWidgetIncrement->resizeColumnsToContents();
ui->tableWidgetIncrement->resizeRowsToContents();
ui->tableWidgetIncrement->verticalHeader()->setDefaultSectionSize(20);
} }
void DialogIncrements::FillLengthLines(){ void DialogIncrements::FillLengthLines(){
@ -138,6 +143,9 @@ void DialogIncrements::FillLengthLines(){
item->setTextAlignment(Qt::AlignHCenter); item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetLines->setItem(currentRow, 1, item); ui->tableWidgetLines->setItem(currentRow, 1, item);
} }
ui->tableWidgetLines->resizeColumnsToContents();
ui->tableWidgetLines->resizeRowsToContents();
ui->tableWidgetLines->verticalHeader()->setDefaultSectionSize(20);
} }
void DialogIncrements::FillLengthSplines(){ void DialogIncrements::FillLengthSplines(){
@ -159,6 +167,9 @@ void DialogIncrements::FillLengthSplines(){
item->setTextAlignment(Qt::AlignHCenter); item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetSplines->setItem(currentRow, 1, item); ui->tableWidgetSplines->setItem(currentRow, 1, item);
} }
ui->tableWidgetSplines->resizeColumnsToContents();
ui->tableWidgetSplines->resizeRowsToContents();
ui->tableWidgetSplines->verticalHeader()->setDefaultSectionSize(20);
} }
void DialogIncrements::FillLengthArcs(){ void DialogIncrements::FillLengthArcs(){
@ -180,6 +191,9 @@ void DialogIncrements::FillLengthArcs(){
item->setTextAlignment(Qt::AlignHCenter); item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetArcs->setItem(currentRow, 1, item); ui->tableWidgetArcs->setItem(currentRow, 1, item);
} }
ui->tableWidgetArcs->resizeColumnsToContents();
ui->tableWidgetArcs->resizeRowsToContents();
ui->tableWidgetArcs->verticalHeader()->setDefaultSectionSize(20);
} }
void DialogIncrements::FullUpdateFromFile(){ void DialogIncrements::FullUpdateFromFile(){
@ -386,9 +400,7 @@ void DialogIncrements::cellChanged ( qint32 row, qint32 column ){
} }
void DialogIncrements::InitialStandartTable(){ void DialogIncrements::InitialStandartTable(){
ui->tableWidgetStandart->resizeColumnsToContents(); ui->tableWidgetStandart->setSortingEnabled(false);
ui->tableWidgetStandart->resizeRowsToContents();
ui->tableWidgetStandart->verticalHeader()->setDefaultSectionSize(20);
ui->tableWidgetStandart->setHorizontalHeaderItem(0, new QTableWidgetItem("Позначення")); ui->tableWidgetStandart->setHorizontalHeaderItem(0, new QTableWidgetItem("Позначення"));
ui->tableWidgetStandart->setHorizontalHeaderItem(1, new QTableWidgetItem("Розрах. знач.")); ui->tableWidgetStandart->setHorizontalHeaderItem(1, new QTableWidgetItem("Розрах. знач."));
ui->tableWidgetStandart->setHorizontalHeaderItem(2, new QTableWidgetItem("Базове знач.")); ui->tableWidgetStandart->setHorizontalHeaderItem(2, new QTableWidgetItem("Базове знач."));
@ -398,9 +410,7 @@ void DialogIncrements::InitialStandartTable(){
} }
void DialogIncrements::InitialIncrementTable(){ void DialogIncrements::InitialIncrementTable(){
ui->tableWidgetIncrement->resizeColumnsToContents(); ui->tableWidgetIncrement->setSortingEnabled(false);
ui->tableWidgetIncrement->resizeRowsToContents();
ui->tableWidgetIncrement->verticalHeader()->setDefaultSectionSize(20);
ui->tableWidgetIncrement->setHorizontalHeaderItem(0, new QTableWidgetItem("Позначення")); ui->tableWidgetIncrement->setHorizontalHeaderItem(0, new QTableWidgetItem("Позначення"));
ui->tableWidgetIncrement->setHorizontalHeaderItem(1, new QTableWidgetItem("Розрах. знач.")); ui->tableWidgetIncrement->setHorizontalHeaderItem(1, new QTableWidgetItem("Розрах. знач."));
ui->tableWidgetIncrement->setHorizontalHeaderItem(2, new QTableWidgetItem("Базове знач.")); ui->tableWidgetIncrement->setHorizontalHeaderItem(2, new QTableWidgetItem("Базове знач."));
@ -410,25 +420,16 @@ void DialogIncrements::InitialIncrementTable(){
} }
void DialogIncrements::InitialLinesTable(){ void DialogIncrements::InitialLinesTable(){
ui->tableWidgetLines->resizeColumnsToContents();
ui->tableWidgetLines->resizeRowsToContents();
ui->tableWidgetLines->verticalHeader()->setDefaultSectionSize(20);
ui->tableWidgetLines->setHorizontalHeaderItem(0, new QTableWidgetItem("Лінія")); ui->tableWidgetLines->setHorizontalHeaderItem(0, new QTableWidgetItem("Лінія"));
ui->tableWidgetLines->setHorizontalHeaderItem(1, new QTableWidgetItem("Довжина")); ui->tableWidgetLines->setHorizontalHeaderItem(1, new QTableWidgetItem("Довжина"));
} }
void DialogIncrements::InitialSplinesTable(){ void DialogIncrements::InitialSplinesTable(){
ui->tableWidgetSplines->resizeColumnsToContents();
ui->tableWidgetSplines->resizeRowsToContents();
ui->tableWidgetSplines->verticalHeader()->setDefaultSectionSize(20);
ui->tableWidgetSplines->setHorizontalHeaderItem(0, new QTableWidgetItem("Лінія")); ui->tableWidgetSplines->setHorizontalHeaderItem(0, new QTableWidgetItem("Лінія"));
ui->tableWidgetSplines->setHorizontalHeaderItem(1, new QTableWidgetItem("Довжина")); ui->tableWidgetSplines->setHorizontalHeaderItem(1, new QTableWidgetItem("Довжина"));
} }
void DialogIncrements::InitialArcsTable(){ void DialogIncrements::InitialArcsTable(){
ui->tableWidgetArcs->resizeColumnsToContents();
ui->tableWidgetArcs->resizeRowsToContents();
ui->tableWidgetArcs->verticalHeader()->setDefaultSectionSize(20);
ui->tableWidgetArcs->setHorizontalHeaderItem(0, new QTableWidgetItem("Лінія")); ui->tableWidgetArcs->setHorizontalHeaderItem(0, new QTableWidgetItem("Лінія"));
ui->tableWidgetArcs->setHorizontalHeaderItem(1, new QTableWidgetItem("Довжина")); ui->tableWidgetArcs->setHorizontalHeaderItem(1, new QTableWidgetItem("Довжина"));
} }

View File

@ -20,7 +20,7 @@
<enum>QTabWidget::North</enum> <enum>QTabWidget::North</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="tabStandart"> <widget class="QWidget" name="tabStandart">
<attribute name="title"> <attribute name="title">
@ -118,6 +118,9 @@
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum> <enum>QAbstractItemView::SingleSelection</enum>
</property> </property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>

View File

@ -85,14 +85,10 @@ void DialogLineIntersect::ChoosedObject(qint64 id, Scene::Type type){
void DialogLineIntersect::DialogAccepted(){ void DialogLineIntersect::DialogAccepted(){
pointName = ui->lineEditNamePoint->text(); pointName = ui->lineEditNamePoint->text();
qint32 index = ui->comboBoxP1Line1->currentIndex(); p1Line1 = getCurrentPointId(ui->comboBoxP1Line1);
p1Line1 = qvariant_cast<qint64>(ui->comboBoxP1Line1->itemData(index)); p2Line1 = getCurrentPointId(ui->comboBoxP2Line1);
index = ui->comboBoxP2Line1->currentIndex(); p1Line2 = getCurrentPointId(ui->comboBoxP1Line2);
p2Line1 = qvariant_cast<qint64>(ui->comboBoxP2Line1->itemData(index)); p2Line2 = getCurrentPointId(ui->comboBoxP2Line2);
index = ui->comboBoxP1Line2->currentIndex();
p1Line2 = qvariant_cast<qint64>(ui->comboBoxP1Line2->itemData(index));
index = ui->comboBoxP2Line2->currentIndex();
p2Line2 = qvariant_cast<qint64>(ui->comboBoxP2Line2->itemData(index));
emit DialogClosed(QDialog::Accepted); emit DialogClosed(QDialog::Accepted);
} }

View File

@ -91,10 +91,8 @@ void DialogNormal::DialogAccepted(){
typeLine = GetTypeLine(ui->comboBoxLineType); typeLine = GetTypeLine(ui->comboBoxLineType);
formula = ui->lineEditFormula->text(); formula = ui->lineEditFormula->text();
angle = ui->spinBoxAngle->value(); angle = ui->spinBoxAngle->value();
qint32 index = ui->comboBoxFirstPoint->currentIndex(); firstPointId = getCurrentPointId(ui->comboBoxFirstPoint);
firstPointId = qvariant_cast<qint64>(ui->comboBoxFirstPoint->itemData(index)); secondPointId = getCurrentPointId(ui->comboBoxSecondPoint);
index = ui->comboBoxSecondPoint->currentIndex();
secondPointId = qvariant_cast<qint64>(ui->comboBoxSecondPoint->itemData(index));
emit DialogClosed(QDialog::Accepted); emit DialogClosed(QDialog::Accepted);
} }
@ -102,18 +100,16 @@ qint64 DialogNormal::getSecondPointId() const{
return secondPointId; return secondPointId;
} }
void DialogNormal::setSecondPointId(const qint64 &value){ void DialogNormal::setSecondPointId(const qint64 &value, const qint64 &id){
secondPointId = value; setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id);
ChangeCurrentData(ui->comboBoxSecondPoint, value);
} }
qint64 DialogNormal::getFirstPointId() const{ qint64 DialogNormal::getFirstPointId() const{
return firstPointId; return firstPointId;
} }
void DialogNormal::setFirstPointId(const qint64 &value){ void DialogNormal::setFirstPointId(const qint64 &value, const qint64 &id){
firstPointId = value; setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id);
ChangeCurrentData(ui->comboBoxFirstPoint, value);
} }
qint32 DialogNormal::getAngle() const{ qint32 DialogNormal::getAngle() const{

View File

@ -29,9 +29,9 @@ public:
qint32 getAngle() const; qint32 getAngle() const;
void setAngle(const qint32 &value); void setAngle(const qint32 &value);
qint64 getFirstPointId() const; qint64 getFirstPointId() const;
void setFirstPointId(const qint64 &value); void setFirstPointId(const qint64 &value, const qint64 &id);
qint64 getSecondPointId() const; qint64 getSecondPointId() const;
void setSecondPointId(const qint64 &value); void setSecondPointId(const qint64 &value, const qint64 &id);
public slots: public slots:
virtual void ChoosedObject(qint64 id, Scene::Type type); virtual void ChoosedObject(qint64 id, Scene::Type type);
virtual void DialogAccepted(); virtual void DialogAccepted();

View File

@ -81,12 +81,9 @@ void DialogShoulderPoint::DialogAccepted(){
pointName = ui->lineEditNamePoint->text(); pointName = ui->lineEditNamePoint->text();
typeLine = GetTypeLine(ui->comboBoxLineType); typeLine = GetTypeLine(ui->comboBoxLineType);
formula = ui->lineEditFormula->text(); formula = ui->lineEditFormula->text();
qint32 index = ui->comboBoxP1Line->currentIndex(); p1Line = getCurrentPointId(ui->comboBoxP1Line);
p1Line = qvariant_cast<qint64>(ui->comboBoxP1Line->itemData(index)); p2Line = getCurrentPointId(ui->comboBoxP2Line);
index = ui->comboBoxP2Line->currentIndex(); pShoulder = getCurrentPointId(ui->comboBoxPShoulder);
p2Line = qvariant_cast<qint64>(ui->comboBoxP2Line->itemData(index));
index = ui->comboBoxPShoulder->currentIndex();
pShoulder = qvariant_cast<qint64>(ui->comboBoxPShoulder->itemData(index));
emit DialogClosed(QDialog::Accepted); emit DialogClosed(QDialog::Accepted);
} }
@ -94,28 +91,24 @@ qint64 DialogShoulderPoint::getPShoulder() const{
return pShoulder; return pShoulder;
} }
void DialogShoulderPoint::setPShoulder(const qint64 &value){ void DialogShoulderPoint::setPShoulder(const qint64 &value, const qint64 &id){
pShoulder = value; setCurrentPointId(ui->comboBoxPShoulder, pShoulder, value, id);
ChangeCurrentData(ui->comboBoxPShoulder, value);
} }
qint64 DialogShoulderPoint::getP2Line() const{ qint64 DialogShoulderPoint::getP2Line() const{
return p2Line; return p2Line;
} }
void DialogShoulderPoint::setP2Line(const qint64 &value){ void DialogShoulderPoint::setP2Line(const qint64 &value, const qint64 &id){
p2Line = value; setCurrentPointId(ui->comboBoxP2Line, p2Line, value, id);
ChangeCurrentData(ui->comboBoxP2Line, value);
} }
qint64 DialogShoulderPoint::getP1Line() const{ qint64 DialogShoulderPoint::getP1Line() const{
return p1Line; return p1Line;
} }
void DialogShoulderPoint::setP1Line(const qint64 &value) void DialogShoulderPoint::setP1Line(const qint64 &value, const qint64 &id){
{ setCurrentPointId(ui->comboBoxP1Line, p1Line, value, id);
p1Line = value;
ChangeCurrentData(ui->comboBoxP1Line, value);
} }
QString DialogShoulderPoint::getFormula() const{ QString DialogShoulderPoint::getFormula() const{

View File

@ -23,11 +23,11 @@ public:
QString getFormula() const; QString getFormula() const;
void setFormula(const QString &value); void setFormula(const QString &value);
qint64 getP1Line() const; qint64 getP1Line() const;
void setP1Line(const qint64 &value); void setP1Line(const qint64 &value, const qint64 &id);
qint64 getP2Line() const; qint64 getP2Line() const;
void setP2Line(const qint64 &value); void setP2Line(const qint64 &value, const qint64 &id);
qint64 getPShoulder() const; qint64 getPShoulder() const;
void setPShoulder(const qint64 &value); void setPShoulder(const qint64 &value, const qint64 &id);
public slots: public slots:
virtual void ChoosedObject(qint64 id, Scene::Type type); virtual void ChoosedObject(qint64 id, Scene::Type type);
virtual void DialogAccepted(); virtual void DialogAccepted();

View File

@ -1,9 +1,10 @@
#pragma GCC diagnostic ignored "-Weffc++"
#include "dialogsinglepoint.h" #include "dialogsinglepoint.h"
#include "ui_dialogsinglepoint.h" #include "ui_dialogsinglepoint.h"
#include <QShowEvent> #include <QShowEvent>
#include <QPushButton> #include <QPushButton>
#include <QDebug> #include <QDebug>
#pragma GCC diagnostic warning "-Weffc++"
#include "../options.h" #include "../options.h"
DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) : DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) :

View File

@ -1,7 +1,9 @@
#ifndef DIALOGSINGLEPOINT_H #ifndef DIALOGSINGLEPOINT_H
#define DIALOGSINGLEPOINT_H #define DIALOGSINGLEPOINT_H
#pragma GCC diagnostic ignored "-Weffc++"
#include "dialogtool.h" #include "dialogtool.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "../container/vcontainer.h" #include "../container/vcontainer.h"
namespace Ui { namespace Ui {

View File

@ -38,8 +38,8 @@ void DialogSpline::ChoosedObject(qint64 id, Scene::Type type){
number = 0; number = 0;
index = ui->comboBoxP1->currentIndex(); index = ui->comboBoxP1->currentIndex();
qint64 p1Id = qvariant_cast<qint64>(ui->comboBoxP1->itemData(index)); qint64 p1Id = qvariant_cast<qint64>(ui->comboBoxP1->itemData(index));
QPointF p1 = data->GetPoint(p1Id); QPointF p1 = data->GetPoint(p1Id).toQPointF();
QPointF p4 = data->GetPoint(id); QPointF p4 = data->GetPoint(id).toQPointF();
ui->spinBoxAngle1->setValue(QLineF(p1, p4).angle()); ui->spinBoxAngle1->setValue(QLineF(p1, p4).angle());
ui->spinBoxAngle2->setValue(QLineF(p4, p1).angle()); ui->spinBoxAngle2->setValue(QLineF(p4, p1).angle());
} }
@ -51,10 +51,8 @@ void DialogSpline::ChoosedObject(qint64 id, Scene::Type type){
} }
void DialogSpline::DialogAccepted(){ void DialogSpline::DialogAccepted(){
qint32 index = ui->comboBoxP1->currentIndex(); p1 = getCurrentPointId(ui->comboBoxP1);
p1 = qvariant_cast<qint64>(ui->comboBoxP1->itemData(index)); p4 = getCurrentPointId(ui->comboBoxP4);
index = ui->comboBoxP4->currentIndex();
p4 = qvariant_cast<qint64>(ui->comboBoxP4->itemData(index));
angle1 = ui->spinBoxAngle1->value(); angle1 = ui->spinBoxAngle1->value();
angle2 = ui->spinBoxAngle2->value(); angle2 = ui->spinBoxAngle2->value();
kAsm1 = ui->doubleSpinBoxKasm1->value(); kAsm1 = ui->doubleSpinBoxKasm1->value();

View File

@ -43,15 +43,18 @@ void DialogTool::showEvent(QShowEvent *event){
isInitialized = true;//перший показ вікна вже відбувся isInitialized = true;//перший показ вікна вже відбувся
} }
void DialogTool::FillComboBoxPoints(QComboBox *box) const{ void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const{
box->clear();
const QMap<qint64, VPointF> *points = data->DataPoints(); const QMap<qint64, VPointF> *points = data->DataPoints();
QMapIterator<qint64, VPointF> i(*points); QMapIterator<qint64, VPointF> i(*points);
while (i.hasNext()) { while (i.hasNext()) {
i.next(); i.next();
if(i.key() != id){
VPointF point = i.value(); VPointF point = i.value();
box->addItem(point.name(), i.key()); box->addItem(point.name(), i.key());
} }
} }
}
void DialogTool::FillComboBoxTypeLine(QComboBox *box) const{ void DialogTool::FillComboBoxTypeLine(QComboBox *box) const{
QStringList list; QStringList list;
@ -89,7 +92,7 @@ void DialogTool::ChangeCurrentText(QComboBox *box, const QString &value){
} }
} }
void DialogTool::ChangeCurrentData(QComboBox *box, const qint64 &value){ void DialogTool::ChangeCurrentData(QComboBox *box, const qint64 &value) const{
qint32 index = box->findData(value); qint32 index = box->findData(value);
if(index != -1){ if(index != -1){
box->setCurrentIndex(index); box->setCurrentIndex(index);
@ -137,6 +140,25 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label)
timer->stop(); timer->stop();
} }
void DialogTool::setCurrentPointId(QComboBox *box, qint64 &pointId, const qint64 &value,
const qint64 &id) const{
Q_CHECK_PTR(box);
FillComboBoxPoints(box, id);
pointId = value;
ChangeCurrentData(box, value);
}
qint64 DialogTool::getCurrentPointId(QComboBox *box) const{
Q_CHECK_PTR(box);
qint32 index = box->currentIndex();
Q_ASSERT(index != -1);
if(index != -1){
return qvariant_cast<qint64>(box->itemData(index));
} else {
return -1;
}
}
void DialogTool::CheckState(){ void DialogTool::CheckState(){
Q_CHECK_PTR(bOk); Q_CHECK_PTR(bOk);
bOk->setEnabled(flagFormula & flagName); bOk->setEnabled(flagFormula & flagName);
@ -293,9 +315,9 @@ void DialogTool::ValChenged(int row){
} }
void DialogTool::UpdateList(){ void DialogTool::UpdateList(){
Q_CHECK_PTR(radioButtonSizeGrowth); if(radioButtonSizeGrowth == 0 || radioButtonStandartTable == 0 || radioButtonIncrements == 0){
Q_CHECK_PTR(radioButtonStandartTable); return;
Q_CHECK_PTR(radioButtonIncrements); }
if(radioButtonSizeGrowth->isChecked()){ if(radioButtonSizeGrowth->isChecked()){
ShowVariable(data->DataBase()); ShowVariable(data->DataBase());
} }

View File

@ -1,6 +1,7 @@
#ifndef DIALOGTOOL_H #ifndef DIALOGTOOL_H
#define DIALOGTOOL_H #define DIALOGTOOL_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QDialog> #include <QDialog>
#include <QComboBox> #include <QComboBox>
#include <QSpinBox> #include <QSpinBox>
@ -10,6 +11,7 @@
#include <QLabel> #include <QLabel>
#include <QRadioButton> #include <QRadioButton>
#include <QTimer> #include <QTimer>
#pragma GCC diagnostic warning "-Weffc++"
#include "../container/vcontainer.h" #include "../container/vcontainer.h"
#include "../options.h" #include "../options.h"
@ -62,17 +64,19 @@ protected:
QRadioButton *radioButtonLengthLine; QRadioButton *radioButtonLengthLine;
void closeEvent ( QCloseEvent * event ); void closeEvent ( QCloseEvent * event );
void showEvent( QShowEvent *event ); void showEvent( QShowEvent *event );
void FillComboBoxPoints(QComboBox *box)const; void FillComboBoxPoints(QComboBox *box, const qint64 &id = 0)const;
void FillComboBoxTypeLine(QComboBox *box) const; void FillComboBoxTypeLine(QComboBox *box) const;
virtual void CheckState(); virtual void CheckState();
QString GetTypeLine(const QComboBox *box)const; QString GetTypeLine(const QComboBox *box)const;
template <class key, class val> void ShowVariable(const QMap<key, val> *var); template <class key, class val> void ShowVariable(const QMap<key, val> *var);
void SetupTypeLine(QComboBox *box, const QString &value); void SetupTypeLine(QComboBox *box, const QString &value);
void ChangeCurrentText(QComboBox *box, const QString &value); void ChangeCurrentText(QComboBox *box, const QString &value);
void ChangeCurrentData(QComboBox *box, const qint64 &value); void ChangeCurrentData(QComboBox *box, const qint64 &value) const;
void PutValHere(QLineEdit *lineEdit, QListWidget *listWidget); void PutValHere(QLineEdit *lineEdit, QListWidget *listWidget);
void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer); void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer);
void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label);
void setCurrentPointId(QComboBox *box, qint64 &pointId, const qint64 &value, const qint64 &id) const;
qint64 getCurrentPointId(QComboBox *box) const;
}; };
#endif // DIALOGTOOL_H #endif // DIALOGTOOL_H

View File

@ -3,27 +3,38 @@
#include "varc.h" #include "varc.h"
#include <QDebug> #include <QDebug>
VArc::VArc (){ VArc::VArc () : f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), formulaRadius(QString()),
f1 = 0; center(0), points(0){
formulaF1 = QString();
f2 = 0;
formulaF2 = QString();
radius = 0;
formulaRadius = QString();
center = 0;
points = 0;
} }
VArc::VArc (const QMap<qint64, VPointF> *points, qint64 center, qreal radius, QString formulaRadius, VArc::VArc (const QMap<qint64, VPointF> *points, qint64 center, qreal radius, QString formulaRadius,
qreal f1, QString formulaF1, qreal f2, QString formulaF2 ){ qreal f1, QString formulaF1, qreal f2, QString formulaF2 )
this->points = points; : f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), radius(radius), formulaRadius(formulaRadius),
this->f1 = f1; center(center), points(points){
this->formulaF1 = formulaF1; }
this->f2 = f2;
this->formulaF2 = formulaF2; VArc::VArc(const VArc &arc): f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0),
this->radius = radius; formulaRadius(QString()), center(0), points(0){
this->formulaRadius = formulaRadius; this->points = arc.GetDataPoints();
this->center = center; this->f1 = arc.GetF1();
this->formulaF1 = arc.GetFormulaF1();
this->f2 = arc.GetF2();
this->formulaF2 = arc.GetFormulaF2();
this->radius = arc.GetRadius();
this->formulaRadius = arc.GetFormulaRadius();
this->center = arc.GetCenter();
}
const VArc &VArc::operator =(const VArc &arc){
this->points = arc.GetDataPoints();
this->f1 = arc.GetF1();
this->formulaF1 = arc.GetFormulaF1();
this->f2 = arc.GetF2();
this->formulaF2 = arc.GetFormulaF2();
this->radius = arc.GetRadius();
this->formulaRadius = arc.GetFormulaRadius();
this->center = arc.GetCenter();
return *this;
} }
qreal VArc::GetF1() const{ qreal VArc::GetF1() const{
@ -60,7 +71,7 @@ qint64 VArc::GetCenter() const{
QPointF VArc::GetCenterPoint() const{ QPointF VArc::GetCenterPoint() const{
if(points->contains(center)){ if(points->contains(center)){
return points->value(center); return points->value(center).toQPointF();
} else { } else {
qCritical()<<"Не можу знайти id = "<<center<<" в таблиці."; qCritical()<<"Не можу знайти id = "<<center<<" в таблиці.";
throw"Не можу знайти точку за id."; throw"Не можу знайти точку за id.";

View File

@ -24,6 +24,8 @@ public:
*/ */
VArc (const QMap<qint64, VPointF> *points, qint64 center, qreal radius, QString formulaRadius, VArc (const QMap<qint64, VPointF> *points, qint64 center, qreal radius, QString formulaRadius,
qreal f1, QString formulaF1, qreal f2 , QString formulaF2); qreal f1, QString formulaF1, qreal f2 , QString formulaF2);
VArc(const VArc &arc);
const VArc& operator= (const VArc &arc);
/** /**
* @brief GetF1 повертає початковий кут дуги. * @brief GetF1 повертає початковий кут дуги.
* @return повертає кут в градусах. * @return повертає кут в градусах.

View File

@ -57,8 +57,8 @@ void VSpline::ModifiSpl ( qint64 p1, qint64 p4, qreal angle1, qreal angle2,
// if ( angle > 180 ){ // if ( angle > 180 ){
// angle = 360 - angle; // angle = 360 - angle;
// } // }
QPointF point1 = GetPointP1(); QPointF point1 = GetPointP1().toQPointF();
QPointF point4 = GetPointP4(); QPointF point4 = GetPointP4().toQPointF();
radius = QLineF(QPointF(point1.x(), point4.y()),point4).length(); radius = QLineF(QPointF(point1.x(), point4.y()),point4).length();
// radius = QLineF(GetPointP1(), GetPointP4()).length() / 2 / sin( angle * M_PI / 180.0 ); // radius = QLineF(GetPointP1(), GetPointP4()).length() / 2 / sin( angle * M_PI / 180.0 );
L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 ); L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 );
@ -75,8 +75,8 @@ void VSpline::ModifiSpl (qint64 p1, QPointF p2, QPointF p3, qint64 p4, qreal kCu
this->p2 = p2; this->p2 = p2;
this->p3 = p3; this->p3 = p3;
this->p4 = p4; this->p4 = p4;
this->angle1 = QLineF ( GetPointP1(), p2 ).angle(); this->angle1 = QLineF ( GetPointP1().toQPointF(), p2 ).angle();
this->angle2 = QLineF ( GetPointP4(), p3 ).angle(); this->angle2 = QLineF ( GetPointP4().toQPointF(), p3 ).angle();
QLineF p1pX(GetPointP1().x(), GetPointP1().y(), GetPointP1().x() + 100, GetPointP1().y()); QLineF p1pX(GetPointP1().x(), GetPointP1().y(), GetPointP1().x() + 100, GetPointP1().y());
p1pX.setAngle( angle1 ); p1pX.setAngle( angle1 );
@ -85,15 +85,15 @@ void VSpline::ModifiSpl (qint64 p1, QPointF p2, QPointF p3, qint64 p4, qreal kCu
// if ( angle >= 180 ){ // if ( angle >= 180 ){
// angle = 360 - angle; // angle = 360 - angle;
// } // }
QPointF point1 = GetPointP1(); QPointF point1 = GetPointP1().toQPointF();
QPointF point4 = GetPointP4(); QPointF point4 = GetPointP4().toQPointF();
radius = QLineF(QPointF(point1.x(), point4.y()),point4).length(); radius = QLineF(QPointF(point1.x(), point4.y()),point4).length();
// radius = QLineF(GetPointP1(), GetPointP4()).length() / 2 / sin( angle * M_PI / 180.0 ); // radius = QLineF(GetPointP1(), GetPointP4()).length() / 2 / sin( angle * M_PI / 180.0 );
L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 ); L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 );
this->kCurve = kCurve; this->kCurve = kCurve;
this->kAsm1 = QLineF ( GetPointP1(), p2 ).length()/L; this->kAsm1 = QLineF ( GetPointP1().toQPointF(), p2 ).length()/L;
this->kAsm2 = QLineF ( GetPointP4(), p3 ).length()/L; this->kAsm2 = QLineF ( GetPointP4().toQPointF(), p3 ).length()/L;
} }
//void VSpline::RotationSpl (QPointF pRotate, qreal angle ){ //void VSpline::RotationSpl (QPointF pRotate, qreal angle ){
@ -165,7 +165,7 @@ qreal VSpline::GetAngle2 () const{
} }
qreal VSpline::GetLength () const{ qreal VSpline::GetLength () const{
return LengthBezier ( GetPointP1(), this->p2, this->p3, GetPointP4()); return LengthBezier ( GetPointP1().toQPointF(), this->p2, this->p3, GetPointP4().toQPointF());
} }
QString VSpline::GetName() const{ QString VSpline::GetName() const{
@ -274,7 +274,7 @@ void VSpline::PutAlongSpl (QPointF &moveP, qreal move ) const{
} }
QVector<QPointF> VSpline::GetPoints () const{ QVector<QPointF> VSpline::GetPoints () const{
return GetPoints(GetPointP1(), p2, p3, GetPointP4()); return GetPoints(GetPointP1().toQPointF(), p2, p3, GetPointP4().toQPointF());
} }
QVector<QPointF> VSpline::GetPoints (QPointF p1, QPointF p2, QPointF p3, QPointF p4) const{ QVector<QPointF> VSpline::GetPoints (QPointF p1, QPointF p2, QPointF p3, QPointF p4) const{

View File

@ -2,7 +2,9 @@
#define VSPLINEPATH_H #define VSPLINEPATH_H
#include "vsplinepoint.h" #include "vsplinepoint.h"
#pragma GCC diagnostic ignored "-Weffc++"
#include <QVector> #include <QVector>
#pragma GCC diagnostic warning "-Weffc++"
#include "vspline.h" #include "vspline.h"
namespace SplinePoint{ namespace SplinePoint{

View File

@ -1,8 +1,10 @@
#ifndef VSPLINEPOINT_H #ifndef VSPLINEPOINT_H
#define VSPLINEPOINT_H #define VSPLINEPOINT_H
#pragma GCC diagnostic ignored "-Weffc++"
#include "QtGlobal" #include "QtGlobal"
#include <QMetaType> #include <QMetaType>
#pragma GCC diagnostic pop
/** /**
* @brief The VSplinePoint клас, що містить у собі інформацію про точки сплайну. * @brief The VSplinePoint клас, що містить у собі інформацію про точки сплайну.

View File

@ -1,6 +1,8 @@
#pragma GCC diagnostic ignored "-Weffc++"
#include "mainwindow.h" #include "mainwindow.h"
#include <QApplication> #include <QApplication>
#include <QTextCodec> #include <QTextCodec>
#pragma GCC diagnostic warning "-Weffc++"
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg){ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg){
QByteArray localMsg = msg.toLocal8Bit(); QByteArray localMsg = msg.toLocal8Bit();

View File

@ -1,6 +1,6 @@
#pragma GCC diagnostic ignored "-Weffc++"
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QLabel> #include <QLabel>
#include <QSpinBox> #include <QSpinBox>
#include <QScrollBar> #include <QScrollBar>
@ -10,7 +10,6 @@
#include <QFileDialog> #include <QFileDialog>
#include <QDebug> #include <QDebug>
#include "options.h"
#include "tools/vtoolendline.h" #include "tools/vtoolendline.h"
#include "tools/vtoolline.h" #include "tools/vtoolline.h"
#include "tools/vtoolalongline.h" #include "tools/vtoolalongline.h"
@ -21,6 +20,8 @@
#include "tools/vtoolspline.h" #include "tools/vtoolspline.h"
#include "tools/vtoolarc.h" #include "tools/vtoolarc.h"
#include "tools/vtoolsplinepath.h" #include "tools/vtoolsplinepath.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "options.h"
#include "geometry/vspline.h" #include "geometry/vspline.h"
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
@ -33,7 +34,13 @@ MainWindow::MainWindow(QWidget *parent) :
ToolBarDraws(); ToolBarDraws();
QRectF sceneRect = QRectF(0, 0, PaperSize, PaperSize); QRectF sceneRect = QRectF(0, 0, PaperSize, PaperSize);
scene = new VMainGraphicsScene(sceneRect); scene = new VMainGraphicsScene(sceneRect);
ui->graphicsView->setScene(scene); view = new VMainGraphicsView();
ui->LayoutView->addWidget(view);
view->setScene(scene);
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
policy.setHorizontalStretch(12);
view->setSizePolicy(policy);
//view->setMinimumSize(800, 600);
connect(scene, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove); connect(scene, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
connect(ui->toolButtonSinglePoint, &QToolButton::clicked, this, connect(ui->toolButtonSinglePoint, &QToolButton::clicked, this,
@ -73,7 +80,6 @@ MainWindow::MainWindow(QWidget *parent) :
&MainWindow::ToolSplinePath); &MainWindow::ToolSplinePath);
data = new VContainer; data = new VContainer;
CreateManTableIGroup ();
doc = new VDomDocument(data); doc = new VDomDocument(data);
doc->CreateEmptyFile(); doc->CreateEmptyFile();
@ -159,6 +165,27 @@ void MainWindow::OptionDraw(){
comboBoxDraws->setItemText(index, nameDraw); comboBoxDraws->setItemText(index, nameDraw);
} }
template <typename Dialog, typename Func>
void MainWindow::SetToolButton(bool checked, Tools::Enum t, const QString &cursor,
QSharedPointer<Dialog> &dialog, Func closeDialogSlot){
if(checked){
CanselTool();
tool = t;
QPixmap pixmap(cursor);
QCursor cur(pixmap, 2, 3);
view->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialog = QSharedPointer<Dialog>(new Dialog(data));
connect(scene, &VMainGraphicsScene::ChoosedObject, dialog.data(), &Dialog::ChoosedObject);
connect(dialog.data(), &Dialog::DialogClosed, this, closeDialogSlot);
connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList);
} else {
if(QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())){
tButton->setChecked(true);
}
}
}
/* /*
* Інструмет базова точка креслення. * Інструмет базова точка креслення.
*/ */
@ -168,7 +195,7 @@ void MainWindow::ToolSinglePoint(bool checked){
tool = Tools::SinglePointTool; tool = Tools::SinglePointTool;
QPixmap pixmap(":/cursor/spoint_cursor.png"); QPixmap pixmap(":/cursor/spoint_cursor.png");
QCursor cur(pixmap, 2, 3); QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur); view->setCursor(cur);
helpLabel->setText("Виберіть розташування для точки."); helpLabel->setText("Виберіть розташування для точки.");
dialogSinglePoint = new DialogSinglePoint(data); dialogSinglePoint = new DialogSinglePoint(data);
//покажемо вікно як тільки буде вибрано місце розташування для точки //покажемо вікно як тільки буде вибрано місце розташування для точки
@ -181,444 +208,143 @@ void MainWindow::ToolSinglePoint(bool checked){
} }
} }
void MainWindow::ToolEndLine(bool checked){ void MainWindow::ClosedDialogSinglePoint(int result){
if(checked){ if(result == QDialog::Accepted){
CanselTool(); QPointF point = dialogSinglePoint->getPoint();
tool = Tools::EndLineTool; QString name = dialogSinglePoint->getName();
QPixmap pixmap(":/cursor/endline_cursor.png");
QCursor cur(pixmap, 2, 3); qint64 id = data->AddPoint(VPointF(point.x(), point.y(), name, 5, 10));
ui->graphicsView->setCursor(cur); VToolSinglePoint *spoint = new VToolSinglePoint(doc, data, id, Tool::FromGui);
helpLabel->setText("Заповніть усі поля."); scene->addItem(spoint);
dialogEndLine = new DialogEndLine(data, this); connect(spoint, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogEndLine, QMap<qint64, VDataTool*>* tools = doc->getTools();
&DialogEndLine::ChoosedObject); tools->insert(id, spoint);
connect(dialogEndLine, &DialogEndLine::DialogClosed, this, ArrowTool();
&MainWindow::ClosedDialogEndLine); ui->toolButtonSinglePoint->setEnabled(false);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogEndLine, &DialogEndLine::UpdateList); qint32 index = comboBoxDraws->currentIndex();
} else { comboBoxDraws->setItemData(index, false);
ui->toolButtonEndLine->setChecked(true); ui->actionSave->setEnabled(true);
SetEnableTool(true);
} }
ArrowTool();
}
void MainWindow::ToolEndLine(bool checked){
SetToolButton(checked, Tools::EndLineTool, ":/cursor/endline_cursor.png", dialogEndLine,
&MainWindow::ClosedDialogEndLine);
} }
void MainWindow::ClosedDialogEndLine(int result){ void MainWindow::ClosedDialogEndLine(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
QString pointName = dialogEndLine->getPointName(); VToolEndLine::Create(dialogEndLine, scene, doc, data);
QString typeLine = dialogEndLine->getTypeLine();
QString formula = dialogEndLine->getFormula();
qint32 angle = dialogEndLine->getAngle();
qint64 basePointId = dialogEndLine->getBasePointId();
VPointF basePoint = data->GetPoint(basePointId);
QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y()));
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
line.setAngle(angle);
qint64 id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, 5, 10));
data->AddLine(basePointId, id);
VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle, basePointId,
Tool::FromGui);
scene->addItem(point);
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
ArrowTool(); ArrowTool();
} }
void MainWindow::ToolLine(bool checked){ void MainWindow::ToolLine(bool checked){
if(checked){ SetToolButton(checked, Tools::LineTool, ":/cursor/line_cursor.png", dialogLine,
CanselTool(); &MainWindow::ClosedDialogLine);
tool = Tools::LineTool;
QPixmap pixmap(":/cursor/line_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogLine = new DialogLine(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogLine, &DialogLine::ChoosedObject);
connect(dialogLine, &DialogLine::DialogClosed, this, &MainWindow::ClosedDialogLine);
} else {
ui->toolButtonLine->setChecked(true);
}
} }
void MainWindow::ClosedDialogLine(int result){ void MainWindow::ClosedDialogLine(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
qint64 firstPoint = dialogLine->getFirstPoint(); VToolLine::Create(dialogLine, scene, doc, data);
qint64 secondPoint = dialogLine->getSecondPoint();
data->AddLine(firstPoint, secondPoint);
qint64 id = data->getNextId();
VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, Tool::FromGui);
scene->addItem(line);
connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
} }
ArrowTool(); ArrowTool();
} }
void MainWindow::ToolAlongLine(bool checked){ void MainWindow::ToolAlongLine(bool checked){
if(checked){ SetToolButton(checked, Tools::AlongLineTool, ":/cursor/alongline_cursor.png", dialogAlongLine,
CanselTool(); &MainWindow::ClosedDialogAlongLine);
tool = Tools::AlongLineTool;
QPixmap pixmap(":/cursor/alongline_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogAlongLine = new DialogAlongLine(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogAlongLine, &DialogAlongLine::ChoosedObject);
connect(dialogAlongLine, &DialogLine::DialogClosed, this, &MainWindow::ClosedDialogAlongLine);
} else {
ui->toolButtonAlongLine->setChecked(true);
}
} }
void MainWindow::ClosedDialogAlongLine(int result){ void MainWindow::ClosedDialogAlongLine(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
QString formula = dialogAlongLine->getFormula(); VToolAlongLine::Create(dialogAlongLine, scene, doc, data);
qint64 firstPointId = dialogAlongLine->getFirstPointId();
qint64 secondPointId = dialogAlongLine->getSecondPointId();
QString typeLine = dialogAlongLine->getTypeLine();
QString pointName = dialogAlongLine->getPointName();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF());
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
qint64 id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, 5, 10));
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId,
typeLine, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
ArrowTool(); ArrowTool();
} }
void MainWindow::ToolShoulderPoint(bool checked){ void MainWindow::ToolShoulderPoint(bool checked){
if(checked){ SetToolButton(checked, Tools::ShoulderPointTool, ":/cursor/shoulder_cursor.png", dialogShoulderPoint,
CanselTool();
tool = Tools::ShoulderPointTool;
QPixmap pixmap(":/cursor/shoulder_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogShoulderPoint = new DialogShoulderPoint(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogShoulderPoint,
&DialogShoulderPoint::ChoosedObject);
connect(dialogShoulderPoint, &DialogShoulderPoint::DialogClosed, this,
&MainWindow::ClosedDialogShoulderPoint); &MainWindow::ClosedDialogShoulderPoint);
} else {
ui->toolButtonShoulderPoint->setChecked(true);
}
} }
void MainWindow::ClosedDialogShoulderPoint(int result){ void MainWindow::ClosedDialogShoulderPoint(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
QString formula = dialogShoulderPoint->getFormula(); VToolShoulderPoint::Create(dialogShoulderPoint, scene, doc, data);
qint64 p1Line = dialogShoulderPoint->getP1Line();
qint64 p2Line = dialogShoulderPoint->getP2Line();
qint64 pShoulder = dialogShoulderPoint->getPShoulder();
QString typeLine = dialogShoulderPoint->getTypeLine();
QString pointName = dialogShoulderPoint->getPointName();
VPointF firstPoint = data->GetPoint(p1Line);
VPointF secondPoint = data->GetPoint(p2Line);
VPointF shoulderPoint = data->GetPoint(pShoulder);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint, secondPoint, shoulderPoint,
result*PrintDPI/25.4);
qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10));
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula, p1Line,
p2Line, pShoulder, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
ArrowTool(); ArrowTool();
} }
void MainWindow::ToolNormal(bool checked){ void MainWindow::ToolNormal(bool checked){
if(checked){ SetToolButton(checked, Tools::NormalTool, ":/cursor/normal_cursor.png", dialogNormal,
CanselTool();
tool = Tools::NormalTool;
QPixmap pixmap(":/cursor/normal_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogNormal = new DialogNormal(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogNormal,
&DialogNormal::ChoosedObject);
connect(dialogNormal, &DialogNormal::DialogClosed, this,
&MainWindow::ClosedDialogNormal); &MainWindow::ClosedDialogNormal);
} else {
ui->toolButtonNormal->setChecked(true);
}
} }
void MainWindow::ClosedDialogNormal(int result){ void MainWindow::ClosedDialogNormal(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
QString formula = dialogNormal->getFormula(); VToolNormal::Create(dialogNormal, scene, doc, data);
qint64 firstPointId = dialogNormal->getFirstPointId();
qint64 secondPointId = dialogNormal->getSecondPointId();
QString typeLine = dialogNormal->getTypeLine();
QString pointName = dialogNormal->getPointName();
qint32 angle = dialogNormal->getAngle();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolNormal::FindPoint(firstPoint, secondPoint, result*PrintDPI/25.4,
angle);
qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10));
data->AddLine(firstPointId, id);
VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle, firstPointId,
secondPointId, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
ArrowTool(); ArrowTool();
} }
void MainWindow::ToolBisector(bool checked){ void MainWindow::ToolBisector(bool checked){
if(checked){ SetToolButton(checked, Tools::BisectorTool, ":/cursor/bisector_cursor.png", dialogBisector,
CanselTool();
tool = Tools::BisectorTool;
QPixmap pixmap(":/cursor/bisector_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogBisector = new DialogBisector(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogBisector,
&DialogBisector::ChoosedObject);
connect(dialogBisector, &DialogBisector::DialogClosed, this,
&MainWindow::ClosedDialogBisector); &MainWindow::ClosedDialogBisector);
} else {
ui->toolButtonBisector->setChecked(true);
}
} }
void MainWindow::ClosedDialogBisector(int result){ void MainWindow::ClosedDialogBisector(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
QString formula = dialogBisector->getFormula(); VToolBisector::Create(dialogBisector, scene, doc, data);
qint64 firstPointId = dialogBisector->getFirstPointId();
qint64 secondPointId = dialogBisector->getSecondPointId();
qint64 thirdPointId = dialogBisector->getThirdPointId();
QString typeLine = dialogBisector->getTypeLine();
QString pointName = dialogBisector->getPointName();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
VPointF thirdPoint = data->GetPoint(thirdPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolBisector::FindPoint(firstPoint, secondPoint, thirdPoint,
result*PrintDPI/25.4);
qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10));
data->AddLine(secondPointId, id);
VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId,
secondPointId, thirdPointId, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
ArrowTool(); ArrowTool();
} }
void MainWindow::ToolLineIntersect(bool checked){ void MainWindow::ToolLineIntersect(bool checked){
if(checked){ SetToolButton(checked, Tools::LineIntersectTool, ":/cursor/intersect_cursor.png", dialogLineIntersect,
CanselTool();
tool = Tools::LineIntersectTool;
QPixmap pixmap(":/cursor/intersect_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogLineIntersect = new DialogLineIntersect(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogLineIntersect,
&DialogLineIntersect::ChoosedObject);
connect(dialogLineIntersect, &DialogLineIntersect::DialogClosed, this,
&MainWindow::ClosedDialogLineIntersect); &MainWindow::ClosedDialogLineIntersect);
} else {
ui->toolButtonLineIntersect->setChecked(true);
}
} }
void MainWindow::ClosedDialogLineIntersect(int result){ void MainWindow::ClosedDialogLineIntersect(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
qint64 p1Line1Id = dialogLineIntersect->getP1Line1(); VToolLineIntersect::Create(dialogLineIntersect, scene, doc, data);
qint64 p2Line1Id = dialogLineIntersect->getP2Line1();
qint64 p1Line2Id = dialogLineIntersect->getP1Line2();
qint64 p2Line2Id = dialogLineIntersect->getP2Line2();
QString pointName = dialogLineIntersect->getPointName();
VPointF p1Line1 = data->GetPoint(p1Line1Id);
VPointF p2Line1 = data->GetPoint(p2Line1Id);
VPointF p1Line2 = data->GetPoint(p1Line2Id);
VPointF p2Line2 = data->GetPoint(p2Line2Id);
QLineF line1(p1Line1, p2Line1);
QLineF line2(p1Line2, p2Line2);
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){
qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10));
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id,
p2Line1Id, p1Line2Id,
p2Line2Id, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolLineIntersect::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
ArrowTool(); ArrowTool();
} }
void MainWindow::ToolSpline(bool checked){ void MainWindow::ToolSpline(bool checked){
if(checked){ SetToolButton(checked, Tools::SplineTool, ":/cursor/spline_cursor.png", dialogSpline,
CanselTool();
tool = Tools::SplineTool;
QPixmap pixmap(":/cursor/spline_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogSpline = new DialogSpline(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogSpline,
&DialogSpline::ChoosedObject);
connect(dialogSpline, &DialogSpline::DialogClosed, this,
&MainWindow::ClosedDialogSpline); &MainWindow::ClosedDialogSpline);
} else {
ui->toolButtonSpline->setChecked(true);
}
} }
void MainWindow::ClosedDialogSpline(int result){ void MainWindow::ClosedDialogSpline(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
qint64 p1 = dialogSpline->getP1(); VToolSpline::Create(dialogSpline, scene, doc, data);
qint64 p4 = dialogSpline->getP4();
qreal kAsm1 = dialogSpline->getKAsm1();
qreal kAsm2 = dialogSpline->getKAsm2();
qreal angle1 = dialogSpline->getAngle1();
qreal angle2 = dialogSpline->getAngle2();
qreal kCurve = dialogSpline->getKCurve();
VSpline spline = VSpline(data->DataPoints(), p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve);
qint64 id = data->AddSpline(spline);
data->AddLengthSpline(data->GetNameSpline(p1, p4), spline.GetLength());
VToolSpline *spl = new VToolSpline(doc, data, id, Tool::FromGui);
scene->addItem(spl);
connect(spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
} }
ArrowTool(); ArrowTool();
} }
void MainWindow::ToolArc(bool checked){ void MainWindow::ToolArc(bool checked){
if(checked){ SetToolButton(checked, Tools::ArcTool, ":/cursor/arc_cursor.png", dialogArc,
CanselTool();
tool = Tools::ArcTool;
QPixmap pixmap(":/cursor/arc_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точку центру.");
dialogArc = new DialogArc(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogArc,
&DialogArc::ChoosedObject);
connect(dialogArc, &DialogArc::DialogClosed, this,
&MainWindow::ClosedDialogArc); &MainWindow::ClosedDialogArc);
} else {
ui->toolButtonSpline->setChecked(true);
}
} }
void MainWindow::ClosedDialogArc(int result){ void MainWindow::ClosedDialogArc(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
qint64 center = dialogArc->GetCenter(); VToolArc::Create(dialogArc, scene, doc, data);
QString radius = dialogArc->GetRadius();
QString f1 = dialogArc->GetF1();
QString f2 = dialogArc->GetF2();
qreal calcRadius, calcF1, calcF2;
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(radius, &errorMsg);
if(errorMsg.isEmpty()){
calcRadius = result*PrintDPI/25.4;
}
errorMsg.clear();
result = cal.eval(f1, &errorMsg);
if(errorMsg.isEmpty()){
calcF1 = result;
}
errorMsg.clear();
result = cal.eval(f2, &errorMsg);
if(errorMsg.isEmpty()){
calcF2 = result;
}
VArc arc = VArc(data->DataPoints(), center, calcRadius, radius, calcF1, f1, calcF2, f2 );
qint64 id = data->AddArc(arc);
data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength());
VToolArc *toolArc = new VToolArc(doc, data, id, Tool::FromGui);
scene->addItem(toolArc);
connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
} }
ArrowTool(); ArrowTool();
} }
void MainWindow::ToolSplinePath(bool checked){ void MainWindow::ToolSplinePath(bool checked){
if(checked){ SetToolButton(checked, Tools::SplinePathTool, ":/cursor/splinepath_cursor.png", dialogSplinePath,
CanselTool();
tool = Tools::SplinePathTool;
QPixmap pixmap(":/cursor/splinepath_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точку.");
dialogSplinePath = new DialogSplinePath(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogSplinePath,
&DialogSplinePath::ChoosedObject);
connect(dialogSplinePath, &DialogSplinePath::DialogClosed, this,
&MainWindow::ClosedDialogSplinePath); &MainWindow::ClosedDialogSplinePath);
} else {
ui->toolButtonSplinePath->setChecked(true);
}
} }
void MainWindow::ClosedDialogSplinePath(int result){ void MainWindow::ClosedDialogSplinePath(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
VSplinePath path = dialogSplinePath->GetPath(); VToolSplinePath::Create(dialogSplinePath, scene, doc, data);
qint64 id = data->AddSplinePath(path);
data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength());
VToolSplinePath *tool = new VToolSplinePath(doc, data, id, Tool::FromGui);
scene->addItem(tool);
connect(tool, &VToolSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
} }
ArrowTool(); ArrowTool();
} }
@ -633,9 +359,9 @@ void MainWindow::showEvent( QShowEvent *event ){
return; return;
} }
// do your init stuff here // do your init stuff here
QScrollBar *horScrollBar = ui->graphicsView->horizontalScrollBar(); QScrollBar *horScrollBar = view->horizontalScrollBar();
horScrollBar->setValue(horScrollBar->minimum()); horScrollBar->setValue(horScrollBar->minimum());
QScrollBar *verScrollBar = ui->graphicsView->verticalScrollBar(); QScrollBar *verScrollBar = view->verticalScrollBar();
verScrollBar->setValue(verScrollBar->minimum()); verScrollBar->setValue(verScrollBar->minimum());
isInitialized = true;//перший показ вікна вже відбувся isInitialized = true;//перший показ вікна вже відбувся
@ -731,61 +457,61 @@ void MainWindow::CanselTool(){
ui->toolButtonSinglePoint->setChecked(false); ui->toolButtonSinglePoint->setChecked(false);
break; break;
case Tools::EndLineTool: case Tools::EndLineTool:
delete dialogEndLine; dialogEndLine.clear();
ui->toolButtonEndLine->setChecked(false); ui->toolButtonEndLine->setChecked(false);
scene->setFocus(Qt::OtherFocusReason); scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection(); scene->clearSelection();
break; break;
case Tools::LineTool: case Tools::LineTool:
delete dialogLine; dialogLine.clear();
ui->toolButtonLine->setChecked(false); ui->toolButtonLine->setChecked(false);
scene->setFocus(Qt::OtherFocusReason); scene->setFocus(Qt::OtherFocusReason);
scene->clearFocus(); scene->clearFocus();
break; break;
case Tools::AlongLineTool: case Tools::AlongLineTool:
delete dialogAlongLine; dialogAlongLine.clear();
ui->toolButtonAlongLine->setChecked(false); ui->toolButtonAlongLine->setChecked(false);
scene->setFocus(Qt::OtherFocusReason); scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection(); scene->clearSelection();
break; break;
case Tools::ShoulderPointTool: case Tools::ShoulderPointTool:
delete dialogShoulderPoint; dialogShoulderPoint.clear();
ui->toolButtonShoulderPoint->setChecked(false); ui->toolButtonShoulderPoint->setChecked(false);
scene->setFocus(Qt::OtherFocusReason); scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection(); scene->clearSelection();
break; break;
case Tools::NormalTool: case Tools::NormalTool:
delete dialogNormal; dialogNormal.clear();
ui->toolButtonNormal->setChecked(false); ui->toolButtonNormal->setChecked(false);
scene->setFocus(Qt::OtherFocusReason); scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection(); scene->clearSelection();
break; break;
case Tools::BisectorTool: case Tools::BisectorTool:
delete dialogBisector; dialogBisector.clear();
ui->toolButtonBisector->setChecked(false); ui->toolButtonBisector->setChecked(false);
scene->setFocus(Qt::OtherFocusReason); scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection(); scene->clearSelection();
break; break;
case Tools::LineIntersectTool: case Tools::LineIntersectTool:
delete dialogLineIntersect; dialogLineIntersect.clear();
ui->toolButtonLineIntersect->setChecked(false); ui->toolButtonLineIntersect->setChecked(false);
scene->setFocus(Qt::OtherFocusReason); scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection(); scene->clearSelection();
break; break;
case Tools::SplineTool: case Tools::SplineTool:
delete dialogSpline; dialogSpline.clear();
ui->toolButtonSpline->setChecked(false); ui->toolButtonSpline->setChecked(false);
scene->setFocus(Qt::OtherFocusReason); scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection(); scene->clearSelection();
break; break;
case Tools::ArcTool: case Tools::ArcTool:
delete dialogArc; dialogArc.clear();
ui->toolButtonArc->setChecked(false); ui->toolButtonArc->setChecked(false);
scene->setFocus(Qt::OtherFocusReason); scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection(); scene->clearSelection();
break; break;
case Tools::SplinePathTool: case Tools::SplinePathTool:
delete dialogSplinePath; dialogSplinePath.clear();
ui->toolButtonSplinePath->setChecked(false); ui->toolButtonSplinePath->setChecked(false);
scene->setFocus(Qt::OtherFocusReason); scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection(); scene->clearSelection();
@ -798,7 +524,7 @@ void MainWindow::ArrowTool(){
ui->actionArrowTool->setChecked(true); ui->actionArrowTool->setChecked(true);
tool = Tools::ArrowTool; tool = Tools::ArrowTool;
QCursor cur(Qt::ArrowCursor); QCursor cur(Qt::ArrowCursor);
ui->graphicsView->setCursor(cur); view->setCursor(cur);
helpLabel->setText(""); helpLabel->setText("");
} }
@ -815,24 +541,6 @@ void MainWindow::keyPressEvent ( QKeyEvent * event ){
QMainWindow::keyPressEvent ( event ); QMainWindow::keyPressEvent ( event );
} }
void MainWindow::ClosedDialogSinglePoint(int result){
if(result == QDialog::Accepted){
QPointF point = dialogSinglePoint->getPoint();
QString name = dialogSinglePoint->getName();
qint64 id = data->AddPoint(VPointF(point.x(), point.y(), name, 5, 10));
VToolSinglePoint *spoint = new VToolSinglePoint(doc, data, id, Tool::FromGui);
scene->addItem(spoint);
connect(spoint, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
ArrowTool();
ui->toolButtonSinglePoint->setEnabled(false);
qint32 index = comboBoxDraws->currentIndex();
comboBoxDraws->setItemData(index, false);
ui->actionSave->setEnabled(true);
SetEnableTool(true);
}
ArrowTool();
}
void MainWindow::ActionDraw(bool checked){ void MainWindow::ActionDraw(bool checked){
if(checked){ if(checked){
ui->actionDetails->setChecked(false); ui->actionDetails->setChecked(false);
@ -854,6 +562,8 @@ void MainWindow::ActionSaveAs(){
QString defaultFilter("Lekalo files (*.xml)"); QString defaultFilter("Lekalo files (*.xml)");
QString fName = QFileDialog::getSaveFileName(this, "Зберегти файл як", QDir::homePath(), QString fName = QFileDialog::getSaveFileName(this, "Зберегти файл як", QDir::homePath(),
filters, &defaultFilter); filters, &defaultFilter);
if(fName.isEmpty())
return;
if(fName.indexOf(".xml",fName.size()-4)<0){ if(fName.indexOf(".xml",fName.size()-4)<0){
fName.append(".xml"); fName.append(".xml");
} }
@ -891,6 +601,8 @@ void MainWindow::ActionSave(){
void MainWindow::ActionOpen(){ void MainWindow::ActionOpen(){
QString filter("Lekalo files (*.xml)"); QString filter("Lekalo files (*.xml)");
QString fName = QFileDialog::getOpenFileName(this, tr("Відкрити файл"), QDir::homePath(), filter); QString fName = QFileDialog::getOpenFileName(this, tr("Відкрити файл"), QDir::homePath(), filter);
if(fName.isEmpty())
return;
fileName = fName; fileName = fName;
QFileInfo info(fileName); QFileInfo info(fileName);
QString title(info.fileName()); QString title(info.fileName());
@ -899,11 +611,12 @@ void MainWindow::ActionOpen(){
QFile file(fileName); QFile file(fileName);
if(file.open(QIODevice::ReadOnly)){ if(file.open(QIODevice::ReadOnly)){
if(doc->setContent(&file)){ if(doc->setContent(&file)){
scene->clear();
comboBoxDraws->clear(); comboBoxDraws->clear();
// ui->toolButtonSinglePoint->setEnabled(true);
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged); this, &MainWindow::currentDrawChanged);
doc->Parse(Document::FullParse, scene, comboBoxDraws); doc->Parse(Document::FullParse, scene, comboBoxDraws);
CreateManTableIGroup ();
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged); this, &MainWindow::currentDrawChanged);
ui->actionSave->setEnabled(true); ui->actionSave->setEnabled(true);
@ -914,10 +627,7 @@ void MainWindow::ActionOpen(){
if ( index != -1 ) { // -1 for not found if ( index != -1 ) { // -1 for not found
comboBoxDraws->setCurrentIndex(index); comboBoxDraws->setCurrentIndex(index);
} }
if(comboBoxDraws->count() == 1){
}
file.close();
}
if(ui->toolButtonSinglePoint->isEnabled()==false){ if(ui->toolButtonSinglePoint->isEnabled()==false){
SetEnableTool(true); SetEnableTool(true);
} else { } else {
@ -925,11 +635,17 @@ void MainWindow::ActionOpen(){
} }
} }
}
file.close();
}
}
void MainWindow::ActionNew(){ void MainWindow::ActionNew(){
setWindowTitle("Valentina"); setWindowTitle("Valentina");
fileName.clear();
data->Clear(); data->Clear();
doc->clear(); doc->clear();
CreateManTableIGroup (); scene->clear();
CanselTool(); CanselTool();
comboBoxDraws->clear(); comboBoxDraws->clear();
fileName.clear(); fileName.clear();
@ -945,64 +661,6 @@ void MainWindow::haveChange(){
} }
} }
void MainWindow::CreateManTableIGroup () const{
data->AddStandartTableCell("Pkor", VStandartTableCell(84, 0, 3));
data->AddStandartTableCell("Pkor", VStandartTableCell(84, 0, 3));
data->AddStandartTableCell("Vtos", VStandartTableCell(1450, 2, 51));
data->AddStandartTableCell("Vtosh", VStandartTableCell(1506, 2, 54));
data->AddStandartTableCell("Vpt", VStandartTableCell(1438, 3, 52));
data->AddStandartTableCell("Vst", VStandartTableCell(1257, -1, 49));
data->AddStandartTableCell("Vlt", VStandartTableCell(1102, 0, 43));
data->AddStandartTableCell("Vk", VStandartTableCell(503, 0, 22));
data->AddStandartTableCell("Vsht", VStandartTableCell(1522, 2, 54));
data->AddStandartTableCell("Vzy", VStandartTableCell(1328, 0, 49));
data->AddStandartTableCell("Vlop", VStandartTableCell(1320, 0, 49));
data->AddStandartTableCell("Vps", VStandartTableCell(811, -1, 36));
data->AddStandartTableCell("Osh", VStandartTableCell(404,8, 2));
data->AddStandartTableCell("OgI", VStandartTableCell(1034, 36, 4));
data->AddStandartTableCell("OgII", VStandartTableCell(1044, 38, 2));
data->AddStandartTableCell("OgIII", VStandartTableCell(1000, 40, 0));
data->AddStandartTableCell("Ot", VStandartTableCell(780, 40, 0));
data->AddStandartTableCell("Ob", VStandartTableCell(984, 30, 10));
data->AddStandartTableCell("ObI", VStandartTableCell(964, 24, 12));
data->AddStandartTableCell("Obed", VStandartTableCell(566, 18, 6));
data->AddStandartTableCell("Ok", VStandartTableCell(386, 8, 8));
data->AddStandartTableCell("Oi", VStandartTableCell(380, 8, 6));
data->AddStandartTableCell("Osch", VStandartTableCell(234, 4, 4));
data->AddStandartTableCell("Os", VStandartTableCell(350, 2, 8));
data->AddStandartTableCell("Dsb", VStandartTableCell(1120, 0, 44));
data->AddStandartTableCell("Dsp", VStandartTableCell(1110, 0, 43));
data->AddStandartTableCell("Dn", VStandartTableCell(826, -3, 37));
data->AddStandartTableCell("Dps", VStandartTableCell(316, 4, 7));
data->AddStandartTableCell("Dpob", VStandartTableCell(783, 14, 15));
data->AddStandartTableCell("Ds", VStandartTableCell(260, 1, 6));
data->AddStandartTableCell("Op", VStandartTableCell(316, 12, 0));
data->AddStandartTableCell("Ozap", VStandartTableCell(180, 4, 0));
data->AddStandartTableCell("Pkis", VStandartTableCell(250, 4, 0));
data->AddStandartTableCell("SHp", VStandartTableCell(160, 1, 4));
data->AddStandartTableCell("Dlych", VStandartTableCell(500, 2, 15));
data->AddStandartTableCell("Dzap", VStandartTableCell(768, 2, 24));
data->AddStandartTableCell("DIIIp", VStandartTableCell(970, 2, 29));
data->AddStandartTableCell("Vprp", VStandartTableCell(214, 3, 3));
data->AddStandartTableCell("Vg", VStandartTableCell(262, 8, 3));
data->AddStandartTableCell("Dtp", VStandartTableCell(460, 7, 9));
data->AddStandartTableCell("Dp", VStandartTableCell(355, 5, 5));
data->AddStandartTableCell("Vprz", VStandartTableCell(208, 3, 5));
data->AddStandartTableCell("Dts", VStandartTableCell(438, 2, 10));
data->AddStandartTableCell("DtsI", VStandartTableCell(469, 2, 10));
data->AddStandartTableCell("Dvcht", VStandartTableCell(929, 9, 19));
data->AddStandartTableCell("SHg", VStandartTableCell(370, 14, 4));
data->AddStandartTableCell("Cg", VStandartTableCell(224, 6, 0));
data->AddStandartTableCell("SHs", VStandartTableCell(416, 10, 2));
data->AddStandartTableCell("dpzr", VStandartTableCell(121, 6, 0));
data->AddStandartTableCell("Ogol", VStandartTableCell(576, 4, 4));
data->AddStandartTableCell("Ssh1", VStandartTableCell(205, 5, 0));
data->AddStandartTableCell("St", VStandartTableCell(410, 20, 0));
data->AddStandartTableCell("Drzap", VStandartTableCell(594, 3, 19));
data->AddStandartTableCell("DbII", VStandartTableCell(1020, 0, 44));
data->AddStandartTableCell("Sb", VStandartTableCell(504, 15, 4));
}
void MainWindow::ChangedSize(const QString & text){ void MainWindow::ChangedSize(const QString & text){
qint32 size = text.toInt(); qint32 size = text.toInt();
data->SetSize(size*10); data->SetSize(size*10);

View File

@ -1,13 +1,17 @@
#ifndef MAINWINDOW_H #ifndef MAINWINDOW_H
#define MAINWINDOW_H #define MAINWINDOW_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QMainWindow> #include <QMainWindow>
#include <QLabel> #include <QLabel>
#include <QtXml> #include <QtXml>
#include <QComboBox> #include <QComboBox>
#include <QSharedPointer> #include <QSharedPointer>
#include <QToolButton>
#include <QSharedPointer>
#include "widgets/vmaingraphicsscene.h" #include "widgets/vmaingraphicsscene.h"
#include "widgets/vmaingraphicsview.h"
#include "dialogs/dialogsinglepoint.h" #include "dialogs/dialogsinglepoint.h"
#include "dialogs/dialogincrements.h" #include "dialogs/dialogincrements.h"
#include "dialogs/dialogline.h" #include "dialogs/dialogline.h"
@ -22,6 +26,7 @@
#include "dialogs/dialogsplinepath.h" #include "dialogs/dialogsplinepath.h"
#include "tools/vtoolsinglepoint.h" #include "tools/vtoolsinglepoint.h"
#include "xml/vdomdocument.h" #include "xml/vdomdocument.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "container/vcontainer.h" #include "container/vcontainer.h"
namespace Ui { namespace Ui {
@ -100,19 +105,20 @@ private:
VMainGraphicsScene *scene; VMainGraphicsScene *scene;
QLabel *mouseCoordinate; QLabel *mouseCoordinate;
QLabel *helpLabel; QLabel *helpLabel;
VMainGraphicsView *view;
bool isInitialized; bool isInitialized;
DialogSinglePoint *dialogSinglePoint; DialogSinglePoint *dialogSinglePoint;
DialogIncrements *dialogTable; DialogIncrements *dialogTable;
DialogEndLine *dialogEndLine; QSharedPointer<DialogEndLine> dialogEndLine;
DialogLine *dialogLine; QSharedPointer<DialogLine> dialogLine;
DialogAlongLine *dialogAlongLine; QSharedPointer<DialogAlongLine> dialogAlongLine;
DialogShoulderPoint *dialogShoulderPoint; QSharedPointer<DialogShoulderPoint> dialogShoulderPoint;
DialogNormal *dialogNormal; QSharedPointer<DialogNormal> dialogNormal;
DialogBisector *dialogBisector; QSharedPointer<DialogBisector> dialogBisector;
DialogLineIntersect *dialogLineIntersect; QSharedPointer<DialogLineIntersect> dialogLineIntersect;
DialogSpline *dialogSpline; QSharedPointer<DialogSpline> dialogSpline;
DialogArc *dialogArc; QSharedPointer<DialogArc> dialogArc;
DialogSplinePath *dialogSplinePath; QSharedPointer<DialogSplinePath> dialogSplinePath;
VDomDocument *doc; VDomDocument *doc;
VContainer *data; VContainer *data;
QComboBox *comboBoxDraws; QComboBox *comboBoxDraws;
@ -122,9 +128,11 @@ private:
void ToolBarDraws(); void ToolBarDraws();
void CanselTool(); void CanselTool();
void ArrowTool(); void ArrowTool();
void CreateManTableIGroup () const;
void SetEnableWidgets(bool enable); void SetEnableWidgets(bool enable);
void SetEnableTool(bool enable); void SetEnableTool(bool enable);
template <typename Dialog, typename Func>
void SetToolButton(bool checked, Tools::Enum t, const QString &cursor, QSharedPointer<Dialog> &dialog,
Func closeDialogSlot);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -14,62 +14,35 @@
<string>Valentina</string> <string>Valentina</string>
</property> </property>
<widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout">
<item row="0" column="2"> <item>
<widget class="QGraphicsView" name="graphicsView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>6</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>922</width>
<height>582</height>
</size>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="sceneRect">
<rectf>
<x>0.000000000000000</x>
<y>0.000000000000000</y>
<width>50000.000000000000000</width>
<height>50000.000000000000000</height>
</rectf>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing</set>
</property>
<property name="renderHints">
<set>QPainter::Antialiasing|QPainter::TextAntialiasing</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolBox" name="toolBox"> <widget class="QToolBox" name="toolBox">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Fixed" vsizetype="Minimum">
<horstretch>1</horstretch> <horstretch>1</horstretch>
<verstretch>0</verstretch> <verstretch>1</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="page"> <widget class="QWidget" name="page">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>154</width> <width>150</width>
<height>104</height> <height>104</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Maximum"> <sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -229,12 +202,12 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>154</width> <width>1074</width>
<height>58</height> <height>58</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -296,12 +269,12 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>154</width> <width>1074</width>
<height>58</height> <height>58</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -363,12 +336,12 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>154</width> <width>1074</width>
<height>58</height> <height>58</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -404,6 +377,16 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="LayoutView" stretch="">
<property name="spacing">
<number>10</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QMenuBar" name="menuBar"> <widget class="QMenuBar" name="menuBar">

View File

@ -1,16 +1,19 @@
#pragma GCC diagnostic ignored "-Weffc++"
#include "vabstracttool.h" #include "vabstracttool.h"
#include <QDebug> #include <QDebug>
#pragma GCC diagnostic pop
VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id){ VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent):
VDataTool(data, parent){
this->doc = doc; this->doc = doc;
this->data = data;
this->id = id; this->id = id;
nameActivDraw = doc->GetNameActivDraw(); nameActivDraw = doc->GetNameActivDraw();
ignoreContextMenuEvent = false;//don't ignore context menu events; ignoreContextMenuEvent = false;//don't ignore context menu events;
connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VAbstractTool::ChangedActivDraw); connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VAbstractTool::ChangedActivDraw);
connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VAbstractTool::ChangedNameDraw); connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VAbstractTool::ChangedNameDraw);
connect(this, &VAbstractTool::haveLiteChange, this->doc, &VDomDocument::haveLiteChange); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange);
connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile); connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile);
connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree);
} }
@ -65,3 +68,14 @@ void VAbstractTool::AddToCalculation(const QDomElement &domElement){
qCritical()<<"Не можу знайти тег калькуляції."<< Q_FUNC_INFO; qCritical()<<"Не можу знайти тег калькуляції."<< Q_FUNC_INFO;
} }
} }
const VContainer *VAbstractTool::getData()const{
return &data;
}
void VAbstractTool::setData(const VContainer &value){
data = value;
}
void VAbstractTool::setDialog(){
}

View File

@ -1,10 +1,12 @@
#ifndef VABSTRACTTOOL_H #ifndef VABSTRACTTOOL_H
#define VABSTRACTTOOL_H #define VABSTRACTTOOL_H
#include <QObject> #pragma GCC diagnostic ignored "-Weffc++"
#include <QMenu>
#include "../container/vcontainer.h"
#include "../xml/vdomdocument.h" #include "../xml/vdomdocument.h"
#include "vdatatool.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "../container/vcontainer.h"
namespace Tool{ namespace Tool{
enum Enum enum Enum
@ -14,24 +16,24 @@ namespace Tool{
}; };
} }
class VAbstractTool:public QObject class VAbstractTool:public VDataTool
{ {
Q_OBJECT Q_OBJECT
public: public:
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id); VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0);
virtual ~VAbstractTool(); virtual ~VAbstractTool();
virtual void setDialog();
public slots: public slots:
virtual void FullUpdateFromFile()=0; virtual void FullUpdateFromFile()=0;
void ChangedNameDraw(const QString oldName, const QString newName); void ChangedNameDraw(const QString oldName, const QString newName);
virtual void ChangedActivDraw(const QString newName); virtual void ChangedActivDraw(const QString newName);
virtual void FullUpdateFromGui(int result)=0; virtual void FullUpdateFromGui(int result)=0;
signals: signals:
void haveLiteChange(); void toolhaveChange();
void ChoosedTool(qint64 id, Scene::Type type); void ChoosedTool(qint64 id, Scene::Type type);
void FullUpdateTree(); void FullUpdateTree();
protected: protected:
VDomDocument *doc; VDomDocument *doc;
VContainer *data;
qint64 id; qint64 id;
bool ignoreContextMenuEvent; bool ignoreContextMenuEvent;
QString nameActivDraw; QString nameActivDraw;
@ -41,5 +43,28 @@ protected:
void AddAttribute(QDomElement &domElement, const QString &name, const qreal &value); void AddAttribute(QDomElement &domElement, const QString &name, const qreal &value);
void AddAttribute(QDomElement &domElement, const QString &name, const QString &value); void AddAttribute(QDomElement &domElement, const QString &name, const QString &value);
void AddToCalculation(const QDomElement &domElement); void AddToCalculation(const QDomElement &domElement);
const VContainer *getData() const;
void setData(const VContainer &value);
template <typename Dialog, typename Tool>
void ContextMenu(QSharedPointer<Dialog> &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialog = QSharedPointer<Dialog>(new Dialog(getData()));
connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), &VMainGraphicsScene::ChoosedObject,
dialog.data(), &Dialog::ChoosedObject);
connect(dialog.data(), &Dialog::DialogClosed, tool,
&Tool::FullUpdateFromGui);
connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList);
tool->setDialog();
dialog->show();
}
}
}
}; };
#endif // VABSTRACTTOOL_H #endif // VABSTRACTTOOL_H

23
tools/vdatatool.cpp Normal file
View File

@ -0,0 +1,23 @@
#pragma GCC diagnostic ignored "-Weffc++"
#include "vdatatool.h"
#pragma GCC diagnostic warning "-Weffc++"
VDataTool::VDataTool(VContainer *data, QObject *parent) :
QObject(parent){
this->data = *data;
}
VDataTool::~VDataTool(){
}
const VDataTool &VDataTool::operator =(const VDataTool &tool){
data = tool.getData();
}
VContainer VDataTool::getData() const{
return data;
}
void VDataTool::setData(const VContainer *value){
data = *value;
}

28
tools/vdatatool.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef VDATATOOL_H
#define VDATATOOL_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QObject>
#pragma GCC diagnostic warning "-Weffc++"
#include "../container/vcontainer.h"
class VDataTool : public QObject
{
Q_OBJECT
public:
explicit VDataTool(VContainer *data, QObject *parent = 0);
virtual ~VDataTool();
const VDataTool& operator= (const VDataTool &tool);
VContainer getData() const;
void setData(const VContainer *value);
signals:
public slots:
protected:
VContainer data;
};
#endif // VDATATOOL_H

View File

@ -44,35 +44,11 @@ void VToolAlongLine::FullUpdateFromGui(int result){
} }
void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){ ContextMenu(dialogAlongLine, this, event);
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::ChoosedObject);
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);
dialogAlongLine->setFirstPointId(basePointId);
dialogAlongLine->setSecondPointId(secondPointId);
dialogAlongLine->setPointName(p.name());
dialogAlongLine->show();
}
}
} }
void VToolAlongLine::AddToFile(){ void VToolAlongLine::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id); VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point"); QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);
@ -87,4 +63,65 @@ void VToolAlongLine::AddToFile(){
AddAttribute(domElement, "secondPoint", secondPointId); AddAttribute(domElement, "secondPoint", secondPointId);
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
}
void VToolAlongLine::setDialog(){
Q_ASSERT(!dialogAlongLine.isNull());
if(!dialogAlongLine.isNull()){
VPointF p = VAbstractTool::data.GetPoint(id);
dialogAlongLine->setTypeLine(typeLine);
dialogAlongLine->setFormula(formula);
dialogAlongLine->setFirstPointId(basePointId, id);
dialogAlongLine->setSecondPointId(secondPointId, id);
dialogAlongLine->setPointName(p.name());
}
}
void VToolAlongLine::Create(QSharedPointer<DialogAlongLine> &dialog, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data){
QString formula = dialog->getFormula();
qint64 firstPointId = dialog->getFirstPointId();
qint64 secondPointId = dialog->getSecondPointId();
QString typeLine = dialog->getTypeLine();
QString pointName = dialog->getPointName();
Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, scene, doc, data,
Document::FullParse, Tool::FromGui);
}
void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QString &typeLine,
const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId,
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, Document::Enum parse, Tool::Enum typeCreation){
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF());
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
} else {
data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools();
VDataTool *tool = tools->value(id);
tool->VDataTool::setData(data);
tools->insert(id, tool);
}
}
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
if(parse == Document::FullParse){
VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId,
secondPointId, typeLine, typeCreation);
scene->addItem(point);
connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,point);
}
}
} }

View File

@ -11,12 +11,20 @@ public:
VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula,
const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine, const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine,
Tool::Enum typeCreation, QGraphicsItem * parent = 0); Tool::Enum typeCreation, QGraphicsItem * parent = 0);
virtual void setDialog();
static void Create(QSharedPointer<DialogAlongLine> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(const qint64 _id, const QString &pointName, const QString &typeLine,
const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId,
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, Document::Enum parse, Tool::Enum typeCreation);
public slots: public slots:
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result); virtual void FullUpdateFromGui(int result);
protected: protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile(); virtual void AddToFile();
private: private:
qint64 secondPointId; qint64 secondPointId;
QSharedPointer<DialogAlongLine> dialogAlongLine; QSharedPointer<DialogAlongLine> dialogAlongLine;

View File

@ -1,5 +1,6 @@
#include "vtoolarc.h" #include "vtoolarc.h"
#include <QMenu> #include <QMenu>
#include "../container/calculator.h"
VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation,
QGraphicsItem *parent):VAbstractTool(doc, data, id), QGraphicsPathItem(parent){ QGraphicsItem *parent):VAbstractTool(doc, data, id), QGraphicsPathItem(parent){
@ -17,6 +18,73 @@ VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum ty
} }
} }
void VToolArc::setDialog(){
Q_ASSERT(!dialogArc.isNull());
if(!dialogArc.isNull()){
VArc arc = VAbstractTool::data.GetArc(id);
dialogArc->SetCenter(arc.GetCenter());
dialogArc->SetRadius(arc.GetFormulaRadius());
dialogArc->SetF1(arc.GetFormulaF1());
dialogArc->SetF2(arc.GetFormulaF2());
}
}
void VToolArc::Create(QSharedPointer<DialogArc> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data){
qint64 center = dialog->GetCenter();
QString radius = dialog->GetRadius();
QString f1 = dialog->GetF1();
QString f2 = dialog->GetF2();
Create(0, center, radius, f1, f2, scene, doc, data, Document::FullParse, Tool::FromGui);
}
void VToolArc::Create(const qint64 _id, const qint64 &center, const QString &radius, const QString &f1,
const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, Document::Enum parse, Tool::Enum typeCreation){
qreal calcRadius = 0, calcF1 = 0, calcF2 = 0;
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(radius, &errorMsg);
if(errorMsg.isEmpty()){
calcRadius = result*PrintDPI/25.4;
}
errorMsg.clear();
result = cal.eval(f1, &errorMsg);
if(errorMsg.isEmpty()){
calcF1 = result;
}
errorMsg.clear();
result = cal.eval(f2, &errorMsg);
if(errorMsg.isEmpty()){
calcF2 = result;
}
VArc arc = VArc(data->DataPoints(), center, calcRadius, radius, calcF1, f1, calcF2, f2 );
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddArc(arc);
} else {
data->UpdateArc(id, arc);
if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools();
VDataTool *tool = tools->value(id);
tool->VDataTool::setData(data);
tools->insert(id, tool);
}
}
data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength());
if(parse == Document::FullParse){
VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation);
scene->addItem(toolArc);
connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,toolArc);
}
}
void VToolArc::FullUpdateFromFile(){ void VToolArc::FullUpdateFromFile(){
RefreshGeometry(); RefreshGeometry();
} }
@ -50,32 +118,11 @@ void VToolArc::ChangedActivDraw(const QString newName){
} }
void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){ ContextMenu(dialogArc, this, event);
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogArc = QSharedPointer<DialogArc>(new DialogArc(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogArc.data(), &DialogArc::ChoosedObject);
connect(dialogArc.data(), &DialogArc::DialogClosed, this,
&VToolArc::FullUpdateFromGui);
VArc arc = VAbstractTool::data->GetArc(id);
dialogArc->GetCenter(arc.GetCenter());
dialogArc->GetRadius(arc.GetFormulaRadius());
dialogArc->GetF1(arc.GetFormulaF1());
dialogArc->GetF2(arc.GetFormulaF2());
dialogArc->show();
}
}
} }
void VToolArc::AddToFile(){ void VToolArc::AddToFile(){
VArc arc = VAbstractTool::data->GetArc(id); VArc arc = VAbstractTool::data.GetArc(id);
QDomElement domElement = doc->createElement("arc"); QDomElement domElement = doc->createElement("arc");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);
@ -86,6 +133,7 @@ void VToolArc::AddToFile(){
AddAttribute(domElement, "angle2", arc.GetFormulaF2()); AddAttribute(domElement, "angle2", arc.GetFormulaF2());
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
} }
void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
@ -106,7 +154,7 @@ void VToolArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
} }
void VToolArc::RefreshGeometry(){ void VToolArc::RefreshGeometry(){
VArc arc = VAbstractTool::data->GetArc(id); VArc arc = VAbstractTool::data.GetArc(id);
QPainterPath path; QPainterPath path;
path.addPath(arc.GetPath()); path.addPath(arc.GetPath());
path.setFillRule( Qt::WindingFill ); path.setFillRule( Qt::WindingFill );

View File

@ -14,6 +14,12 @@ class VToolArc :public VAbstractTool, public QGraphicsPathItem
public: public:
VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation,
QGraphicsItem * parent = 0); QGraphicsItem * parent = 0);
virtual void setDialog();
static void Create(QSharedPointer<DialogArc> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(const qint64 _id, const qint64 &center, const QString &radius,
const QString &f1, const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, Document::Enum parse, Tool::Enum typeCreation);
public slots: public slots:
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result); virtual void FullUpdateFromGui(int result);

View File

@ -1,5 +1,7 @@
#pragma GCC diagnostic ignored "-Weffc++"
#include "vtoolbisector.h" #include "vtoolbisector.h"
#include <QMenu> #include <QMenu>
#pragma GCC diagnostic warning "-Weffc++"
VToolBisector::VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, VToolBisector::VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,
const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId,
@ -26,6 +28,71 @@ QPointF VToolBisector::FindPoint(const QPointF &firstPoint, const QPointF &secon
return line1.p2(); return line1.p2();
} }
void VToolBisector::setDialog(){
Q_ASSERT(!dialogBisector.isNull());
if(!dialogBisector.isNull()){
VPointF p = VAbstractTool::data.GetPoint(id);
dialogBisector->setTypeLine(typeLine);
dialogBisector->setFormula(formula);
dialogBisector->setFirstPointId(firstPointId, id);
dialogBisector->setSecondPointId(basePointId, id);
dialogBisector->setThirdPointId(thirdPointId, id);
dialogBisector->setPointName(p.name());
}
}
void VToolBisector::Create(QSharedPointer<DialogBisector> &dialog, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data){
QString formula = dialog->getFormula();
qint64 firstPointId = dialog->getFirstPointId();
qint64 secondPointId = dialog->getSecondPointId();
qint64 thirdPointId = dialog->getThirdPointId();
QString typeLine = dialog->getTypeLine();
QString pointName = dialog->getPointName();
Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, pointName, 5, 10, scene, doc, data,
Document::FullParse, Tool::FromGui);
}
void VToolBisector::Create(const qint64 _id, const QString &formula, const qint64 &firstPointId,
const qint64 &secondPointId, const qint64 &thirdPointId, const QString &typeLine,
const QString &pointName, const qreal &mx, const qreal &my,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
Document::Enum parse, Tool::Enum typeCreation){
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
VPointF thirdPoint = data->GetPoint(thirdPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolBisector::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
thirdPoint.toQPointF(), result*PrintDPI/25.4);
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
} else {
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools();
VDataTool *tool = tools->value(id);
tool->VDataTool::setData(data);
tools->insert(id, tool);
}
}
data->AddLine(firstPointId, id);
if(parse == Document::FullParse){
VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula,
firstPointId, secondPointId, thirdPointId,
typeCreation);
scene->addItem(point);
connect(point, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,point);
}
}
}
void VToolBisector::FullUpdateFromFile(){ void VToolBisector::FullUpdateFromFile(){
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){ if(domElement.isElement()){
@ -55,36 +122,11 @@ void VToolBisector::FullUpdateFromGui(int result){
} }
void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){ ContextMenu(dialogBisector, this, event);
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogBisector = QSharedPointer<DialogBisector>(new DialogBisector(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogBisector.data(), &DialogBisector::ChoosedObject);
connect(dialogBisector.data(), &DialogBisector::DialogClosed, this,
&VToolBisector::FullUpdateFromGui);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogBisector.data(),
&DialogBisector::UpdateList);
VPointF p = VAbstractTool::data->GetPoint(id);
dialogBisector->setTypeLine(typeLine);
dialogBisector->setFormula(formula);
dialogBisector->setFirstPointId(firstPointId);
dialogBisector->setSecondPointId(basePointId);
dialogBisector->setThirdPointId(thirdPointId);
dialogBisector->setPointName(p.name());
dialogBisector->show();
}
}
} }
void VToolBisector::AddToFile(){ void VToolBisector::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id); VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point"); QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);
@ -100,4 +142,5 @@ void VToolBisector::AddToFile(){
AddAttribute(domElement, "thirdPoint", thirdPointId); AddAttribute(domElement, "thirdPoint", thirdPointId);
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
} }

View File

@ -1,10 +1,11 @@
#ifndef VTOOLBISECTOR_H #ifndef VTOOLBISECTOR_H
#define VTOOLBISECTOR_H #define VTOOLBISECTOR_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QSharedPointer> #include <QSharedPointer>
#include "vtoollinepoint.h" #include "vtoollinepoint.h"
#include "../dialogs/dialogbisector.h" #include "../dialogs/dialogbisector.h"
#pragma GCC diagnostic warning "-Weffc++"
class VToolBisector : public VToolLinePoint class VToolBisector : public VToolLinePoint
{ {
@ -14,6 +15,13 @@ public:
const qint64 &thirdPointId, Tool::Enum typeCreation, QGraphicsItem * parent = 0); const qint64 &thirdPointId, Tool::Enum typeCreation, QGraphicsItem * parent = 0);
static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint,
const QPointF &thirdPoint, const qreal& length); const QPointF &thirdPoint, const qreal& length);
virtual void setDialog();
static void Create(QSharedPointer<DialogBisector> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(const qint64 _id, const QString &formula, const qint64 &firstPointId,
const qint64 &secondPointId, const qint64 &thirdPointId, const QString &typeLine,
const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, Document::Enum parse, Tool::Enum typeCreation);
public slots: public slots:
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result); virtual void FullUpdateFromGui(int result);

View File

@ -14,6 +14,66 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id
} }
} }
void VToolEndLine::setDialog(){
Q_ASSERT(!dialogEndLine.isNull());
if(!dialogEndLine.isNull()){
VPointF p = VAbstractTool::data.GetPoint(id);
dialogEndLine->setTypeLine(typeLine);
dialogEndLine->setFormula(formula);
dialogEndLine->setAngle(angle);
dialogEndLine->setBasePointId(basePointId, id);
dialogEndLine->setPointName(p.name());
}
}
void VToolEndLine::Create(QSharedPointer<DialogEndLine> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data){
QString pointName = dialog->getPointName();
QString typeLine = dialog->getTypeLine();
QString formula = dialog->getFormula();
qint32 angle = dialog->getAngle();
qint64 basePointId = dialog->getBasePointId();
Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse,
Tool::FromGui);
}
void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QString &typeLine,
const QString &formula, const qint32 &angle, const qint64 &basePointId,
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, Document::Enum parse, Tool::Enum typeCreation){
VPointF basePoint = data->GetPoint(basePointId);
QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y()));
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
line.setAngle(angle);
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
} else {
data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools();
VDataTool *tool = tools->value(id);
tool->VDataTool::setData(data);
tools->insert(id, tool);
}
}
data->AddLine(basePointId, id);
if(parse == Document::FullParse){
VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle,
basePointId, typeCreation);
scene->addItem(point);
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,point);
}
}
}
void VToolEndLine::FullUpdateFromFile(){ void VToolEndLine::FullUpdateFromFile(){
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){ if(domElement.isElement()){
@ -26,30 +86,7 @@ void VToolEndLine::FullUpdateFromFile(){
} }
void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){ ContextMenu(dialogEndLine, this, event);
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogEndLine = QSharedPointer<DialogEndLine>(new DialogEndLine(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogEndLine.data(), &DialogEndLine::ChoosedObject);
connect(dialogEndLine.data(), &DialogEndLine::DialogClosed, this,
&VToolEndLine::FullUpdateFromGui);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogEndLine.data(), &DialogEndLine::UpdateList);
VPointF p = VAbstractTool::data->GetPoint(id);
dialogEndLine->setTypeLine(typeLine);
dialogEndLine->setFormula(formula);
dialogEndLine->setAngle(angle);
dialogEndLine->setBasePointId(basePointId);
dialogEndLine->setPointName(p.name());
dialogEndLine->show();
}
}
} }
void VToolEndLine::FullUpdateFromGui(int result){ void VToolEndLine::FullUpdateFromGui(int result){
@ -68,7 +105,7 @@ void VToolEndLine::FullUpdateFromGui(int result){
} }
void VToolEndLine::AddToFile(){ void VToolEndLine::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id); VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point"); QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);
@ -83,5 +120,6 @@ void VToolEndLine::AddToFile(){
AddAttribute(domElement, "basePoint", basePointId); AddAttribute(domElement, "basePoint", basePointId);
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
} }

View File

@ -14,6 +14,13 @@ public:
const QString &typeLine, const QString &formula, const qint32 &angle, const QString &typeLine, const QString &formula, const qint32 &angle,
const qint64 &basePointId, Tool::Enum typeCreation, const qint64 &basePointId, Tool::Enum typeCreation,
QGraphicsItem * parent = 0); QGraphicsItem * parent = 0);
virtual void setDialog();
static void Create(QSharedPointer<DialogEndLine> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(const qint64 _id, const QString &pointName, const QString &typeLine,
const QString &formula, const qint32 &angle, const qint64 &basePointId, const qreal &mx, const qreal &my,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse,
Tool::Enum typeCreation);
public slots: public slots:
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result); virtual void FullUpdateFromGui(int result);

View File

@ -21,14 +21,46 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs
} }
} }
void VToolLine::setDialog(){
dialogLine->setFirstPoint(firstPoint);
dialogLine->setSecondPoint(secondPoint);
}
void VToolLine::Create(QSharedPointer<DialogLine> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data){
qint64 firstPoint = dialog->getFirstPoint();
qint64 secondPoint = dialog->getSecondPoint();
Create(0, firstPoint, secondPoint, scene, doc, data, Document::FullParse, Tool::FromGui);
}
void VToolLine::Create(const qint64 &id, const qint64 &firstPoint, const qint64 &secondPoint,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse,
Tool::Enum typeCreation){
data->AddLine(firstPoint, secondPoint);
if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools();
VDataTool *tool = tools->value(id);
tool->VDataTool::setData(data);
tools->insert(id, tool);
}
if(parse == Document::FullParse){
qint64 id = data->getNextId();
VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeCreation);
scene->addItem(line);
connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,line);
}
}
void VToolLine::FullUpdateFromFile(){ void VToolLine::FullUpdateFromFile(){
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){ if(domElement.isElement()){
firstPoint = domElement.attribute("firstPoint", "").toLongLong(); firstPoint = domElement.attribute("firstPoint", "").toLongLong();
secondPoint = domElement.attribute("secondPoint", "").toLongLong(); secondPoint = domElement.attribute("secondPoint", "").toLongLong();
} }
VPointF first = VAbstractTool::data->GetPoint(firstPoint); VPointF first = VAbstractTool::data.GetPoint(firstPoint);
VPointF second = VAbstractTool::data->GetPoint(secondPoint); VPointF second = VAbstractTool::data.GetPoint(secondPoint);
this->setLine(QLineF(first.toQPointF(), second.toQPointF())); this->setLine(QLineF(first.toQPointF(), second.toQPointF()));
} }
@ -57,23 +89,7 @@ void VToolLine::ChangedActivDraw(const QString newName){
} }
void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){ ContextMenu(dialogLine, this, event);
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogLine = QSharedPointer<DialogLine>(new DialogLine(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogLine.data(), &DialogLine::ChoosedObject);
connect(dialogLine.data(), &DialogLine::DialogClosed, this, &VToolLine::FullUpdateFromGui);
dialogLine->setFirstPoint(firstPoint);
dialogLine->setSecondPoint(secondPoint);
dialogLine->show();
}
}
} }
@ -84,6 +100,7 @@ void VToolLine::AddToFile(){
AddAttribute(domElement, "secondPoint", secondPoint); AddAttribute(domElement, "secondPoint", secondPoint);
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
} }
void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event){

View File

@ -11,6 +11,12 @@ class VToolLine: public VAbstractTool, public QGraphicsLineItem
public: public:
VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint, VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint,
Tool::Enum typeCreation, QGraphicsItem * parent = 0); Tool::Enum typeCreation, QGraphicsItem * parent = 0);
virtual void setDialog();
static void Create(QSharedPointer<DialogLine> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(const qint64 &id, const qint64 &firstPoint, const qint64 &secondPoint,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse,
Tool::Enum typeCreation);
public slots: public slots:
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
virtual void ChangedActivDraw(const QString newName); virtual void ChangedActivDraw(const QString newName);

View File

@ -14,6 +14,72 @@ VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, cons
} }
} }
void VToolLineIntersect::setDialog(){
Q_ASSERT(!dialogLineIntersect.isNull());
if(!dialogLineIntersect.isNull()){
VPointF p = VAbstractTool::data.GetPoint(id);
dialogLineIntersect->setP1Line1(p1Line1);
dialogLineIntersect->setP2Line1(p2Line1);
dialogLineIntersect->setP1Line2(p1Line2);
dialogLineIntersect->setP2Line2(p2Line2);
dialogLineIntersect->setPointName(p.name());
}
}
void VToolLineIntersect::Create(QSharedPointer<DialogLineIntersect> &dialog, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data){
qint64 p1Line1Id = dialog->getP1Line1();
qint64 p2Line1Id = dialog->getP2Line1();
qint64 p1Line2Id = dialog->getP1Line2();
qint64 p2Line2Id = dialog->getP2Line2();
QString pointName = dialog->getPointName();
Create(0, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, pointName, 5, 10, scene, doc, data,
Document::FullParse, Tool::FromGui);
}
void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id,
const qint64 &p1Line2Id, const qint64 &p2Line2Id, const QString &pointName,
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, Document::Enum parse, Tool::Enum typeCreation){
VPointF p1Line1 = data->GetPoint(p1Line1Id);
VPointF p2Line1 = data->GetPoint(p2Line1Id);
VPointF p1Line2 = data->GetPoint(p1Line2Id);
VPointF p2Line2 = data->GetPoint(p2Line2Id);
QLineF line1(p1Line1.toQPointF(), p2Line1.toQPointF());
QLineF line2(p1Line2.toQPointF(), p2Line2.toQPointF());
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
} else {
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools();
VDataTool *tool = tools->value(id);
tool->VDataTool::setData(data);
tools->insert(id, tool);
}
}
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
if(parse == Document::FullParse){
VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id,
p2Line1Id, p1Line2Id,
p2Line2Id, typeCreation);
scene->addItem(point);
connect(point, &VToolLineIntersect::ChoosedTool, scene,
&VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,point);
}
}
}
void VToolLineIntersect::FullUpdateFromFile(){ void VToolLineIntersect::FullUpdateFromFile(){
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){ if(domElement.isElement()){
@ -41,33 +107,11 @@ void VToolLineIntersect::FullUpdateFromGui(int result){
} }
void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){ ContextMenu(dialogLineIntersect, this, event);
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogLineIntersect = QSharedPointer<DialogLineIntersect>(new DialogLineIntersect(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogLineIntersect.data(), &DialogLineIntersect::ChoosedObject);
connect(dialogLineIntersect.data(), &DialogLineIntersect::DialogClosed, this,
&VToolLineIntersect::FullUpdateFromGui);
VPointF p = VAbstractTool::data->GetPoint(id);
dialogLineIntersect->setP1Line1(p1Line1);
dialogLineIntersect->setP2Line1(p2Line1);
dialogLineIntersect->setP1Line2(p1Line2);
dialogLineIntersect->setP2Line2(p2Line2);
dialogLineIntersect->setPointName(p.name());
dialogLineIntersect->show();
}
}
} }
void VToolLineIntersect::AddToFile(){ void VToolLineIntersect::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id); VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point"); QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);
@ -82,4 +126,5 @@ void VToolLineIntersect::AddToFile(){
AddAttribute(domElement, "p2Line2", p2Line2); AddAttribute(domElement, "p2Line2", p2Line2);
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
} }

View File

@ -12,6 +12,13 @@ public:
const qint64 &p2Line1, const qint64 &p1Line2, const qint64 &p2Line1, const qint64 &p1Line2,
const qint64 &p2Line2, Tool::Enum typeCreation, const qint64 &p2Line2, Tool::Enum typeCreation,
QGraphicsItem * parent = 0); QGraphicsItem * parent = 0);
virtual void setDialog();
static void Create(QSharedPointer<DialogLineIntersect> &dialog, VMainGraphicsScene *scene,
VDomDocument *doc,VContainer *data);
static void Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id,
const qint64 &p1Line2Id, const qint64 &p2Line2Id, const QString &pointName,
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, Document::Enum parse, Tool::Enum typeCreation);
public slots: public slots:
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result); virtual void FullUpdateFromGui(int result);

View File

@ -2,16 +2,12 @@
VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,
const QString &formula, const qint64 &basePointId, const qint32 &angle, const QString &formula, const qint64 &basePointId, const qint32 &angle,
QGraphicsItem *parent):VToolPoint(doc, data, id, parent){ QGraphicsItem *parent): VToolPoint(doc, data, id, parent), typeLine(typeLine), formula(formula),
this->typeLine = typeLine; angle(angle), basePointId(basePointId), mainLine(0){
this->formula = formula;
this->angle = angle;
this->basePointId = basePointId;
//Лінія, що з'єднує дві точки //Лінія, що з'єднує дві точки
VPointF point1 = data->GetPoint(basePointId); QPointF point1 = data->GetPoint(basePointId).toQPointF();
VPointF point2 = data->GetPoint(id); QPointF point2 = data->GetPoint(id).toQPointF();
mainLine = new QGraphicsLineItem(QLineF(point1.toQPointF(), point2.toQPointF()), this); mainLine = new QGraphicsLineItem(QLineF(point1 - point2, point2 - point2), this);
mainLine->setPen(QPen(Qt::black, widthHairLine)); mainLine->setPen(QPen(Qt::black, widthHairLine));
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
if(typeLine == "none"){ if(typeLine == "none"){
@ -33,9 +29,9 @@ void VToolLinePoint::ChangedActivDraw(const QString newName){
void VToolLinePoint::RefreshGeometry(){ void VToolLinePoint::RefreshGeometry(){
VToolPoint::RefreshGeometry(); VToolPoint::RefreshGeometry();
VPointF point = VAbstractTool::data->GetPoint(id); QPointF point = VAbstractTool::data.GetPoint(id).toQPointF();
VPointF basePoint = VAbstractTool::data->GetPoint(basePointId); QPointF basePoint = VAbstractTool::data.GetPoint(basePointId).toQPointF();
mainLine->setLine(QLineF(basePoint.toQPointF(), point.toQPointF())); mainLine->setLine(QLineF(basePoint - point, point - point));
if(typeLine == "none"){ if(typeLine == "none"){
mainLine->setVisible(false); mainLine->setVisible(false);
} else { } else {

View File

@ -1,7 +1,9 @@
#ifndef VTOOLLINEPOINT_H #ifndef VTOOLLINEPOINT_H
#define VTOOLLINEPOINT_H #define VTOOLLINEPOINT_H
#pragma GCC diagnostic ignored "-Weffc++"
#include "vtoolpoint.h" #include "vtoolpoint.h"
#pragma GCC diagnostic warning "-Weffc++"
class VToolLinePoint : public VToolPoint class VToolLinePoint : public VToolPoint
{ {

View File

@ -13,6 +13,67 @@ VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id,
} }
void VToolNormal::setDialog(){
Q_ASSERT(!dialogNormal.isNull());
if(!dialogNormal.isNull()){
VPointF p = VAbstractTool::data.GetPoint(id);
dialogNormal->setTypeLine(typeLine);
dialogNormal->setFormula(formula);
dialogNormal->setAngle(angle);
dialogNormal->setFirstPointId(basePointId, id);
dialogNormal->setSecondPointId(secondPointId, id);
dialogNormal->setPointName(p.name());
}
}
void VToolNormal::Create(QSharedPointer<DialogNormal> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data){
QString formula = dialog->getFormula();
qint64 firstPointId = dialog->getFirstPointId();
qint64 secondPointId = dialog->getSecondPointId();
QString typeLine = dialog->getTypeLine();
QString pointName = dialog->getPointName();
qint32 angle = dialog->getAngle();
Create(0, formula, firstPointId, secondPointId, typeLine, pointName, angle, 5, 10, scene, doc, data,
Document::FullParse, Tool::FromGui);
}
void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 &firstPointId,
const qint64 &secondPointId, const QString typeLine, const QString pointName,
const qint32 angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation){
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolNormal::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
result*PrintDPI/25.4, angle);
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
} else {
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools();
VDataTool *tool = tools->value(id);
tool->VDataTool::setData(data);
tools->insert(id, tool);
}
}
data->AddLine(firstPointId, id);
if(parse == Document::FullParse){
VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle,
firstPointId, secondPointId, typeCreation);
scene->addItem(point);
connect(point, &VToolNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,point);
}
}
}
QPointF VToolNormal::FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, QPointF VToolNormal::FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length,
const qint32 &angle){ const qint32 &angle){
QLineF line(firstPoint, secondPoint); QLineF line(firstPoint, secondPoint);
@ -51,35 +112,11 @@ void VToolNormal::FullUpdateFromGui(int result){
} }
void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){ ContextMenu(dialogNormal, this, event);
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogNormal = QSharedPointer<DialogNormal>(new DialogNormal(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogNormal.data(), &DialogNormal::ChoosedObject);
connect(dialogNormal.data(), &DialogNormal::DialogClosed, this,
&VToolNormal::FullUpdateFromGui);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogNormal.data(), &DialogNormal::UpdateList);
VPointF p = VAbstractTool::data->GetPoint(id);
dialogNormal->setTypeLine(typeLine);
dialogNormal->setFormula(formula);
dialogNormal->setAngle(angle);
dialogNormal->setFirstPointId(basePointId);
dialogNormal->setSecondPointId(secondPointId);
dialogNormal->setPointName(p.name());
dialogNormal->show();
}
}
} }
void VToolNormal::AddToFile(){ void VToolNormal::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id); VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point"); QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);
@ -95,4 +132,5 @@ void VToolNormal::AddToFile(){
AddAttribute(domElement, "secondPoint", secondPointId); AddAttribute(domElement, "secondPoint", secondPointId);
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
} }

View File

@ -14,6 +14,13 @@ public:
const qint32 &angle, const qint64 &firstPointId, const qint32 &angle, const qint64 &firstPointId,
const qint64 &secondPointId, Tool::Enum typeCreation, const qint64 &secondPointId, Tool::Enum typeCreation,
QGraphicsItem * parent = 0); QGraphicsItem * parent = 0);
virtual void setDialog();
static void Create(QSharedPointer<DialogNormal> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(const qint64 _id, const QString &formula, const qint64 &firstPointId,
const qint64 &secondPointId, const QString typeLine, const QString pointName,
const qint32 angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation);
static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint,
const qreal &length, const qint32 &angle = 0); const qreal &length, const qint32 &angle = 0);
public slots: public slots:

View File

@ -13,43 +13,35 @@ VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id,
radius = 1.5*PrintDPI/25.4; radius = 1.5*PrintDPI/25.4;
//create circle //create circle
VPointF point = data->GetPoint(id); VPointF point = data->GetPoint(id);
QRectF rec = QRectF(point.x(), point.y(), radius*2, radius*2); QRectF rec = QRectF(0, 0, radius*2, radius*2);
rec.translate(point.x()-rec.center().x(), point.y()-rec.center().y()); rec.translate(-rec.center().x(), -rec.center().y());
this->setRect(rec); this->setRect(rec);
this->setPen(QPen(Qt::black, widthHairLine)); this->setPen(QPen(Qt::black, widthHairLine));
this->setBrush(QBrush(Qt::NoBrush)); this->setBrush(QBrush(Qt::NoBrush));
this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setAcceptHoverEvents(true); this->setAcceptHoverEvents(true);
this->setPos(point.toQPointF());
//Тексто мітка точки //Тексто мітка точки
namePoint = new VGraphicsSimpleTextItem(point.name(), this); namePoint = new VGraphicsSimpleTextItem(point.name(), this);
rec = this->rect(); rec = this->rect();
namePoint->setPos(QPointF(rec.center().x()+point.mx(), rec.center().y()+point.my())); namePoint->setPos(QPointF(point.mx(), point.my()));
connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this,
&VToolPoint::NameChangePosition); &VToolPoint::NameChangePosition);
//Лінія, що з'єднує точку і мітку //Лінія, що з'єднує точку і мітку
QRectF nameRec = namePoint->sceneBoundingRect(); lineName = new QGraphicsLineItem(this);
QPointF p1, p2; RefreshLine();
LineIntersectCircle(rec.center(), radius, QLineF(rec.center(), nameRec.center()), p1, p2);
QPointF pRec = LineIntersectRect(nameRec, QLineF(rec.center(), nameRec.center()));
lineName = new QGraphicsLineItem(QLineF(p1, pRec), this);
lineName->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
if(QLineF(p1, pRec).length() <= 4*PrintDPI/25.4){
lineName->setVisible(false);
} else {
lineName->setVisible(true);
}
} }
void VToolPoint::NameChangePosition(const QPointF pos){ void VToolPoint::NameChangePosition(const QPointF pos){
VPointF point = VAbstractTool::data->GetPoint(id); VPointF point = VAbstractTool::data.GetPoint(id);
QRectF rec = this->rect(); QPointF p = pos - this->pos();
point.setMx(pos.x() - rec.center().x()); point.setMx(p.x());
point.setMy(pos.y() - rec.center().y()); point.setMy(p.y());
RefreshLine(); RefreshLine();
LiteUpdateFromGui(point.mx(), point.my()); LiteUpdateFromGui(point.mx(), point.my());
VAbstractTool::data->UpdatePoint(id, point); VAbstractTool::data.UpdatePoint(id, point);
} }
QPointF VToolPoint::LineIntersectRect(QRectF rec, QLineF line) const{ QPointF VToolPoint::LineIntersectRect(QRectF rec, QLineF line) const{
@ -79,11 +71,10 @@ QPointF VToolPoint::LineIntersectRect(QRectF rec, QLineF line) const{
void VToolPoint::RefreshLine(){ void VToolPoint::RefreshLine(){
QRectF nameRec = namePoint->sceneBoundingRect(); QRectF nameRec = namePoint->sceneBoundingRect();
QPointF p1, p2; QPointF p1, p2;
QRectF rec = this->rect(); LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- pos()), p1, p2);
LineIntersectCircle(rec.center(), radius, QLineF(rec.center(), nameRec.center()), p1, p2); QPointF pRec = LineIntersectRect(nameRec, QLineF(pos(), nameRec.center()));
QPointF pRec = LineIntersectRect(nameRec, QLineF(rec.center(), nameRec.center())); lineName->setLine(QLineF(p1, pRec - pos()));
lineName->setLine(QLineF(p1, pRec)); if(QLineF(p1, pRec - pos()).length() <= 4*PrintDPI/25.4){
if(QLineF(p1, pRec).length() <= 4*PrintDPI/25.4){
lineName->setVisible(false); lineName->setVisible(false);
} else { } else {
lineName->setVisible(true); lineName->setVisible(true);
@ -148,7 +139,7 @@ void VToolPoint::LiteUpdateFromGui(qreal mx, qreal my){
if(domElement.isElement()){ if(domElement.isElement()){
domElement.setAttribute("mx", QString().setNum(mx/PrintDPI*25.4)); domElement.setAttribute("mx", QString().setNum(mx/PrintDPI*25.4));
domElement.setAttribute("my", QString().setNum(my/PrintDPI*25.4)); domElement.setAttribute("my", QString().setNum(my/PrintDPI*25.4));
emit haveLiteChange(); emit toolhaveChange();
} }
} }
@ -179,14 +170,17 @@ void VToolPoint::ChangedActivDraw(const QString newName){
} }
void VToolPoint::RefreshGeometry(){ void VToolPoint::RefreshGeometry(){
VPointF point = VAbstractTool::data->GetPoint(id); VPointF point = VAbstractTool::data.GetPoint(id);
QRectF rec = QRectF(point.x(), point.y(), radius*2, radius*2); QRectF rec = QRectF(0, 0, radius*2, radius*2);
rec.translate(point.x()-rec.center().x(), point.y()-rec.center().y()); rec.translate(-rec.center().x(), -rec.center().y());
this->setRect(rec); this->setRect(rec);
this->setPos(point.toQPointF());
rec = this->rect(); disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this,
&VToolPoint::NameChangePosition);
namePoint->setText(point.name()); namePoint->setText(point.name());
namePoint->setPos(QPointF(rec.center().x()+point.mx(), rec.center().y()+point.my())); namePoint->setPos(QPointF(point.mx(), point.my()));
connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this,
&VToolPoint::NameChangePosition);
RefreshLine(); RefreshLine();
} }

View File

@ -1,11 +1,13 @@
#ifndef VTOOLPOINT_H #ifndef VTOOLPOINT_H
#define VTOOLPOINT_H #define VTOOLPOINT_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QGraphicsLineItem> #include <QGraphicsLineItem>
#include <QGraphicsEllipseItem> #include <QGraphicsEllipseItem>
#include "../widgets/vgraphicssimpletextitem.h" #include "../widgets/vgraphicssimpletextitem.h"
#include "../options.h"
#include "vabstracttool.h" #include "vabstracttool.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "../options.h"
class VToolPoint: public VAbstractTool, public QGraphicsEllipseItem class VToolPoint: public VAbstractTool, public QGraphicsEllipseItem
{ {

View File

@ -16,6 +16,19 @@ VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, cons
} }
void VToolShoulderPoint::setDialog(){
Q_ASSERT(!dialogShoulderPoint.isNull());
if(!dialogShoulderPoint.isNull()){
VPointF p = VAbstractTool::data.GetPoint(id);
dialogShoulderPoint->setTypeLine(typeLine);
dialogShoulderPoint->setFormula(formula);
dialogShoulderPoint->setP1Line(basePointId, id);
dialogShoulderPoint->setP2Line(p2Line, id);
dialogShoulderPoint->setPShoulder(pShoulder, id);
dialogShoulderPoint->setPointName(p.name());
}
}
QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder,
const qreal &length){ const qreal &length){
QLineF line = QLineF(p1Line, p2Line); QLineF line = QLineF(p1Line, p2Line);
@ -37,6 +50,60 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li
} }
} }
void VToolShoulderPoint::Create(QSharedPointer<DialogShoulderPoint> &dialog, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data){
QString formula = dialog->getFormula();
qint64 p1Line = dialog->getP1Line();
qint64 p2Line = dialog->getP2Line();
qint64 pShoulder = dialog->getPShoulder();
QString typeLine = dialog->getTypeLine();
QString pointName = dialog->getPointName();
Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, scene, doc, data,
Document::FullParse, Tool::FromGui);
}
void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const qint64 &p1Line,
const qint64 &p2Line, const qint64 &pShoulder, const QString &typeLine,
const QString &pointName, const qreal &mx, const qreal &my,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
Document::Enum parse, Tool::Enum typeCreation){
VPointF firstPoint = data->GetPoint(p1Line);
VPointF secondPoint = data->GetPoint(p2Line);
VPointF shoulderPoint = data->GetPoint(pShoulder);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
shoulderPoint.toQPointF(), result*PrintDPI/25.4);
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
} else {
data->UpdatePoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools();
VDataTool *tool = tools->value(id);
tool->VDataTool::setData(data);
tools->insert(id, tool);
}
}
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
if(parse == Document::FullParse){
VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula,
p1Line, p2Line, pShoulder,
typeCreation);
scene->addItem(point);
connect(point, &VToolShoulderPoint::ChoosedTool, scene,
&VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,point);
}
}
}
void VToolShoulderPoint::FullUpdateFromFile(){ void VToolShoulderPoint::FullUpdateFromFile(){
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){ if(domElement.isElement()){
@ -66,37 +133,11 @@ void VToolShoulderPoint::FullUpdateFromGui(int result){
} }
void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){ ContextMenu(dialogShoulderPoint, this, event);
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogShoulderPoint =
QSharedPointer<DialogShoulderPoint>(new DialogShoulderPoint(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogShoulderPoint.data(), &DialogShoulderPoint::ChoosedObject);
connect(dialogShoulderPoint.data(), &DialogShoulderPoint::DialogClosed, this,
&VToolShoulderPoint::FullUpdateFromGui);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogShoulderPoint.data(),
&DialogShoulderPoint::UpdateList);
VPointF p = VAbstractTool::data->GetPoint(id);
dialogShoulderPoint->setTypeLine(typeLine);
dialogShoulderPoint->setFormula(formula);
dialogShoulderPoint->setP1Line(basePointId);
dialogShoulderPoint->setP2Line(p2Line);
dialogShoulderPoint->setPShoulder(pShoulder);
dialogShoulderPoint->setPointName(p.name());
dialogShoulderPoint->show();
}
}
} }
void VToolShoulderPoint::AddToFile(){ void VToolShoulderPoint::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id); VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point"); QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);
@ -112,4 +153,5 @@ void VToolShoulderPoint::AddToFile(){
AddAttribute(domElement, "pShoulder", pShoulder); AddAttribute(domElement, "pShoulder", pShoulder);
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
} }

View File

@ -11,8 +11,15 @@ public:
const QString &typeLine, const QString &formula, const qint64 &p1Line, const QString &typeLine, const QString &formula, const qint64 &p1Line,
const qint64 &p2Line, const qint64 &pShoulder, Tool::Enum typeCreation, const qint64 &p2Line, const qint64 &pShoulder, Tool::Enum typeCreation,
QGraphicsItem * parent = 0); QGraphicsItem * parent = 0);
virtual void setDialog();
static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder,
const qreal &length); const qreal &length);
static void Create(QSharedPointer<DialogShoulderPoint> &dialog, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data);
static void Create(const qint64 _id, const QString &formula, const qint64 &p1Line, const qint64 &p2Line,
const qint64 &pShoulder, const QString &typeLine, const QString &pointName,
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, Document::Enum parse, Tool::Enum typeCreation);
public slots: public slots:
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result); virtual void FullUpdateFromGui(int result);

View File

@ -12,13 +12,15 @@
VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation,
QGraphicsItem * parent ):VToolPoint(doc, data, id, parent){ QGraphicsItem * parent ):VToolPoint(doc, data, id, parent){
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
if(typeCreation == Tool::FromGui){ if(typeCreation == Tool::FromGui){
AddToFile(); AddToFile();
} }
} }
void VToolSinglePoint::AddToFile(){ void VToolSinglePoint::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id); VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point"); QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);
@ -30,22 +32,37 @@ void VToolSinglePoint::AddToFile(){
AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); AddAttribute(domElement, "my", point.my()/PrintDPI*25.4);
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
}
QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){
if (change == ItemPositionChange && scene()) {
// value - это новое положение.
QPointF newPos = value.toPointF();
QRectF rect = scene()->sceneRect();
if (!rect.contains(newPos)) {
// Сохраняем элемент внутри прямоугольника сцены.
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
return newPos;
}
}
if (change == ItemPositionHasChanged && scene()) {
// value - это новое положение.
QPointF newPos = value.toPointF();
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
domElement.setAttribute("x", QString().setNum(newPos.x()/PrintDPI*25.4));
domElement.setAttribute("y", QString().setNum(newPos.y()/PrintDPI*25.4));
//I don't now why but signal does not work.
doc->FullUpdateTree();
}
}
return QGraphicsItem::itemChange(change, value);
} }
void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){
if(!ignoreContextMenuEvent){ ContextMenu(dialogSinglePoint, this, event);
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogSinglePoint = QSharedPointer<DialogSinglePoint>(new DialogSinglePoint(VAbstractTool::data));
VPointF p = VAbstractTool::data->GetPoint(id);
dialogSinglePoint->setData(p.name(), p.toQPointF());
connect(dialogSinglePoint.data(), &DialogSinglePoint::DialogClosed, this,
&VToolSinglePoint::FullUpdateFromGui);
dialogSinglePoint->exec();
}
}
} }
void VToolSinglePoint::FullUpdateFromFile(){ void VToolSinglePoint::FullUpdateFromFile(){
@ -61,8 +78,19 @@ void VToolSinglePoint::FullUpdateFromGui(int result){
domElement.setAttribute("name", name); domElement.setAttribute("name", name);
domElement.setAttribute("x", QString().setNum(p.x()/PrintDPI*25.4)); domElement.setAttribute("x", QString().setNum(p.x()/PrintDPI*25.4));
domElement.setAttribute("y", QString().setNum(p.y()/PrintDPI*25.4)); domElement.setAttribute("y", QString().setNum(p.y()/PrintDPI*25.4));
emit FullUpdateTree(); //I don't now why but signal does not work.
doc->FullUpdateTree();
} }
} }
dialogSinglePoint.clear(); dialogSinglePoint.clear();
} }
void VToolSinglePoint::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
VToolPoint::ChangedActivDraw(newName);
} else {
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
VToolPoint::ChangedActivDraw(newName);
}
}

View File

@ -15,11 +15,13 @@ public:
public slots: public slots:
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result); virtual void FullUpdateFromGui(int result);
virtual void ChangedActivDraw(const QString newName);
signals: signals:
void FullUpdateTree(); void FullUpdateTree();
protected: protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile(); virtual void AddToFile();
QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
private: private:
QSharedPointer<DialogSinglePoint> dialogSinglePoint; QSharedPointer<DialogSinglePoint> dialogSinglePoint;
}; };

View File

@ -16,7 +16,7 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, Tool::E
this->setAcceptHoverEvents(true); this->setAcceptHoverEvents(true);
VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePoint::FirstPoint, spl.GetP2(), VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePoint::FirstPoint, spl.GetP2(),
spl.GetPointP1(), this); spl.GetPointP1().toQPointF(), this);
connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this, connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition); &VToolSpline::ControlPointChangePosition);
connect(this, &VToolSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine); connect(this, &VToolSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine);
@ -24,7 +24,7 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, Tool::E
controlPoints.append(controlPoint1); controlPoints.append(controlPoint1);
VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePoint::LastPoint, spl.GetP3(), VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePoint::LastPoint, spl.GetP3(),
spl.GetPointP4(), this); spl.GetPointP4().toQPointF(), this);
connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this, connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition); &VToolSpline::ControlPointChangePosition);
connect(this, &VToolSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine); connect(this, &VToolSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine);
@ -36,13 +36,67 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, Tool::E
} }
} }
void VToolSpline::setDialog(){
Q_ASSERT(!dialogSpline.isNull());
if(!dialogSpline.isNull()){
VSpline spl = VAbstractTool::data.GetSpline(id);
dialogSpline->setP1(spl.GetP1());
dialogSpline->setP4(spl.GetP4());
dialogSpline->setAngle1(spl.GetAngle1());
dialogSpline->setAngle2(spl.GetAngle2());
dialogSpline->setKAsm1(spl.GetKasm1());
dialogSpline->setKAsm2(spl.GetKasm2());
dialogSpline->setKCurve(spl.GetKcurve());
}
}
void VToolSpline::Create(QSharedPointer<DialogSpline> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data){
qint64 p1 = dialog->getP1();
qint64 p4 = dialog->getP4();
qreal kAsm1 = dialog->getKAsm1();
qreal kAsm2 = dialog->getKAsm2();
qreal angle1 = dialog->getAngle1();
qreal angle2 = dialog->getAngle2();
qreal kCurve = dialog->getKCurve();
Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, doc, data, Document::FullParse,
Tool::FromGui);
}
void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1,
const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse,
Tool::Enum typeCreation){
VSpline spline = VSpline(data->DataPoints(), p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve);
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddSpline(spline);
} else {
data->UpdateSpline(id, spline);
if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools();
VDataTool *tool = tools->value(id);
tool->VDataTool::setData(data);
tools->insert(id, tool);
}
}
data->AddLengthSpline(data->GetNameSpline(p1, p4), spline.GetLength());
if(parse == Document::FullParse){
VToolSpline *spl = new VToolSpline(doc, data, id, typeCreation);
scene->addItem(spl);
connect(spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,spl);
}
}
void VToolSpline::FullUpdateFromFile(){ void VToolSpline::FullUpdateFromFile(){
RefreshGeometry(); RefreshGeometry();
} }
void VToolSpline::FullUpdateFromGui(int result){ void VToolSpline::FullUpdateFromGui(int result){
if(result == QDialog::Accepted){ if(result == QDialog::Accepted){
VSpline spl = VSpline (VAbstractTool::data->DataPoints(), dialogSpline->getP1(), VSpline spl = VSpline (VAbstractTool::data.DataPoints(), dialogSpline->getP1(),
dialogSpline->getP4(), dialogSpline->getAngle1(), dialogSpline->getAngle2(), dialogSpline->getP4(), dialogSpline->getAngle1(), dialogSpline->getAngle2(),
dialogSpline->getKAsm1(), dialogSpline->getKAsm2(), dialogSpline->getKCurve()); dialogSpline->getKAsm1(), dialogSpline->getKAsm2(), dialogSpline->getKCurve());
@ -57,7 +111,7 @@ void VToolSpline::FullUpdateFromGui(int result){
connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this, connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition); &VToolSpline::ControlPointChangePosition);
spl = VSpline (VAbstractTool::data->DataPoints(), dialogSpline->getP1(), controlPoints[0]->pos(), spl = VSpline (VAbstractTool::data.DataPoints(), dialogSpline->getP1(), controlPoints[0]->pos(),
controlPoints[1]->pos(), dialogSpline->getP4(), dialogSpline->getKCurve()); controlPoints[1]->pos(), dialogSpline->getP4(), dialogSpline->getKCurve());
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){ if(domElement.isElement()){
@ -77,7 +131,7 @@ void VToolSpline::FullUpdateFromGui(int result){
void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position,
const QPointF pos){ const QPointF pos){
Q_UNUSED(indexSpline); Q_UNUSED(indexSpline);
VSpline spl = VAbstractTool::data->GetSpline(id); VSpline spl = VAbstractTool::data.GetSpline(id);
if(position == SplinePoint::FirstPoint){ if(position == SplinePoint::FirstPoint){
spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());
} else { } else {
@ -95,35 +149,11 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePo
} }
void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){ ContextMenu(dialogSpline, this, event);
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogSpline = QSharedPointer<DialogSpline>(new DialogSpline(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogSpline.data(), &DialogSpline::ChoosedObject);
connect(dialogSpline.data(), &DialogSpline::DialogClosed, this,
&VToolSpline::FullUpdateFromGui);
VSpline spl = VAbstractTool::data->GetSpline(id);
dialogSpline->setP1(spl.GetP1());
dialogSpline->setP4(spl.GetP4());
dialogSpline->setAngle1(spl.GetAngle1());
dialogSpline->setAngle2(spl.GetAngle2());
dialogSpline->setKAsm1(spl.GetKasm1());
dialogSpline->setKAsm2(spl.GetKasm2());
dialogSpline->setKCurve(spl.GetKcurve());
dialogSpline->show();
}
}
} }
void VToolSpline::AddToFile(){ void VToolSpline::AddToFile(){
VSpline spl = VAbstractTool::data->GetSpline(id); VSpline spl = VAbstractTool::data.GetSpline(id);
QDomElement domElement = doc->createElement("spline"); QDomElement domElement = doc->createElement("spline");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);
@ -137,6 +167,7 @@ void VToolSpline::AddToFile(){
AddAttribute(domElement, "kCurve", spl.GetKcurve()); AddAttribute(domElement, "kCurve", spl.GetKcurve());
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
} }
void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
@ -157,17 +188,28 @@ void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
} }
void VToolSpline::RefreshGeometry(){ void VToolSpline::RefreshGeometry(){
VSpline spl = VAbstractTool::data->GetSpline(id); VSpline spl = VAbstractTool::data.GetSpline(id);
QPainterPath path; QPainterPath path;
path.addPath(spl.GetPath()); path.addPath(spl.GetPath());
path.setFillRule( Qt::WindingFill ); path.setFillRule( Qt::WindingFill );
this->setPath(path); this->setPath(path);
QPointF splinePoint = VAbstractTool::data->GetPoint(spl.GetP1()); QPointF splinePoint = VAbstractTool::data.GetPoint(spl.GetP1()).toQPointF();
QPointF controlPoint = spl.GetP2(); QPointF controlPoint = spl.GetP2();
emit RefreshLine(1, SplinePoint::FirstPoint, controlPoint, splinePoint); emit RefreshLine(1, SplinePoint::FirstPoint, controlPoint, splinePoint);
splinePoint = VAbstractTool::data->GetPoint(spl.GetP4()); splinePoint = VAbstractTool::data.GetPoint(spl.GetP4()).toQPointF();
controlPoint = spl.GetP3(); controlPoint = spl.GetP3();
emit RefreshLine(1, SplinePoint::LastPoint, controlPoint, splinePoint); emit RefreshLine(1, SplinePoint::LastPoint, controlPoint, splinePoint);
disconnect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
disconnect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
controlPoints[0]->setPos(spl.GetP2());
controlPoints[1]->setPos(spl.GetP3());
connect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
} }

View File

@ -15,6 +15,13 @@ class VToolSpline:public VAbstractTool, public QGraphicsPathItem
public: public:
VToolSpline ( VDomDocument *doc, VContainer *data, qint64 id, VToolSpline ( VDomDocument *doc, VContainer *data, qint64 id,
Tool::Enum typeCreation, QGraphicsItem * parent = 0 ); Tool::Enum typeCreation, QGraphicsItem * parent = 0 );
virtual void setDialog();
static void Create(QSharedPointer<DialogSpline> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1,
const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse,
Tool::Enum typeCreation);
signals: signals:
void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position, void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position,
const QPointF &controlPoint, const QPointF &splinePoint ); const QPointF &controlPoint, const QPointF &splinePoint );

View File

@ -16,14 +16,15 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id,
for(qint32 i = 1; i<=splPath.Count(); ++i){ for(qint32 i = 1; i<=splPath.Count(); ++i){
VSpline spl = splPath.GetSpline(i); VSpline spl = splPath.GetSpline(i);
VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePoint::FirstPoint, spl.GetP2(), VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePoint::FirstPoint, spl.GetP2(),
spl.GetPointP1(), this); spl.GetPointP1().toQPointF(), this);
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition); &VToolSplinePath::ControlPointChangePosition);
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine); connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
controlPoints.append(controlPoint); controlPoints.append(controlPoint);
controlPoint = new VControlPointSpline(i, SplinePoint::LastPoint, spl.GetP3(),spl.GetPointP4(), this); controlPoint = new VControlPointSpline(i, SplinePoint::LastPoint, spl.GetP3(),
spl.GetPointP4().toQPointF(), this);
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition); &VToolSplinePath::ControlPointChangePosition);
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine); connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
@ -36,6 +37,45 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id,
} }
} }
void VToolSplinePath::setDialog(){
Q_ASSERT(!dialogSplinePath.isNull());
if(!dialogSplinePath.isNull()){
VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
dialogSplinePath->SetPath(splPath);
}
}
void VToolSplinePath::Create(QSharedPointer<DialogSplinePath> &dialog, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data){
VSplinePath path = dialog->GetPath();
Create(0, path, scene, doc, data, Document::FullParse, Tool::FromGui);
}
void VToolSplinePath::Create(const qint64 _id, const VSplinePath &path, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data, Document::Enum parse,
Tool::Enum typeCreation){
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddSplinePath(path);
} else {
data->UpdateSplinePath(id, path);
if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools();
VDataTool *tool = tools->value(id);
tool->VDataTool::setData(data);
tools->insert(id, tool);
}
}
data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength());
if(parse == Document::FullParse){
VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation);
scene->addItem(spl);
connect(spl, &VToolSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id,spl);
}
}
void VToolSplinePath::FullUpdateFromFile(){ void VToolSplinePath::FullUpdateFromFile(){
RefreshGeometry(); RefreshGeometry();
} }
@ -57,7 +97,7 @@ void VToolSplinePath::FullUpdateFromGui(int result){
connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition); &VToolSplinePath::ControlPointChangePosition);
spl = VSpline (VAbstractTool::data->DataPoints(), spl.GetP1(), controlPoints[j-2]->pos(), spl = VSpline (VAbstractTool::data.DataPoints(), spl.GetP1(), controlPoints[j-2]->pos(),
controlPoints[j-1]->pos(), spl.GetP4(), splPath.getKCurve()); controlPoints[j-1]->pos(), spl.GetP4(), splPath.getKCurve());
CorectControlPoints(spl, splPath, i-1, i, SplinePoint::FirstPoint); CorectControlPoints(spl, splPath, i-1, i, SplinePoint::FirstPoint);
CorectControlPoints(spl, splPath, i, i, SplinePoint::LastPoint); CorectControlPoints(spl, splPath, i, i, SplinePoint::LastPoint);
@ -78,7 +118,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, Spli
const QPointF pos) const QPointF pos)
{ {
qint32 index = 0; qint32 index = 0;
VSplinePath splPath = VAbstractTool::data->GetSplinePath(id); VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
VSpline spl = splPath.GetSpline(indexSpline); VSpline spl = splPath.GetSpline(indexSpline);
if(position == SplinePoint::FirstPoint){ if(position == SplinePoint::FirstPoint){
spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());
@ -162,27 +202,11 @@ void VToolSplinePath::ChangedActivDraw(const QString newName){
} }
void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){ ContextMenu(dialogSplinePath, this, event);
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogSplinePath = QSharedPointer<DialogSplinePath>(new DialogSplinePath(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogSplinePath.data(), &DialogSplinePath::ChoosedObject);
connect(dialogSplinePath.data(), &DialogSplinePath::DialogClosed, this,
&VToolSplinePath::FullUpdateFromGui);
VSplinePath splPath = VAbstractTool::data->GetSplinePath(id);
dialogSplinePath->SetPath(splPath);
dialogSplinePath->show();
}
}
} }
void VToolSplinePath::AddToFile(){ void VToolSplinePath::AddToFile(){
VSplinePath splPath = VAbstractTool::data->GetSplinePath(id); VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
QDomElement domElement = doc->createElement("spline"); QDomElement domElement = doc->createElement("spline");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);
@ -194,6 +218,7 @@ void VToolSplinePath::AddToFile(){
} }
AddToCalculation(domElement); AddToCalculation(domElement);
emit toolhaveChange();
} }
void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint){ void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint){
@ -225,19 +250,31 @@ void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
} }
void VToolSplinePath::RefreshGeometry(){ void VToolSplinePath::RefreshGeometry(){
VSplinePath splPath = VAbstractTool::data->GetSplinePath(id); VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
QPainterPath path; QPainterPath path;
path.addPath(splPath.GetPath()); path.addPath(splPath.GetPath());
path.setFillRule( Qt::WindingFill ); path.setFillRule( Qt::WindingFill );
this->setPath(path); this->setPath(path);
for(qint32 i = 1; i<=splPath.Count(); ++i){ for(qint32 i = 1; i<=splPath.Count(); ++i){
VSpline spl = splPath.GetSpline(i); VSpline spl = splPath.GetSpline(i);
QPointF splinePoint = VAbstractTool::data->GetPoint(spl.GetP1()); QPointF splinePoint = VAbstractTool::data.GetPoint(spl.GetP1()).toQPointF();
QPointF controlPoint = spl.GetP2(); QPointF controlPoint = spl.GetP2();
emit RefreshLine(i, SplinePoint::FirstPoint, controlPoint, splinePoint); emit RefreshLine(i, SplinePoint::FirstPoint, controlPoint, splinePoint);
splinePoint = VAbstractTool::data->GetPoint(spl.GetP4()); splinePoint = VAbstractTool::data.GetPoint(spl.GetP4()).toQPointF();
controlPoint = spl.GetP3(); controlPoint = spl.GetP3();
emit RefreshLine(i, SplinePoint::LastPoint, controlPoint, splinePoint); emit RefreshLine(i, SplinePoint::LastPoint, controlPoint, splinePoint);
qint32 j = i*2;
disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
controlPoints[j-2]->setPos(spl.GetP2());
controlPoints[j-1]->setPos(spl.GetP3());
connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
} }
} }

View File

@ -14,6 +14,11 @@ class VToolSplinePath:public VAbstractTool, public QGraphicsPathItem
public: public:
VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id,
Tool::Enum typeCreation, QGraphicsItem * parent = 0); Tool::Enum typeCreation, QGraphicsItem * parent = 0);
virtual void setDialog();
static void Create(QSharedPointer<DialogSplinePath> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(const qint64 _id, const VSplinePath &path, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation);
signals: signals:
void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos,
const QPointF &controlPoint, const QPointF &splinePoint); const QPointF &controlPoint, const QPointF &splinePoint);

View File

@ -46,7 +46,6 @@
*/ */
#include <QtGui> #include <QtGui>
#include "delegate.h" #include "delegate.h"
SpinBoxDelegate::SpinBoxDelegate(QObject *parent) SpinBoxDelegate::SpinBoxDelegate(QObject *parent)

View File

@ -59,8 +59,8 @@
const QModelIndex &/* index */) const const QModelIndex &/* index */) const
{ {
QDoubleSpinBox *editor = new QDoubleSpinBox(parent); QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
editor->setMinimum(-1000); editor->setMinimum(-1000.0);
editor->setMaximum(1000); editor->setMaximum(1000.0);
return editor; return editor;
} }
@ -79,7 +79,7 @@
{ {
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor); QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
spinBox->interpretText(); spinBox->interpretText();
int value = spinBox->value(); qreal value = spinBox->value();
model->setData(index, value, Qt::EditRole); model->setData(index, value, Qt::EditRole);
} }

View File

@ -44,16 +44,16 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang
if (change == ItemPositionChange && scene()) { if (change == ItemPositionChange && scene()) {
// value - это новое положение. // value - это новое положение.
QPointF newPos = value.toPointF(); QPointF newPos = value.toPointF();
qDebug()<<this->rect(); // qDebug()<<this->rect();
QRectF rect = scene()->sceneRect(); // QRectF rect = scene()->sceneRect();
if (!rect.contains(newPos)) { // if (!rect.contains(newPos)) {
// Сохраняем элемент внутри прямоугольника сцены. // // Сохраняем элемент внутри прямоугольника сцены.
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left()))); // newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top()))); // newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
emit ControlPointChangePosition(indexSpline, position, newPos); // emit ControlPointChangePosition(indexSpline, position, newPos);
return newPos; // return newPos;
} // }
emit ControlPointChangePosition(indexSpline, position, newPos); emit ControlPointChangePosition(indexSpline, position, newPos);
} }
return QGraphicsItem::itemChange(change, value); return QGraphicsItem::itemChange(change, value);

View File

@ -14,15 +14,15 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphic
QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QVariant &value){ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QVariant &value){
if (change == ItemPositionChange && scene()) { if (change == ItemPositionChange && scene()) {
// value - это новое положение. // value - это новое положение.
QPointF newPos = value.toPointF(); QPointF newPos = value.toPointF() + this->parentItem()->pos();
QRectF rect = scene()->sceneRect(); // QRectF rect = scene()->sceneRect();
if (!rect.contains(newPos)) { // if (!rect.contains(newPos)) {
// Сохраняем элемент внутри прямоугольника сцены. // // Сохраняем элемент внутри прямоугольника сцены.
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left()))); // newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top()))); // newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
emit NameChangePosition(newPos); // emit NameChangePosition(newPos - this->parentItem()->pos());
return newPos; // return newPos - this->parentItem()->pos();
} // }
emit NameChangePosition(newPos); emit NameChangePosition(newPos);
} }
return QGraphicsItem::itemChange(change, value); return QGraphicsItem::itemChange(change, value);

View File

@ -1,14 +1,13 @@
#include "vmaingraphicsscene.h" #include "vmaingraphicsscene.h"
#include <QDebug> #include <QDebug>
#include <QApplication>
#include <QScrollBar>
VMainGraphicsScene::VMainGraphicsScene():QGraphicsScene(){
VMainGraphicsScene::VMainGraphicsScene():QGraphicsScene()
{
} }
VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent):QGraphicsScene ( sceneRect, parent ) VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent):QGraphicsScene ( sceneRect, parent ){
{
} }
void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event){ void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event){

View File

@ -2,6 +2,7 @@
#define VMAINGRAPHICSSCENE_H #define VMAINGRAPHICSSCENE_H
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include "../options.h" #include "../options.h"
@ -14,7 +15,7 @@ public:
VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = 0); VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = 0);
public slots: public slots:
void ChoosedItem(qint64 id, Scene::Type type); void ChoosedItem(qint64 id, Scene::Type type);
private: protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent* event); void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
signals: signals:

View File

@ -0,0 +1,31 @@
#include "vmaingraphicsview.h"
#include <QApplication>
#include <QWheelEvent>
#include <QScrollBar>
VMainGraphicsView::VMainGraphicsView(QWidget *parent) :
QGraphicsView(parent){
QGraphicsView::setResizeAnchor(QGraphicsView::AnchorUnderMouse);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
}
void VMainGraphicsView::wheelEvent(QWheelEvent *event){
if (QApplication::keyboardModifiers() == Qt::ControlModifier){
// Если нажата клавиша CTRL этот код выполнится
if ((event->delta())>0){
ZoomIn();
} else if ((event->delta())<0){
ZoomOut();
}
} else {
verticalScrollBar()->setValue(verticalScrollBar()->value() - event->delta());
}
}
void VMainGraphicsView::ZoomIn(){
scale(1.1,1.1);
}
void VMainGraphicsView::ZoomOut(){
scale(1/1.1,1/1.1);
}

View File

@ -0,0 +1,32 @@
#ifndef VMAINGRAPHICSVIEW_H
#define VMAINGRAPHICSVIEW_H
#include <QGraphicsView>
class VMainGraphicsView : public QGraphicsView
{
Q_OBJECT
public:
explicit VMainGraphicsView(QWidget *parent = 0);
signals:
protected:
/**
* @brief wheelEvent обробник повороту колеса мишки.
* @param event передається подія.
*/
void wheelEvent ( QWheelEvent * event );
public slots:
/**
* @brief ZoomIn збільшує масштаб листа.
*/
void ZoomIn();
/**
* @brief ZoomOut зменшує масштаб листа.
*/
void ZoomOut();
};
#endif // VMAINGRAPHICSVIEW_H

View File

@ -1,6 +1,6 @@
#pragma GCC diagnostic ignored "-Weffc++"
#include "vdomdocument.h" #include "vdomdocument.h"
#include <QDebug> #include <QDebug>
#include "../tools/vtoolsinglepoint.h" #include "../tools/vtoolsinglepoint.h"
#include "../tools/vtoolendline.h" #include "../tools/vtoolendline.h"
#include "../tools/vtoolline.h" #include "../tools/vtoolline.h"
@ -12,11 +12,13 @@
#include "../tools/vtoolspline.h" #include "../tools/vtoolspline.h"
#include "../tools/vtoolarc.h" #include "../tools/vtoolarc.h"
#include "../tools/vtoolsplinepath.h" #include "../tools/vtoolsplinepath.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "../options.h" #include "../options.h"
#include "../container/calculator.h" #include "../container/calculator.h"
#include "../geometry/vsplinepoint.h" #include "../geometry/vsplinepoint.h"
VDomDocument::VDomDocument(VContainer *data) : QDomDocument() { VDomDocument::VDomDocument(VContainer *data) : QDomDocument() {
this->data = data; this->data = data;
} }
@ -29,13 +31,15 @@ VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data) :
this->data = data; this->data = data;
} }
VDomDocument::~VDomDocument(){
}
QDomElement VDomDocument::elementById(const QString& id){ QDomElement VDomDocument::elementById(const QString& id){
if (map.contains(id)) { if (map.contains(id)) {
QDomElement e = map[id]; QDomElement e = map[id];
if (e.parentNode().nodeType() != QDomNode::BaseNode) { if (e.parentNode().nodeType() != QDomNode::BaseNode) {
return e; return e;
} }
map.remove(id); map.remove(id);
} }
@ -227,6 +231,7 @@ void VDomDocument::Parse(Document::Enum parse, VMainGraphicsScene *scene, QCombo
nameActivDraw.clear(); nameActivDraw.clear();
scene->clear(); scene->clear();
comboBoxDraws->clear(); comboBoxDraws->clear();
tools.clear();
} else { } else {
data->ClearLengthLines(); data->ClearLengthLines();
data->ClearLengthArcs(); data->ClearLengthArcs();
@ -259,6 +264,10 @@ void VDomDocument::Parse(Document::Enum parse, VMainGraphicsScene *scene, QCombo
} }
} }
QMap<qint64, VDataTool *> *VDomDocument::getTools(){
return &tools;
}
void VDomDocument::ParseIncrementsElement(const QDomNode &node){ void VDomDocument::ParseIncrementsElement(const QDomNode &node){
QDomNode domNode = node.firstChild(); QDomNode domNode = node.firstChild();
while(!domNode.isNull()){ while(!domNode.isNull()){
@ -267,15 +276,16 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node){
if(!domElement.isNull()){ if(!domElement.isNull()){
if(domElement.tagName() == "increment"){ if(domElement.tagName() == "increment"){
QString name,desc; QString name,desc;
qint32 base; qreal base;
qreal ksize, kgrowth; qreal ksize, kgrowth;
qint64 id; qint64 id;
id = domElement.attribute("id", "").toLongLong(); id = domElement.attribute("id", "").toLongLong();
name = domElement.attribute("name", ""); name = domElement.attribute("name", "");
base = domElement.attribute("base","").toInt(); base = domElement.attribute("base","").toDouble();
ksize = domElement.attribute("ksize","").toDouble(); ksize = domElement.attribute("ksize","").toDouble();
kgrowth = domElement.attribute("kgrowth","").toDouble(); kgrowth = domElement.attribute("kgrowth","").toDouble();
desc = domElement.attribute("description",""); desc = domElement.attribute("description","");
data->UpdateId(id);
data->AddIncrementTableRow(name, data->AddIncrementTableRow(name,
VIncrementTableRow(id, base, ksize, kgrowth, desc)); VIncrementTableRow(id, base, ksize, kgrowth, desc));
} }
@ -378,248 +388,110 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
data->UpdatePoint(id, VPointF(x, y, name, mx, my)); data->UpdatePoint(id, VPointF(x, y, name, mx, my));
if(parse != Document::FullParse){
VToolSinglePoint *spoint = qobject_cast<VToolSinglePoint*>(tools[id]);
spoint->VDataTool::setData(data);
tools[id] = spoint;
}
if(parse == Document::FullParse){ if(parse == Document::FullParse){
VToolSinglePoint *spoint = new VToolSinglePoint(this, data, id, Tool::FromFile); VToolSinglePoint *spoint = new VToolSinglePoint(this, data, id, Tool::FromFile);
scene->addItem(spoint); scene->addItem(spoint);
connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
tools[id] = spoint;
} }
} }
return; return;
} }
if(type == "endLine"){ if(type == "endLine"){
if(!domElement.isNull()){ if(!domElement.isNull()){
QString name, typeLine, formula; qint64 id = domElement.attribute("id", "").toLongLong();
qreal mx=5, my=10; QString name = domElement.attribute("name", "");
qint64 id, basePointId; qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qint32 angle; qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
QString typeLine = domElement.attribute("typeLine", "");
id = domElement.attribute("id", "").toLongLong(); QString formula = domElement.attribute("length", "");
name = domElement.attribute("name", ""); qint64 basePointId = domElement.attribute("basePoint", "").toLongLong();
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qint32 angle = domElement.attribute("angle", "").toInt();
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this, data,
parse, Tool::FromFile);
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
basePointId = domElement.attribute("basePoint", "").toLongLong();
angle = domElement.attribute("angle", "").toInt();
VPointF basePoint = data->GetPoint(basePointId);
QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y()));
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
line.setAngle(angle);
data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), name, mx, my));
data->AddLine(basePointId, id);
if(parse == Document::FullParse){
VToolEndLine *point = new VToolEndLine(this, data, id, typeLine, formula, angle,
basePointId, Tool::FromFile);
scene->addItem(point);
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
}
} }
return; return;
} }
if(type == "alongLine"){ if(type == "alongLine"){
if(!domElement.isNull()){ if(!domElement.isNull()){
QString name, typeLine, formula; qint64 id = domElement.attribute("id", "").toLongLong();
qreal mx=5, my=10; QString name = domElement.attribute("name", "");
qint64 id, firstPointId, secondPointId; qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
id = domElement.attribute("id", "").toLongLong(); QString typeLine = domElement.attribute("typeLine", "");
name = domElement.attribute("name", ""); QString formula = domElement.attribute("length", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong();
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong();
VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my,
typeLine = domElement.attribute("typeLine", ""); scene, this, data, parse, Tool::FromFile);
formula = domElement.attribute("length", "");
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF());
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), name, mx, my));
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
if(parse == Document::FullParse){
VToolAlongLine *point = new VToolAlongLine(this, data, id, formula, firstPointId,
secondPointId, typeLine, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
}
} }
return; return;
} }
if(type == "shoulder"){ if(type == "shoulder"){
if(!domElement.isNull()){ if(!domElement.isNull()){
QString name, typeLine, formula; qint64 id = domElement.attribute("id", "").toLongLong();
qreal mx=5, my=10; QString name = domElement.attribute("name", "");
qint64 id, p1Line, p2Line, pShoulder; qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
id = domElement.attribute("id", "").toLongLong(); QString typeLine = domElement.attribute("typeLine", "");
name = domElement.attribute("name", ""); QString formula = domElement.attribute("length", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qint64 p1Line = domElement.attribute("p1Line", "").toLongLong();
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; qint64 p2Line = domElement.attribute("p2Line", "").toLongLong();
qint64 pShoulder = domElement.attribute("pShoulder", "").toLongLong();
typeLine = domElement.attribute("typeLine", ""); VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my,
formula = domElement.attribute("length", ""); scene, this, data, parse, Tool::FromFile);
p1Line = domElement.attribute("p1Line", "").toLongLong();
p2Line = domElement.attribute("p2Line", "").toLongLong();
pShoulder = domElement.attribute("pShoulder", "").toLongLong();
VPointF firstPoint = data->GetPoint(p1Line);
VPointF secondPoint = data->GetPoint(p2Line);
VPointF shoulderPoint = data->GetPoint(pShoulder);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint, secondPoint, shoulderPoint,
result*PrintDPI/25.4);
data->UpdatePoint(id,VPointF(fPoint.x(), fPoint.y(), name, mx, my));
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
if(parse == Document::FullParse){
VToolShoulderPoint *point = new VToolShoulderPoint(this, data, id, typeLine, formula,
p1Line, p2Line, pShoulder,
Tool::FromGui);
scene->addItem(point);
connect(point, &VToolShoulderPoint::ChoosedTool, scene,
&VMainGraphicsScene::ChoosedItem);
}
}
} }
return; return;
} }
if(type == "normal"){ if(type == "normal"){
if(!domElement.isNull()){ if(!domElement.isNull()){
QString name, typeLine, formula; qint64 id = domElement.attribute("id", "").toLongLong();
qreal mx=5, my=10, angle; QString name = domElement.attribute("name", "");
qint64 id, firstPointId, secondPointId; qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
id = domElement.attribute("id", "").toLongLong(); QString typeLine = domElement.attribute("typeLine", "");
name = domElement.attribute("name", ""); QString formula = domElement.attribute("length", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong();
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong();
qreal angle = domElement.attribute("angle", "").toInt();
typeLine = domElement.attribute("typeLine", ""); VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle,
formula = domElement.attribute("length", ""); mx, my, scene, this, data, parse, Tool::FromFile);
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
angle = domElement.attribute("angle", "").toInt();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolNormal::FindPoint(firstPoint, secondPoint, result*PrintDPI/25.4,
angle);
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), name, mx, my));
data->AddLine(firstPointId, id);
if(parse == Document::FullParse){
VToolNormal *point = new VToolNormal(this, data, id, typeLine, formula, angle,
firstPointId, secondPointId, Tool::FromFile);
scene->addItem(point);
connect(point, &VToolNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
}
} }
return; return;
} }
if(type == "bisector"){ if(type == "bisector"){
if(!domElement.isNull()){ if(!domElement.isNull()){
QString name, typeLine, formula; qint64 id = domElement.attribute("id", "").toLongLong();
qreal mx=5, my=10; QString name = domElement.attribute("name", "");
qint64 id, firstPointId, secondPointId, thirdPointId; qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
id = domElement.attribute("id", "").toLongLong(); QString typeLine = domElement.attribute("typeLine", "");
name = domElement.attribute("name", ""); QString formula = domElement.attribute("length", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong();
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong();
qint64 thirdPointId = domElement.attribute("thirdPoint", "").toLongLong();
typeLine = domElement.attribute("typeLine", ""); VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine,
formula = domElement.attribute("length", ""); name, mx, my, scene, this, data, parse, Tool::FromFile);
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
thirdPointId = domElement.attribute("thirdPoint", "").toLongLong();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
VPointF thirdPoint = data->GetPoint(thirdPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VToolBisector::FindPoint(firstPoint, secondPoint, thirdPoint,
result*PrintDPI/25.4);
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), name, mx, my));
data->AddLine(firstPointId, id);
if(parse == Document::FullParse){
VToolBisector *point = new VToolBisector(this, data, id, typeLine, formula,
firstPointId, secondPointId, thirdPointId,
Tool::FromFile);
scene->addItem(point);
connect(point, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
}
} }
return; return;
} }
if(type == "lineIntersect"){ if(type == "lineIntersect"){
if(!domElement.isNull()){ if(!domElement.isNull()){
QString name; qint64 id = domElement.attribute("id", "").toLongLong();
qreal mx=5, my=10; QString name = domElement.attribute("name", "");
qint64 id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id; qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
id = domElement.attribute("id", "").toLongLong(); qint64 p1Line1Id = domElement.attribute("p1Line1", "").toLongLong();
name = domElement.attribute("name", ""); qint64 p2Line1Id = domElement.attribute("p2Line1", "").toLongLong();
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qint64 p1Line2Id = domElement.attribute("p1Line2", "").toLongLong();
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; qint64 p2Line2Id = domElement.attribute("p2Line2", "").toLongLong();
VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, scene,
p1Line1Id = domElement.attribute("p1Line1", "").toLongLong(); this, data, parse, Tool::FromFile);
p2Line1Id = domElement.attribute("p2Line1", "").toLongLong();
p1Line2Id = domElement.attribute("p1Line2", "").toLongLong();
p2Line2Id = domElement.attribute("p2Line2", "").toLongLong();
VPointF p1Line1 = data->GetPoint(p1Line1Id);
VPointF p2Line1 = data->GetPoint(p2Line1Id);
VPointF p1Line2 = data->GetPoint(p1Line2Id);
VPointF p2Line2 = data->GetPoint(p2Line2Id);
QLineF line1(p1Line1, p2Line1);
QLineF line2(p1Line2, p2Line2);
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), name, mx, my));
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
if(parse == Document::FullParse){
VToolLineIntersect *point = new VToolLineIntersect(this, data, id, p1Line1Id,
p2Line1Id, p1Line2Id,
p2Line2Id, Tool::FromFile);
scene->addItem(point);
connect(point, &VToolLineIntersect::ChoosedTool, scene,
&VMainGraphicsScene::ChoosedItem);
}
}
} }
return; return;
} }
@ -628,18 +500,10 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement, void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement,
Document::Enum parse){ Document::Enum parse){
if(!domElement.isNull()){ if(!domElement.isNull()){
qint64 firstPoint; qint64 id = domElement.attribute("id", "").toLongLong();
qint64 secondPoint; qint64 firstPoint = domElement.attribute("firstPoint", "").toLongLong();
qint64 secondPoint = domElement.attribute("secondPoint", "").toLongLong();
firstPoint = domElement.attribute("firstPoint", "").toLongLong(); VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile);
secondPoint = domElement.attribute("secondPoint", "").toLongLong();
data->AddLine(firstPoint, secondPoint);
if(parse == Document::FullParse){
qint64 id = data->getNextId();
VToolLine *line = new VToolLine(this, data, id, firstPoint, secondPoint, Tool::FromFile);
scene->addItem(line);
connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
} }
@ -647,32 +511,21 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
Document::Enum parse, const QString &type){ Document::Enum parse, const QString &type){
if(type == "simple"){ if(type == "simple"){
if(!domElement.isNull()){ if(!domElement.isNull()){
qreal angle1, angle2, kAsm1, kAsm2, kCurve; qint64 id = domElement.attribute("id", "").toLongLong();
qint64 id, point1, point4; qint64 point1 = domElement.attribute("point1", "").toLongLong();
qint64 point4 = domElement.attribute("point4", "").toLongLong();
id = domElement.attribute("id", "").toLongLong(); qreal angle1 = domElement.attribute("angle1","").toDouble();
point1 = domElement.attribute("point1", "").toLongLong(); qreal angle2 = domElement.attribute("angle2","").toDouble();
point4 = domElement.attribute("point4", "").toLongLong(); qreal kAsm1 = domElement.attribute("kAsm1","").toDouble();
angle1 = domElement.attribute("angle1","").toDouble(); qreal kAsm2 = domElement.attribute("kAsm2","").toDouble();
angle2 = domElement.attribute("angle2","").toDouble(); qreal kCurve = domElement.attribute("kCurve","").toDouble();
kAsm1 = domElement.attribute("kAsm1","").toDouble(); VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data,
kAsm2 = domElement.attribute("kAsm2","").toDouble(); parse, Tool::FromFile);
kCurve = domElement.attribute("kCurve","").toDouble();
VSpline spline = VSpline(data->DataPoints(), point1, point4, angle1, angle2, kAsm1, kAsm2, kCurve);
data->UpdateSpline(id, spline);
data->AddLengthSpline(data->GetNameSpline(point1, point4), spline.GetLength());
if(parse == Document::FullParse){
VToolSpline *spl = new VToolSpline(this, data, id, Tool::FromFile);
scene->addItem(spl);
connect(spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
return; return;
} }
if(type == "path"){ if(type == "path"){
if(!domElement.isNull()){ if(!domElement.isNull()){
qint64 id = domElement.attribute("id", "").toLongLong(); qint64 id = domElement.attribute("id", "").toLongLong();
qreal kCurve = domElement.attribute("kCurve","").toDouble(); qreal kCurve = domElement.attribute("kCurve","").toDouble();
VSplinePath path(data->DataPoints(), kCurve); VSplinePath path(data->DataPoints(), kCurve);
@ -690,17 +543,9 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2); VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2);
path.append(splPoint); path.append(splPoint);
} }
} }
} }
VToolSplinePath::Create(id, path, scene, this, data, Document::FullParse, Tool::FromFile);
data->UpdateSplinePath(id, path);
data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength());
if(parse == Document::FullParse){
VToolSplinePath *spl = new VToolSplinePath(this, data, id, Tool::FromFile);
scene->addItem(spl);
connect(spl, &VToolSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
return; return;
} }
@ -710,44 +555,12 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement
Document::Enum parse, const QString &type){ Document::Enum parse, const QString &type){
if(type == "simple"){ if(type == "simple"){
if(!domElement.isNull()){ if(!domElement.isNull()){
QString radius, f1, f2; qint64 id = domElement.attribute("id", "").toLongLong();
qint64 id, center; qint64 center = domElement.attribute("center", "").toLongLong();
QString radius = domElement.attribute("radius", "");
id = domElement.attribute("id", "").toLongLong(); QString f1 = domElement.attribute("angle1", "");
center = domElement.attribute("center", "").toLongLong(); QString f2 = domElement.attribute("angle2","");
radius = domElement.attribute("radius", ""); VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile);
f1 = domElement.attribute("angle1", "");
f2 = domElement.attribute("angle2","");
qreal calcRadius = 0, calcF1 = 0, calcF2 = 0;
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(radius, &errorMsg);
if(errorMsg.isEmpty()){
calcRadius = result*PrintDPI/25.4;
}
errorMsg.clear();
result = cal.eval(f1, &errorMsg);
if(errorMsg.isEmpty()){
calcF1 = result;
}
errorMsg.clear();
result = cal.eval(f2, &errorMsg);
if(errorMsg.isEmpty()){
calcF2 = result;
}
VArc arc = VArc(data->DataPoints(), center, calcRadius, radius, calcF1, f1, calcF2, f2 );
data->UpdateArc(id, arc);
data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength());
if(parse == Document::FullParse){
VToolArc *toolArc = new VToolArc(this, data, id, Tool::FromFile);
scene->addItem(toolArc);
connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
return; return;
} }

View File

@ -1,13 +1,15 @@
#ifndef VDOMDOCUMENT_H #ifndef VDOMDOCUMENT_H
#define VDOMDOCUMENT_H #define VDOMDOCUMENT_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QDomDocument> #include <QDomDocument>
#include <QMap> #include <QMap>
#include <QObject> #include <QObject>
#include <QComboBox> #include <QComboBox>
#include "../container/vcontainer.h" #include "../container/vcontainer.h"
#include "../widgets/vmaingraphicsscene.h" #include "../widgets/vmaingraphicsscene.h"
#include "../tools/vdatatool.h"
#pragma GCC diagnostic warning "-Weffc++"
namespace Document{ namespace Document{
enum Enum enum Enum
@ -24,6 +26,7 @@ public:
VDomDocument(VContainer *data); VDomDocument(VContainer *data);
VDomDocument(const QString& name, VContainer *data); VDomDocument(const QString& name, VContainer *data);
VDomDocument(const QDomDocumentType& doctype, VContainer *data); VDomDocument(const QDomDocumentType& doctype, VContainer *data);
~VDomDocument();
QDomElement elementById(const QString& id); QDomElement elementById(const QString& id);
void CreateEmptyFile(); void CreateEmptyFile();
void ChangeActivDraw(const QString& name); void ChangeActivDraw(const QString& name);
@ -35,6 +38,7 @@ public:
bool appendDraw(const QString& name); bool appendDraw(const QString& name);
void SetNameDraw(const QString& name); void SetNameDraw(const QString& name);
void Parse(Document::Enum parse, VMainGraphicsScene *scene, QComboBox *comboBoxDraws); void Parse(Document::Enum parse, VMainGraphicsScene *scene, QComboBox *comboBoxDraws);
QMap<qint64, VDataTool*>* getTools();
signals: signals:
void ChangedActivDraw(const QString newName); void ChangedActivDraw(const QString newName);
void ChangedNameDraw(const QString oldName, const QString newName); void ChangedNameDraw(const QString oldName, const QString newName);
@ -47,6 +51,7 @@ private:
QMap<QString, QDomElement> map; QMap<QString, QDomElement> map;
QString nameActivDraw; QString nameActivDraw;
VContainer *data; VContainer *data;
QMap<qint64, VDataTool*> tools;
bool find(QDomElement node, const QString& id); bool find(QDomElement node, const QString& id);
bool CheckNameDraw(const QString& name) const; bool CheckNameDraw(const QString& name) const;
void SetActivDraw(const QString& name); void SetActivDraw(const QString& name);