From 6879b732cb96e70efaeade6981dd54fd6c7c29a3 Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 28 Jul 2013 01:18:06 +0300 Subject: [PATCH] Add tool AlongLine. --- Valentina.pro | 21 +- cursor.qrc | 1 + cursor/alongline_cursor.png | Bin 0 -> 1300 bytes dialogs/dialogalongline.cpp | 142 ++++++++++++ dialogs/dialogalongline.h | 42 ++++ dialogs/dialogalongline.ui | 281 ++++++++++++++++++++++++ dialogs/dialogendline.cpp | 272 +++-------------------- dialogs/dialogendline.h | 83 ++------ dialogs/dialogendline.ui | 2 +- dialogs/dialogincrements.cpp | 17 +- dialogs/dialogincrements.h | 12 +- dialogs/dialogline.cpp | 42 +--- dialogs/dialogline.h | 19 +- dialogs/dialogsinglepoint.cpp | 58 +---- dialogs/dialogsinglepoint.h | 18 +- dialogs/dialogtool.cpp | 320 ++++++++++++++++++++++++++++ dialogs/dialogtool.h | 75 +++++++ icon.qrc | 1 + icon/32x32/along_line.png | Bin 0 -> 689 bytes mainwindow.cpp | 99 ++++++--- mainwindow.h | 12 +- mainwindow.ui | 31 ++- options.h | 4 +- tools/vabstracttool.cpp | 12 +- tools/vabstracttool.h | 4 +- tools/vtoolalongline.cpp | 142 ++++++++++++ tools/vtoolalongline.h | 30 +++ tools/vtoolendline.cpp | 57 ++--- tools/vtoolendline.h | 4 +- tools/vtoolline.cpp | 46 ++-- tools/vtoolline.h | 7 +- tools/vtoolpoint.cpp | 15 ++ tools/vtoolpoint.h | 4 +- tools/vtoolsimplepoint.cpp | 31 ++- tools/vtoolsimplepoint.h | 4 +- widgets/vgraphicssimpletextitem.cpp | 13 +- widgets/vgraphicssimpletextitem.h | 10 +- xml/vdomdocument.cpp | 39 ++++ 38 files changed, 1384 insertions(+), 586 deletions(-) create mode 100644 cursor/alongline_cursor.png create mode 100644 dialogs/dialogalongline.cpp create mode 100644 dialogs/dialogalongline.h create mode 100644 dialogs/dialogalongline.ui create mode 100644 dialogs/dialogtool.cpp create mode 100644 dialogs/dialogtool.h create mode 100644 icon/32x32/along_line.png create mode 100644 tools/vtoolalongline.cpp create mode 100644 tools/vtoolalongline.h diff --git a/Valentina.pro b/Valentina.pro index 2dd2a5464..90541aca6 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -31,7 +31,10 @@ SOURCES += main.cpp\ tools/vtoolendline.cpp \ tools/vtoolline.cpp \ tools/vabstracttool.cpp \ - dialogs/dialogline.cpp + dialogs/dialogline.cpp \ + tools/vtoolalongline.cpp \ + dialogs/dialogtool.cpp \ + dialogs/dialogalongline.cpp HEADERS += mainwindow.h \ widgets/vmaingraphicsscene.h \ @@ -53,14 +56,26 @@ HEADERS += mainwindow.h \ tools/vtoolendline.h \ tools/vtoolline.h \ tools/vabstracttool.h \ - dialogs/dialogline.h + dialogs/dialogline.h \ + tools/vtoolalongline.h \ + dialogs/dialogtool.h \ + dialogs/dialogalongline.h FORMS += mainwindow.ui \ dialogs/dialogsinglepoint.ui \ dialogs/dialogincrements.ui \ dialogs/dialogendline.ui \ - dialogs/dialogline.ui + dialogs/dialogline.ui \ + dialogs/dialogalongline.ui RESOURCES += \ icon.qrc \ cursor.qrc + +CONFIG(debug, debug|release){ + # Debug + QMAKE_CXXFLAGS += -O0 -Wall -Wextra -pedantic -std=c++0x +}else{ + # Release + QMAKE_CXXFLAGS += -O1 -std=c++0x +} diff --git a/cursor.qrc b/cursor.qrc index eda5c9def..453c3545d 100644 --- a/cursor.qrc +++ b/cursor.qrc @@ -3,5 +3,6 @@ cursor/spoint_cursor.png cursor/endline_cursor.png cursor/line_cursor.png + cursor/alongline_cursor.png diff --git a/cursor/alongline_cursor.png b/cursor/alongline_cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..3fac66a28852fe2e151ed6c9204588581e3b4160 GIT binary patch literal 1300 zcmV+v1?&2WP)Vl&|00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru-3J*GCOLjQ9cBOk06}y` zSad^gZEa<4bO1wAML|?gQaT`KWG!lNWoICEF)lD5D0OpbZf77#N=G0{P(?=|b~Z98 zEFf`pVQgu1c_2L?IWP*aMOc#n00dM?L_t(Y$HkXhOcZAn$A4#LS1Pb5+v;wKjYb=j zCajf&CK#j_Fr}FF0xb#YL)(b9-2_ltN^0#(A9^!slfIeuK@x2sZb?kzgN6sQsYcRZ zNJuc6LcKv#svuOk?(CdCII~$4EmYQ?etrR%41ca zv9a-LC=}9gIIODr++zi=sHo@xbp87EnmXRq)s4lncdd7u zh-hhPskXPbFHalisbbqU0IG^%7z6?Vs;a6+)8=-OyGL6@lJBk}t*xzyhz5f}-Lz>_ zX4*J+`A!uP!Q=6us+>D_Zo(Zue*Czk&F!gTSr)^?!&*~Qqn2e+Q&YpvojVr?d@hS! zF-?<1A^{+6ZEXOQmzOWT+vjq*Wm%{ys+vqj{r&v_{>_^=uUXWimfGBeBO=M>&Shj| z=&Dt#^pV}38sQHLKoObMpPrs3Gc%J|EVl0S>C?WFl9Iu)va%bG6mWC7elA5sgucE$ zB9Tbn=;$apIXNE!-!2;G4^l=|v27bw<-&yv3=Iu2F)=aYuIcRToIm)(qJ1t(JRZ+1 z8f@F9qod=q%F4>iEiEkrMMXuA&bh1Dy~Es;EanIN!C>&e1)OP`$s{8p*tU(& z=hMQ%LKz<)pOx_}%SvWGRV5ye0}u*@7RKX_9Xpcs98kkBl1HqvvU0)4>Fn9FvS7|_ z+r}`AWJPlWD;kY1sH7Gb7whibyO^As^d32S#8>-n#MrgxeL3{~4_vwWyVUJ#y5H@t zs{!ij>MrHw<^AOM`+u#ju69eR2_)vDz{t(vtX=QCJvBBqeml#T%gU$MGIR^ptX|8T zZ`Ec1)1G^air4EU9*>iqo!z^C|Nc*%sg1x(z-pieXn6o;0noj-zTOxZxH|dA^#OZg za*A6cH;EoQS`6d^L|cz^)$RS@A^=;rZtVdyH#gU=udg2f_BJ&&g`EwT0-rk;D=-Y~ z0m?<>6%lz^L|z510XA^W87mQy7e%BDr~*!a+a+CV9S;*J%Hxt=g$>fPdb3^ zhjCyAxCD#=e*+gCV0E6CfIH6IZ@_I}DrJvbK%RSb{shSF?d{d>?(T3wLBWX>@Y}#Q zj`cVe90vXp5zE=kP}Nr88Q{8zyr-&hK!7DcHV^?`bM`n4%*^*funu^^0qO(JKaBH( zUw%Q`k1gCB9mD&Cmn)ZtNF?G#fcrOe{;RJK_ITzA-tV-3lWu^G1qH-@ISJU@7`sD` zFALK&JN?Ujoq?4B{3`=wEb)@IpTh0o3TCW33|;?|X)A$gm@LiAV#SK5$nxcKEE-J@ z`1Wu)Kc6_o#~(ErfndOM=1eSMim9RJH_EbQ%W2rxn5cf^b^ZZhpV&jEZzll&0000< KMNUMnLSTaau3UZq literal 0 HcmV?d00001 diff --git a/dialogs/dialogalongline.cpp b/dialogs/dialogalongline.cpp new file mode 100644 index 000000000..e89bad390 --- /dev/null +++ b/dialogs/dialogalongline.cpp @@ -0,0 +1,142 @@ +#include "dialogalongline.h" +#include "ui_dialogalongline.h" + +DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) : + DialogTool(data, parent), ui(new Ui::DialogAlongLine) +{ + ui->setupUi(this); + number = 0; + listWidget = ui->listWidget; + labelResultCalculation = ui->labelResultCalculation; + labelDescription = ui->labelDescription; + radioButtonSizeGrowth = ui->radioButtonSizeGrowth; + radioButtonStandartTable = ui->radioButtonStandartTable; + radioButtonIncrements = ui->radioButtonIncrements; + radioButtonLengthLine = ui->radioButtonLengthLine; + lineEditFormula = ui->lineEditFormula; + flagFormula = false; + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogAlongLine::DialogAccepted); + flagName = false; + CheckState(); + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogAlongLine::DialogRejected); + FillComboBoxTypeLine(ui->comboBoxLineType); + FillComboBoxPoints(ui->comboBoxFirstPoint); + FillComboBoxPoints(ui->comboBoxSecondPoint); + + connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogAlongLine::PutHere); + connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogAlongLine::PutVal); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogAlongLine::ValChenged); + + ShowBase(); + connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogAlongLine::SizeGrowth); + connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogAlongLine::StandartTable); + connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogAlongLine::Increments); + connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogAlongLine::LengthLines); + connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula); + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged); + connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogAlongLine::FormulaChanged); +} + +DialogAlongLine::~DialogAlongLine() +{ + delete ui; +} + +void DialogAlongLine::ChoosedPoint(qint64 id, Scene::Type type){ + if(type == Scene::Point){ + VPointF point = data->GetPoint(id); + if(number == 0){ + qint32 index = ui->comboBoxFirstPoint->findText(point.name()); + if ( index != -1 ) { // -1 for not found + ui->comboBoxFirstPoint->setCurrentIndex(index); + number++; + return; + } + } + if(number == 1){ + qint32 index = ui->comboBoxSecondPoint->findText(point.name()); + if ( index != -1 ) { // -1 for not found + ui->comboBoxSecondPoint->setCurrentIndex(index); + number = 0; + } + if(!isInitialized){ + this->show(); + } + } + } +} + +void DialogAlongLine::DialogAccepted(){ + pointName = ui->lineEditNamePoint->text(); + typeLine = GetTypeLine(ui->comboBoxLineType); + formula = ui->lineEditFormula->text(); + qint32 index = ui->comboBoxFirstPoint->currentIndex(); + firstPointId = qvariant_cast(ui->comboBoxFirstPoint->itemData(index)); + index = ui->comboBoxSecondPoint->currentIndex(); + secondPointId = qvariant_cast(ui->comboBoxSecondPoint->itemData(index)); + emit DialogClosed(QDialog::Accepted); +} + +qint64 DialogAlongLine::getSecondPointId() const{ + return secondPointId; +} + +void DialogAlongLine::setSecondPointId(const qint64 &value){ + secondPointId = value; + qint32 index = ui->comboBoxSecondPoint->findData(secondPointId); + if(index != -1){ + ui->comboBoxSecondPoint->setCurrentIndex(index); + } +} + +qint64 DialogAlongLine::getFirstPointId() const{ + return firstPointId; +} + +void DialogAlongLine::setFirstPointId(const qint64 &value){ + firstPointId = value; + qint32 index = ui->comboBoxFirstPoint->findData(firstPointId); + if(index != -1){ + ui->comboBoxFirstPoint->setCurrentIndex(index); + } +} + +QString DialogAlongLine::getFormula() const{ + return formula; +} + +void DialogAlongLine::setFormula(const QString &value){ + formula = value; + ui->lineEditFormula->setText(formula); +} + +QString DialogAlongLine::getTypeLine() const{ + return typeLine; +} + +void DialogAlongLine::setTypeLine(const QString &value){ + typeLine = value; + if(typeLine == "hair"){ + qint32 index = ui->comboBoxLineType->findText("Лінія"); + if(index != -1){ + ui->comboBoxLineType->setCurrentIndex(index); + } + } + if(typeLine == "none"){ + qint32 index = ui->comboBoxLineType->findText("Без лінії"); + if(index != -1){ + ui->comboBoxLineType->setCurrentIndex(index); + } + } +} + +QString DialogAlongLine::getPointName() const{ + return pointName; +} + +void DialogAlongLine::setPointName(const QString &value){ + pointName = value; + ui->lineEditNamePoint->setText(pointName); +} diff --git a/dialogs/dialogalongline.h b/dialogs/dialogalongline.h new file mode 100644 index 000000000..2c8c64e62 --- /dev/null +++ b/dialogs/dialogalongline.h @@ -0,0 +1,42 @@ +#ifndef DIALOGALONGLINE_H +#define DIALOGALONGLINE_H + +#include "dialogtool.h" +#include "../options.h" +#include "../container/vcontainer.h" +#include "../container/calculator.h" + +namespace Ui { +class DialogAlongLine; +} + +class DialogAlongLine : public DialogTool +{ + Q_OBJECT +public: + explicit DialogAlongLine(const VContainer *data, QWidget *parent = 0); + ~DialogAlongLine(); + QString getPointName() const; + void setPointName(const QString &value); + QString getTypeLine() const; + void setTypeLine(const QString &value); + QString getFormula() const; + void setFormula(const QString &value); + qint64 getFirstPointId() const; + void setFirstPointId(const qint64 &value); + qint64 getSecondPointId() const; + void setSecondPointId(const qint64 &value); +public slots: + virtual void ChoosedPoint(qint64 id, Scene::Type type); + virtual void DialogAccepted(); +private: + Ui::DialogAlongLine *ui; + qint32 number; + QString pointName; + QString typeLine; + QString formula; + qint64 firstPointId; + qint64 secondPointId; +}; + +#endif // DIALOGALONGLINE_H diff --git a/dialogs/dialogalongline.ui b/dialogs/dialogalongline.ui new file mode 100644 index 000000000..5ad3ff2c1 --- /dev/null +++ b/dialogs/dialogalongline.ui @@ -0,0 +1,281 @@ + + + DialogAlongLine + + + + 0 + 0 + 470 + 454 + + + + Dialog + + + + + + + + + 0 + 0 + + + + Відстань + + + + + + + + + + ... + + + + :/icon/24x24/equal.png:/icon/24x24/equal.png + + + + 24 + 24 + + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + _ + + + + + + + + + + + + + + + Ім'я нової точки + + + + + + + + + + ... + + + + :/icon/24x24/putHere.png:/icon/24x24/putHere.png + + + + 24 + 24 + + + + + + + + + + + + Перша точка + + + + + + + + + + + + + + Друга точка + + + + + + + + + + + + + + Тип лінії + + + + + + + + + + + + + + Вхідні данні + + + + + + + Розмір і зріст + + + true + + + + + + + Стандартна таблиця + + + + + + + Прибавки + + + + + + + Довжини ліній + + + + + + + false + + + Довжини дуг + + + + + + + false + + + Довжини сплайнів + + + + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogAlongLine + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogAlongLine + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/dialogs/dialogendline.cpp b/dialogs/dialogendline.cpp index 8e3c7e11c..664d5eb22 100644 --- a/dialogs/dialogendline.cpp +++ b/dialogs/dialogendline.cpp @@ -7,19 +7,27 @@ #include "../container/calculator.h" DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) : - QDialog(parent), ui(new Ui::DialogEndLine) + DialogTool(data, parent), ui(new Ui::DialogEndLine) { ui->setupUi(this); + spinBoxAngle = ui->spinBoxAngle; + listWidget = ui->listWidget; + labelResultCalculation = ui->labelResultCalculation; + labelDescription = ui->labelDescription; + radioButtonSizeGrowth = ui->radioButtonSizeGrowth; + radioButtonStandartTable = ui->radioButtonStandartTable; + radioButtonIncrements = ui->radioButtonIncrements; + radioButtonLengthLine = ui->radioButtonLengthLine; + lineEditFormula = ui->lineEditFormula; flagFormula = false; - flagName = false; - this->data = data; bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogEndLine::DialogAccepted); - bOk->setEnabled(false); - FillComboBoxBasePoint(); - QStringList list; - list<<"Лінія"<<"Без лінії"; - ui->comboBoxLineType->addItems(list); + flagName = false; + CheckState(); + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogEndLine::DialogRejected); + FillComboBoxPoints(ui->comboBoxBasePoint); + FillComboBoxTypeLine(ui->comboBoxLineType); connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, &DialogEndLine::ArrowDown); @@ -37,107 +45,18 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) : &DialogEndLine::ArrowRightUp); connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this, &DialogEndLine::ArrowRightDown); - connect(ui->toolButtonPutHere, &QPushButton::clicked, this, - &DialogEndLine::ClickedToolButtonPutHere); + connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEndLine::PutHere); connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEndLine::PutVal); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); ShowBase(); - connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, - &DialogEndLine::ClickedSizeGrowth); - connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, - &DialogEndLine::ClickedStandartTable); - connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, - &DialogEndLine::ClickedIncrements); - connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, - &DialogEndLine::ClickedLengthLines); - connect(ui->toolButtonEqual, &QPushButton::clicked, this, - &DialogEndLine::ClickedToolButtonEqual); - connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NameChanged); + connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogEndLine::SizeGrowth); + connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogEndLine::StandartTable); + connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogEndLine::Increments); + connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogEndLine::LengthLines); + connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogEndLine::EvalFormula); + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogEndLine::FormulaChanged); - - timerFormula = new QTimer(this); - connect(timerFormula, &QTimer::timeout, this, &DialogEndLine::ClickedToolButtonEqual); -} - -void DialogEndLine::ShowBase(){ - disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); - ui->listWidget->clear(); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); - const QMap *base = data->DataBase(); - QMapIterator i(*base); - while (i.hasNext()) { - i.next(); - QListWidgetItem *item = new QListWidgetItem(i.key()); - item->setFont(QFont("Times", 12, QFont::Bold)); - ui->listWidget->addItem(item); - } - ui->listWidget->setCurrentRow (0); -} - -void DialogEndLine::ShowStandartTable(){ - disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); - ui->listWidget->clear(); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); - const QMap *standartTable = data->DataStandartTable(); - QMapIterator i(*standartTable); - while (i.hasNext()) { - i.next(); - QListWidgetItem *item = new QListWidgetItem(i.key()); - item->setFont(QFont("Times", 12, QFont::Bold)); - ui->listWidget->addItem(item); - } - ui->listWidget->setCurrentRow (0); -} - -void DialogEndLine::ShowIncrementTable(){ - disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); - ui->listWidget->clear(); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); - const QMap *incrementTable = data->DataIncrementTable(); - QMapIterator i(*incrementTable); - while (i.hasNext()) { - i.next(); - QListWidgetItem *item = new QListWidgetItem(i.key()); - item->setFont(QFont("Times", 12, QFont::Bold)); - ui->listWidget->addItem(item); - } - ui->listWidget->setCurrentRow (0); -} - -void DialogEndLine::ShowLengthLines(){ - disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); - ui->listWidget->clear(); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); - const QMap *linesTable = data->DataLengthLines(); - QMapIterator i(*linesTable); - while (i.hasNext()) { - i.next(); - QListWidgetItem *item = new QListWidgetItem(i.key()); - item->setFont(QFont("Times", 12, QFont::Bold)); - ui->listWidget->addItem(item); - } - ui->listWidget->setCurrentRow (0); -} - -void DialogEndLine::CheackState(){ - bOk->setEnabled(flagFormula & flagName); -} - -void DialogEndLine::ClickedSizeGrowth(){ - ShowBase(); -} - -void DialogEndLine::ClickedStandartTable(){ - ShowStandartTable(); -} - -void DialogEndLine::ClickedLengthLines(){ - ShowLengthLines(); -} - -void DialogEndLine::ClickedIncrements(){ - ShowIncrementTable(); } void DialogEndLine::ChoosedPoint(qint64 id, Scene::Type type){ @@ -198,11 +117,6 @@ void DialogEndLine::setAngle(const qint32 &value){ ui->spinBoxAngle->setValue(angle); } -void DialogEndLine::closeEvent ( QCloseEvent * event ){ - DialogClosed(QDialog::Rejected); - event->accept(); -} - qint64 DialogEndLine::getBasePointId() const { return basePointId; @@ -217,150 +131,14 @@ void DialogEndLine::setBasePointId(const qint64 &value) } } -void DialogEndLine::FillComboBoxBasePoint(){ - const QMap *points = data->DataPoints(); - QMapIterator i(*points); - while (i.hasNext()) { - i.next(); - VPointF point = i.value(); - ui->comboBoxBasePoint->addItem(point.name(), i.key()); - } -} - -void DialogEndLine::ArrowUp(){ - ui->spinBoxAngle->setValue(90); -} - -void DialogEndLine::ArrowDown(){ - ui->spinBoxAngle->setValue(270); -} - -void DialogEndLine::ArrowLeft(){ - ui->spinBoxAngle->setValue(180); -} - -void DialogEndLine::ArrowRight(){ - ui->spinBoxAngle->setValue(0); -} - -void DialogEndLine::ArrowLeftUp(){ - ui->spinBoxAngle->setValue(135); -} - -void DialogEndLine::ArrowLeftDown(){ - ui->spinBoxAngle->setValue(225); -} - -void DialogEndLine::ArrowRightUp(){ - ui->spinBoxAngle->setValue(45); -} - -void DialogEndLine::ArrowRightDown(){ - ui->spinBoxAngle->setValue(315); -} - -void DialogEndLine::ClickedToolButtonPutHere(){ - QListWidgetItem *item = ui->listWidget->currentItem(); - QString val = item->text(); - ui->lineEditFormula->setText(ui->lineEditFormula->text().append(val)); -} - -void DialogEndLine::PutVal(QListWidgetItem *item){ - QString val = item->text(); - ui->lineEditFormula->setText(ui->lineEditFormula->text().append(val)); -} - -void DialogEndLine::ValChenged(int row){ - if(ui->listWidget->count() == 0){ - return; - } - QListWidgetItem *item = ui->listWidget->item( row ); - if(ui->radioButtonSizeGrowth->isChecked()){ - if(item->text()=="Р"){ - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->growth()).arg("Зріст"); - ui->labelDescription->setText(desc); - } - if(item->text()=="Сг"){ - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->size()).arg("Розмір"); - ui->labelDescription->setText(desc); - } - } - if(ui->radioButtonStandartTable->isChecked()){ - VStandartTableCell stable = data->GetStandartTableCell(item->text()); - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandartTableCell(item->text())) - .arg(stable.GetDescription()); - ui->labelDescription->setText(desc); - } - if(ui->radioButtonIncrements->isChecked()){ - VIncrementTableRow itable = data->GetIncrementTableRow(item->text()); - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text())) - .arg(itable.getDescription()); - ui->labelDescription->setText(desc); - } -} - -void DialogEndLine::ClickedToolButtonEqual(){ - if(ui->lineEditFormula->text().isEmpty()){ - flagFormula = false; - } else { - Calculator cal(data); - QString errorMsg; - qreal result = cal.eval(ui->lineEditFormula->text(),&errorMsg); - if(!errorMsg.isEmpty()){ - ui->labelResultCalculation->setText("Помилка."); - flagFormula = false; - } else { - ui->labelResultCalculation->setText(QString().setNum(result)); - flagFormula = true; - } - } - CheackState(); - timerFormula->stop(); -} - -void DialogEndLine::NameChanged(){ - QString name = ui->lineEditNamePoint->text(); - if(name.isEmpty() || name.contains(" ")){ - flagName = false; - } else { - flagName = true; - } - CheackState(); -} - -void DialogEndLine::FormulaChanged(){ - if(ui->lineEditFormula->text().isEmpty()){ - flagFormula = false; - CheackState(); - return; - } - timerFormula->start(1000); -} - void DialogEndLine::DialogAccepted(){ pointName = ui->lineEditNamePoint->text(); - if(ui->comboBoxLineType->currentText()=="Лінія"){ - typeLine = QString("hair"); - } else { - typeLine = QString("none"); - } + typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); angle = ui->spinBoxAngle->value(); qint32 index = ui->comboBoxBasePoint->currentIndex(); basePointId = qvariant_cast(ui->comboBoxBasePoint->itemData(index)); - DialogClosed(QDialog::Accepted); -} - -void DialogEndLine::UpdateList(){ - if(ui->radioButtonSizeGrowth->isChecked()){ - ShowBase(); - } - if(ui->radioButtonStandartTable->isChecked()){ - ShowStandartTable(); - } - if(ui->radioButtonIncrements->isChecked()){ - ShowIncrementTable(); - } + emit DialogClosed(QDialog::Accepted); } DialogEndLine::~DialogEndLine() diff --git a/dialogs/dialogendline.h b/dialogs/dialogendline.h index 9166f4704..04449e3df 100644 --- a/dialogs/dialogendline.h +++ b/dialogs/dialogendline.h @@ -1,7 +1,7 @@ #ifndef DIALOGENDLINE_H #define DIALOGENDLINE_H -#include +#include "dialogtool.h" #include #include #include @@ -14,71 +14,32 @@ namespace Ui { class DialogEndLine; } -class DialogEndLine : public QDialog +class DialogEndLine : public DialogTool { - Q_OBJECT - + Q_OBJECT public: - explicit DialogEndLine(const VContainer *data, QWidget *parent = 0); - ~DialogEndLine(); - QString getPointName() const; - void setPointName(const QString &value); - - QString getTypeLine() const; - void setTypeLine(const QString &value); - - QString getFormula() const; - void setFormula(const QString &value); - - qint32 getAngle() const; - void setAngle(const qint32 &value); - - qint64 getBasePointId() const; - void setBasePointId(const qint64 &value); -signals: - void DialogClosed(int result); + explicit DialogEndLine(const VContainer *data, QWidget *parent = 0); + ~DialogEndLine(); + QString getPointName() const; + void setPointName(const QString &value); + QString getTypeLine() const; + void setTypeLine(const QString &value); + QString getFormula() const; + void setFormula(const QString &value); + qint32 getAngle() const; + void setAngle(const qint32 &value); + qint64 getBasePointId() const; + void setBasePointId(const qint64 &value); public slots: - void ChoosedPoint(qint64 id, Scene::Type type); - void ArrowUp(); - void ArrowDown(); - void ArrowLeft(); - void ArrowRight(); - void ArrowLeftUp(); - void ArrowLeftDown(); - void ArrowRightUp(); - void ArrowRightDown(); - void ClickedSizeGrowth(); - void ClickedStandartTable(); - void ClickedLengthLines(); - void ClickedIncrements(); - void ClickedToolButtonPutHere(); - void PutVal(QListWidgetItem * item); - void ValChenged(int row); - void ClickedToolButtonEqual(); - void NameChanged(); - void FormulaChanged(); - void DialogAccepted(); - void UpdateList(); -protected: - void closeEvent ( QCloseEvent * event ); + virtual void ChoosedPoint(qint64 id, Scene::Type type); + virtual void DialogAccepted(); private: Ui::DialogEndLine *ui; - const VContainer *data; - QPushButton *bOk; - QTimer *timerFormula; - bool flagFormula; - bool flagName; - QString pointName; - QString typeLine; - QString formula; - qint32 angle; - qint64 basePointId; - void FillComboBoxBasePoint(); - void ShowBase(); - void ShowStandartTable(); - void ShowIncrementTable(); - void ShowLengthLines(); - void CheackState(); + QString pointName; + QString typeLine; + QString formula; + qint32 angle; + qint64 basePointId; }; #endif // DIALOGENDLINE_H diff --git a/dialogs/dialogendline.ui b/dialogs/dialogendline.ui index badf97c3c..b0ab33ffb 100644 --- a/dialogs/dialogendline.ui +++ b/dialogs/dialogendline.ui @@ -361,7 +361,7 @@ - Вихідні данні + Вхідні данні diff --git a/dialogs/dialogincrements.cpp b/dialogs/dialogincrements.cpp index 0a4fc3ccb..0e1a7dbee 100644 --- a/dialogs/dialogincrements.cpp +++ b/dialogs/dialogincrements.cpp @@ -8,10 +8,10 @@ #include "../widgets/doubledelegate.h" DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent) : - QDialog(parent), ui(new Ui::DialogIncrements){ + DialogTool(data, parent), ui(new Ui::DialogIncrements){ ui->setupUi(this); - this->data = data; this->doc = doc; + this->data = data; InitialStandartTable(); InitialIncrementTable(); InitialLinesTable(); @@ -33,8 +33,8 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); - QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogIncrements::clickedButtonOk); + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogIncrements::DialogAccepted); } void DialogIncrements::FillStandartTable(){ @@ -335,11 +335,6 @@ void DialogIncrements::cellChanged ( qint32 row, qint32 column ){ } } -void DialogIncrements::closeEvent ( QCloseEvent * event ){ - emit closedActionTable(); - event->accept(); -} - void DialogIncrements::InitialStandartTable(){ ui->tableWidgetStandart->resizeColumnsToContents(); ui->tableWidgetStandart->resizeRowsToContents(); @@ -372,8 +367,8 @@ void DialogIncrements::InitialLinesTable(){ ui->tableWidgetLines->setHorizontalHeaderItem(1, new QTableWidgetItem("Довжина")); } -void DialogIncrements::clickedButtonOk(){ - emit closedActionTable(); +void DialogIncrements::DialogAccepted(){ + emit DialogClosed(QDialog::Accepted); } DialogIncrements::~DialogIncrements(){ diff --git a/dialogs/dialogincrements.h b/dialogs/dialogincrements.h index cf57cc331..86e77c889 100644 --- a/dialogs/dialogincrements.h +++ b/dialogs/dialogincrements.h @@ -1,7 +1,7 @@ #ifndef DIALOGINCREMENTS_H #define DIALOGINCREMENTS_H -#include +#include "dialogtool.h" #include #include "../container/vcontainer.h" @@ -11,10 +11,9 @@ namespace Ui { class DialogIncrements; } -class DialogIncrements : public QDialog +class DialogIncrements : public DialogTool { - Q_OBJECT - + Q_OBJECT public: explicit DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent = 0); ~DialogIncrements(); @@ -23,13 +22,10 @@ public slots: void clickedToolButtonRemove(); void cellChanged ( qint32 row, qint32 column ); void FullUpdateFromFile(); - void clickedButtonOk(); + virtual void DialogAccepted(); signals: void FullUpdateTree(); void haveLiteChange(); - void closedActionTable(); -protected: - void closeEvent ( QCloseEvent * event ); private: Ui::DialogIncrements *ui; VContainer *data; diff --git a/dialogs/dialogline.cpp b/dialogs/dialogline.cpp index db8f7ab3b..1fd7a6356 100644 --- a/dialogs/dialogline.cpp +++ b/dialogs/dialogline.cpp @@ -4,14 +4,15 @@ #include DialogLine::DialogLine(const VContainer *data, QWidget *parent) : - QDialog(parent), ui(new Ui::DialogLine) + DialogTool(data, parent), ui(new Ui::DialogLine) { ui->setupUi(this); - this->data = data; - QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogLine::DialogAccepted); - FillComboBox(ui->comboBoxFirstPoint); - FillComboBox(ui->comboBoxSecondPoint); + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogLine::DialogRejected); + FillComboBoxPoints(ui->comboBoxFirstPoint); + FillComboBoxPoints(ui->comboBoxSecondPoint); number = 0; } @@ -45,26 +46,6 @@ void DialogLine::setFirstPoint(const qint64 &value){ } } -void DialogLine::closeEvent(QCloseEvent *event){ - DialogClosed(QDialog::Rejected); - event->accept(); -} - -void DialogLine::showEvent(QShowEvent *event){ - QDialog::showEvent( event ); - if( event->spontaneous() ){ - return; - } - - if(isInitialized){ - return; - } - - // do your init stuff here - - isInitialized = true;//перший показ вікна вже відбувся -} - void DialogLine::DialogAccepted(){ qint32 index = ui->comboBoxFirstPoint->currentIndex(); @@ -74,17 +55,6 @@ void DialogLine::DialogAccepted(){ DialogClosed(QDialog::Accepted); } -void DialogLine::FillComboBox(QComboBox *box){ - const QMap *points = data->DataPoints(); - QMapIterator i(*points); - while (i.hasNext()) { - i.next(); - VPointF point = i.value(); - box->addItem(point.name(), i.key()); - } -} - - void DialogLine::ChoosedPoint(qint64 id, Scene::Type type){ if(type == Scene::Point){ VPointF point = data->GetPoint(id); diff --git a/dialogs/dialogline.h b/dialogs/dialogline.h index 470c33ed1..65cbf996f 100644 --- a/dialogs/dialogline.h +++ b/dialogs/dialogline.h @@ -1,7 +1,7 @@ #ifndef DIALOGLINE_H #define DIALOGLINE_H -#include +#include "dialogtool.h" #include "../container/vcontainer.h" #include "../options.h" #include @@ -10,35 +10,24 @@ namespace Ui { class DialogLine; } -class DialogLine : public QDialog +class DialogLine : public DialogTool { Q_OBJECT - public: explicit DialogLine(const VContainer *data, QWidget *parent = 0); - ~DialogLine(); - + ~DialogLine(); qint64 getFirstPoint() const; void setFirstPoint(const qint64 &value); - qint64 getSecondPoint() const; void setSecondPoint(const qint64 &value); -signals: - void DialogClosed(int result); public slots: void ChoosedPoint(qint64 id, Scene::Type type); - void DialogAccepted(); -protected: - void closeEvent ( QCloseEvent * event ); - void showEvent( QShowEvent *event ); + virtual void DialogAccepted(); private: Ui::DialogLine *ui; - const VContainer *data; qint32 number; qint64 firstPoint; qint64 secondPoint; - bool isInitialized; - void FillComboBox(QComboBox *box); }; #endif // DIALOGLINE_H diff --git a/dialogs/dialogsinglepoint.cpp b/dialogs/dialogsinglepoint.cpp index 530f72ba7..72bb47530 100644 --- a/dialogs/dialogsinglepoint.cpp +++ b/dialogs/dialogsinglepoint.cpp @@ -6,20 +6,19 @@ #include "../options.h" -DialogSinglePoint::DialogSinglePoint(QWidget *parent) : - QDialog(parent), - ui(new Ui::DialogSinglePoint) +DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) : + DialogTool(data, parent), ui(new Ui::DialogSinglePoint) { ui->setupUi(this); - isInitialized = false; ui->doubleSpinBoxX->setRange(0,PaperSize/PrintDPI*25.4); ui->doubleSpinBoxY->setRange(0,PaperSize/PrintDPI*25.4); - QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok); - pOkButton->setEnabled(false); - connect(pOkButton, &QPushButton::clicked, this, &DialogSinglePoint::OkOperation); - connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSinglePoint::NameChanged); - QPushButton* pCanselButton = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(pCanselButton, &QPushButton::clicked, this, &DialogSinglePoint::CanselOperation); + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + flagName = false; + CheckState(); + connect(bOk, &QPushButton::clicked, this, &DialogSinglePoint::DialogAccepted); + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogSinglePoint::DialogRejected); + connect(ui->lineEditName,&QLineEdit::textChanged, this, &DialogSinglePoint::NamePointChanged); } void DialogSinglePoint::mousePress(QPointF scenePos){ @@ -33,46 +32,11 @@ void DialogSinglePoint::mousePress(QPointF scenePos){ } } -void DialogSinglePoint::showEvent( QShowEvent *event ){ - QDialog::showEvent( event ); - if( event->spontaneous() ){ - return; - } - - if(isInitialized){ - return; - } - - // do your init stuff here - - isInitialized = true;//перший показ вікна вже відбувся -} - -void DialogSinglePoint::NameChanged(){ - QString name = ui->lineEditName->text(); - if(name.isEmpty() || name.contains(" ")){ - QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok); - pOkButton->setEnabled(false); - } else { - QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok); - pOkButton->setEnabled(true); - } -} - -void DialogSinglePoint::CanselOperation(){ - emit ToolCanseled(); -} - -void DialogSinglePoint::OkOperation(){ +void DialogSinglePoint::DialogAccepted(){ point = QPointF(ui->doubleSpinBoxX->value()*PrintDPI/25.4, ui->doubleSpinBoxY->value()*PrintDPI/25.4); name = ui->lineEditName->text(); - emit SinglePointCreated(ui->lineEditName->text(), point); -} - -void DialogSinglePoint::closeEvent ( QCloseEvent * event ){ - emit ToolCanseled(); - event->accept(); + emit DialogClosed(QDialog::Accepted); } void DialogSinglePoint::setData(const QString name, const QPointF point){ diff --git a/dialogs/dialogsinglepoint.h b/dialogs/dialogsinglepoint.h index 3b948b44f..e624ddaec 100644 --- a/dialogs/dialogsinglepoint.h +++ b/dialogs/dialogsinglepoint.h @@ -1,35 +1,27 @@ #ifndef DIALOGSINGLEPOINT_H #define DIALOGSINGLEPOINT_H -#include +#include "dialogtool.h" +#include "../container/vcontainer.h" namespace Ui { class DialogSinglePoint; } -class DialogSinglePoint : public QDialog +class DialogSinglePoint : public DialogTool { Q_OBJECT public: - explicit DialogSinglePoint(QWidget *parent = 0); + explicit DialogSinglePoint(const VContainer *data, QWidget *parent = 0); void setData(const QString name, const QPointF point); QString getName()const; QPointF getPoint()const; ~DialogSinglePoint(); -signals: - void ToolCanseled(); - void SinglePointCreated(const QString name, const QPointF point); public slots: void mousePress(QPointF scenePos); - void NameChanged(); - void CanselOperation(); - void OkOperation(); -protected: - void showEvent( QShowEvent *event ); - void closeEvent ( QCloseEvent * event ); + virtual void DialogAccepted(); private: Ui::DialogSinglePoint *ui; - bool isInitialized; QString name; QPointF point; }; diff --git a/dialogs/dialogtool.cpp b/dialogs/dialogtool.cpp new file mode 100644 index 000000000..0f6cf09b2 --- /dev/null +++ b/dialogs/dialogtool.cpp @@ -0,0 +1,320 @@ +#include "dialogtool.h" +#include +#include +#include "../container/calculator.h" + +DialogTool::DialogTool(const VContainer *data, QWidget *parent):QDialog(parent){ + Q_CHECK_PTR(data); + this->data = data; + flagName = true; + flagFormula = true; + timerFormula = new QTimer(this); + connect(timerFormula, &QTimer::timeout, this, &DialogTool::EvalFormula); + isInitialized = false; + + bOk = 0; + spinBoxAngle = 0; + lineEditFormula = 0; + listWidget = 0; + labelResultCalculation = 0; + labelDescription = 0; + radioButtonSizeGrowth = 0; + radioButtonStandartTable = 0; + radioButtonIncrements = 0; + radioButtonLengthLine = 0; +} + +DialogTool::~DialogTool() +{ +} + +void DialogTool::closeEvent(QCloseEvent *event){ + DialogClosed(QDialog::Rejected); + event->accept(); +} + +void DialogTool::showEvent(QShowEvent *event){ + QDialog::showEvent( event ); + if( event->spontaneous() ){ + return; + } + + if(isInitialized){ + return; + } + + // do your init stuff here + isInitialized = true;//перший показ вікна вже відбувся +} + +void DialogTool::FillComboBoxPoints(QComboBox *box) const{ + const QMap *points = data->DataPoints(); + QMapIterator i(*points); + while (i.hasNext()) { + i.next(); + VPointF point = i.value(); + box->addItem(point.name(), i.key()); + } +} + +void DialogTool::FillComboBoxTypeLine(QComboBox *box) const{ + QStringList list; + list<<"Лінія"<<"Без лінії"; + box->addItems(list); +} + +QString DialogTool::GetTypeLine(const QComboBox *box) const{ + if(box->currentText()=="Лінія"){ + return QString("hair"); + } else { + return QString("none"); + } +} + +void DialogTool::ShowBase(){ + Q_CHECK_PTR(listWidget); + disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->clear(); + connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + const QMap *base = data->DataBase(); + QMapIterator i(*base); + while (i.hasNext()) { + i.next(); + QListWidgetItem *item = new QListWidgetItem(i.key()); + item->setFont(QFont("Times", 12, QFont::Bold)); + listWidget->addItem(item); + } + listWidget->setCurrentRow (0); +} + +void DialogTool::ShowStandartTable(){ + Q_CHECK_PTR(listWidget); + disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->clear(); + connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + const QMap *standartTable = data->DataStandartTable(); + QMapIterator i(*standartTable); + while (i.hasNext()) { + i.next(); + QListWidgetItem *item = new QListWidgetItem(i.key()); + item->setFont(QFont("Times", 12, QFont::Bold)); + listWidget->addItem(item); + } + listWidget->setCurrentRow (0); +} + +void DialogTool::ShowIncrementTable(){ + Q_CHECK_PTR(listWidget); + disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->clear(); + connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + const QMap *incrementTable = data->DataIncrementTable(); + QMapIterator i(*incrementTable); + while (i.hasNext()) { + i.next(); + QListWidgetItem *item = new QListWidgetItem(i.key()); + item->setFont(QFont("Times", 12, QFont::Bold)); + listWidget->addItem(item); + } + listWidget->setCurrentRow (0); +} + +void DialogTool::ShowLengthLines(){ + Q_CHECK_PTR(listWidget); + disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->clear(); + connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + const QMap *linesTable = data->DataLengthLines(); + QMapIterator i(*linesTable); + while (i.hasNext()) { + i.next(); + QListWidgetItem *item = new QListWidgetItem(i.key()); + item->setFont(QFont("Times", 12, QFont::Bold)); + listWidget->addItem(item); + } + listWidget->setCurrentRow (0); +} + +void DialogTool::CheckState(){ + Q_CHECK_PTR(bOk); + bOk->setEnabled(flagFormula & flagName); +} + + +void DialogTool::ChoosedPoint(qint64 id, Scene::Type type){ + Q_UNUSED(id); + Q_UNUSED(type); +} + +void DialogTool::NamePointChanged(){ + QLineEdit* edit = qobject_cast(sender()); + if (edit){ + QString name = edit->text(); + if(name.isEmpty() || name.contains(" ")){ + flagName = false; + } else { + flagName = true; + } + } + CheckState(); +} + +void DialogTool::DialogAccepted(){ + emit DialogClosed(QDialog::Accepted); +} + +void DialogTool::DialogRejected(){ + emit DialogClosed(QDialog::Rejected); +} + +void DialogTool::FormulaChanged(){ + QLineEdit* edit = qobject_cast(sender()); + if(edit){ + if(edit->text().isEmpty()){ + flagFormula = false; + CheckState(); + return; + } + timerFormula->start(1000); + } +} + +void DialogTool::ArrowUp(){ + Q_CHECK_PTR(spinBoxAngle); + spinBoxAngle->setValue(90); +} + +void DialogTool::ArrowDown(){ + Q_CHECK_PTR(spinBoxAngle); + spinBoxAngle->setValue(270); +} + +void DialogTool::ArrowLeft(){ + Q_CHECK_PTR(spinBoxAngle); + spinBoxAngle->setValue(180); +} + +void DialogTool::ArrowRight(){ + Q_CHECK_PTR(spinBoxAngle); + spinBoxAngle->setValue(0); +} + +void DialogTool::ArrowLeftUp(){ + Q_CHECK_PTR(spinBoxAngle); + spinBoxAngle->setValue(135); +} + +void DialogTool::ArrowLeftDown(){ + Q_CHECK_PTR(spinBoxAngle); + spinBoxAngle->setValue(225); +} + +void DialogTool::ArrowRightUp(){ + Q_CHECK_PTR(spinBoxAngle); + spinBoxAngle->setValue(45); +} + +void DialogTool::ArrowRightDown(){ + Q_CHECK_PTR(spinBoxAngle); + spinBoxAngle->setValue(315); +} + +void DialogTool::EvalFormula(){ + Q_CHECK_PTR(lineEditFormula); + Q_CHECK_PTR(labelResultCalculation); + if(lineEditFormula->text().isEmpty()){ + flagFormula = false; + } else { + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(lineEditFormula->text(),&errorMsg); + if(!errorMsg.isEmpty()){ + labelResultCalculation->setText("Помилка."); + flagFormula = false; + } else { + labelResultCalculation->setText(QString().setNum(result)); + flagFormula = true; + } + } + CheckState(); + timerFormula->stop(); +} + +void DialogTool::SizeGrowth(){ + ShowBase(); +} + +void DialogTool::StandartTable(){ + ShowStandartTable(); +} + +void DialogTool::LengthLines(){ + ShowLengthLines(); +} + +void DialogTool::Increments(){ + ShowIncrementTable(); +} + +void DialogTool::PutHere(){ + Q_CHECK_PTR(lineEditFormula); + Q_CHECK_PTR(listWidget); + QListWidgetItem *item = listWidget->currentItem(); + QString val = item->text(); + lineEditFormula->setText(lineEditFormula->text().append(val)); +} + +void DialogTool::PutVal(QListWidgetItem *item){ + Q_CHECK_PTR(lineEditFormula); + QString val = item->text(); + lineEditFormula->setText(lineEditFormula->text().append(val)); +} + +void DialogTool::ValChenged(int row){ + Q_CHECK_PTR(listWidget); + Q_CHECK_PTR(labelDescription); + Q_CHECK_PTR(radioButtonSizeGrowth); + Q_CHECK_PTR(radioButtonStandartTable); + Q_CHECK_PTR(radioButtonIncrements); + if(listWidget->count() == 0){ + return; + } + QListWidgetItem *item = listWidget->item( row ); + if(radioButtonSizeGrowth->isChecked()){ + if(item->text()=="Р"){ + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->growth()).arg("Зріст"); + labelDescription->setText(desc); + } + if(item->text()=="Сг"){ + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->size()).arg("Розмір"); + labelDescription->setText(desc); + } + } + if(radioButtonStandartTable->isChecked()){ + VStandartTableCell stable = data->GetStandartTableCell(item->text()); + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandartTableCell(item->text())) + .arg(stable.GetDescription()); + labelDescription->setText(desc); + } + if(radioButtonIncrements->isChecked()){ + VIncrementTableRow itable = data->GetIncrementTableRow(item->text()); + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text())) + .arg(itable.getDescription()); + labelDescription->setText(desc); + } +} + +void DialogTool::UpdateList(){ + Q_CHECK_PTR(radioButtonSizeGrowth); + Q_CHECK_PTR(radioButtonStandartTable); + Q_CHECK_PTR(radioButtonIncrements); + if(radioButtonSizeGrowth->isChecked()){ + ShowBase(); + } + if(radioButtonStandartTable->isChecked()){ + ShowStandartTable(); + } + if(radioButtonIncrements->isChecked()){ + ShowIncrementTable(); + } +} diff --git a/dialogs/dialogtool.h b/dialogs/dialogtool.h new file mode 100644 index 000000000..42260b699 --- /dev/null +++ b/dialogs/dialogtool.h @@ -0,0 +1,75 @@ +#ifndef DIALOGTOOL_H +#define DIALOGTOOL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../container/vcontainer.h" +#include "../options.h" + +class DialogTool : public QDialog +{ + Q_OBJECT +public: + DialogTool(const VContainer *data, QWidget *parent = 0); + virtual ~DialogTool(); +signals: + void DialogClosed(int result); +public slots: + virtual void ChoosedPoint(qint64 id, Scene::Type type); + void NamePointChanged(); + virtual void DialogAccepted(); + virtual void DialogRejected(); + void FormulaChanged(); + void ArrowUp(); + void ArrowDown(); + void ArrowLeft(); + void ArrowRight(); + void ArrowLeftUp(); + void ArrowLeftDown(); + void ArrowRightUp(); + void ArrowRightDown(); + void EvalFormula(); + void SizeGrowth(); + void StandartTable(); + void LengthLines(); + void Increments(); + void PutHere(); + void PutVal(QListWidgetItem * item); + void ValChenged(int row); + void UpdateList(); +protected: + const VContainer *data; + bool isInitialized; + bool flagName; + bool flagFormula; + QTimer *timerFormula; + QPushButton *bOk; + QSpinBox *spinBoxAngle; + QLineEdit *lineEditFormula; + QListWidget *listWidget; + QLabel *labelResultCalculation; + QLabel *labelDescription; + QRadioButton *radioButtonSizeGrowth; + QRadioButton *radioButtonStandartTable; + QRadioButton *radioButtonIncrements; + QRadioButton *radioButtonLengthLine; + void closeEvent ( QCloseEvent * event ); + void showEvent( QShowEvent *event ); + void FillComboBoxPoints(QComboBox *box)const; + void FillComboBoxTypeLine(QComboBox *box) const; + void CheckState(); + QString GetTypeLine(const QComboBox *box)const; + void ShowBase(); + void ShowStandartTable(); + void ShowIncrementTable(); + void ShowLengthLines(); +}; + +#endif // DIALOGTOOL_H diff --git a/icon.qrc b/icon.qrc index e5c34325d..66955c589 100644 --- a/icon.qrc +++ b/icon.qrc @@ -20,5 +20,6 @@ icon/24x24/equal.png icon/32x32/segment.png icon/32x32/line.png + icon/32x32/along_line.png diff --git a/icon/32x32/along_line.png b/icon/32x32/along_line.png new file mode 100644 index 0000000000000000000000000000000000000000..5a1fca3ba0a661b4dbd7f81c2cddc8004270b007 GIT binary patch literal 689 zcmV;i0#5yjP)aFG=y==dL;K8ds>D9Y8uYM8n(p&Lh zRSHHd1r-w%1W{TKCRNmJcgD*bT|&Axac6(95cVC|XWl=*nFwI`s|GLwH1+)+;3-Mh zfmL8zpH<*SnIG>1PIv6}cVA<{WHs$eKz*njM&B*znqUA1n9o@=KLl1dfCWD1tl17- zf}g;;)_jz9b7KE3(NXIF=YUxt(wI}gEgj1ZAPE5g&;yPDbGw7^ygp+nr9Q9z{_lP1CC)GUdH5v>dqr-EJ44?VOtu z5z;hWwAL01AqQEcnP`d#&bdXP2AtO>J*7sqs}mJQaU26I11oCPJ>VPg1$YeH1df$) zZrlTQGUtT@Qk|NGNsMS*y#=ZYke!&bz=bjZW-=emj&D`_AvnMb;OmHsiUW?1>k~2o zK%$mCtGh;fprWy=_Cpd1pbtC;UIHI9BX4vfS|U>S-j4-Qgc`tYW6WB{wr?Gz98wTK zqC2hvN4)o~D2kfSxyrvXAq8e(0C5AixgrN&Uf$xcFQKPTRm) zIGGbWI;jtoolButtonLine, &QToolButton::clicked, this, &MainWindow::ToolLine); + connect(ui->toolButtonAlongLine, &QToolButton::clicked, this, + &MainWindow::ToolAlongLine); data = new VContainer; CreateManTableIGroup (); @@ -145,14 +148,12 @@ void MainWindow::ToolSinglePoint(bool checked){ QCursor cur(pixmap, 2, 3); ui->graphicsView->setCursor(cur); helpLabel->setText("Виберіть розташування для точки."); - dialogSinglePoint = new DialogSinglePoint; + dialogSinglePoint = new DialogSinglePoint(data); //покажемо вікно як тільки буде вибрано місце розташування для точки connect(scene, &VMainGraphicsScene::mousePress, dialogSinglePoint, &DialogSinglePoint::mousePress); - //головне вікно отримає сигнал відміни створення точки - connect(dialogSinglePoint, &DialogSinglePoint::ToolCanseled, this, &MainWindow::ToolCanseled); - connect(dialogSinglePoint, &DialogSinglePoint::SinglePointCreated, this, - &MainWindow::SinglePointCreated); + connect(dialogSinglePoint, &DialogSinglePoint::DialogClosed, this, + &MainWindow::ClosedDialogSinglePoint); } else { //не даємо користувачу зняти виділення кнопки ui->toolButtonSinglePoint->setChecked(true); } @@ -234,6 +235,48 @@ void MainWindow::ClosedDialogLine(int result){ 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::ChoosedPoint); + connect(dialogAlongLine, &DialogLine::DialogClosed, this, &MainWindow::ClosedDialogAlongLine); + } else { + ui->toolButtonAlongLine->setChecked(true); + } +} + +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)); + VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId, + typeLine, Tool::FromGui); + scene->addItem(point); + connect(point, &VToolAlongLine::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem); + } + } + ArrowTool(); +} + void MainWindow::showEvent( QShowEvent *event ){ QMainWindow::showEvent( event ); if( event->spontaneous() ){ @@ -352,6 +395,11 @@ void MainWindow::CanselTool(){ ui->toolButtonLine->setChecked(false); scene->clearFocus(); break; + case Tools::AlongLineTool: + delete dialogAlongLine; + ui->toolButtonAlongLine->setChecked(false); + scene->clearFocus(); + break; } } @@ -377,23 +425,24 @@ void MainWindow::keyPressEvent ( QKeyEvent * event ){ QMainWindow::keyPressEvent ( event ); } -void MainWindow::ToolCanseled(){ +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)); + VToolSimplePoint *spoint = new VToolSimplePoint(doc, data, id, Tool::FromGui); + scene->addItem(spoint); + connect(spoint, &VToolPoint::ChoosedPoint, 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::SinglePointCreated(const QString name, const QPointF point){ - qint64 id = data->AddPoint(VPointF(point.x(), point.y(), name, 5, 10)); - VToolSimplePoint *spoint = new VToolSimplePoint(doc, data, id, Tool::FromGui); - scene->addItem(spoint); - connect(spoint, &VToolPoint::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem); - ArrowTool(); - ui->toolButtonSinglePoint->setEnabled(false); - qint32 index = comboBoxDraws->currentIndex(); - comboBoxDraws->setItemData(index, false); - ui->actionSave->setEnabled(true); - SetEnableTool(true); -} - void MainWindow::ActionDraw(bool checked){ if(checked){ ui->actionDetails->setChecked(false); @@ -590,8 +639,8 @@ void MainWindow::SetEnableWidgets(bool enable){ void MainWindow::ActionTable(bool checked){ if(checked){ - dialogTable = new DialogIncrements(data, doc, 0); - connect(dialogTable, &DialogIncrements::closedActionTable, this, + dialogTable = new DialogIncrements(data, doc, this); + connect(dialogTable, &DialogIncrements::DialogClosed, this, &MainWindow::ClosedActionTable); dialogTable->show(); } else { @@ -605,16 +654,10 @@ void MainWindow::ClosedActionTable(){ delete dialogTable; } -void MainWindow::closeEvent ( QCloseEvent * event ){ - if(ui->actionTable->isChecked()==true){ - delete dialogTable; - } - event->accept(); -} - void MainWindow::SetEnableTool(bool enable){ ui->toolButtonEndLine->setEnabled(enable); ui->toolButtonLine->setEnabled(enable); + ui->toolButtonAlongLine->setEnabled(enable); } MainWindow::~MainWindow(){ diff --git a/mainwindow.h b/mainwindow.h index 1702fb86c..29b091442 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -5,11 +5,13 @@ #include #include #include +#include #include "widgets/vmaingraphicsscene.h" #include "dialogs/dialogsinglepoint.h" #include "dialogs/dialogincrements.h" #include "dialogs/dialogline.h" +#include "dialogs/dialogalongline.h" #include "tools/vtoolsimplepoint.h" #include "xml/vdomdocument.h" #include "container/vcontainer.h" @@ -25,7 +27,8 @@ namespace Tools{ ArrowTool, SinglePointTool, EndLineTool, - LineTool + LineTool, + AlongLineTool }; } @@ -41,8 +44,7 @@ public slots: void ActionAroowTool(); void ActionDraw(bool checked); void ActionDetails(bool checked); - void ToolCanseled(); - void SinglePointCreated(const QString name, const QPointF point); + void ClosedDialogSinglePoint(int result); void ActionNewDraw(); void currentDrawChanged( int index ); void OptionDraw(); @@ -59,10 +61,11 @@ public slots: void ClosedDialogEndLine(int result); void ToolLine(bool checked); void ClosedDialogLine(int result); + void ToolAlongLine(bool checked); + void ClosedDialogAlongLine(int result); protected: virtual void keyPressEvent ( QKeyEvent * event ); virtual void showEvent( QShowEvent *event ); - virtual void closeEvent ( QCloseEvent * event ); private: Ui::MainWindow *ui; Tools::Enum tool; @@ -74,6 +77,7 @@ private: DialogIncrements *dialogTable; DialogEndLine *dialogEndLine; DialogLine *dialogLine; + DialogAlongLine *dialogAlongLine; VDomDocument *doc; VContainer *data; QComboBox *comboBoxDraws; diff --git a/mainwindow.ui b/mainwindow.ui index 81db520a6..12f1da402 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -57,7 +57,7 @@ - 1 + 0 @@ -109,10 +109,26 @@ - + + + false + ... + + + :/icon/32x32/along_line.png:/icon/32x32/along_line.png + + + + 24 + 24 + + + + true + @@ -202,7 +218,7 @@ 0 0 - 154 + 117 45 @@ -230,7 +246,7 @@ 0 0 - 154 + 117 45 @@ -474,11 +490,4 @@ - - - - false - - - diff --git a/options.h b/options.h index 68633c0a4..3c3c170f3 100644 --- a/options.h +++ b/options.h @@ -3,8 +3,8 @@ #define PrintDPI 96 #define PaperSize 50000 -#define WidthMainLine 0.8*PrintDPI/25.4 -#define widthHairLine WidthMainLine/3 +#define widthMainLine 0.8*PrintDPI/25.4 +#define widthHairLine widthMainLine/3 namespace Scene{ enum Type diff --git a/tools/vabstracttool.cpp b/tools/vabstracttool.cpp index 1b3fd8340..38d73ecd0 100644 --- a/tools/vabstracttool.cpp +++ b/tools/vabstracttool.cpp @@ -54,9 +54,15 @@ void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, c VAbstractTool::~VAbstractTool(){ } -QString VAbstractTool::GetNameLine(qint64 firstPoint, qint64 secondPoint) const{ +QString VAbstractTool::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const{ VPointF first = data->GetPoint(firstPoint); VPointF second = data->GetPoint(secondPoint); - QString name = QString("Line_%1_%2").arg(first.name(), second.name()); - return name; + return QString("Line_%1_%2").arg(first.name(), second.name()); +} + +void VAbstractTool::AddLine(const qint64 &firstPointId, const qint64 &secondPointId) const{ + QString nameLine = GetNameLine(firstPointId, secondPointId); + VPointF firstPoint = data->GetPoint(firstPointId); + VPointF secondPoint = data->GetPoint(secondPointId); + data->AddLine(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length()); } diff --git a/tools/vabstracttool.h b/tools/vabstracttool.h index 1eb4615e8..40dd50412 100644 --- a/tools/vabstracttool.h +++ b/tools/vabstracttool.h @@ -24,6 +24,7 @@ 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 ChoosedPoint(qint64 id, Scene::Type type); @@ -39,6 +40,7 @@ protected: void AddAttribute(QDomElement &domElement, const QString &name, const qint32 &value); void AddAttribute(QDomElement &domElement, const QString &name, const qreal &value); void AddAttribute(QDomElement &domElement, const QString &name, const QString &value); - QString GetNameLine(qint64 firstPoint, qint64 secondPoint) const; + QString GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const; + void AddLine(const qint64 &firstPointId, const qint64 &secondPointId) const; }; #endif // VABSTRACTTOOL_H diff --git a/tools/vtoolalongline.cpp b/tools/vtoolalongline.cpp new file mode 100644 index 000000000..721d2c10e --- /dev/null +++ b/tools/vtoolalongline.cpp @@ -0,0 +1,142 @@ +#include "vtoolalongline.h" +#include "../container/calculator.h" +#include +#include +#include + +VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, + const qint64 &firstPointId, const qint64 &secondPointId, + const QString &typeLine, Tool::Enum typeCreation, + QGraphicsItem *parent):VToolPoint(doc, data, id, parent){ + connect(this, &VToolAlongLine::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); + this->typeLine = typeLine; + this->formula = formula; + this->firstPointId = firstPointId; + this->secondPointId = secondPointId; + + //Лінія, якщо потрібно. + 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); + mainLine = new QGraphicsLineItem(line, this); + mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + if(typeLine == "none"){ + mainLine->setVisible(false); + } else { + mainLine->setVisible(true); + } + + AddLine(firstPointId, id); + AddLine(id, secondPointId); + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } + } +} + +void VToolAlongLine::FullUpdateFromFile(){ + QString name; + qreal mx, my; + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + 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 point = VAbstractTool::data->GetPoint(id); + RefreshBaseGeometry(name, point.x(), point.y(), mx, my); + VPointF firstPoint = VAbstractTool::data->GetPoint(firstPointId); + VPointF secondPoint = VAbstractTool::data->GetPoint(secondPointId); + mainLine->setLine(QLineF(firstPoint.toQPointF(), secondPoint.toQPointF())); + + AddLine(firstPointId, id); + AddLine(id, secondPointId); +} + +void VToolAlongLine::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogAlongLine->getPointName()); + domElement.setAttribute("typeLine", dialogAlongLine->getTypeLine()); + domElement.setAttribute("length", dialogAlongLine->getFormula()); + domElement.setAttribute("firstPoint", QString().setNum(dialogAlongLine->getFirstPointId())); + domElement.setAttribute("secondPoint", QString().setNum(dialogAlongLine->getSecondPointId())); + emit FullUpdateTree(); + } + + } + dialogAlongLine.clear(); +} + +void VToolAlongLine::ChangedActivDraw(const QString newName){ + if(nameActivDraw == newName){ + mainLine->setPen(QPen(Qt::black, widthHairLine)); + VToolPoint::ChangedActivDraw(newName); + } else { + mainLine->setPen(QPen(Qt::gray, widthHairLine)); + VToolPoint::ChangedActivDraw(newName); + } +} + +void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + if(!ignoreContextMenuEvent){ + QMenu menu; + QAction *actionOption = menu.addAction("Властивості"); + QAction *selectedAction = menu.exec(event->screenPos()); + if(selectedAction == actionOption){ + dialogAlongLine = QSharedPointer(new DialogAlongLine(VAbstractTool::data)); + + connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject, + dialogAlongLine.data(), &DialogAlongLine::ChoosedPoint); + connect(dialogAlongLine.data(), &DialogAlongLine::DialogClosed, this, + &VToolAlongLine::FullUpdateFromGui); + connect(doc, &VDomDocument::FullUpdateFromFile, dialogAlongLine.data(), + &DialogAlongLine::UpdateList); + + VPointF p = VAbstractTool::data->GetPoint(id); + + dialogAlongLine->setTypeLine(typeLine); + dialogAlongLine->setFormula(formula); + dialogAlongLine->setFirstPointId(firstPointId); + dialogAlongLine->setSecondPointId(secondPointId); + dialogAlongLine->setPointName(p.name()); + + dialogAlongLine->show(); + } + } +} + +void VToolAlongLine::AddToFile(){ + VPointF point = VAbstractTool::data->GetPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "alongLine"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); + AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + + AddAttribute(domElement, "typeLine", typeLine); + AddAttribute(domElement, "length", formula); + AddAttribute(domElement, "firstPoint", firstPointId); + AddAttribute(domElement, "secondPoint", secondPointId); + + QDomElement calcElement; + bool ok = doc->GetActivCalculationElement(calcElement); + if(ok){ + calcElement.appendChild(domElement); + } else { + qCritical()<<"Не можу знайти тег калькуляції."<< Q_FUNC_INFO; + } +} diff --git a/tools/vtoolalongline.h b/tools/vtoolalongline.h new file mode 100644 index 000000000..a4ad20571 --- /dev/null +++ b/tools/vtoolalongline.h @@ -0,0 +1,30 @@ +#ifndef VTOOLALONGLINE_H +#define VTOOLALONGLINE_H + +#include "vtoolpoint.h" +#include "../dialogs/dialogalongline.h" + +class VToolAlongLine : public VToolPoint +{ + Q_OBJECT +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); +public slots: + virtual void FullUpdateFromFile(); + virtual void ChangedActivDraw(const QString newName); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + QString typeLine; + QString formula; + qint64 firstPointId; + qint64 secondPointId; + QGraphicsLineItem *mainLine; + QSharedPointer dialogAlongLine; +}; + +#endif // VTOOLALONGLINE_H diff --git a/tools/vtoolendline.cpp b/tools/vtoolendline.cpp index 6b6245692..6ee187261 100644 --- a/tools/vtoolendline.cpp +++ b/tools/vtoolendline.cpp @@ -25,9 +25,7 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id mainLine->setVisible(true); } - QString nameLine = GetNameLine(basePointId, id); - QLineF line = QLineF(basePoint.toQPointF(), point.toQPointF()); - data->AddLine(nameLine, line.length()); + AddLine(basePointId, id); if(typeCreation == Tool::FromGui){ AddToFile(); @@ -52,9 +50,7 @@ void VToolEndLine::FullUpdateFromFile(){ VPointF basePoint = VAbstractTool::data->GetPoint(basePointId); mainLine->setLine(QLineF(basePoint.toQPointF(), point.toQPointF())); - QString nameLine = GetNameLine(basePointId, id); - QLineF line = QLineF(basePoint.toQPointF(), point.toQPointF()); - VAbstractTool::data->AddLine(nameLine, line.length()); + AddLine(basePointId, id); } void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ @@ -67,7 +63,8 @@ void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject, dialogEndLine.data(), &DialogEndLine::ChoosedPoint); - connect(dialogEndLine.data(), &DialogEndLine::DialogClosed, this, &VToolEndLine::ClosedDialogEndLine); + connect(dialogEndLine.data(), &DialogEndLine::DialogClosed, this, + &VToolEndLine::FullUpdateFromGui); connect(doc, &VDomDocument::FullUpdateFromFile, dialogEndLine.data(), &DialogEndLine::UpdateList); VPointF p = VAbstractTool::data->GetPoint(id); @@ -83,26 +80,17 @@ void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ } } -void VToolEndLine::ClosedDialogEndLine(int result){ +void VToolEndLine::FullUpdateFromGui(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 = VAbstractTool::data->GetPoint(basePointId); - QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y())); - Calculator cal(VAbstractTool::data); - QString errorMsg; - qreal result = cal.eval(formula, &errorMsg); - if(errorMsg.isEmpty()){ - line.setLength(result/PrintDPI*25.4); - line.setAngle(angle); - - FullUpdateFromGui(pointName, typeLine, formula, angle, basePointId); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogEndLine->getPointName()); + domElement.setAttribute("typeLine", dialogEndLine->getTypeLine()); + domElement.setAttribute("length", dialogEndLine->getFormula()); + domElement.setAttribute("angle", QString().setNum(dialogEndLine->getAngle())); + domElement.setAttribute("basePoint", QString().setNum(dialogEndLine->getBasePointId())); + emit FullUpdateTree(); } - } dialogEndLine.clear(); } @@ -140,22 +128,3 @@ void VToolEndLine::AddToFile(){ qCritical()<<"Не можу знайти тег калькуляції."<< Q_FUNC_INFO; } } - -void VToolEndLine::FullUpdateFromGui(const QString &name, const QString &typeLine, const QString &formula, - const qreal &angle, const qint64 &basePointId){ - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - this->typeLine = typeLine; - this->formula = formula; - this->angle = angle; - this->basePointId = basePointId; - - domElement.setAttribute("name", name); - - domElement.setAttribute("typeLine", typeLine); - domElement.setAttribute("length", formula); - domElement.setAttribute("angle", QString().setNum(angle)); - domElement.setAttribute("basePoint", QString().setNum(basePointId)); - emit FullUpdateTree(); - } -} diff --git a/tools/vtoolendline.h b/tools/vtoolendline.h index 97c4dd2cc..fb2f3d7d9 100644 --- a/tools/vtoolendline.h +++ b/tools/vtoolendline.h @@ -16,7 +16,7 @@ public: QGraphicsItem * parent = 0); public slots: virtual void FullUpdateFromFile(); - void ClosedDialogEndLine(int result); + virtual void FullUpdateFromGui(int result); virtual void ChangedActivDraw(const QString newName); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); @@ -28,8 +28,6 @@ private: qint64 basePointId; QGraphicsLineItem *mainLine; QSharedPointer dialogEndLine; - void FullUpdateFromGui(const QString &name, const QString &typeLine, const QString &formula, - const qreal &angle, const qint64 &basePointId); }; #endif // VTOOLENDLINE_H diff --git a/tools/vtoolline.cpp b/tools/vtoolline.cpp index 92fe893b0..6d966b0fc 100644 --- a/tools/vtoolline.cpp +++ b/tools/vtoolline.cpp @@ -3,7 +3,8 @@ #include VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint, - Tool::Enum typeCreation):VAbstractTool(doc, data, id){ + Tool::Enum typeCreation, QGraphicsItem *parent):VAbstractTool(doc, data, id), + QGraphicsLineItem(parent){ connect(this, &VToolLine::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); this->firstPoint = firstPoint; this->secondPoint = secondPoint; @@ -14,9 +15,9 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs this->setLine(QLineF(first.toQPointF(), second.toQPointF())); this->setFlag(QGraphicsItem::ItemStacksBehindParent, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); - QString nameLine = GetNameLine(firstPoint, secondPoint); - data->AddLine(nameLine, QLineF(first.toQPointF(), second.toQPointF()).length()); + AddLine(firstPoint, secondPoint); if(typeCreation == Tool::FromGui){ AddToFile(); @@ -32,15 +33,17 @@ void VToolLine::FullUpdateFromFile(){ VPointF first = VAbstractTool::data->GetPoint(firstPoint); VPointF second = VAbstractTool::data->GetPoint(secondPoint); this->setLine(QLineF(first.toQPointF(), second.toQPointF())); - QString nameLine = GetNameLine(firstPoint, secondPoint); - VAbstractTool::data->AddLine(nameLine, QLineF(first.toQPointF(), second.toQPointF()).length()); + AddLine(firstPoint, secondPoint); } -void VToolLine::ClosedDialogLine(int result){ +void VToolLine::FullUpdateFromGui(int result){ if(result == QDialog::Accepted){ - qint64 firstPoint = dialogLine->getFirstPoint(); - qint64 secondPoint = dialogLine->getSecondPoint(); - FullUpdateFromGui(firstPoint, secondPoint); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("firstPoint", QString().setNum(dialogLine->getFirstPoint())); + domElement.setAttribute("secondPoint", QString().setNum(dialogLine->getSecondPoint())); + emit FullUpdateTree(); + } } dialogLine.clear(); } @@ -48,9 +51,11 @@ void VToolLine::ClosedDialogLine(int result){ void VToolLine::ChangedActivDraw(const QString newName){ if(nameActivDraw == newName){ this->setPen(QPen(Qt::black, widthHairLine)); + this->setAcceptHoverEvents (true); VAbstractTool::ChangedActivDraw(newName); } else { this->setPen(QPen(Qt::gray, widthHairLine)); + this->setAcceptHoverEvents (false); VAbstractTool::ChangedActivDraw(newName); } } @@ -65,7 +70,7 @@ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject, dialogLine.data(), &DialogLine::ChoosedPoint); - connect(dialogLine.data(), &DialogLine::DialogClosed, this, &VToolLine::ClosedDialogLine); + connect(dialogLine.data(), &DialogLine::DialogClosed, this, &VToolLine::FullUpdateFromGui); dialogLine->setFirstPoint(firstPoint); dialogLine->setSecondPoint(secondPoint); @@ -78,9 +83,7 @@ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolLine::AddToFile(){ QDomElement domElement = doc->createElement("line"); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "firstPoint", firstPoint); AddAttribute(domElement, "secondPoint", secondPoint); @@ -93,14 +96,13 @@ void VToolLine::AddToFile(){ } } -void VToolLine::FullUpdateFromGui(qint64 firstPoint, qint64 secondPoint){ - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - this->firstPoint = firstPoint; - this->secondPoint = secondPoint; - - domElement.setAttribute("firstPoint", QString().setNum(firstPoint)); - domElement.setAttribute("secondPoint", QString().setNum(secondPoint)); - emit FullUpdateTree(); - } +void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(Qt::black, widthMainLine)); } + +void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(Qt::black, widthHairLine)); +} + diff --git a/tools/vtoolline.h b/tools/vtoolline.h index f2dcf8131..a4f1b5fa4 100644 --- a/tools/vtoolline.h +++ b/tools/vtoolline.h @@ -10,19 +10,20 @@ class VToolLine: public VAbstractTool, public QGraphicsLineItem Q_OBJECT public: VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint, - Tool::Enum typeCreation); + Tool::Enum typeCreation, QGraphicsItem * parent = 0); public slots: virtual void FullUpdateFromFile(); - void ClosedDialogLine(int result); virtual void ChangedActivDraw(const QString newName); + virtual void FullUpdateFromGui(int result); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); private: qint64 firstPoint; qint64 secondPoint; QSharedPointer dialogLine; - void FullUpdateFromGui(qint64 firstPoint, qint64 secondPoint); }; #endif // VTOOLLINE_H diff --git a/tools/vtoolpoint.cpp b/tools/vtoolpoint.cpp index 2488bca86..d3b44a6f8 100644 --- a/tools/vtoolpoint.cpp +++ b/tools/vtoolpoint.cpp @@ -19,6 +19,7 @@ VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, this->setPen(QPen(Qt::black, widthHairLine)); this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); //Тексто мітка точки namePoint = new VGraphicsSimpleTextItem(point.name(), this); @@ -166,7 +167,9 @@ void VToolPoint::ChangedActivDraw(const QString newName){ namePoint->setFlag(QGraphicsItem::ItemIsSelectable, true); namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); namePoint->setBrush(QBrush(Qt::black)); + namePoint->setAcceptHoverEvents(true); lineName->setPen(QPen(Qt::black, widthHairLine)); + this->setAcceptHoverEvents(true); VAbstractTool::ChangedActivDraw(newName); } else { this->setPen(QPen(Qt::gray, widthHairLine)); @@ -175,7 +178,9 @@ void VToolPoint::ChangedActivDraw(const QString newName){ namePoint->setFlag(QGraphicsItem::ItemIsSelectable, false); namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); namePoint->setBrush(QBrush(Qt::gray)); + namePoint->setAcceptHoverEvents(false); lineName->setPen(QPen(Qt::gray, widthHairLine)); + this->setAcceptHoverEvents (false); VAbstractTool::ChangedActivDraw(newName); } } @@ -200,6 +205,16 @@ void VToolPoint::RefreshBaseGeometry(const QString &name, const qreal &x, const RefreshLine(); } +void VToolPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(Qt::black, widthMainLine)); +} + +void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(Qt::black, widthHairLine)); +} + VToolPoint::~VToolPoint(){ } diff --git a/tools/vtoolpoint.h b/tools/vtoolpoint.h index 16601fd1a..c907b487a 100644 --- a/tools/vtoolpoint.h +++ b/tools/vtoolpoint.h @@ -17,6 +17,7 @@ public: public slots: void NameChangePosition(const QPointF pos); virtual void ChangedActivDraw(const QString newName); + virtual void FullUpdateFromGui(int result) = 0; protected: qreal radius; VGraphicsSimpleTextItem *namePoint; @@ -24,7 +25,8 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); void RefreshBaseGeometry(const QString &name, const qreal &x, const qreal &y, const qreal &mx, const qreal &my); - + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); private: qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, QPointF &p2) const; diff --git a/tools/vtoolsimplepoint.cpp b/tools/vtoolsimplepoint.cpp index 496a48c45..eecfd5da4 100644 --- a/tools/vtoolsimplepoint.cpp +++ b/tools/vtoolsimplepoint.cpp @@ -9,11 +9,9 @@ #include "../options.h" #include "../container/vpointf.h" -#include "../dialogs/dialogsinglepoint.h" VToolSimplePoint::VToolSimplePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, QGraphicsItem * parent ):VToolPoint(doc, data, id, parent){ - ignoreContextMenuEvent = false;//don't ignore context menu events; connect(this, &VToolSimplePoint::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); if(typeCreation == Tool::FromGui){ AddToFile(); @@ -41,14 +39,18 @@ void VToolSimplePoint::AddToFile(){ } } -void VToolSimplePoint::FullUpdateFromGui(const QString &name, qreal x, qreal y){ - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", name); - domElement.setAttribute("x", QString().setNum(x/PrintDPI*25.4)); - domElement.setAttribute("y", QString().setNum(y/PrintDPI*25.4)); - emit FullUpdateTree(); +void VToolSimplePoint::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QPointF p = dialogSinglePoint->getPoint(); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogSinglePoint->getName()); + domElement.setAttribute("x", QString().setNum(p.x()/PrintDPI*25.4)); + domElement.setAttribute("y", QString().setNum(p.y()/PrintDPI*25.4)); + emit FullUpdateTree(); + } } + dialogSinglePoint.clear(); } void VToolSimplePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){ @@ -57,15 +59,12 @@ void VToolSimplePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event QAction *actionOption = menu.addAction("Властивості"); QAction *selectedAction = menu.exec(event->screenPos()); if(selectedAction == actionOption){ - DialogSinglePoint *dialogSinglePoint = new DialogSinglePoint; + dialogSinglePoint = QSharedPointer(new DialogSinglePoint(VAbstractTool::data)); + connect(dialogSinglePoint.data(), &DialogSinglePoint::DialogClosed, this, + &VToolSimplePoint::FullUpdateFromGui); VPointF p = VAbstractTool::data->GetPoint(id); dialogSinglePoint->setData(p.name(), p.toQPointF()); - qint32 result = dialogSinglePoint->exec(); - if(result == QDialog::Accepted){ - QPointF p = dialogSinglePoint->getPoint(); - FullUpdateFromGui(dialogSinglePoint->getName(), p.x(), p.y()); - } - delete dialogSinglePoint; + dialogSinglePoint->exec(); } } } diff --git a/tools/vtoolsimplepoint.h b/tools/vtoolsimplepoint.h index 0d0bc4f41..11e1938bb 100644 --- a/tools/vtoolsimplepoint.h +++ b/tools/vtoolsimplepoint.h @@ -4,6 +4,7 @@ #include "../container/vcontainer.h" #include "../xml/vdomdocument.h" #include "vtoolpoint.h" +#include "../dialogs/dialogsinglepoint.h" class VToolSimplePoint : public VToolPoint { @@ -13,11 +14,12 @@ public: Tool::Enum typeCreation, QGraphicsItem * parent = 0 ); public slots: virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); private: - void FullUpdateFromGui(const QString& name, qreal x, qreal y); + QSharedPointer dialogSinglePoint; }; #endif // VTOOLSIMPLEPOINT_H diff --git a/widgets/vgraphicssimpletextitem.cpp b/widgets/vgraphicssimpletextitem.cpp index 339654831..b0302f349 100644 --- a/widgets/vgraphicssimpletextitem.cpp +++ b/widgets/vgraphicssimpletextitem.cpp @@ -8,6 +8,7 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphic this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + this->setAcceptHoverEvents(true); } QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QVariant &value){ @@ -25,4 +26,14 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV emit NameChangePosition(newPos); } return QGraphicsItem::itemChange(change, value); - } +} + +void VGraphicsSimpleTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setBrush(Qt::green); +} + +void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setBrush(Qt::black); +} diff --git a/widgets/vgraphicssimpletextitem.h b/widgets/vgraphicssimpletextitem.h index 4a07edccc..ef8073d78 100644 --- a/widgets/vgraphicssimpletextitem.h +++ b/widgets/vgraphicssimpletextitem.h @@ -7,12 +7,14 @@ class VGraphicsSimpleTextItem : public QObject, public QGraphicsSimpleTextItem { Q_OBJECT public: - VGraphicsSimpleTextItem(QGraphicsItem * parent = 0); - VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent = 0 ); + VGraphicsSimpleTextItem(QGraphicsItem * parent = 0); + VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent = 0 ); signals: - void NameChangePosition(const QPointF pos); + void NameChangePosition(const QPointF pos); protected: - QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); + QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); }; #endif // VGRAPHICSSIMPLETEXTITEM_H diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index 19258f4c6..331fcfe50 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -4,6 +4,7 @@ #include "../tools/vtoolsimplepoint.h" #include "../tools/vtoolendline.h" #include "../tools/vtoolline.h" +#include "../tools/vtoolalongline.h" #include "../options.h" #include "../container/calculator.h" @@ -367,6 +368,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen } } } + return; } if(type == "endLine"){ if(!domElement.isNull()){ @@ -403,6 +405,43 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen } } } + return; + } + if(type == "alongLine"){ + if(!domElement.isNull()){ + QString name, typeLine, formula; + qreal mx=5, my=10; + qint64 id, firstPointId, secondPointId; + if(!domElement.isNull()){ + 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)); + if(parse == Document::FullParse){ + VToolAlongLine *point = new VToolAlongLine(this, data, id, formula, firstPointId, + secondPointId, typeLine, Tool::FromGui); + scene->addItem(point); + connect(point, &VToolAlongLine::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem); + } + } + } + } + return; } }