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\
mainwindow.cpp \
widgets/vmaingraphicsscene.cpp \
dialogs/dialogsinglepoint.cpp \
widgets/vgraphicssimpletextitem.cpp \
xml/vdomdocument.cpp \
@ -54,7 +53,10 @@ SOURCES += main.cpp\
geometry/vsplinepoint.cpp \
geometry/vsplinepath.cpp \
tools/vtoolsplinepath.cpp \
dialogs/dialogsplinepath.cpp
dialogs/dialogsplinepath.cpp \
widgets/vmaingraphicsscene.cpp \
widgets/vmaingraphicsview.cpp \
tools/vdatatool.cpp
HEADERS += mainwindow.h \
widgets/vmaingraphicsscene.h \
@ -99,7 +101,9 @@ HEADERS += mainwindow.h \
geometry/vsplinepoint.h \
geometry/vsplinepath.h \
tools/vtoolsplinepath.h \
dialogs/dialogsplinepath.h
dialogs/dialogsplinepath.h \
widgets/vmaingraphicsview.h \
tools/vdatatool.h
FORMS += mainwindow.ui \
dialogs/dialogsinglepoint.ui \
@ -121,7 +125,9 @@ RESOURCES += \
CONFIG(debug, debug|release){
# 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{
# Release
QMAKE_CXXFLAGS += -O1 -std=c++0x

View File

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

View File

@ -1,11 +1,13 @@
#ifndef VCONTAINER_H
#define VCONTAINER_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QMap>
#include <QTableWidget>
#include "vpointf.h"
#include "vstandarttablecell.h"
#include "vincrementtablerow.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "../geometry/vspline.h"
#include "../geometry/varc.h"
#include "../geometry/vsplinepath.h"
@ -85,6 +87,7 @@ public:
const QMap<QString, qreal> *DataLengthArcs() const;
const QMap<QString, qreal> *DataLineArcs() const;
const QMap<qint64, VSplinePath> *DataSplinePaths() const;
void UpdateId(qint64 newId);
private:
qint64 _id;
QMap<QString, qint32> base;
@ -98,6 +101,10 @@ private:
QMap<qint64, VArc> arcs;
QMap<QString, qreal> lengthArcs;
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

View File

@ -8,7 +8,7 @@ VIncrementTableRow::VIncrementTableRow(){
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){
this->id = id;
this->base = base;
@ -41,11 +41,11 @@ void VIncrementTableRow::setKsize(const qreal &value){
ksize = value;
}
qint32 VIncrementTableRow::getBase() const{
qreal VIncrementTableRow::getBase() const{
return base;
}
void VIncrementTableRow::setBase(const qint32 &value){
void VIncrementTableRow::setBase(const qreal &value){
base = value;
}

View File

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

View File

@ -1,20 +1,29 @@
#include "vpointf.h"
VPointF::VPointF():QPointF(){
VPointF::VPointF(){
_mx = 0;
_my = 0;
this->_x = 0;
this->_y = 0;
}
VPointF::VPointF ( const VPointF & point ):QPointF(point){
VPointF::VPointF ( const VPointF & point ){
_name = point.name();
_mx = point.mx();
_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;
_mx = mx;
_my = my;
this->_x = x;
this->_y = y;
}
VPointF::~VPointF(){
}
QString VPointF::name() const{
@ -42,5 +51,21 @@ void VPointF::setMy(qreal my){
}
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
#define VPOINTF_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QPointF>
#include <QString>
#pragma GCC diagnostic warning "-Weffc++"
class VPointF : public QPointF
class VPointF
{
public:
VPointF();
VPointF (const VPointF &point );
VPointF ( qreal x, qreal y, QString name, qreal mx, qreal my );
~VPointF();
QString name() const;
qreal mx() const;
qreal my() const;
@ -17,10 +20,17 @@ public:
void setMx(qreal mx);
void setMy(qreal my);
QPointF toQPointF()const;
qreal x() const;
void setX(const qreal &value);
qreal y() const;
void setY(const qreal &value);
private:
QString _name;
qreal _mx;
qreal _my;
qreal _x;
qreal _y;
};
#endif // VPOINTF_H

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -43,13 +43,16 @@ void DialogTool::showEvent(QShowEvent *event){
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();
QMapIterator<qint64, VPointF> i(*points);
while (i.hasNext()) {
i.next();
VPointF point = i.value();
box->addItem(point.name(), i.key());
if(i.key() != id){
VPointF point = i.value();
box->addItem(point.name(), i.key());
}
}
}
@ -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);
if(index != -1){
box->setCurrentIndex(index);
@ -137,6 +140,25 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label)
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(){
Q_CHECK_PTR(bOk);
bOk->setEnabled(flagFormula & flagName);
@ -293,9 +315,9 @@ void DialogTool::ValChenged(int row){
}
void DialogTool::UpdateList(){
Q_CHECK_PTR(radioButtonSizeGrowth);
Q_CHECK_PTR(radioButtonStandartTable);
Q_CHECK_PTR(radioButtonIncrements);
if(radioButtonSizeGrowth == 0 || radioButtonStandartTable == 0 || radioButtonIncrements == 0){
return;
}
if(radioButtonSizeGrowth->isChecked()){
ShowVariable(data->DataBase());
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
#pragma GCC diagnostic ignored "-Weffc++"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
#include <QSpinBox>
#include <QScrollBar>
@ -10,7 +10,6 @@
#include <QFileDialog>
#include <QDebug>
#include "options.h"
#include "tools/vtoolendline.h"
#include "tools/vtoolline.h"
#include "tools/vtoolalongline.h"
@ -21,6 +20,8 @@
#include "tools/vtoolspline.h"
#include "tools/vtoolarc.h"
#include "tools/vtoolsplinepath.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "options.h"
#include "geometry/vspline.h"
MainWindow::MainWindow(QWidget *parent) :
@ -33,7 +34,13 @@ MainWindow::MainWindow(QWidget *parent) :
ToolBarDraws();
QRectF sceneRect = QRectF(0, 0, PaperSize, PaperSize);
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(ui->toolButtonSinglePoint, &QToolButton::clicked, this,
@ -73,7 +80,6 @@ MainWindow::MainWindow(QWidget *parent) :
&MainWindow::ToolSplinePath);
data = new VContainer;
CreateManTableIGroup ();
doc = new VDomDocument(data);
doc->CreateEmptyFile();
@ -159,6 +165,27 @@ void MainWindow::OptionDraw(){
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;
QPixmap pixmap(":/cursor/spoint_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
view->setCursor(cur);
helpLabel->setText("Виберіть розташування для точки.");
dialogSinglePoint = new DialogSinglePoint(data);
//покажемо вікно як тільки буде вибрано місце розташування для точки
@ -181,444 +208,143 @@ void MainWindow::ToolSinglePoint(bool checked){
}
}
void MainWindow::ToolEndLine(bool checked){
if(checked){
CanselTool();
tool = Tools::EndLineTool;
QPixmap pixmap(":/cursor/endline_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Заповніть усі поля.");
dialogEndLine = new DialogEndLine(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogEndLine,
&DialogEndLine::ChoosedObject);
connect(dialogEndLine, &DialogEndLine::DialogClosed, this,
&MainWindow::ClosedDialogEndLine);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogEndLine, &DialogEndLine::UpdateList);
} else {
ui->toolButtonEndLine->setChecked(true);
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);
QMap<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id, spoint);
ArrowTool();
ui->toolButtonSinglePoint->setEnabled(false);
qint32 index = comboBoxDraws->currentIndex();
comboBoxDraws->setItemData(index, false);
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){
if(result == QDialog::Accepted){
QString pointName = dialogEndLine->getPointName();
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);
}
VToolEndLine::Create(dialogEndLine, scene, doc, data);
}
ArrowTool();
}
void MainWindow::ToolLine(bool checked){
if(checked){
CanselTool();
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);
}
SetToolButton(checked, Tools::LineTool, ":/cursor/line_cursor.png", dialogLine,
&MainWindow::ClosedDialogLine);
}
void MainWindow::ClosedDialogLine(int result){
if(result == QDialog::Accepted){
qint64 firstPoint = dialogLine->getFirstPoint();
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);
VToolLine::Create(dialogLine, scene, doc, data);
}
ArrowTool();
}
void MainWindow::ToolAlongLine(bool checked){
if(checked){
CanselTool();
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);
}
SetToolButton(checked, Tools::AlongLineTool, ":/cursor/alongline_cursor.png", dialogAlongLine,
&MainWindow::ClosedDialogAlongLine);
}
void MainWindow::ClosedDialogAlongLine(int result){
if(result == QDialog::Accepted){
QString formula = dialogAlongLine->getFormula();
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);
}
VToolAlongLine::Create(dialogAlongLine, scene, doc, data);
}
ArrowTool();
}
void MainWindow::ToolShoulderPoint(bool checked){
if(checked){
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);
} else {
ui->toolButtonShoulderPoint->setChecked(true);
}
SetToolButton(checked, Tools::ShoulderPointTool, ":/cursor/shoulder_cursor.png", dialogShoulderPoint,
&MainWindow::ClosedDialogShoulderPoint);
}
void MainWindow::ClosedDialogShoulderPoint(int result){
if(result == QDialog::Accepted){
QString formula = dialogShoulderPoint->getFormula();
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);
}
VToolShoulderPoint::Create(dialogShoulderPoint, scene, doc, data);
}
ArrowTool();
}
void MainWindow::ToolNormal(bool checked){
if(checked){
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);
} else {
ui->toolButtonNormal->setChecked(true);
}
SetToolButton(checked, Tools::NormalTool, ":/cursor/normal_cursor.png", dialogNormal,
&MainWindow::ClosedDialogNormal);
}
void MainWindow::ClosedDialogNormal(int result){
if(result == QDialog::Accepted){
QString formula = dialogNormal->getFormula();
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);
}
VToolNormal::Create(dialogNormal, scene, doc, data);
}
ArrowTool();
}
void MainWindow::ToolBisector(bool checked){
if(checked){
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);
} else {
ui->toolButtonBisector->setChecked(true);
}
SetToolButton(checked, Tools::BisectorTool, ":/cursor/bisector_cursor.png", dialogBisector,
&MainWindow::ClosedDialogBisector);
}
void MainWindow::ClosedDialogBisector(int result){
if(result == QDialog::Accepted){
QString formula = dialogBisector->getFormula();
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);
}
VToolBisector::Create(dialogBisector, scene, doc, data);
}
ArrowTool();
}
void MainWindow::ToolLineIntersect(bool checked){
if(checked){
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);
} else {
ui->toolButtonLineIntersect->setChecked(true);
}
SetToolButton(checked, Tools::LineIntersectTool, ":/cursor/intersect_cursor.png", dialogLineIntersect,
&MainWindow::ClosedDialogLineIntersect);
}
void MainWindow::ClosedDialogLineIntersect(int result){
if(result == QDialog::Accepted){
qint64 p1Line1Id = dialogLineIntersect->getP1Line1();
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);
}
VToolLineIntersect::Create(dialogLineIntersect, scene, doc, data);
}
ArrowTool();
}
void MainWindow::ToolSpline(bool checked){
if(checked){
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);
} else {
ui->toolButtonSpline->setChecked(true);
}
SetToolButton(checked, Tools::SplineTool, ":/cursor/spline_cursor.png", dialogSpline,
&MainWindow::ClosedDialogSpline);
}
void MainWindow::ClosedDialogSpline(int result){
if(result == QDialog::Accepted){
qint64 p1 = dialogSpline->getP1();
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);
VToolSpline::Create(dialogSpline, scene, doc, data);
}
ArrowTool();
}
void MainWindow::ToolArc(bool checked){
if(checked){
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);
} else {
ui->toolButtonSpline->setChecked(true);
}
SetToolButton(checked, Tools::ArcTool, ":/cursor/arc_cursor.png", dialogArc,
&MainWindow::ClosedDialogArc);
}
void MainWindow::ClosedDialogArc(int result){
if(result == QDialog::Accepted){
qint64 center = dialogArc->GetCenter();
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);
VToolArc::Create(dialogArc, scene, doc, data);
}
ArrowTool();
}
void MainWindow::ToolSplinePath(bool checked){
if(checked){
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);
} else {
ui->toolButtonSplinePath->setChecked(true);
}
SetToolButton(checked, Tools::SplinePathTool, ":/cursor/splinepath_cursor.png", dialogSplinePath,
&MainWindow::ClosedDialogSplinePath);
}
void MainWindow::ClosedDialogSplinePath(int result){
if(result == QDialog::Accepted){
VSplinePath path = dialogSplinePath->GetPath();
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);
VToolSplinePath::Create(dialogSplinePath, scene, doc, data);
}
ArrowTool();
}
@ -633,9 +359,9 @@ void MainWindow::showEvent( QShowEvent *event ){
return;
}
// do your init stuff here
QScrollBar *horScrollBar = ui->graphicsView->horizontalScrollBar();
QScrollBar *horScrollBar = view->horizontalScrollBar();
horScrollBar->setValue(horScrollBar->minimum());
QScrollBar *verScrollBar = ui->graphicsView->verticalScrollBar();
QScrollBar *verScrollBar = view->verticalScrollBar();
verScrollBar->setValue(verScrollBar->minimum());
isInitialized = true;//перший показ вікна вже відбувся
@ -703,7 +429,7 @@ void MainWindow::currentDrawChanged( int index ){
if(index != -1) {
bool status = qvariant_cast<bool>(comboBoxDraws->itemData(index));
ui->toolButtonSinglePoint->setEnabled(status);
if(ui->toolButtonSinglePoint->isEnabled()==false){
if(ui->toolButtonSinglePoint->isEnabled() == false){
SetEnableTool(true);
} else {
SetEnableTool(false);
@ -731,61 +457,61 @@ void MainWindow::CanselTool(){
ui->toolButtonSinglePoint->setChecked(false);
break;
case Tools::EndLineTool:
delete dialogEndLine;
dialogEndLine.clear();
ui->toolButtonEndLine->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::LineTool:
delete dialogLine;
dialogLine.clear();
ui->toolButtonLine->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearFocus();
break;
case Tools::AlongLineTool:
delete dialogAlongLine;
dialogAlongLine.clear();
ui->toolButtonAlongLine->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::ShoulderPointTool:
delete dialogShoulderPoint;
dialogShoulderPoint.clear();
ui->toolButtonShoulderPoint->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::NormalTool:
delete dialogNormal;
dialogNormal.clear();
ui->toolButtonNormal->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::BisectorTool:
delete dialogBisector;
dialogBisector.clear();
ui->toolButtonBisector->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::LineIntersectTool:
delete dialogLineIntersect;
dialogLineIntersect.clear();
ui->toolButtonLineIntersect->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::SplineTool:
delete dialogSpline;
dialogSpline.clear();
ui->toolButtonSpline->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::ArcTool:
delete dialogArc;
dialogArc.clear();
ui->toolButtonArc->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::SplinePathTool:
delete dialogSplinePath;
dialogSplinePath.clear();
ui->toolButtonSplinePath->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
@ -798,7 +524,7 @@ void MainWindow::ArrowTool(){
ui->actionArrowTool->setChecked(true);
tool = Tools::ArrowTool;
QCursor cur(Qt::ArrowCursor);
ui->graphicsView->setCursor(cur);
view->setCursor(cur);
helpLabel->setText("");
}
@ -815,24 +541,6 @@ void MainWindow::keyPressEvent ( QKeyEvent * 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){
if(checked){
ui->actionDetails->setChecked(false);
@ -854,6 +562,8 @@ void MainWindow::ActionSaveAs(){
QString defaultFilter("Lekalo files (*.xml)");
QString fName = QFileDialog::getSaveFileName(this, "Зберегти файл як", QDir::homePath(),
filters, &defaultFilter);
if(fName.isEmpty())
return;
if(fName.indexOf(".xml",fName.size()-4)<0){
fName.append(".xml");
}
@ -891,6 +601,8 @@ void MainWindow::ActionSave(){
void MainWindow::ActionOpen(){
QString filter("Lekalo files (*.xml)");
QString fName = QFileDialog::getOpenFileName(this, tr("Відкрити файл"), QDir::homePath(), filter);
if(fName.isEmpty())
return;
fileName = fName;
QFileInfo info(fileName);
QString title(info.fileName());
@ -899,11 +611,12 @@ void MainWindow::ActionOpen(){
QFile file(fileName);
if(file.open(QIODevice::ReadOnly)){
if(doc->setContent(&file)){
scene->clear();
comboBoxDraws->clear();
// ui->toolButtonSinglePoint->setEnabled(true);
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
doc->Parse(Document::FullParse, scene, comboBoxDraws);
CreateManTableIGroup ();
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
ui->actionSave->setEnabled(true);
@ -914,22 +627,25 @@ void MainWindow::ActionOpen(){
if ( index != -1 ) { // -1 for not found
comboBoxDraws->setCurrentIndex(index);
}
if(comboBoxDraws->count() == 1){
if(ui->toolButtonSinglePoint->isEnabled()==false){
SetEnableTool(true);
} else {
SetEnableTool(false);
}
}
}
file.close();
}
if(ui->toolButtonSinglePoint->isEnabled()==false){
SetEnableTool(true);
} else {
SetEnableTool(false);
}
}
void MainWindow::ActionNew(){
setWindowTitle("Valentina");
fileName.clear();
data->Clear();
doc->clear();
CreateManTableIGroup ();
scene->clear();
CanselTool();
comboBoxDraws->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){
qint32 size = text.toInt();
data->SetSize(size*10);

View File

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

View File

@ -14,62 +14,35 @@
<string>Valentina</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="2">
<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">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolBox" name="toolBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Fixed" vsizetype="Minimum">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>154</width>
<width>150</width>
<height>104</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Maximum">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -229,12 +202,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>154</width>
<width>1074</width>
<height>58</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -296,12 +269,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>154</width>
<width>1074</width>
<height>58</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -363,12 +336,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>154</width>
<width>1074</width>
<height>58</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -404,6 +377,16 @@
</widget>
</widget>
</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>
</widget>
<widget class="QMenuBar" name="menuBar">

View File

@ -1,16 +1,19 @@
#pragma GCC diagnostic ignored "-Weffc++"
#include "vabstracttool.h"
#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->data = data;
this->id = id;
nameActivDraw = doc->GetNameActivDraw();
ignoreContextMenuEvent = false;//don't ignore context menu events;
connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VAbstractTool::ChangedActivDraw);
connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VAbstractTool::ChangedNameDraw);
connect(this, &VAbstractTool::haveLiteChange, this->doc, &VDomDocument::haveLiteChange);
connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange);
connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile);
connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree);
}
@ -65,3 +68,14 @@ void VAbstractTool::AddToCalculation(const QDomElement &domElement){
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
#define VABSTRACTTOOL_H
#include <QObject>
#include "../container/vcontainer.h"
#pragma GCC diagnostic ignored "-Weffc++"
#include <QMenu>
#include "../xml/vdomdocument.h"
#include "vdatatool.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "../container/vcontainer.h"
namespace Tool{
enum Enum
@ -14,24 +16,24 @@ namespace Tool{
};
}
class VAbstractTool:public QObject
class VAbstractTool:public VDataTool
{
Q_OBJECT
public:
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id);
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0);
virtual ~VAbstractTool();
virtual void setDialog();
public slots:
virtual void FullUpdateFromFile()=0;
void ChangedNameDraw(const QString oldName, const QString newName);
virtual void ChangedActivDraw(const QString newName);
virtual void FullUpdateFromGui(int result)=0;
signals:
void haveLiteChange();
void toolhaveChange();
void ChoosedTool(qint64 id, Scene::Type type);
void FullUpdateTree();
protected:
VDomDocument *doc;
VContainer *data;
qint64 id;
bool ignoreContextMenuEvent;
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 QString &value);
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

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){
if(!ignoreContextMenuEvent){
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogAlongLine = QSharedPointer<DialogAlongLine>(new DialogAlongLine(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogAlongLine.data(), &DialogAlongLine::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();
}
}
ContextMenu(dialogAlongLine, this, event);
}
void VToolAlongLine::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id);
VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id);
@ -87,4 +63,65 @@ void VToolAlongLine::AddToFile(){
AddAttribute(domElement, "secondPoint", secondPointId);
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,15 +11,23 @@ public:
VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula,
const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine,
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:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
private:
qint64 secondPointId;
QSharedPointer<DialogAlongLine> dialogAlongLine;
QSharedPointer<DialogAlongLine> dialogAlongLine;
};
#endif // VTOOLALONGLINE_H

View File

@ -1,5 +1,6 @@
#include "vtoolarc.h"
#include <QMenu>
#include "../container/calculator.h"
VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation,
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(){
RefreshGeometry();
}
@ -50,32 +118,11 @@ void VToolArc::ChangedActivDraw(const QString newName){
}
void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
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();
}
}
ContextMenu(dialogArc, this, event);
}
void VToolArc::AddToFile(){
VArc arc = VAbstractTool::data->GetArc(id);
VArc arc = VAbstractTool::data.GetArc(id);
QDomElement domElement = doc->createElement("arc");
AddAttribute(domElement, "id", id);
@ -86,6 +133,7 @@ void VToolArc::AddToFile(){
AddAttribute(domElement, "angle2", arc.GetFormulaF2());
AddToCalculation(domElement);
emit toolhaveChange();
}
void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
@ -106,7 +154,7 @@ void VToolArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
}
void VToolArc::RefreshGeometry(){
VArc arc = VAbstractTool::data->GetArc(id);
VArc arc = VAbstractTool::data.GetArc(id);
QPainterPath path;
path.addPath(arc.GetPath());
path.setFillRule( Qt::WindingFill );

View File

@ -14,6 +14,12 @@ class VToolArc :public VAbstractTool, public QGraphicsPathItem
public:
VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation,
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:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);

View File

@ -1,5 +1,7 @@
#pragma GCC diagnostic ignored "-Weffc++"
#include "vtoolbisector.h"
#include <QMenu>
#pragma GCC diagnostic warning "-Weffc++"
VToolBisector::VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,
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();
}
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(){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
@ -55,36 +122,11 @@ void VToolBisector::FullUpdateFromGui(int result){
}
void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
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();
}
}
ContextMenu(dialogBisector, this, event);
}
void VToolBisector::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id);
VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id);
@ -100,4 +142,5 @@ void VToolBisector::AddToFile(){
AddAttribute(domElement, "thirdPoint", thirdPointId);
AddToCalculation(domElement);
emit toolhaveChange();
}

View File

@ -1,10 +1,11 @@
#ifndef VTOOLBISECTOR_H
#define VTOOLBISECTOR_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QSharedPointer>
#include "vtoollinepoint.h"
#include "../dialogs/dialogbisector.h"
#pragma GCC diagnostic warning "-Weffc++"
class VToolBisector : public VToolLinePoint
{
@ -14,6 +15,13 @@ public:
const qint64 &thirdPointId, Tool::Enum typeCreation, QGraphicsItem * parent = 0);
static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint,
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:
virtual void FullUpdateFromFile();
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(){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
@ -26,30 +86,7 @@ void VToolEndLine::FullUpdateFromFile(){
}
void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
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();
}
}
ContextMenu(dialogEndLine, this, event);
}
void VToolEndLine::FullUpdateFromGui(int result){
@ -68,7 +105,7 @@ void VToolEndLine::FullUpdateFromGui(int result){
}
void VToolEndLine::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id);
VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id);
@ -83,5 +120,6 @@ void VToolEndLine::AddToFile(){
AddAttribute(domElement, "basePoint", basePointId);
AddToCalculation(domElement);
emit toolhaveChange();
}

View File

@ -14,6 +14,13 @@ public:
const QString &typeLine, const QString &formula, const qint32 &angle,
const qint64 &basePointId, Tool::Enum typeCreation,
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:
virtual void FullUpdateFromFile();
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(){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
firstPoint = domElement.attribute("firstPoint", "").toLongLong();
secondPoint = domElement.attribute("secondPoint", "").toLongLong();
}
VPointF first = VAbstractTool::data->GetPoint(firstPoint);
VPointF second = VAbstractTool::data->GetPoint(secondPoint);
VPointF first = VAbstractTool::data.GetPoint(firstPoint);
VPointF second = VAbstractTool::data.GetPoint(secondPoint);
this->setLine(QLineF(first.toQPointF(), second.toQPointF()));
}
@ -57,23 +89,7 @@ void VToolLine::ChangedActivDraw(const QString newName){
}
void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
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();
}
}
ContextMenu(dialogLine, this, event);
}
@ -84,6 +100,7 @@ void VToolLine::AddToFile(){
AddAttribute(domElement, "secondPoint", secondPoint);
AddToCalculation(domElement);
emit toolhaveChange();
}
void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event){

View File

@ -11,6 +11,12 @@ class VToolLine: public VAbstractTool, public QGraphicsLineItem
public:
VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint,
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:
virtual void FullUpdateFromFile();
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(){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
@ -41,33 +107,11 @@ void VToolLineIntersect::FullUpdateFromGui(int result){
}
void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
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();
}
}
ContextMenu(dialogLineIntersect, this, event);
}
void VToolLineIntersect::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id);
VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id);
@ -82,4 +126,5 @@ void VToolLineIntersect::AddToFile(){
AddAttribute(domElement, "p2Line2", p2Line2);
AddToCalculation(domElement);
emit toolhaveChange();
}

View File

@ -12,6 +12,13 @@ public:
const qint64 &p2Line1, const qint64 &p1Line2,
const qint64 &p2Line2, Tool::Enum typeCreation,
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:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);

View File

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

View File

@ -1,7 +1,9 @@
#ifndef VTOOLLINEPOINT_H
#define VTOOLLINEPOINT_H
#pragma GCC diagnostic ignored "-Weffc++"
#include "vtoolpoint.h"
#pragma GCC diagnostic warning "-Weffc++"
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,
const qint32 &angle){
QLineF line(firstPoint, secondPoint);
@ -51,35 +112,11 @@ void VToolNormal::FullUpdateFromGui(int result){
}
void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
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();
}
}
ContextMenu(dialogNormal, this, event);
}
void VToolNormal::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id);
VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id);
@ -95,4 +132,5 @@ void VToolNormal::AddToFile(){
AddAttribute(domElement, "secondPoint", secondPointId);
AddToCalculation(domElement);
emit toolhaveChange();
}

View File

@ -14,6 +14,13 @@ public:
const qint32 &angle, const qint64 &firstPointId,
const qint64 &secondPointId, Tool::Enum typeCreation,
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,
const qreal &length, const qint32 &angle = 0);
public slots:

View File

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

View File

@ -1,11 +1,13 @@
#ifndef VTOOLPOINT_H
#define VTOOLPOINT_H
#pragma GCC diagnostic ignored "-Weffc++"
#include <QGraphicsLineItem>
#include <QGraphicsEllipseItem>
#include "../widgets/vgraphicssimpletextitem.h"
#include "../options.h"
#include "vabstracttool.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "../options.h"
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,
const qreal &length){
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(){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
@ -66,37 +133,11 @@ void VToolShoulderPoint::FullUpdateFromGui(int result){
}
void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
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();
}
}
ContextMenu(dialogShoulderPoint, this, event);
}
void VToolShoulderPoint::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id);
VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id);
@ -112,4 +153,5 @@ void VToolShoulderPoint::AddToFile(){
AddAttribute(domElement, "pShoulder", pShoulder);
AddToCalculation(domElement);
emit toolhaveChange();
}

View File

@ -11,8 +11,15 @@ public:
const QString &typeLine, const QString &formula, const qint64 &p1Line,
const qint64 &p2Line, const qint64 &pShoulder, Tool::Enum typeCreation,
QGraphicsItem * parent = 0);
virtual void setDialog();
static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder,
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:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);

View File

@ -12,13 +12,15 @@
VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation,
QGraphicsItem * parent ):VToolPoint(doc, data, id, parent){
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
if(typeCreation == Tool::FromGui){
AddToFile();
}
}
void VToolSinglePoint::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id);
VPointF point = VAbstractTool::data.GetPoint(id);
QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id);
@ -30,22 +32,37 @@ void VToolSinglePoint::AddToFile(){
AddAttribute(domElement, "my", point.my()/PrintDPI*25.4);
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 ){
if(!ignoreContextMenuEvent){
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();
}
}
ContextMenu(dialogSinglePoint, this, event);
}
void VToolSinglePoint::FullUpdateFromFile(){
@ -61,8 +78,19 @@ void VToolSinglePoint::FullUpdateFromGui(int result){
domElement.setAttribute("name", name);
domElement.setAttribute("x", QString().setNum(p.x()/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();
}
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:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);
virtual void ChangedActivDraw(const QString newName);
signals:
void FullUpdateTree();
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
private:
QSharedPointer<DialogSinglePoint> dialogSinglePoint;
};

View File

@ -16,7 +16,7 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, Tool::E
this->setAcceptHoverEvents(true);
VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePoint::FirstPoint, spl.GetP2(),
spl.GetPointP1(), this);
spl.GetPointP1().toQPointF(), this);
connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
connect(this, &VToolSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine);
@ -24,7 +24,7 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, Tool::E
controlPoints.append(controlPoint1);
VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePoint::LastPoint, spl.GetP3(),
spl.GetPointP4(), this);
spl.GetPointP4().toQPointF(), this);
connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
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(){
RefreshGeometry();
}
void VToolSpline::FullUpdateFromGui(int result){
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->getKAsm1(), dialogSpline->getKAsm2(), dialogSpline->getKCurve());
@ -57,7 +111,7 @@ void VToolSpline::FullUpdateFromGui(int result){
connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
&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());
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
@ -77,7 +131,7 @@ void VToolSpline::FullUpdateFromGui(int result){
void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position,
const QPointF pos){
Q_UNUSED(indexSpline);
VSpline spl = VAbstractTool::data->GetSpline(id);
VSpline spl = VAbstractTool::data.GetSpline(id);
if(position == SplinePoint::FirstPoint){
spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());
} else {
@ -95,35 +149,11 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePo
}
void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
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();
}
}
ContextMenu(dialogSpline, this, event);
}
void VToolSpline::AddToFile(){
VSpline spl = VAbstractTool::data->GetSpline(id);
VSpline spl = VAbstractTool::data.GetSpline(id);
QDomElement domElement = doc->createElement("spline");
AddAttribute(domElement, "id", id);
@ -137,6 +167,7 @@ void VToolSpline::AddToFile(){
AddAttribute(domElement, "kCurve", spl.GetKcurve());
AddToCalculation(domElement);
emit toolhaveChange();
}
void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
@ -157,17 +188,28 @@ void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
}
void VToolSpline::RefreshGeometry(){
VSpline spl = VAbstractTool::data->GetSpline(id);
VSpline spl = VAbstractTool::data.GetSpline(id);
QPainterPath path;
path.addPath(spl.GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
QPointF splinePoint = VAbstractTool::data->GetPoint(spl.GetP1());
QPointF splinePoint = VAbstractTool::data.GetPoint(spl.GetP1()).toQPointF();
QPointF controlPoint = spl.GetP2();
emit RefreshLine(1, SplinePoint::FirstPoint, controlPoint, splinePoint);
splinePoint = VAbstractTool::data->GetPoint(spl.GetP4());
splinePoint = VAbstractTool::data.GetPoint(spl.GetP4()).toQPointF();
controlPoint = spl.GetP3();
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:
VToolSpline ( VDomDocument *doc, VContainer *data, qint64 id,
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:
void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position,
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){
VSpline spl = splPath.GetSpline(i);
VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePoint::FirstPoint, spl.GetP2(),
spl.GetPointP1(), this);
spl.GetPointP1().toQPointF(), this);
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
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,
&VToolSplinePath::ControlPointChangePosition);
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(){
RefreshGeometry();
}
@ -57,7 +97,7 @@ void VToolSplinePath::FullUpdateFromGui(int result){
connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
&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());
CorectControlPoints(spl, splPath, i-1, i, SplinePoint::FirstPoint);
CorectControlPoints(spl, splPath, i, i, SplinePoint::LastPoint);
@ -78,7 +118,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, Spli
const QPointF pos)
{
qint32 index = 0;
VSplinePath splPath = VAbstractTool::data->GetSplinePath(id);
VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
VSpline spl = splPath.GetSpline(indexSpline);
if(position == SplinePoint::FirstPoint){
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){
if(!ignoreContextMenuEvent){
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();
}
}
ContextMenu(dialogSplinePath, this, event);
}
void VToolSplinePath::AddToFile(){
VSplinePath splPath = VAbstractTool::data->GetSplinePath(id);
VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
QDomElement domElement = doc->createElement("spline");
AddAttribute(domElement, "id", id);
@ -194,6 +218,7 @@ void VToolSplinePath::AddToFile(){
}
AddToCalculation(domElement);
emit toolhaveChange();
}
void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint){
@ -225,19 +250,31 @@ void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
}
void VToolSplinePath::RefreshGeometry(){
VSplinePath splPath = VAbstractTool::data->GetSplinePath(id);
VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
QPainterPath path;
path.addPath(splPath.GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
for(qint32 i = 1; i<=splPath.Count(); ++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();
emit RefreshLine(i, SplinePoint::FirstPoint, controlPoint, splinePoint);
splinePoint = VAbstractTool::data->GetPoint(spl.GetP4());
splinePoint = VAbstractTool::data.GetPoint(spl.GetP4()).toQPointF();
controlPoint = spl.GetP3();
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:
VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id,
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:
void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos,
const QPointF &controlPoint, const QPointF &splinePoint);

View File

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

View File

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

View File

@ -44,16 +44,16 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang
if (change == ItemPositionChange && scene()) {
// value - это новое положение.
QPointF newPos = value.toPointF();
qDebug()<<this->rect();
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())));
// qDebug()<<this->rect();
// 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())));
emit ControlPointChangePosition(indexSpline, position, newPos);
return newPos;
}
// emit ControlPointChangePosition(indexSpline, position, newPos);
// return newPos;
// }
emit ControlPointChangePosition(indexSpline, position, newPos);
}
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){
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())));
emit NameChangePosition(newPos);
return newPos;
}
QPointF newPos = value.toPointF() + this->parentItem()->pos();
// 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())));
// emit NameChangePosition(newPos - this->parentItem()->pos());
// return newPos - this->parentItem()->pos();
// }
emit NameChangePosition(newPos);
}
return QGraphicsItem::itemChange(change, value);

View File

@ -1,14 +1,13 @@
#include "vmaingraphicsscene.h"
#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){

View File

@ -2,6 +2,7 @@
#define VMAINGRAPHICSSCENE_H
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsSceneMouseEvent>
#include "../options.h"
@ -14,7 +15,7 @@ public:
VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = 0);
public slots:
void ChoosedItem(qint64 id, Scene::Type type);
private:
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
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 <QDebug>
#include "../tools/vtoolsinglepoint.h"
#include "../tools/vtoolendline.h"
#include "../tools/vtoolline.h"
@ -12,11 +12,13 @@
#include "../tools/vtoolspline.h"
#include "../tools/vtoolarc.h"
#include "../tools/vtoolsplinepath.h"
#pragma GCC diagnostic warning "-Weffc++"
#include "../options.h"
#include "../container/calculator.h"
#include "../geometry/vsplinepoint.h"
VDomDocument::VDomDocument(VContainer *data) : QDomDocument() {
this->data = data;
}
@ -29,13 +31,15 @@ VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data) :
this->data = data;
}
VDomDocument::~VDomDocument(){
}
QDomElement VDomDocument::elementById(const QString& id){
if (map.contains(id)) {
QDomElement e = map[id];
if (e.parentNode().nodeType() != QDomNode::BaseNode) {
return e;
}
map.remove(id);
}
@ -227,6 +231,7 @@ void VDomDocument::Parse(Document::Enum parse, VMainGraphicsScene *scene, QCombo
nameActivDraw.clear();
scene->clear();
comboBoxDraws->clear();
tools.clear();
} else {
data->ClearLengthLines();
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){
QDomNode domNode = node.firstChild();
while(!domNode.isNull()){
@ -267,15 +276,16 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node){
if(!domElement.isNull()){
if(domElement.tagName() == "increment"){
QString name,desc;
qint32 base;
qreal base;
qreal ksize, kgrowth;
qint64 id;
id = domElement.attribute("id", "").toLongLong();
name = domElement.attribute("name", "");
base = domElement.attribute("base","").toInt();
base = domElement.attribute("base","").toDouble();
ksize = domElement.attribute("ksize","").toDouble();
kgrowth = domElement.attribute("kgrowth","").toDouble();
desc = domElement.attribute("description","");
data->UpdateId(id);
data->AddIncrementTableRow(name,
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;
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){
VToolSinglePoint *spoint = new VToolSinglePoint(this, data, id, Tool::FromFile);
scene->addItem(spoint);
connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
tools[id] = spoint;
}
}
return;
}
if(type == "endLine"){
if(!domElement.isNull()){
QString name, typeLine, formula;
qreal mx=5, my=10;
qint64 id, basePointId;
qint32 angle;
id = domElement.attribute("id", "").toLongLong();
name = domElement.attribute("name", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
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);
}
}
qint64 id = domElement.attribute("id", "").toLongLong();
QString name = domElement.attribute("name", "");
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
QString typeLine = domElement.attribute("typeLine", "");
QString formula = domElement.attribute("length", "");
qint64 basePointId = domElement.attribute("basePoint", "").toLongLong();
qint32 angle = domElement.attribute("angle", "").toInt();
VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this, data,
parse, Tool::FromFile);
}
return;
}
if(type == "alongLine"){
if(!domElement.isNull()){
QString name, typeLine, formula;
qreal mx=5, my=10;
qint64 id, firstPointId, secondPointId;
id = domElement.attribute("id", "").toLongLong();
name = domElement.attribute("name", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
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);
}
}
qint64 id = domElement.attribute("id", "").toLongLong();
QString name = domElement.attribute("name", "");
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
QString typeLine = domElement.attribute("typeLine", "");
QString formula = domElement.attribute("length", "");
qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong();
qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong();
VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my,
scene, this, data, parse, Tool::FromFile);
}
return;
}
if(type == "shoulder"){
if(!domElement.isNull()){
QString name, typeLine, formula;
qreal mx=5, my=10;
qint64 id, p1Line, p2Line, pShoulder;
id = domElement.attribute("id", "").toLongLong();
name = domElement.attribute("name", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
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);
}
}
qint64 id = domElement.attribute("id", "").toLongLong();
QString name = domElement.attribute("name", "");
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
QString typeLine = domElement.attribute("typeLine", "");
QString formula = domElement.attribute("length", "");
qint64 p1Line = domElement.attribute("p1Line", "").toLongLong();
qint64 p2Line = domElement.attribute("p2Line", "").toLongLong();
qint64 pShoulder = domElement.attribute("pShoulder", "").toLongLong();
VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my,
scene, this, data, parse, Tool::FromFile);
}
return;
}
if(type == "normal"){
if(!domElement.isNull()){
QString name, typeLine, formula;
qreal mx=5, my=10, angle;
qint64 id, firstPointId, secondPointId;
id = domElement.attribute("id", "").toLongLong();
name = domElement.attribute("name", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
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);
}
}
qint64 id = domElement.attribute("id", "").toLongLong();
QString name = domElement.attribute("name", "");
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
QString typeLine = domElement.attribute("typeLine", "");
QString formula = domElement.attribute("length", "");
qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong();
qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong();
qreal angle = domElement.attribute("angle", "").toInt();
VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle,
mx, my, scene, this, data, parse, Tool::FromFile);
}
return;
}
if(type == "bisector"){
if(!domElement.isNull()){
QString name, typeLine, formula;
qreal mx=5, my=10;
qint64 id, firstPointId, secondPointId, thirdPointId;
id = domElement.attribute("id", "").toLongLong();
name = domElement.attribute("name", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
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);
}
}
qint64 id = domElement.attribute("id", "").toLongLong();
QString name = domElement.attribute("name", "");
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
QString typeLine = domElement.attribute("typeLine", "");
QString formula = domElement.attribute("length", "");
qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong();
qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong();
qint64 thirdPointId = domElement.attribute("thirdPoint", "").toLongLong();
VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine,
name, mx, my, scene, this, data, parse, Tool::FromFile);
}
return;
}
if(type == "lineIntersect"){
if(!domElement.isNull()){
QString name;
qreal mx=5, my=10;
qint64 id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id;
id = domElement.attribute("id", "").toLongLong();
name = domElement.attribute("name", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
p1Line1Id = domElement.attribute("p1Line1", "").toLongLong();
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);
}
}
qint64 id = domElement.attribute("id", "").toLongLong();
QString name = domElement.attribute("name", "");
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
qint64 p1Line1Id = domElement.attribute("p1Line1", "").toLongLong();
qint64 p2Line1Id = domElement.attribute("p2Line1", "").toLongLong();
qint64 p1Line2Id = domElement.attribute("p1Line2", "").toLongLong();
qint64 p2Line2Id = domElement.attribute("p2Line2", "").toLongLong();
VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, scene,
this, data, parse, Tool::FromFile);
}
return;
}
@ -628,18 +500,10 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement,
Document::Enum parse){
if(!domElement.isNull()){
qint64 firstPoint;
qint64 secondPoint;
firstPoint = domElement.attribute("firstPoint", "").toLongLong();
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);
}
qint64 id = domElement.attribute("id", "").toLongLong();
qint64 firstPoint = domElement.attribute("firstPoint", "").toLongLong();
qint64 secondPoint = domElement.attribute("secondPoint", "").toLongLong();
VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile);
}
}
@ -647,32 +511,21 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
Document::Enum parse, const QString &type){
if(type == "simple"){
if(!domElement.isNull()){
qreal angle1, angle2, kAsm1, kAsm2, kCurve;
qint64 id, point1, point4;
id = domElement.attribute("id", "").toLongLong();
point1 = domElement.attribute("point1", "").toLongLong();
point4 = domElement.attribute("point4", "").toLongLong();
angle1 = domElement.attribute("angle1","").toDouble();
angle2 = domElement.attribute("angle2","").toDouble();
kAsm1 = domElement.attribute("kAsm1","").toDouble();
kAsm2 = domElement.attribute("kAsm2","").toDouble();
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);
}
qint64 id = domElement.attribute("id", "").toLongLong();
qint64 point1 = domElement.attribute("point1", "").toLongLong();
qint64 point4 = domElement.attribute("point4", "").toLongLong();
qreal angle1 = domElement.attribute("angle1","").toDouble();
qreal angle2 = domElement.attribute("angle2","").toDouble();
qreal kAsm1 = domElement.attribute("kAsm1","").toDouble();
qreal kAsm2 = domElement.attribute("kAsm2","").toDouble();
qreal kCurve = domElement.attribute("kCurve","").toDouble();
VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data,
parse, Tool::FromFile);
}
return;
}
if(type == "path"){
if(!domElement.isNull()){
qint64 id = domElement.attribute("id", "").toLongLong();
qreal kCurve = domElement.attribute("kCurve","").toDouble();
VSplinePath path(data->DataPoints(), kCurve);
@ -690,17 +543,9 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2);
path.append(splPoint);
}
}
}
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);
}
VToolSplinePath::Create(id, path, scene, this, data, Document::FullParse, Tool::FromFile);
}
return;
}
@ -710,44 +555,12 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement
Document::Enum parse, const QString &type){
if(type == "simple"){
if(!domElement.isNull()){
QString radius, f1, f2;
qint64 id, center;
id = domElement.attribute("id", "").toLongLong();
center = domElement.attribute("center", "").toLongLong();
radius = domElement.attribute("radius", "");
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);
}
qint64 id = domElement.attribute("id", "").toLongLong();
qint64 center = domElement.attribute("center", "").toLongLong();
QString radius = domElement.attribute("radius", "");
QString f1 = domElement.attribute("angle1", "");
QString f2 = domElement.attribute("angle2","");
VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile);
}
return;
}

View File

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