diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 40cf59383..718475811 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -41,8 +41,8 @@ //--------------------------------------------------------------------------------------------------------------------- DialogTool::DialogTool(const VContainer *data, QWidget *parent) :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(nullptr), - bOk(nullptr), spinBoxAngle(nullptr), lineEditFormula(nullptr), plainTextEditFormula(nullptr), listWidget(nullptr), - labelResultCalculation(nullptr), labelDescription(nullptr), labelEditNamePoint(nullptr), + bOk(nullptr), bApply(nullptr), spinBoxAngle(nullptr), lineEditFormula(nullptr), plainTextEditFormula(nullptr), + listWidget(nullptr), labelResultCalculation(nullptr), labelDescription(nullptr), labelEditNamePoint(nullptr), labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), radioButtonLengthCurve(nullptr), lineStyles(QStringList()), associatedTool(nullptr) @@ -520,6 +520,9 @@ void DialogTool::CheckState() { Q_CHECK_PTR(bOk); bOk->setEnabled(flagFormula && flagName); + Q_CHECK_PTR(bApply); + bApply->setEnabled(flagFormula && flagName); + } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 88ba9f998..8a3c1f23e 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -70,8 +70,14 @@ public: */ DialogTool(const VContainer *data, QWidget *parent = nullptr); virtual ~DialogTool() {} - inline VAbstractTool* GetAssociatedTool() { return this->associatedTool;} - inline void SetAssociatedTool(VAbstractTool* tool) { this->associatedTool=tool;} + inline VAbstractTool* GetAssociatedTool() + { + return this->associatedTool; + } + inline void SetAssociatedTool(VAbstractTool* tool) + { + this->associatedTool=tool; + } signals: /** * @brief DialogClosed signal dialog closed @@ -219,6 +225,10 @@ protected: * @brief bOk button ok */ QPushButton *bOk; + /** + * @brief bApply button apply + */ + QPushButton *bApply; /** * @brief spinBoxAngle spinbox for angle */ @@ -474,10 +484,13 @@ protected: Q_CHECK_PTR(bCancel); connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected); // TODO issue #79 - QPushButton *bApply = ui->buttonBox->button(QDialogButtonBox::Apply); + bApply = ui->buttonBox->button(QDialogButtonBox::Apply); Q_CHECK_PTR(bApply); connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply); } + /** + * @brief associatedTool vdrawtool associated with opened dialog. + */ VAbstractTool* associatedTool; private: /** diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 75fc96107..7f6511ee9 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -264,14 +264,38 @@ void MainWindow::SetToolButton2(bool checked, Valentina::Tools t, const QString //--------------------------------------------------------------------------------------------------------------------- template void MainWindow::ClosedDialog(int result) -{ +{// TODO ISSUE 79 : delete Q_CHECK_PTR(dialogTool); if (result == QDialog::Accepted) { + DrawTool::Create(dialogTool, currentScene, doc, pattern); + } + ArrowTool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void MainWindow::ClosedDialog2(int result) +{ // TODO ISSUE 79 : rename + Q_CHECK_PTR(dialogTool); + if (result == QDialog::Accepted) + { + // Only create tool if not already created with apply if (dialogTool->GetAssociatedTool() == nullptr) { - DrawTool::Create(dialogTool, currentScene, doc, pattern); + dialogTool->SetAssociatedTool( + dynamic_cast (DrawTool::Create(dialogTool, currentScene, doc, pattern))); } + else + { // Or update associated tool with data + VDrawTool * vtool= static_cast(dialogTool->GetAssociatedTool()); + vtool->FullUpdateFromGuiApply(); + } + } + if (dialogTool->GetAssociatedTool() != nullptr) + { + VDrawTool * vtool= static_cast(dialogTool->GetAssociatedTool()); + vtool->DialogLinkDestroy(); } ArrowTool(); } @@ -282,20 +306,22 @@ void MainWindow::ApplyDialog() {// TODO ISSUE 79 : copy Q_CHECK_PTR(dialogTool); - // TODO ISSUE 79 : Only create on first apply for now, - // need function for updating in dialogtools or drawtool - + // Only create tool if not already created with apply if (dialogTool->GetAssociatedTool() == nullptr) { dialogTool->SetAssociatedTool( - dynamic_cast (DrawTool::Create(dialogTool, currentScene, doc, pattern))); + static_cast (DrawTool::Create(dialogTool, currentScene, doc, pattern))); + } + else + { // Or update associated tool with data + VDrawTool * vtool= static_cast(dialogTool->GetAssociatedTool()); + vtool->FullUpdateFromGuiApply(); } - //ArrowTool(); } //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolEndLine(bool checked) -{ +{// TODO ISSUE 79 : copy // SetToolButton(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), // &MainWindow::ClosedDialogEndLine); SetToolButton2(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), @@ -311,7 +337,7 @@ void MainWindow::ApplyDialogEndLine() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ClosedDialogEndLine(int result) { - ClosedDialog(result); + ClosedDialog2(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index c0c70d47a..e31923daf 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -534,11 +534,17 @@ private: */ void MinimumScrollBar(); template - /** + /** // TODO ISSUE 79 : delete * @brief ClosedDialog handle close dialog * @param result result working dialog. */ void ClosedDialog(int result); + template + /** // TODO ISSUE 79 : rename + * @brief ClosedDialog handle close dialog + * @param result result working dialog. + */ + void ClosedDialog2(int result); /** // TODO ISSUE 79 : copy * @brief ApplyDialog handle apply in dialog */ diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 9b654a862..4a331c016 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -107,6 +107,12 @@ void VDrawTool::FullUpdateFromGuiApply() } } +//--------------------------------------------------------------------------------------------------------------------- +void VDrawTool::DialogLinkDestroy() +{ + this->dialog=nullptr; +} + //--------------------------------------------------------------------------------------------------------------------- void VDrawTool::SetFactor(qreal factor) { diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index b00a23c13..e77e6a099 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -55,6 +55,10 @@ public: * @brief setDialog set dialog when user want change tool option. */ virtual void setDialog() {} + /** + * @brief DialogLinkDestroy removes dialog pointer + */ + virtual void DialogLinkDestroy(); /** * @brief ignoreContextMenu set ignore contect menu tool. * @param enable true - ignore. diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index 34bf39956..69e0e636b 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -76,8 +76,14 @@ VToolEndLine* VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene QString formula = dialogTool->getFormula(); qreal angle = dialogTool->getAngle(); quint32 basePointId = dialogTool->getBasePointId(); - return Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, - Valentina::FromGui); + + VToolEndLine *point; + point=Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, + Valentina::FromGui); + if (point != nullptr) { + point->dialog=dialogTool; + } + return point; } //---------------------------------------------------------------------------------------------------------------------