diff --git a/src/dialogs/dialogs.h b/src/dialogs/dialogs.h index e61d49cb5..9cdc7c318 100644 --- a/src/dialogs/dialogs.h +++ b/src/dialogs/dialogs.h @@ -45,8 +45,11 @@ #include "dialogspline.h" #include "dialogsplinepath.h" #include "dialogheight.h" +#include "dialogcutarc.h" #include "dialogcutspline.h" #include "dialogcutsplinepath.h" #include "dialoguniondetails.h" +#include "dialogtriangle.h" +#include "dialogpointofintersection.h" #endif // DIALOGS_H diff --git a/src/dialogs/dialogtool.cpp b/src/dialogs/dialogtool.cpp index fdb056d20..45a6890d6 100644 --- a/src/dialogs/dialogtool.cpp +++ b/src/dialogs/dialogtool.cpp @@ -46,6 +46,8 @@ DialogTool::DialogTool(const VContainer *data, QWidget *parent) //Keep synchronize with VAbstractTool styles list!!! lineStyles<hide(); +// } +// else +// { +// this->show(); +// } +} + template void DialogTool::ShowVariable(const QHash *var) { diff --git a/src/dialogs/dialogtool.h b/src/dialogs/dialogtool.h index ef8346c0d..bd2bf58e4 100644 --- a/src/dialogs/dialogtool.h +++ b/src/dialogs/dialogtool.h @@ -177,6 +177,11 @@ public slots: * @brief UpdateList update lists of variables */ void UpdateList(); + /** + * @brief ApplicationDeactivate hide and show dialog simultaneously with parent window. + * @param type true - hide, false - show window. + */ + void ApplicationDeactivate(bool type); protected: Q_DISABLE_COPY(DialogTool) /** diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2c64bc70d..799fb7b2c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -77,22 +77,11 @@ private: MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainWindow), pattern(0), doc(0), tool(Tool::ArrowTool), currentScene(0), sceneDraw(0), sceneDetails(0), mouseCoordinate(0), helpLabel(0), view(0), isInitialized(false), dialogTable(0), - dialogEndLine(QSharedPointer()), dialogLine(QSharedPointer()), - dialogAlongLine(QSharedPointer()), - dialogShoulderPoint(QSharedPointer()), dialogNormal(QSharedPointer()), - dialogBisector(QSharedPointer()), - dialogLineIntersect(QSharedPointer()), dialogSpline(QSharedPointer()), - dialogArc(QSharedPointer()), dialogSplinePath(QSharedPointer()), - dialogPointOfContact(QSharedPointer()), - dialogDetail(QSharedPointer()), dialogHeight(QSharedPointer()), - dialogTriangle(QSharedPointer()), - dialogPointOfIntersection(QSharedPointer()), - dialogCutSpline(QSharedPointer()), dialogCutSplinePath (QSharedPointer()), - dialogUnionDetails(QSharedPointer()), dialogCutArc(QSharedPointer()), - dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), - mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true) + dialogTool(0), dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), + mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true) { ui->setupUi(this); + qApp->installEventFilter(this); static const char * GENERIC_ICON_TO_CHECK = "document-open"; if (QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK) == false) { @@ -287,7 +276,7 @@ void MainWindow::OptionDraw() template void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &cursor, const QString &toolTip, - QSharedPointer &dialog, Func closeDialogSlot) + Func closeDialogSlot) { if (checked) { @@ -297,11 +286,13 @@ void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &curso QCursor cur(pixmap, 2, 3); view->setCursor(cur); helpLabel->setText(toolTip); - dialog = QSharedPointer(new Dialog(pattern)); - connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialog.data(), &Dialog::ChoosedObject); - connect(dialog.data(), &Dialog::DialogClosed, this, closeDialogSlot); - connect(dialog.data(), &Dialog::ToolTip, this, &MainWindow::ShowToolTip); - connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); + dialogTool = new Dialog(pattern, this); + Q_CHECK_PTR(dialogTool); + connect(this, &MainWindow::ApplicationDeactivate, dialogTool, &DialogTool::ApplicationDeactivate); + connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChoosedObject); + connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot); + connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); + connect(doc, &VDomDocument::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList); } else { @@ -313,192 +304,171 @@ void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &curso } } -template -void MainWindow::ClosedDialog(QSharedPointer &dialog, int result) +template +void MainWindow::ClosedDialog(int result) { + Q_CHECK_PTR(dialogTool); if (result == QDialog::Accepted) { - DrawTool::Create(dialog, currentScene, doc, pattern); + DrawTool::Create(dialogTool, currentScene, doc, pattern); } ArrowTool(); } void MainWindow::ToolEndLine(bool checked) { - SetToolButton(checked, Tool::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), - dialogEndLine, &MainWindow::ClosedDialogEndLine); + SetToolButton(checked, Tool::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), + &MainWindow::ClosedDialogEndLine); } void MainWindow::ClosedDialogEndLine(int result) { - ClosedDialog(dialogEndLine, result); + ClosedDialog(result); } void MainWindow::ToolLine(bool checked) { - SetToolButton(checked, Tool::LineTool, ":/cursor/line_cursor.png", tr("Select first point"), - dialogLine, &MainWindow::ClosedDialogLine); + SetToolButton(checked, Tool::LineTool, ":/cursor/line_cursor.png", tr("Select first point"), + &MainWindow::ClosedDialogLine); } void MainWindow::ClosedDialogLine(int result) { - ClosedDialog(dialogLine, result); + ClosedDialog(result); } void MainWindow::ToolAlongLine(bool checked) { - SetToolButton(checked, Tool::AlongLineTool, ":/cursor/alongline_cursor.png", tr("Select point"), - dialogAlongLine, &MainWindow::ClosedDialogAlongLine); + SetToolButton(checked, Tool::AlongLineTool, ":/cursor/alongline_cursor.png", tr("Select point"), + &MainWindow::ClosedDialogAlongLine); } void MainWindow::ClosedDialogAlongLine(int result) { - ClosedDialog(dialogAlongLine, result); + ClosedDialog(result); } void MainWindow::ToolShoulderPoint(bool checked) { - SetToolButton(checked, Tool::ShoulderPointTool, ":/cursor/shoulder_cursor.png", - tr("Select first point of line"), dialogShoulderPoint, - &MainWindow::ClosedDialogShoulderPoint); + SetToolButton(checked, Tool::ShoulderPointTool, ":/cursor/shoulder_cursor.png", + tr("Select first point of line"), &MainWindow::ClosedDialogShoulderPoint); } void MainWindow::ClosedDialogShoulderPoint(int result) { - ClosedDialog(dialogShoulderPoint, result); + ClosedDialog(result); } void MainWindow::ToolNormal(bool checked) { - SetToolButton(checked, Tool::NormalTool, ":/cursor/normal_cursor.png", - tr("Select first point of line"), dialogNormal, &MainWindow::ClosedDialogNormal); + SetToolButton(checked, Tool::NormalTool, ":/cursor/normal_cursor.png", + tr("Select first point of line"), &MainWindow::ClosedDialogNormal); } void MainWindow::ClosedDialogNormal(int result) { - ClosedDialog(dialogNormal, result); + ClosedDialog(result); } void MainWindow::ToolBisector(bool checked) { - SetToolButton(checked, Tool::BisectorTool, ":/cursor/bisector_cursor.png", - tr("Select first point of angle"), dialogBisector, &MainWindow::ClosedDialogBisector); + SetToolButton(checked, Tool::BisectorTool, ":/cursor/bisector_cursor.png", + tr("Select first point of angle"), &MainWindow::ClosedDialogBisector); } void MainWindow::ClosedDialogBisector(int result) { - ClosedDialog(dialogBisector, result); + ClosedDialog(result); } void MainWindow::ToolLineIntersect(bool checked) { - SetToolButton(checked, Tool::LineIntersectTool, ":/cursor/intersect_cursor.png", - tr("Select first point of first line"), dialogLineIntersect, - &MainWindow::ClosedDialogLineIntersect); + SetToolButton(checked, Tool::LineIntersectTool, ":/cursor/intersect_cursor.png", + tr("Select first point of first line"), &MainWindow::ClosedDialogLineIntersect); } void MainWindow::ClosedDialogLineIntersect(int result) { - ClosedDialog(dialogLineIntersect, result); + ClosedDialog(result); } void MainWindow::ToolSpline(bool checked) { - SetToolButton(checked, Tool::SplineTool, ":/cursor/spline_cursor.png", - tr("Select first point curve"), dialogSpline, &MainWindow::ClosedDialogSpline); + SetToolButton(checked, Tool::SplineTool, ":/cursor/spline_cursor.png", + tr("Select first point curve"), &MainWindow::ClosedDialogSpline); } void MainWindow::ClosedDialogSpline(int result) { - ClosedDialog(dialogSpline, result); + ClosedDialog(result); } void MainWindow::ToolCutSpline(bool checked) { - SetToolButton(checked, Tool::CutSplineTool, ":/cursor/spline_cut_point_cursor.png", - tr("Select simple curve"), dialogCutSpline, &MainWindow::ClosedDialogCutSpline); + SetToolButton(checked, Tool::CutSplineTool, ":/cursor/spline_cut_point_cursor.png", + tr("Select simple curve"), &MainWindow::ClosedDialogCutSpline); } void MainWindow::ClosedDialogCutSpline(int result) { - ClosedDialog(dialogCutSpline, result); + ClosedDialog(result); } void MainWindow::ToolArc(bool checked) { - SetToolButton(checked, Tool::ArcTool, ":/cursor/arc_cursor.png", - tr("Select point of center of arc"), dialogArc, &MainWindow::ClosedDialogArc); + SetToolButton(checked, Tool::ArcTool, ":/cursor/arc_cursor.png", + tr("Select point of center of arc"), &MainWindow::ClosedDialogArc); } void MainWindow::ClosedDialogArc(int result) { - ClosedDialog(dialogArc, result); + ClosedDialog(result); } void MainWindow::ToolSplinePath(bool checked) { - SetToolButton(checked, Tool::SplinePathTool, ":/cursor/splinepath_cursor.png", - tr("Select point of curve path"), dialogSplinePath, &MainWindow::ClosedDialogSplinePath); + SetToolButton(checked, Tool::SplinePathTool, ":/cursor/splinepath_cursor.png", + tr("Select point of curve path"), &MainWindow::ClosedDialogSplinePath); } void MainWindow::ClosedDialogSplinePath(int result) { - ClosedDialog(dialogSplinePath, result); + ClosedDialog(result); } void MainWindow::ToolCutSplinePath(bool checked) { - SetToolButton(checked, Tool::CutSplinePathTool, ":/cursor/splinepath_cut_point_cursor.png", - tr("Select curve path"), dialogCutSplinePath, &MainWindow::ClosedDialogCutSplinePath); + SetToolButton(checked, Tool::CutSplinePathTool, ":/cursor/splinepath_cut_point_cursor.png", + tr("Select curve path"), &MainWindow::ClosedDialogCutSplinePath); } void MainWindow::ClosedDialogCutSplinePath(int result) { - ClosedDialog(dialogCutSplinePath, result); + ClosedDialog(result); } void MainWindow::ToolPointOfContact(bool checked) { - SetToolButton(checked, Tool::PointOfContact, ":/cursor/pointcontact_cursor.png", - tr("Select first point of line"), dialogPointOfContact, - &MainWindow::ClosedDialogPointOfContact); + SetToolButton(checked, Tool::PointOfContact, ":/cursor/pointcontact_cursor.png", + tr("Select first point of line"), &MainWindow::ClosedDialogPointOfContact); } void MainWindow::ClosedDialogPointOfContact(int result) { - ClosedDialog(dialogPointOfContact, result); + ClosedDialog(result); } void MainWindow::ToolDetail(bool checked) { - if (checked) - { - CancelTool(); - tool = Tool::Detail; - QPixmap pixmap("://cursor/new_detail_cursor.png"); - QCursor cur(pixmap, 2, 3); - view->setCursor(cur); - helpLabel->setText(tr("Select points, arcs, curves clockwise.")); - dialogDetail = QSharedPointer(new DialogDetail(pattern)); - connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogDetail.data(), - &DialogDetail::ChoosedObject); - connect(dialogDetail.data(), &DialogDetail::DialogClosed, this, &MainWindow::ClosedDialogDetail); - connect(doc, &VDomDocument::FullUpdateFromFile, dialogDetail.data(), &DialogDetail::UpdateList); - } - else - { - if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())) - { - tButton->setChecked(true); - } - } + SetToolButton(checked, Tool::Detail, "://cursor/new_detail_cursor.png", + tr("Select points, arcs, curves clockwise."), &MainWindow::ClosedDialogDetail); } void MainWindow::ClosedDialogDetail(int result) { if (result == QDialog::Accepted) { - VToolDetail::Create(dialogDetail, sceneDetails, doc, pattern); + VToolDetail::Create(dialogTool, sceneDetails, doc, pattern); } ArrowTool(); doc->FullUpdateTree(); @@ -506,63 +476,62 @@ void MainWindow::ClosedDialogDetail(int result) void MainWindow::ToolHeight(bool checked) { - SetToolButton(checked, Tool::Height, ":/cursor/height_cursor.png", tr("Select base point"), - dialogHeight, &MainWindow::ClosedDialogHeight); + SetToolButton(checked, Tool::Height, ":/cursor/height_cursor.png", tr("Select base point"), + &MainWindow::ClosedDialogHeight); } void MainWindow::ClosedDialogHeight(int result) { - ClosedDialog(dialogHeight, result); + ClosedDialog(result); } void MainWindow::ToolTriangle(bool checked) { - SetToolButton(checked, Tool::Triangle, ":/cursor/triangle_cursor.png", tr("Select first point of axis"), - dialogTriangle, &MainWindow::ClosedDialogTriangle); + SetToolButton(checked, Tool::Triangle, ":/cursor/triangle_cursor.png", + tr("Select first point of axis"), &MainWindow::ClosedDialogTriangle); } void MainWindow::ClosedDialogTriangle(int result) { - ClosedDialog(dialogTriangle, result); + ClosedDialog(result); } void MainWindow::ToolPointOfIntersection(bool checked) { - SetToolButton(checked, Tool::PointOfIntersection, ":/cursor/pointofintersect_cursor.png", - tr("Select point vertically"), - dialogPointOfIntersection, &MainWindow::ClosedDialogPointOfIntersection); + SetToolButton(checked, Tool::PointOfIntersection, ":/cursor/pointofintersect_cursor.png", + tr("Select point vertically"), &MainWindow::ClosedDialogPointOfIntersection); } void MainWindow::ClosedDialogPointOfIntersection(int result) { - ClosedDialog(dialogPointOfIntersection, result); + ClosedDialog(result); } void MainWindow::ToolUnionDetails(bool checked) { - SetToolButton(checked, Tool::UnionDetails, ":/cursor/union_cursor.png", - tr("Select detail"), dialogUnionDetails, &MainWindow::ClosedDialogUnionDetails); + SetToolButton(checked, Tool::UnionDetails, ":/cursor/union_cursor.png", tr("Select detail"), + &MainWindow::ClosedDialogUnionDetails); //Must disconnect this signal here. - disconnect(doc, &VDomDocument::FullUpdateFromFile, dialogUnionDetails.data(), &DialogUnionDetails::UpdateList); -} - -void MainWindow::ToolCutArc(bool checked) -{ - SetToolButton(checked, Tool::CutArcTool, ":/cursor/arc_cut_cursor.png", - tr("Select arc"), dialogCutArc, &MainWindow::ClosedDialogCutArc); -} - -void MainWindow::ClosedDialogCutArc(int result) -{ - ClosedDialog(dialogCutArc, result); + disconnect(doc, &VDomDocument::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList); } void MainWindow::ClosedDialogUnionDetails(int result) { - ClosedDialog(dialogUnionDetails, result); + ClosedDialog(result); doc->FullUpdateTree(); } +void MainWindow::ToolCutArc(bool checked) +{ + SetToolButton(checked, Tool::CutArcTool, ":/cursor/arc_cut_cursor.png", tr("Select arc"), + &MainWindow::ClosedDialogCutArc); +} + +void MainWindow::ClosedDialogCutArc(int result) +{ + ClosedDialog(result); +} + void MainWindow::About() { QString fullName = QString("Valentina %1").arg(APP_VERSION); @@ -753,6 +722,8 @@ void MainWindow::mouseMove(const QPointF &scenePos) void MainWindow::CancelTool() { + delete dialogTool; + dialogTool = 0; switch ( tool ) { case Tool::ArrowTool: @@ -764,113 +735,94 @@ void MainWindow::CancelTool() //Nothing to do here because we can't create this tool from main window. break; case Tool::EndLineTool: - dialogEndLine.clear(); ui->toolButtonEndLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::LineTool: - dialogLine.clear(); ui->toolButtonLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearFocus(); break; case Tool::AlongLineTool: - dialogAlongLine.clear(); ui->toolButtonAlongLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::ShoulderPointTool: - dialogShoulderPoint.clear(); ui->toolButtonShoulderPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::NormalTool: - dialogNormal.clear(); ui->toolButtonNormal->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::BisectorTool: - dialogBisector.clear(); ui->toolButtonBisector->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::LineIntersectTool: - dialogLineIntersect.clear(); ui->toolButtonLineIntersect->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::SplineTool: - dialogSpline.clear(); ui->toolButtonSpline->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::ArcTool: - dialogArc.clear(); ui->toolButtonArc->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::SplinePathTool: - dialogSplinePath.clear(); ui->toolButtonSplinePath->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::PointOfContact: - dialogPointOfContact.clear(); ui->toolButtonPointOfContact->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::Detail: - dialogDetail.clear(); ui->toolButtonNewDetail->setChecked(false); break; case Tool::Height: - dialogHeight.clear(); ui->toolButtonHeight->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::Triangle: - dialogTriangle.clear(); ui->toolButtonTriangle->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::PointOfIntersection: - dialogPointOfIntersection.clear(); ui->toolButtonPointOfIntersection->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::CutSplineTool: - dialogCutSpline.clear(); ui->toolButtonSplineCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::CutSplinePathTool: - dialogCutSplinePath.clear(); ui->toolButtonSplinePathCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::UnionDetails: - dialogUnionDetails.clear(); ui->toolButtonUnionDetails->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; case Tool::CutArcTool: - dialogCutArc.clear(); ui->toolButtonArcCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); @@ -1086,6 +1038,29 @@ void MainWindow::Clear() SetEnableTool(false); } +bool MainWindow::eventFilter(QObject *object, QEvent *event) +{ +#ifdef Q_CC_GNU + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wswitch-enum" +#endif + switch(event->type()) + { + case(QEvent::ApplicationDeactivate): + emit ApplicationDeactivate(true); + break; + case(QEvent::ApplicationActivate): + emit ApplicationDeactivate(false); + break; + default: + break; + } +#ifdef Q_CC_GNU + #pragma GCC diagnostic pop +#endif + return QWidget::eventFilter(object, event); +} + void MainWindow::ActionNew() { QProcess *v = new QProcess(this); diff --git a/src/mainwindow.h b/src/mainwindow.h index cc5da1990..89f3f7a91 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -361,6 +361,11 @@ signals: * @param listDetails list of details. */ void ModelChosen(QVector listDetails, const QString &fileName); + /** + * @brief ApplicationDeactivate hide and show dialog simultaneously with parent window. + * @param type true - hide, false - show window. + */ + void ApplicationDeactivate(bool type); protected: /** * @brief keyPressEvent handle key press events. @@ -381,6 +386,13 @@ protected: * @brief Clear reset to default window. */ void Clear(); + /** + * @brief eventFilter event filter main window. + * @param object object. + * @param event event + * @return true if accept. + */ + bool eventFilter(QObject* object, QEvent* event); private: Q_DISABLE_COPY(MainWindow) /** @@ -428,25 +440,7 @@ private: */ bool isInitialized; DialogIncrements *dialogTable; - QSharedPointer dialogEndLine; - QSharedPointer dialogLine; - QSharedPointer dialogAlongLine; - QSharedPointer dialogShoulderPoint; - QSharedPointer dialogNormal; - QSharedPointer dialogBisector; - QSharedPointer dialogLineIntersect; - QSharedPointer dialogSpline; - QSharedPointer dialogArc; - QSharedPointer dialogSplinePath; - QSharedPointer dialogPointOfContact; - QSharedPointer dialogDetail; - QSharedPointer dialogHeight; - QSharedPointer dialogTriangle; - QSharedPointer dialogPointOfIntersection; - QSharedPointer dialogCutSpline; - QSharedPointer dialogCutSplinePath; - QSharedPointer dialogUnionDetails; - QSharedPointer dialogCutArc; + DialogTool *dialogTool; DialogHistory *dialogHistory; /** * @brief comboBoxDraws comboc who show name of pattern peaces. @@ -517,11 +511,10 @@ private: * @param t tool type. * @param cursor path tool cursor icon. * @param toolTip first tooltipe. - * @param dialog pointer to dialog. * @param closeDialogSlot function what handle after close dialog. */ void SetToolButton(bool checked, Tool::Tools t, const QString &cursor, const QString &toolTip, - QSharedPointer &dialog, Func closeDialogSlot); + Func closeDialogSlot); /** * @brief MinimumScrollBar set scroll bar to minimum. */ @@ -537,13 +530,12 @@ private: */ bool ValidatePattern(const QString &schema, const QString &fileName, QString &errorMsg, qint64 &errorLine, qint64 &errorColumn) const; - template + template /** - * @brief ClosedDialog - * @param dialog - * @param result + * @brief ClosedDialog handle close dialog + * @param result result working dialog. */ - void ClosedDialog(QSharedPointer &dialog, int result); + void ClosedDialog(int result); /** * @brief SafeSaveing safe saving pattern file. * @param fileName pattern file name. diff --git a/src/tools/drawTools/vdrawtool.cpp b/src/tools/drawTools/vdrawtool.cpp index e34a8fdca..e4ad8d170 100644 --- a/src/tools/drawTools/vdrawtool.cpp +++ b/src/tools/drawTools/vdrawtool.cpp @@ -32,13 +32,18 @@ qreal VDrawTool::factor = 1; VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id) :VAbstractTool(doc, data, id), ignoreContextMenuEvent(false), ignoreFullUpdate(false), - nameActivDraw(doc->GetNameActivDraw()) + nameActivDraw(doc->GetNameActivDraw()), dialog(0) { connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VDrawTool::ChangedActivDraw); connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VDrawTool::ChangedNameDraw); connect(this->doc, &VDomDocument::ShowTool, this, &VDrawTool::ShowTool); } +VDrawTool::~VDrawTool() +{ + delete dialog; +} + void VDrawTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) { Q_UNUSED(id); @@ -66,6 +71,23 @@ void VDrawTool::ChangedNameDraw(const QString &oldName, const QString &newName) } } +void VDrawTool::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + SaveDialog(domElement); + + emit FullUpdateTree(); + emit toolhaveChange(); + } + } + delete dialog; + dialog = 0; +} + void VDrawTool::SetFactor(qreal factor) { if (factor <= 2 && factor >= 0.5) diff --git a/src/tools/drawTools/vdrawtool.h b/src/tools/drawTools/vdrawtool.h index e17a1ebd3..3e24c9b59 100644 --- a/src/tools/drawTools/vdrawtool.h +++ b/src/tools/drawTools/vdrawtool.h @@ -33,6 +33,7 @@ #include #include +#include "../../dialogs/dialogtool.h" /** * @brief The VDrawTool abstract class for all draw tool. @@ -49,7 +50,7 @@ public: * @param parent parent object. */ VDrawTool(VDomDocument *doc, VContainer *data, qint64 id); - virtual ~VDrawTool() {} + virtual ~VDrawTool(); /** * @brief setDialog set dialog when user want change tool option. */ @@ -82,7 +83,7 @@ public slots: * @brief FullUpdateFromGui refresh tool data after change in options. * @param result keep result working dialog. */ - virtual void FullUpdateFromGui(int result)=0; + virtual void FullUpdateFromGui(int result); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. @@ -105,21 +106,27 @@ protected: * @brief factor scene scale factor. */ static qreal factor; + /** + * @brief dialog dialog options. + */ + DialogTool *dialog; /** * @brief AddToCalculation add tool to calculation tag in pattern file. * @param domElement tag in xml tree. */ void AddToCalculation(const QDomElement &domElement); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement)=0; template /** * @brief ContextMenu show context menu for tool. - * @param dialog dialog option. * @param tool tool. * @param event context menu event. * @param showRemove true - tool have option delete. */ - void ContextMenu(QSharedPointer &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event, - bool showRemove = true) + void ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, bool showRemove = true) { Q_CHECK_PTR(tool); Q_CHECK_PTR(event); @@ -143,14 +150,16 @@ protected: QAction *selectedAction = menu.exec(event->screenPos()); if (selectedAction == actionOption) { - dialog = QSharedPointer(new Dialog(getData())); + QGraphicsScene *scene = tool->scene(); + QList list = scene->views(); + dialog = new Dialog(getData(), list.first()); connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), - &VMainGraphicsScene::ChoosedObject, dialog.data(), &Dialog::ChoosedObject); - connect(dialog.data(), &Dialog::DialogClosed, tool, &Tool::FullUpdateFromGui); + &VMainGraphicsScene::ChoosedObject, dialog, &DialogTool::ChoosedObject); + connect(dialog, &DialogTool::DialogClosed, tool, &Tool::FullUpdateFromGui); if (ignoreFullUpdate == false) { - connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); + connect(doc, &VDomDocument::FullUpdateFromFile, dialog, &DialogTool::UpdateList); } tool->setDialog(); @@ -190,6 +199,8 @@ protected: item->setPen(QPen(currentColor, widthHairLine/factor)); } } +private: + Q_DISABLE_COPY(VDrawTool) }; #endif // VDRAWTOOL_H diff --git a/src/tools/drawTools/vtoolalongline.cpp b/src/tools/drawTools/vtoolalongline.cpp index 9ad9181c8..1b75c1ed7 100644 --- a/src/tools/drawTools/vtoolalongline.cpp +++ b/src/tools/drawTools/vtoolalongline.cpp @@ -28,6 +28,7 @@ #include "vtoolalongline.h" #include "../../container/calculator.h" +#include "../../dialogs/dialogalongline.h" const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); @@ -35,8 +36,7 @@ VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, c const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine, const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent), secondPointId(secondPointId), - dialogAlongLine(QSharedPointer()) + :VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent), secondPointId(secondPointId) { if (typeCreation == Tool::FromGui) @@ -62,25 +62,6 @@ void VToolAlongLine::FullUpdateFromFile() RefreshGeometry(); } -void VToolAlongLine::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogAlongLine->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogAlongLine->getTypeLine()); - SetAttribute(domElement, AttrLength, dialogAlongLine->getFormula()); - SetAttribute(domElement, AttrFirstPoint, dialogAlongLine->getFirstPointId()); - SetAttribute(domElement, AttrSecondPoint, dialogAlongLine->getSecondPointId()); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogAlongLine.clear(); -} - void VToolAlongLine::SetFactor(qreal factor) { VDrawTool::SetFactor(factor); @@ -90,12 +71,12 @@ void VToolAlongLine::SetFactor(qreal factor) //cppcheck-suppress unusedFunction void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogAlongLine, this, event); + ContextMenu(this, event); } void VToolAlongLine::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogAlongLine, this, event); + ContextMenu(this, event); } void VToolAlongLine::AddToFile() @@ -139,25 +120,41 @@ void VToolAlongLine::RemoveReferens() VToolLinePoint::RemoveReferens(); } -void VToolAlongLine::setDialog() +void VToolAlongLine::SaveDialog(QDomElement &domElement) { - Q_ASSERT(dialogAlongLine.isNull() == false); - const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogAlongLine->setTypeLine(typeLine); - dialogAlongLine->setFormula(formula); - dialogAlongLine->setFirstPointId(basePointId, id); - dialogAlongLine->setSecondPointId(secondPointId, id); - dialogAlongLine->setPointName(p->name()); + Q_CHECK_PTR(dialog); + DialogAlongLine *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + SetAttribute(domElement, AttrFirstPoint, dialogTool->getFirstPointId()); + SetAttribute(domElement, AttrSecondPoint, dialogTool->getSecondPointId()); } -void VToolAlongLine::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data) +void VToolAlongLine::setDialog() { - QString formula = dialog->getFormula(); - qint64 firstPointId = dialog->getFirstPointId(); - qint64 secondPointId = dialog->getSecondPointId(); - QString typeLine = dialog->getTypeLine(); - QString pointName = dialog->getPointName(); + Q_CHECK_PTR(dialog); + DialogAlongLine *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + const VPointF *p = VAbstractTool::data.GeometricObject(id); + dialogTool->setTypeLine(typeLine); + dialogTool->setFormula(formula); + dialogTool->setFirstPointId(basePointId, id); + dialogTool->setSecondPointId(secondPointId, id); + dialogTool->setPointName(p->name()); +} + +void VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +{ + Q_CHECK_PTR(dialog); + DialogAlongLine *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + QString formula = dialogTool->getFormula(); + qint64 firstPointId = dialogTool->getFirstPointId(); + qint64 secondPointId = dialogTool->getSecondPointId(); + QString typeLine = dialogTool->getTypeLine(); + QString pointName = dialogTool->getPointName(); Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } diff --git a/src/tools/drawTools/vtoolalongline.h b/src/tools/drawTools/vtoolalongline.h index 4c62d27bb..21c9f7bbd 100644 --- a/src/tools/drawTools/vtoolalongline.h +++ b/src/tools/drawTools/vtoolalongline.h @@ -30,7 +30,6 @@ #define VTOOLALONGLINE_H #include "vtoollinepoint.h" -#include "../../dialogs/dialogalongline.h" /** * @brief The VToolAlongLine class tool for creation point along line. @@ -65,8 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -93,11 +91,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. @@ -126,15 +119,15 @@ protected: * @brief RemoveReferens decrement value of reference. */ virtual void RemoveReferens(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: /** * @brief secondPointId id second point of line. */ qint64 secondPointId; - /** - * @brief dialogAlongLine dialog. - */ - QSharedPointer dialogAlongLine; }; #endif // VTOOLALONGLINE_H diff --git a/src/tools/drawTools/vtoolarc.cpp b/src/tools/drawTools/vtoolarc.cpp index 681a389ba..1bfdc066b 100644 --- a/src/tools/drawTools/vtoolarc.cpp +++ b/src/tools/drawTools/vtoolarc.cpp @@ -28,13 +28,14 @@ #include "vtoolarc.h" #include "../../container/calculator.h" +#include "../../dialogs/dialogarc.h" const QString VToolArc::TagName = QStringLiteral("arc"); const QString VToolArc::ToolType = QStringLiteral("simple"); VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogArc(QSharedPointer()) + :VDrawTool(doc, data, id), QGraphicsPathItem(parent) { const VArc *arc = data->GeometricObject(id); QPainterPath path; @@ -58,21 +59,26 @@ VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::S void VToolArc::setDialog() { - Q_ASSERT(dialogArc.isNull() == false); + Q_CHECK_PTR(dialog); + DialogArc *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VArc *arc = VAbstractTool::data.GeometricObject(id); - dialogArc->SetCenter(arc->GetCenter().id()); - dialogArc->SetF1(arc->GetFormulaF1()); - dialogArc->SetF2(arc->GetFormulaF2()); - dialogArc->SetRadius(arc->GetFormulaRadius()); + dialogTool->SetCenter(arc->GetCenter().id()); + dialogTool->SetF1(arc->GetFormulaF1()); + dialogTool->SetF2(arc->GetFormulaF2()); + dialogTool->SetRadius(arc->GetFormulaRadius()); } -void VToolArc::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - qint64 center = dialog->GetCenter(); - QString radius = dialog->GetRadius(); - QString f1 = dialog->GetF1(); - QString f2 = dialog->GetF2(); + Q_CHECK_PTR(dialog); + DialogArc *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + qint64 center = dialogTool->GetCenter(); + QString radius = dialogTool->GetRadius(); + QString f1 = dialogTool->GetF1(); + QString f2 = dialogTool->GetF2(); Create(0, center, radius, f1, f2, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -137,24 +143,6 @@ void VToolArc::FullUpdateFromFile() RefreshGeometry(); } -void VToolArc::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrCenter, QString().setNum(dialogArc->GetCenter())); - SetAttribute(domElement, AttrRadius, dialogArc->GetRadius()); - SetAttribute(domElement, AttrAngle1, dialogArc->GetF1()); - SetAttribute(domElement, AttrAngle2, dialogArc->GetF2()); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogArc.clear(); -} - void VToolArc::ChangedActivDraw(const QString &newName) { bool selectable = false; @@ -187,7 +175,7 @@ void VToolArc::SetFactor(qreal factor) void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogArc, this, event); + ContextMenu(this, event); } void VToolArc::AddToFile() @@ -278,6 +266,17 @@ void VToolArc::keyReleaseEvent(QKeyEvent *event) QGraphicsItem::keyReleaseEvent ( event ); } +void VToolArc::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogArc *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetCenter())); + SetAttribute(domElement, AttrRadius, dialogTool->GetRadius()); + SetAttribute(domElement, AttrAngle1, dialogTool->GetF1()); + SetAttribute(domElement, AttrAngle2, dialogTool->GetF2()); +} + void VToolArc::RefreshGeometry() { this->setPen(QPen(currentColor, widthHairLine/factor)); diff --git a/src/tools/drawTools/vtoolarc.h b/src/tools/drawTools/vtoolarc.h index fcb203056..1455db910 100644 --- a/src/tools/drawTools/vtoolarc.h +++ b/src/tools/drawTools/vtoolarc.h @@ -31,7 +31,6 @@ #include "vdrawtool.h" #include -#include "../../dialogs/dialogarc.h" #include "../../widgets/vcontrolpointspline.h" /** @@ -62,8 +61,7 @@ public: * @param doc dom document container * @param data container with variables */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool form GUI. * @param _id tool id, 0 if tool doesn't exist yet. @@ -87,11 +85,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data after change in options. - * @param result result working options window. - */ - virtual void FullUpdateFromGui(int result); /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. * @param newName new name active pattern peace. @@ -154,11 +147,11 @@ protected: * @param event key release event. */ virtual void keyReleaseEvent(QKeyEvent * event); -private: /** - * @brief dialogArc dialog. + * @brief SaveDialog save options into file after change in dialog. */ - QSharedPointer dialogArc; + virtual void SaveDialog(QDomElement &domElement); +private: /** * @brief RefreshGeometry refresh item on scene. */ diff --git a/src/tools/drawTools/vtoolbisector.cpp b/src/tools/drawTools/vtoolbisector.cpp index 80defed64..44b28bac6 100644 --- a/src/tools/drawTools/vtoolbisector.cpp +++ b/src/tools/drawTools/vtoolbisector.cpp @@ -28,6 +28,7 @@ #include "vtoolbisector.h" #include "../../container/calculator.h" +#include "../../dialogs/dialogbisector.h" const QString VToolBisector::ToolType = QStringLiteral("bisector"); @@ -35,8 +36,7 @@ VToolBisector::VToolBisector(VDomDocument *doc, VContainer *data, const qint64 & const QString &typeLine, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const qint64 &thirdPointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VToolLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent), firstPointId(0), - thirdPointId(0), dialogBisector(QSharedPointer()) + :VToolLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent), firstPointId(0), thirdPointId(0) { this->firstPointId = firstPointId; this->thirdPointId = thirdPointId; @@ -72,25 +72,30 @@ QPointF VToolBisector::FindPoint(const QPointF &firstPoint, const QPointF &secon void VToolBisector::setDialog() { - Q_ASSERT(dialogBisector.isNull() == false); + Q_CHECK_PTR(dialog); + DialogBisector *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogBisector->setTypeLine(typeLine); - dialogBisector->setFormula(formula); - dialogBisector->setFirstPointId(firstPointId, id); - dialogBisector->setSecondPointId(basePointId, id); - dialogBisector->setThirdPointId(thirdPointId, id); - dialogBisector->setPointName(p->name()); + dialogTool->setTypeLine(typeLine); + dialogTool->setFormula(formula); + dialogTool->setFirstPointId(firstPointId, id); + dialogTool->setSecondPointId(basePointId, id); + dialogTool->setThirdPointId(thirdPointId, id); + dialogTool->setPointName(p->name()); } -void VToolBisector::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolBisector::Create(DialogTool *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(); + Q_CHECK_PTR(dialog); + DialogBisector *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + QString formula = dialogTool->getFormula(); + qint64 firstPointId = dialogTool->getFirstPointId(); + qint64 secondPointId = dialogTool->getSecondPointId(); + qint64 thirdPointId = dialogTool->getThirdPointId(); + QString typeLine = dialogTool->getTypeLine(); + QString pointName = dialogTool->getPointName(); Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, pointName, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -157,26 +162,6 @@ void VToolBisector::FullUpdateFromFile() RefreshGeometry(); } -void VToolBisector::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogBisector->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogBisector->getTypeLine()); - SetAttribute(domElement, AttrLength, dialogBisector->getFormula()); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogBisector->getFirstPointId())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogBisector->getSecondPointId())); - SetAttribute(domElement, AttrThirdPoint, QString().setNum(dialogBisector->getThirdPointId())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogBisector.clear(); -} - void VToolBisector::SetFactor(qreal factor) { VDrawTool::SetFactor(factor); @@ -185,12 +170,12 @@ void VToolBisector::SetFactor(qreal factor) void VToolBisector::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogBisector, this, event); + ContextMenu(this, event); } void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogBisector, this, event); + ContextMenu(this, event); } void VToolBisector::AddToFile() @@ -236,3 +221,16 @@ void VToolBisector::RemoveReferens() doc->DecrementReferens(thirdPointId); VToolLinePoint::RemoveReferens(); } + +void VToolBisector::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogBisector *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); + SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); + SetAttribute(domElement, AttrThirdPoint, QString().setNum(dialogTool->getThirdPointId())); +} diff --git a/src/tools/drawTools/vtoolbisector.h b/src/tools/drawTools/vtoolbisector.h index 4fa17d46f..f019bd35e 100644 --- a/src/tools/drawTools/vtoolbisector.h +++ b/src/tools/drawTools/vtoolbisector.h @@ -30,7 +30,6 @@ #define VTOOLBISECTOR_H #include "vtoollinepoint.h" -#include "../../dialogs/dialogbisector.h" /** * @brief The VToolBisector class tool for creation bisector point. @@ -76,8 +75,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -106,11 +104,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. @@ -139,6 +132,10 @@ protected: * @brief RemoveReferens decrement value of reference. */ virtual void RemoveReferens(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: /** * @brief firstPointId id first point of angle. @@ -148,10 +145,6 @@ private: * @brief thirdPointId id third point of angle. */ qint64 thirdPointId; - /** - * @brief dialogBisector dialog. - */ - QSharedPointer dialogBisector; }; #endif // VTOOLBISECTOR_H diff --git a/src/tools/drawTools/vtoolcutarc.cpp b/src/tools/drawTools/vtoolcutarc.cpp index 4d4ea866b..bd75d9152 100644 --- a/src/tools/drawTools/vtoolcutarc.cpp +++ b/src/tools/drawTools/vtoolcutarc.cpp @@ -28,6 +28,7 @@ #include "vtoolcutarc.h" #include "../../container/calculator.h" +#include "../../dialogs/dialogcutarc.h" const QString VToolCutArc::ToolType = QStringLiteral("cutArc"); const QString VToolCutArc::AttrArc = QStringLiteral("arc"); @@ -35,8 +36,8 @@ const QString VToolCutArc::AttrArc = QStringLiteral("arc"); VToolCutArc::VToolCutArc(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, const qint64 &arcId, const qint64 &arc1id, const qint64 &arc2id, const Tool::Sources &typeCreation, QGraphicsItem * parent) - :VToolPoint(doc, data, id, parent), formula(formula), arcId(arcId), - dialogCutArc(QSharedPointer()), firstArc(), secondArc(), arc1id(arc1id), arc2id(arc2id) + :VToolPoint(doc, data, id, parent), formula(formula), arcId(arcId), firstArc(), secondArc(), arc1id(arc1id), + arc2id(arc2id) { Q_ASSERT_X(arcId > 0, Q_FUNC_INFO, "arcId <= 0"); Q_ASSERT_X(arc1id > 0, Q_FUNC_INFO, "arc1id <= 0"); @@ -66,19 +67,24 @@ VToolCutArc::VToolCutArc(VDomDocument *doc, VContainer *data, const qint64 &id, void VToolCutArc::setDialog() { - Q_ASSERT(dialogCutArc.isNull() == false); + Q_CHECK_PTR(dialog); + DialogCutArc *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *point = VAbstractTool::data.GeometricObject(id); - dialogCutArc->setFormula(formula); - dialogCutArc->setArcId(arcId, id); - dialogCutArc->setPointName(point->name()); + dialogTool->setFormula(formula); + dialogTool->setArcId(arcId, id); + dialogTool->setPointName(point->name()); } -void VToolCutArc::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - QString pointName = dialog->getPointName(); - QString formula = dialog->getFormula(); - qint64 arcId = dialog->getArcId(); + Q_CHECK_PTR(dialog); + DialogCutArc *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + QString pointName = dialogTool->getPointName(); + QString formula = dialogTool->getFormula(); + qint64 arcId = dialogTool->getArcId(); Create(0, pointName, formula, arcId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -164,23 +170,6 @@ void VToolCutArc::FullUpdateFromFile() RefreshGeometry(); } -void VToolCutArc::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogCutArc->getPointName()); - SetAttribute(domElement, AttrLength, dialogCutArc->getFormula()); - SetAttribute(domElement, AttrArc, QString().setNum(dialogCutArc->getArcId())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogCutArc.clear(); -} - void VToolCutArc::ArcChoosed(qint64 id) { emit ChoosedTool(id, Scene::Arc); @@ -211,12 +200,12 @@ void VToolCutArc::ChangedActivDraw(const QString &newName) void VToolCutArc::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogCutArc, this, event); + ContextMenu(this, event); } void VToolCutArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogCutArc, this, event); + ContextMenu(this, event); } void VToolCutArc::AddToFile() @@ -257,6 +246,16 @@ void VToolCutArc::RefreshGeometry() VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); } +void VToolCutArc::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogCutArc *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + SetAttribute(domElement, AttrArc, QString().setNum(dialogTool->getArcId())); +} + void VToolCutArc::RefreshArc(VSimpleArc *sArc, qint64 arcid, SimpleArc::Translation tr) { const VArc *arc = VAbstractTool::data.GeometricObject(arcid); diff --git a/src/tools/drawTools/vtoolcutarc.h b/src/tools/drawTools/vtoolcutarc.h index 0fe9a9440..9d10bcf0a 100644 --- a/src/tools/drawTools/vtoolcutarc.h +++ b/src/tools/drawTools/vtoolcutarc.h @@ -30,7 +30,6 @@ #define VTOOLCUTARC_H #include "vtoolpoint.h" -#include "../../dialogs/dialogcutarc.h" #include "../../widgets/vsimplearc.h" /** @@ -66,8 +65,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -92,26 +90,21 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief ArcChoosed send signal about selection from cutted arc. * @param id object id in container. */ - void ArcChoosed(qint64 id); + void ArcChoosed(qint64 id); /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. * @param newName new name active pattern peace. */ - virtual void ChangedActivDraw(const QString &newName); + virtual void ChangedActivDraw(const QString &newName); /** * @brief ShowContextMenu show context menu. * @param event context menu event. */ - virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); + virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: /** * @brief contextMenuEvent handle context menu events. @@ -129,29 +122,29 @@ protected: /** * @brief RefreshGeometry refresh item on scene. */ - void RefreshGeometry(); + void RefreshGeometry(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: Q_DISABLE_COPY(VToolCutArc) /** * @brief formula keep formula of length */ - QString formula; + QString formula; /** * @brief arcId keep id of arc */ - qint64 arcId; - /** - * @brief DialogCutSpline pointer to the tool's dialog - */ - QSharedPointer dialogCutArc; + qint64 arcId; /** * @brief firstArc first arc after cutting. */ - VSimpleArc *firstArc; + VSimpleArc *firstArc; /** * @brief secondArc second arc after cutting. */ - VSimpleArc *secondArc; + VSimpleArc *secondArc; /** * @brief arc1id id first arc after cutting. */ @@ -166,7 +159,7 @@ private: * @param arcid arc id. * @param tr arc type. */ - void RefreshArc(VSimpleArc *sArc, qint64 arcid, SimpleArc::Translation tr); + void RefreshArc(VSimpleArc *sArc, qint64 arcid, SimpleArc::Translation tr); }; #endif // VTOOLCUTARC_H diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp index 493ec715b..efa9ca3c6 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -28,6 +28,7 @@ #include "vtoolcutspline.h" #include "../../container/calculator.h" +#include "../../dialogs/dialogcutspline.h" const QString VToolCutSpline::ToolType = QStringLiteral("cutSpline"); const QString VToolCutSpline::AttrSpline = QStringLiteral("spline"); @@ -35,8 +36,8 @@ const QString VToolCutSpline::AttrSpline = QStringLiteral("spline"); VToolCutSpline::VToolCutSpline(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, const qint64 &splineId, const qint64 &spl1id, const qint64 &spl2id, const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VToolPoint(doc, data, id, parent), formula(formula), splineId(splineId), - dialogCutSpline(QSharedPointer()), firstSpline(), secondSpline(), spl1id(spl1id), spl2id(spl2id) + :VToolPoint(doc, data, id, parent), formula(formula), splineId(splineId), firstSpline(), secondSpline(), + spl1id(spl1id), spl2id(spl2id) { Q_ASSERT_X(splineId > 0, Q_FUNC_INFO, "splineId <= 0"); Q_ASSERT_X(spl1id > 0, Q_FUNC_INFO, "spl1id <= 0"); @@ -66,19 +67,24 @@ VToolCutSpline::VToolCutSpline(VDomDocument *doc, VContainer *data, const qint64 void VToolCutSpline::setDialog() { - Q_ASSERT(dialogCutSpline.isNull() == false); + Q_CHECK_PTR(dialog); + DialogCutSpline *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *point = VAbstractTool::data.GeometricObject(id); - dialogCutSpline->setFormula(formula); - dialogCutSpline->setSplineId(splineId, id); - dialogCutSpline->setPointName(point->name()); + dialogTool->setFormula(formula); + dialogTool->setSplineId(splineId, id); + dialogTool->setPointName(point->name()); } -void VToolCutSpline::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, +void VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - QString pointName = dialog->getPointName(); - QString formula = dialog->getFormula(); - qint64 splineId = dialog->getSplineId(); + Q_CHECK_PTR(dialog); + DialogCutSpline *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + QString pointName = dialogTool->getPointName(); + QString formula = dialogTool->getFormula(); + qint64 splineId = dialogTool->getSplineId(); Create(0, pointName, formula, splineId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -165,23 +171,6 @@ void VToolCutSpline::FullUpdateFromFile() RefreshGeometry(); } -void VToolCutSpline::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogCutSpline->getPointName()); - SetAttribute(domElement, AttrLength, dialogCutSpline->getFormula()); - SetAttribute(domElement, AttrSpline, QString().setNum(dialogCutSpline->getSplineId())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogCutSpline.clear(); -} - void VToolCutSpline::SplineChoosed(qint64 id) { emit ChoosedTool(id, Scene::Spline); @@ -212,12 +201,12 @@ void VToolCutSpline::ChangedActivDraw(const QString &newName) void VToolCutSpline::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogCutSpline, this, event); + ContextMenu(this, event); } void VToolCutSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogCutSpline, this, event); + ContextMenu(this, event); } void VToolCutSpline::AddToFile() @@ -263,6 +252,16 @@ void VToolCutSpline::RemoveReferens() doc->DecrementReferens(splineId); } +void VToolCutSpline::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogCutSpline *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + SetAttribute(domElement, AttrSpline, QString().setNum(dialogTool->getSplineId())); +} + void VToolCutSpline::RefreshSpline(VSimpleSpline *spline, qint64 splid, SimpleSpline::Translation tr) { const VSpline *spl = VAbstractTool::data.GeometricObject(splid); diff --git a/src/tools/drawTools/vtoolcutspline.h b/src/tools/drawTools/vtoolcutspline.h index 9fbfde464..bdf971598 100644 --- a/src/tools/drawTools/vtoolcutspline.h +++ b/src/tools/drawTools/vtoolcutspline.h @@ -30,7 +30,6 @@ #define VTOOLCUTSPLINE_H #include "vtoolpoint.h" -#include "../../dialogs/dialogcutspline.h" #include "../../widgets/vsimplespline.h" /** @@ -64,8 +63,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -90,63 +88,58 @@ public slots: /** * @brief FullUpdateFromFile update tool data form file. */ - virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result - */ - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); /** * @brief SplineChoosed send signal about selection from spline. * @param id object id in container. */ - void SplineChoosed(qint64 id); + void SplineChoosed(qint64 id); /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. * @param newName new name active pattern peace. */ - virtual void ChangedActivDraw(const QString &newName); + virtual void ChangedActivDraw(const QString &newName); /** * @brief ShowContextMenu show context menu. * @param event context menu event. */ - virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); + virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: /** * @brief contextMenuEvent handle context menu events. * @param event context menu event. */ - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); /** * @brief AddToFile add tag with informations about tool into file. */ - virtual void AddToFile(); + virtual void AddToFile(); /** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ - virtual void RefreshDataInFile(); + virtual void RefreshDataInFile(); /** * @brief RefreshGeometry refresh item on scene. */ - void RefreshGeometry(); + void RefreshGeometry(); /** * @brief RemoveReferens decrement referens value for used objects. */ - virtual void RemoveReferens(); + virtual void RemoveReferens(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: Q_DISABLE_COPY(VToolCutSpline) /** * @brief formula keep formula of length. */ - QString formula; + QString formula; /** * @brief splineId keep id of spline. */ - qint64 splineId; - /** - * @brief DialogCutSpline pointer to the tool's dialog. - */ - QSharedPointer dialogCutSpline; + qint64 splineId; /** * @brief firstSpline first spline after cutting. */ @@ -158,18 +151,18 @@ private: /** * @brief spl1id id first spline after cutting. */ - const qint64 spl1id; + const qint64 spl1id; /** * @brief spl2id id second spline after cutting. */ - const qint64 spl2id; + const qint64 spl2id; /** * @brief RefreshSpline refresh spline on scene. * @param spline spline. * @param splid spline id. * @param tr spline type. */ - void RefreshSpline(VSimpleSpline *spline, qint64 splid, SimpleSpline::Translation tr); + void RefreshSpline(VSimpleSpline *spline, qint64 splid, SimpleSpline::Translation tr); }; #endif // VTOOLCUTSPLINE_H diff --git a/src/tools/drawTools/vtoolcutsplinepath.cpp b/src/tools/drawTools/vtoolcutsplinepath.cpp index 907fcd0cf..30e5ab67a 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -28,6 +28,7 @@ #include "vtoolcutsplinepath.h" #include "../../container/calculator.h" +#include "../../dialogs/dialogcutsplinepath.h" const QString VToolCutSplinePath::ToolType = QStringLiteral("cutSplinePath"); const QString VToolCutSplinePath::AttrSplinePath = QStringLiteral("splinePath"); @@ -36,8 +37,7 @@ VToolCutSplinePath::VToolCutSplinePath(VDomDocument *doc, VContainer *data, cons const QString &formula, const qint64 &splinePathId, const qint64 &splPath1id, const qint64 &splPath2id, const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VToolPoint(doc, data, id, parent), formula(formula), splinePathId(splinePathId), - dialogCutSplinePath(QSharedPointer()), firstSpline(), secondSpline(), + :VToolPoint(doc, data, id, parent), formula(formula), splinePathId(splinePathId), firstSpline(), secondSpline(), splPath1id (splPath1id), splPath2id(splPath2id) { Q_ASSERT_X(splinePathId > 0, Q_FUNC_INFO, "splinePathId <= 0"); @@ -68,19 +68,23 @@ VToolCutSplinePath::VToolCutSplinePath(VDomDocument *doc, VContainer *data, cons void VToolCutSplinePath::setDialog() { - Q_ASSERT(dialogCutSplinePath.isNull() == false); + Q_CHECK_PTR(dialog); + DialogCutSplinePath *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *point = VAbstractTool::data.GeometricObject(id); - dialogCutSplinePath->setFormula(formula); - dialogCutSplinePath->setSplinePathId(splinePathId, id); - dialogCutSplinePath->setPointName(point->name()); + dialogTool->setFormula(formula); + dialogTool->setSplinePathId(splinePathId, id); + dialogTool->setPointName(point->name()); } -void VToolCutSplinePath::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data) +void VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - QString pointName = dialog->getPointName(); - QString formula = dialog->getFormula(); - qint64 splinePathId = dialog->getSplinePathId(); + Q_CHECK_PTR(dialog); + DialogCutSplinePath *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + QString pointName = dialogTool->getPointName(); + QString formula = dialogTool->getFormula(); + qint64 splinePathId = dialogTool->getSplinePathId(); Create(0, pointName, formula, splinePathId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -242,23 +246,6 @@ void VToolCutSplinePath::FullUpdateFromFile() RefreshGeometry(); } -void VToolCutSplinePath::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogCutSplinePath->getPointName()); - SetAttribute(domElement, AttrLength, dialogCutSplinePath->getFormula()); - SetAttribute(domElement, AttrSplinePath, QString().setNum(dialogCutSplinePath->getSplinePathId())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogCutSplinePath.clear(); -} - void VToolCutSplinePath::SplineChoosed(qint64 id) { emit ChoosedTool(id, Scene::SplinePath); @@ -289,12 +276,12 @@ void VToolCutSplinePath::ChangedActivDraw(const QString &newName) void VToolCutSplinePath::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogCutSplinePath, this, event); + ContextMenu(this, event); } void VToolCutSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogCutSplinePath, this, event); + ContextMenu(this, event); } void VToolCutSplinePath::AddToFile() @@ -340,6 +327,16 @@ void VToolCutSplinePath::RemoveReferens() doc->DecrementReferens(splinePathId); } +void VToolCutSplinePath::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogCutSplinePath *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + SetAttribute(domElement, AttrSplinePath, QString().setNum(dialogTool->getSplinePathId())); +} + void VToolCutSplinePath::RefreshSpline(VSimpleSpline *spline, qint64 splPathid, SimpleSpline::Translation tr) { const VSplinePath *splPath = VAbstractTool::data.GeometricObject(splPathid); diff --git a/src/tools/drawTools/vtoolcutsplinepath.h b/src/tools/drawTools/vtoolcutsplinepath.h index d816d6154..7a13d2e5e 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.h +++ b/src/tools/drawTools/vtoolcutsplinepath.h @@ -30,7 +30,6 @@ #define VTOOLCUTSPLINEPATH_H #include "vtoolpoint.h" -#include "../../dialogs/dialogcutsplinepath.h" #include "../../widgets/vsimplespline.h" /** @@ -67,8 +66,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -93,63 +91,58 @@ public slots: /** * @brief FullUpdateFromFile update tool data form file. */ - virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); /** * @brief SplineChoosed send signal about selection splinePath. * @param id object id in container. */ - void SplineChoosed(qint64 id); + void SplineChoosed(qint64 id); /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. * @param newName new name active pattern peace. */ - virtual void ChangedActivDraw(const QString &newName); + virtual void ChangedActivDraw(const QString &newName); /** * @brief ShowContextMenu show context menu. * @param event context menu event. */ - virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); + virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: /** * @brief contextMenuEvent handle context menu events. * @param event context menu event. */ - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); /** * @brief AddToFile add tag with informations about tool into file. */ - virtual void AddToFile(); + virtual void AddToFile(); /** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ - virtual void RefreshDataInFile(); + virtual void RefreshDataInFile(); /** * @brief RefreshGeometry refresh item on scene. */ - void RefreshGeometry(); + void RefreshGeometry(); /** * @brief RemoveReferens decrement referens value for used objects. */ - virtual void RemoveReferens(); + virtual void RemoveReferens(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: Q_DISABLE_COPY(VToolCutSplinePath) /** * @brief formula keep formula of length */ - QString formula; + QString formula; /** * @brief splineId keep id of spline. */ - qint64 splinePathId; - /** - * @brief DialogCutSpline pointer to the tool's dialog. - */ - QSharedPointer dialogCutSplinePath; + qint64 splinePathId; /** * @brief firstSpline first splinePath after cutting. */ @@ -161,18 +154,18 @@ private: /** * @brief splPath1id id first splinePath after cutting. */ - const qint64 splPath1id; + const qint64 splPath1id; /** * @brief splPath2id id second splinePath after cutting. */ - const qint64 splPath2id; + const qint64 splPath2id; /** * @brief RefreshSpline refresh splinePath on scene. * @param spline splinePath. * @param splPathid splinePath id. * @param tr splineType type. */ - void RefreshSpline(VSimpleSpline *spline, qint64 splPathid, SimpleSpline::Translation tr); + void RefreshSpline(VSimpleSpline *spline, qint64 splPathid, SimpleSpline::Translation tr); }; #endif // VTOOLCUTSPLINEPATH_H diff --git a/src/tools/drawTools/vtoolendline.cpp b/src/tools/drawTools/vtoolendline.cpp index 68e915e63..efe9c6a9b 100644 --- a/src/tools/drawTools/vtoolendline.cpp +++ b/src/tools/drawTools/vtoolendline.cpp @@ -29,14 +29,14 @@ #include "vtoolendline.h" #include "../../widgets/vmaingraphicsscene.h" #include "../../container/calculator.h" +#include "../../dialogs/dialogendline.h" const QString VToolEndLine::ToolType = QStringLiteral("endLine"); VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qreal &angle, const qint64 &basePointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VToolLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent), - dialogEndLine(QSharedPointer()) + :VToolLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent) { if (typeCreation == Tool::FromGui) @@ -51,23 +51,28 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id void VToolEndLine::setDialog() { - Q_ASSERT(dialogEndLine.isNull() == false); + Q_CHECK_PTR(dialog); + DialogEndLine *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogEndLine->setTypeLine(typeLine); - dialogEndLine->setFormula(formula); - dialogEndLine->setAngle(angle); - dialogEndLine->setBasePointId(basePointId, id); - dialogEndLine->setPointName(p->name()); + dialogTool->setTypeLine(typeLine); + dialogTool->setFormula(formula); + dialogTool->setAngle(angle); + dialogTool->setBasePointId(basePointId, id); + dialogTool->setPointName(p->name()); } -void VToolEndLine::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - QString pointName = dialog->getPointName(); - QString typeLine = dialog->getTypeLine(); - QString formula = dialog->getFormula(); - qreal angle = dialog->getAngle(); - qint64 basePointId = dialog->getBasePointId(); + Q_CHECK_PTR(dialog); + DialogEndLine *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + QString pointName = dialogTool->getPointName(); + QString typeLine = dialogTool->getTypeLine(); + QString formula = dialogTool->getFormula(); + qreal angle = dialogTool->getAngle(); + qint64 basePointId = dialogTool->getBasePointId(); Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -130,31 +135,12 @@ void VToolEndLine::FullUpdateFromFile() void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogEndLine, this, event); -} - -void VToolEndLine::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogEndLine->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogEndLine->getTypeLine()); - SetAttribute(domElement, AttrLength, dialogEndLine->getFormula()); - SetAttribute(domElement, AttrAngle, QString().setNum(dialogEndLine->getAngle())); - SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogEndLine->getBasePointId())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogEndLine.clear(); + ContextMenu(this, event); } void VToolEndLine::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogEndLine, this, event); + ContextMenu(this, event); } void VToolEndLine::AddToFile() @@ -191,3 +177,15 @@ void VToolEndLine::RefreshDataInFile() SetAttribute(domElement, AttrBasePoint, basePointId); } } + +void VToolEndLine::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogEndLine *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + SetAttribute(domElement, AttrAngle, QString().setNum(dialogTool->getAngle())); + SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); +} diff --git a/src/tools/drawTools/vtoolendline.h b/src/tools/drawTools/vtoolendline.h index 05df2ad7e..a8b3c4992 100644 --- a/src/tools/drawTools/vtoolendline.h +++ b/src/tools/drawTools/vtoolendline.h @@ -30,7 +30,6 @@ #define VTOOLENDLINE_H #include "vtoollinepoint.h" -#include "../../dialogs/dialogendline.h" /** * @brief The VToolEndLine class tool for creation point on the line end. @@ -65,8 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -93,11 +91,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief ShowContextMenu show context menu. * @param event context menu event. @@ -117,11 +110,10 @@ protected: * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ virtual void RefreshDataInFile(); -private: /** - * @brief dialogEndLine pointer to the dialog. + * @brief SaveDialog save options into file after change in dialog. */ - QSharedPointer dialogEndLine; + virtual void SaveDialog(QDomElement &domElement); }; #endif // VTOOLENDLINE_H diff --git a/src/tools/drawTools/vtoolheight.cpp b/src/tools/drawTools/vtoolheight.cpp index db6b8e04d..089218d64 100644 --- a/src/tools/drawTools/vtoolheight.cpp +++ b/src/tools/drawTools/vtoolheight.cpp @@ -27,14 +27,14 @@ *************************************************************************/ #include "vtoolheight.h" +#include "../../dialogs/dialogheight.h" const QString VToolHeight::ToolType = QStringLiteral("height"); VToolHeight::VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, const Tool::Sources &typeCreation, QGraphicsItem * parent) - :VToolLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent), - dialogHeight(QSharedPointer()), p1LineId(p1LineId), p2LineId(p2LineId) + :VToolLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent), p1LineId(p1LineId), p2LineId(p2LineId) { ignoreFullUpdate = true; if (typeCreation == Tool::FromGui) @@ -49,24 +49,29 @@ VToolHeight::VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id, void VToolHeight::setDialog() { - Q_ASSERT(dialogHeight.isNull() == false); + Q_CHECK_PTR(dialog); + DialogHeight *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogHeight->setTypeLine(typeLine); - dialogHeight->setBasePointId(basePointId, id); - dialogHeight->setP1LineId(p1LineId, id); - dialogHeight->setP2LineId(p2LineId, id); - dialogHeight->setPointName(p->name()); + dialogTool->setTypeLine(typeLine); + dialogTool->setBasePointId(basePointId, id); + dialogTool->setP1LineId(p1LineId, id); + dialogTool->setP2LineId(p2LineId, id); + dialogTool->setPointName(p->name()); } -void VToolHeight::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolHeight::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - disconnect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &DialogHeight::UpdateList); - QString pointName = dialog->getPointName(); - QString typeLine = dialog->getTypeLine(); - qint64 basePointId = dialog->getBasePointId(); - qint64 p1LineId = dialog->getP1LineId(); - qint64 p2LineId = dialog->getP2LineId(); + Q_CHECK_PTR(dialog); + DialogHeight *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + disconnect(doc, &VDomDocument::FullUpdateFromFile, dialogTool, &DialogHeight::UpdateList); + QString pointName = dialogTool->getPointName(); + QString typeLine = dialogTool->getTypeLine(); + qint64 basePointId = dialogTool->getBasePointId(); + qint64 p1LineId = dialogTool->getP1LineId(); + qint64 p2LineId = dialogTool->getP2LineId(); Create(0, pointName, typeLine, basePointId, p1LineId, p2LineId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -134,33 +139,14 @@ void VToolHeight::FullUpdateFromFile() } -void VToolHeight::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogHeight->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogHeight->getTypeLine()); - SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogHeight->getBasePointId())); - SetAttribute(domElement, AttrP1Line, QString().setNum(dialogHeight->getP1LineId())); - SetAttribute(domElement, AttrP2Line, QString().setNum(dialogHeight->getP2LineId())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogHeight.clear(); -} - void VToolHeight::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogHeight, this, event); + ContextMenu(this, event); } void VToolHeight::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogHeight, this, event); + ContextMenu(this, event); } void VToolHeight::AddToFile() @@ -198,3 +184,15 @@ void VToolHeight::RefreshDataInFile() SetAttribute(domElement, AttrP2Line, p2LineId); } } + +void VToolHeight::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogHeight *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); + SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->getP1LineId())); + SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2LineId())); +} diff --git a/src/tools/drawTools/vtoolheight.h b/src/tools/drawTools/vtoolheight.h index 60c7f643f..085407efb 100644 --- a/src/tools/drawTools/vtoolheight.h +++ b/src/tools/drawTools/vtoolheight.h @@ -30,7 +30,6 @@ #define VTOOLHEIGHT_H #include "vtoollinepoint.h" -#include "../../dialogs/dialogheight.h" /** * @brief The VToolHeight class tool for creation point of height. Help find point of projection onto line. @@ -65,8 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool * @param _id tool id, 0 if tool doesn't exist yet. @@ -100,11 +98,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief ShowContextMenu show context menu. * @param event context menu event. @@ -123,12 +116,12 @@ protected: /** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ - virtual void RefreshDataInFile(); -private: + virtual void RefreshDataInFile(); /** - * @brief dialogHeight dialog. + * @brief SaveDialog save options into file after change in dialog. */ - QSharedPointer dialogHeight; + virtual void SaveDialog(QDomElement &domElement); +private: /** * @brief p1LineId id first point of line. */ diff --git a/src/tools/drawTools/vtoolline.cpp b/src/tools/drawTools/vtoolline.cpp index 4b253faaa..a0ff4868b 100644 --- a/src/tools/drawTools/vtoolline.cpp +++ b/src/tools/drawTools/vtoolline.cpp @@ -27,13 +27,13 @@ *************************************************************************/ #include "vtoolline.h" +#include "../../dialogs/dialogline.h" const QString VToolLine::TagName = QStringLiteral("line"); VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint, const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VDrawTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint), - dialogLine(QSharedPointer()) + :VDrawTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint) { ignoreFullUpdate = true; //Line @@ -58,15 +58,20 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs void VToolLine::setDialog() { - dialogLine->setFirstPoint(firstPoint); - dialogLine->setSecondPoint(secondPoint); + Q_CHECK_PTR(dialog); + DialogLine *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + dialogTool->setFirstPoint(firstPoint); + dialogTool->setSecondPoint(secondPoint); } -void VToolLine::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data) +void VToolLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - qint64 firstPoint = dialog->getFirstPoint(); - qint64 secondPoint = dialog->getSecondPoint(); + Q_CHECK_PTR(dialog); + DialogLine *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + qint64 firstPoint = dialogTool->getFirstPoint(); + qint64 secondPoint = dialogTool->getSecondPoint(); Create(0, firstPoint, secondPoint, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -111,22 +116,6 @@ void VToolLine::FullUpdateFromFile() RefreshGeometry(); } -void VToolLine::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogLine->getFirstPoint())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogLine->getSecondPoint())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogLine.clear(); -} - void VToolLine::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) { ShowItem(this, id, color, enable); @@ -158,7 +147,7 @@ void VToolLine::ChangedActivDraw(const QString &newName) void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogLine, this, event); + ContextMenu(this, event); } void VToolLine::AddToFile() @@ -230,6 +219,15 @@ void VToolLine::keyReleaseEvent(QKeyEvent *event) QGraphicsItem::keyReleaseEvent ( event ); } +void VToolLine::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogLine *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPoint())); + SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPoint())); +} + void VToolLine::RefreshGeometry() { QDomElement domElement = doc->elementById(QString().setNum(id)); diff --git a/src/tools/drawTools/vtoolline.h b/src/tools/drawTools/vtoolline.h index 44092bb6e..2ddd978ae 100644 --- a/src/tools/drawTools/vtoolline.h +++ b/src/tools/drawTools/vtoolline.h @@ -63,8 +63,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -90,11 +89,6 @@ public slots: * @param newName new name active pattern peace. */ virtual void ChangedActivDraw(const QString &newName); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief ShowTool highlight tool. * @param id object id in container @@ -147,6 +141,10 @@ protected: * @param event key realse event. */ virtual void keyReleaseEvent(QKeyEvent * event); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: /** * @brief firstPoint id first line point. @@ -156,10 +154,6 @@ private: * @brief secondPoint id second line point. */ qint64 secondPoint; - /** - * @brief dialogLine dialog. - */ - QSharedPointer dialogLine; /** * @brief RefreshGeometry refresh item on scene. */ diff --git a/src/tools/drawTools/vtoollineintersect.cpp b/src/tools/drawTools/vtoollineintersect.cpp index 8dc10ef30..a947d08ef 100644 --- a/src/tools/drawTools/vtoollineintersect.cpp +++ b/src/tools/drawTools/vtoollineintersect.cpp @@ -27,6 +27,7 @@ *************************************************************************/ #include "vtoollineintersect.h" +#include "../../dialogs/dialoglineintersect.h" const QString VToolLineIntersect::ToolType = QStringLiteral("lineIntersect"); @@ -35,7 +36,7 @@ VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, cons const qint64 &p2Line2, const Tool::Sources &typeCreation, QGraphicsItem *parent) :VToolPoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), - p2Line2(p2Line2), dialogLineIntersect(QSharedPointer()) + p2Line2(p2Line2) { ignoreFullUpdate = true; if (typeCreation == Tool::FromGui) @@ -50,23 +51,27 @@ VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, cons void VToolLineIntersect::setDialog() { - Q_ASSERT(dialogLineIntersect.isNull() == false); + Q_CHECK_PTR(dialog); + DialogLineIntersect *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogLineIntersect->setP1Line1(p1Line1); - dialogLineIntersect->setP2Line1(p2Line1); - dialogLineIntersect->setP1Line2(p1Line2); - dialogLineIntersect->setP2Line2(p2Line2); - dialogLineIntersect->setPointName(p->name()); + dialogTool->setP1Line1(p1Line1); + dialogTool->setP2Line1(p2Line1); + dialogTool->setP1Line2(p1Line2); + dialogTool->setP2Line2(p2Line2); + dialogTool->setPointName(p->name()); } -void VToolLineIntersect::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data) +void VToolLineIntersect::Create(DialogTool *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(); + Q_CHECK_PTR(dialog); + DialogLineIntersect *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + qint64 p1Line1Id = dialogTool->getP1Line1(); + qint64 p2Line1Id = dialogTool->getP2Line1(); + qint64 p1Line2Id = dialogTool->getP1Line2(); + qint64 p2Line2Id = dialogTool->getP2Line2(); + QString pointName = dialogTool->getPointName(); Create(0, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, pointName, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -139,25 +144,6 @@ void VToolLineIntersect::FullUpdateFromFile() RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); } -void VToolLineIntersect::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogLineIntersect->getPointName()); - SetAttribute(domElement, AttrP1Line1, QString().setNum(dialogLineIntersect->getP1Line1())); - SetAttribute(domElement, AttrP2Line1, QString().setNum(dialogLineIntersect->getP2Line1())); - SetAttribute(domElement, AttrP1Line2, QString().setNum(dialogLineIntersect->getP1Line2())); - SetAttribute(domElement, AttrP2Line2, QString().setNum(dialogLineIntersect->getP2Line2())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogLineIntersect.clear(); -} - void VToolLineIntersect::SetFactor(qreal factor) { VDrawTool::SetFactor(factor); @@ -166,12 +152,12 @@ void VToolLineIntersect::SetFactor(qreal factor) void VToolLineIntersect::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogLineIntersect, this, event); + ContextMenu(this, event); } void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogLineIntersect, this, event); + ContextMenu(this, event); } void VToolLineIntersect::AddToFile() @@ -216,3 +202,15 @@ void VToolLineIntersect::RemoveReferens() doc->DecrementReferens(p1Line2); doc->DecrementReferens(p2Line2); } + +void VToolLineIntersect::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogLineIntersect *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrP1Line1, QString().setNum(dialogTool->getP1Line1())); + SetAttribute(domElement, AttrP2Line1, QString().setNum(dialogTool->getP2Line1())); + SetAttribute(domElement, AttrP1Line2, QString().setNum(dialogTool->getP1Line2())); + SetAttribute(domElement, AttrP2Line2, QString().setNum(dialogTool->getP2Line2())); +} diff --git a/src/tools/drawTools/vtoollineintersect.h b/src/tools/drawTools/vtoollineintersect.h index 520bfc478..f39dc0b6e 100644 --- a/src/tools/drawTools/vtoollineintersect.h +++ b/src/tools/drawTools/vtoollineintersect.h @@ -30,7 +30,6 @@ #define VTOOLLINEINTERSECT_H #include "vtoolpoint.h" -#include "../../dialogs/dialoglineintersect.h" /** * @brief The VToolLineIntersect class help find point intersection lines. @@ -65,8 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -93,11 +91,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. @@ -126,6 +119,10 @@ protected: * @brief RemoveReferens decrement value of reference. */ virtual void RemoveReferens(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: /** * @brief p1Line1 id first point first line. @@ -143,10 +140,6 @@ private: * @brief p2Line2 id second point second line. */ qint64 p2Line2; - /** - * @brief dialogLineIntersect dialog. - */ - QSharedPointer dialogLineIntersect; }; #endif // VTOOLLINEINTERSECT_H diff --git a/src/tools/drawTools/vtoolnormal.cpp b/src/tools/drawTools/vtoolnormal.cpp index 774a4c3fe..38b84591e 100644 --- a/src/tools/drawTools/vtoolnormal.cpp +++ b/src/tools/drawTools/vtoolnormal.cpp @@ -28,6 +28,7 @@ #include "vtoolnormal.h" #include "../../container/calculator.h" +#include "../../dialogs/dialognormal.h" const QString VToolNormal::ToolType = QStringLiteral("normal"); @@ -35,7 +36,7 @@ VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, const qreal &angle, const qint64 &firstPointId, const qint64 &secondPointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) :VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, angle, parent), - secondPointId(secondPointId), dialogNormal(QSharedPointer()) + secondPointId(secondPointId) { if (typeCreation == Tool::FromGui) @@ -50,25 +51,29 @@ VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, void VToolNormal::setDialog() { - Q_ASSERT(dialogNormal.isNull() == false); + Q_CHECK_PTR(dialog); + DialogNormal *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogNormal->setTypeLine(typeLine); - dialogNormal->setFormula(formula); - dialogNormal->setAngle(angle); - dialogNormal->setFirstPointId(basePointId, id); - dialogNormal->setSecondPointId(secondPointId, id); - dialogNormal->setPointName(p->name()); + dialogTool->setTypeLine(typeLine); + dialogTool->setFormula(formula); + dialogTool->setAngle(angle); + dialogTool->setFirstPointId(basePointId, id); + dialogTool->setSecondPointId(secondPointId, id); + dialogTool->setPointName(p->name()); } -void VToolNormal::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data) +void VToolNormal::Create(DialogTool *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(); - qreal angle = dialog->getAngle(); + Q_CHECK_PTR(dialog); + DialogNormal *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + QString formula = dialogTool->getFormula(); + qint64 firstPointId = dialogTool->getFirstPointId(); + qint64 secondPointId = dialogTool->getSecondPointId(); + QString typeLine = dialogTool->getTypeLine(); + QString pointName = dialogTool->getPointName(); + qreal angle = dialogTool->getAngle(); Create(0, formula, firstPointId, secondPointId, typeLine, pointName, angle, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -142,26 +147,6 @@ void VToolNormal::FullUpdateFromFile() RefreshGeometry(); } -void VToolNormal::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogNormal->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogNormal->getTypeLine()); - SetAttribute(domElement, AttrLength, dialogNormal->getFormula()); - SetAttribute(domElement, AttrAngle, QString().setNum(dialogNormal->getAngle())); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogNormal->getFirstPointId())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogNormal->getSecondPointId())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogNormal.clear(); -} - void VToolNormal::SetFactor(qreal factor) { VDrawTool::SetFactor(factor); @@ -170,12 +155,12 @@ void VToolNormal::SetFactor(qreal factor) void VToolNormal::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogNormal, this, event); + ContextMenu(this, event); } void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogNormal, this, event); + ContextMenu(this, event); } void VToolNormal::AddToFile() @@ -220,3 +205,16 @@ void VToolNormal::RemoveReferens() doc->DecrementReferens(secondPointId); VToolLinePoint::RemoveReferens(); } + +void VToolNormal::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogNormal *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + SetAttribute(domElement, AttrAngle, QString().setNum(dialogTool->getAngle())); + SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); + SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); +} diff --git a/src/tools/drawTools/vtoolnormal.h b/src/tools/drawTools/vtoolnormal.h index 8e9947e14..018374b8d 100644 --- a/src/tools/drawTools/vtoolnormal.h +++ b/src/tools/drawTools/vtoolnormal.h @@ -30,7 +30,6 @@ #define VTOOLNORMAL_H #include "vtoollinepoint.h" -#include "../../dialogs/dialognormal.h" /** * @brief The VToolNormal class tool for creation point on normal. Normal begin from first point of line. @@ -67,8 +66,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -107,11 +105,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. @@ -135,20 +128,20 @@ protected: /** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ - virtual void RefreshDataInFile(); + virtual void RefreshDataInFile(); /** * @brief RemoveReferens decrement value of reference. */ virtual void RemoveReferens(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: /** * @brief secondPointId id second line point. */ qint64 secondPointId; - /** - * @brief dialogNormal dialog. - */ - QSharedPointer dialogNormal; }; #endif // VTOOLNORMAL_H diff --git a/src/tools/drawTools/vtoolpoint.h b/src/tools/drawTools/vtoolpoint.h index 6ebcd1e2b..23c4ae4f2 100644 --- a/src/tools/drawTools/vtoolpoint.h +++ b/src/tools/drawTools/vtoolpoint.h @@ -60,11 +60,6 @@ public slots: * @param newName new name active pattern peace. */ virtual void ChangedActivDraw(const QString &newName); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result) = 0; /** * @brief ShowTool highlight tool. * @param id object id in container. diff --git a/src/tools/drawTools/vtoolpointofcontact.cpp b/src/tools/drawTools/vtoolpointofcontact.cpp index 1af818bd6..3516678a3 100644 --- a/src/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/tools/drawTools/vtoolpointofcontact.cpp @@ -28,6 +28,7 @@ #include "vtoolpointofcontact.h" #include "../../container/calculator.h" +#include "../../dialogs/dialogpointofcontact.h" const QString VToolPointOfContact::ToolType = QStringLiteral("pointOfContact"); @@ -36,7 +37,7 @@ VToolPointOfContact::VToolPointOfContact(VDomDocument *doc, VContainer *data, co const qint64 &firstPointId, const qint64 &secondPointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) : VToolPoint(doc, data, id, parent), arcRadius(radius), center(center), firstPointId(firstPointId), - secondPointId(secondPointId), dialogPointOfContact(QSharedPointer()) + secondPointId(secondPointId) { if (typeCreation == Tool::FromGui) { @@ -50,13 +51,15 @@ VToolPointOfContact::VToolPointOfContact(VDomDocument *doc, VContainer *data, co void VToolPointOfContact::setDialog() { - Q_ASSERT(dialogPointOfContact.isNull() == false); + Q_CHECK_PTR(dialog); + DialogPointOfContact *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogPointOfContact->setRadius(arcRadius); - dialogPointOfContact->setCenter(center, id); - dialogPointOfContact->setFirstPoint(firstPointId, id); - dialogPointOfContact->setSecondPoint(secondPointId, id); - dialogPointOfContact->setPointName(p->name()); + dialogTool->setRadius(arcRadius); + dialogTool->setCenter(center, id); + dialogTool->setFirstPoint(firstPointId, id); + dialogTool->setSecondPoint(secondPointId, id); + dialogTool->setPointName(p->name()); } QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, @@ -85,14 +88,16 @@ QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢e return pArc; } -void VToolPointOfContact::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data) +void VToolPointOfContact::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - QString radius = dialog->getRadius(); - qint64 center = dialog->getCenter(); - qint64 firstPointId = dialog->getFirstPoint(); - qint64 secondPointId = dialog->getSecondPoint(); - QString pointName = dialog->getPointName(); + Q_CHECK_PTR(dialog); + DialogPointOfContact *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + QString radius = dialogTool->getRadius(); + qint64 center = dialogTool->getCenter(); + qint64 firstPointId = dialogTool->getFirstPoint(); + qint64 secondPointId = dialogTool->getSecondPoint(); + QString pointName = dialogTool->getPointName(); Create(0, radius, center, firstPointId, secondPointId, pointName, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -162,25 +167,6 @@ void VToolPointOfContact::FullUpdateFromFile() RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); } -void VToolPointOfContact::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogPointOfContact->getPointName()); - SetAttribute(domElement, AttrRadius, dialogPointOfContact->getRadius()); - SetAttribute(domElement, AttrCenter, QString().setNum(dialogPointOfContact->getCenter())); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogPointOfContact->getFirstPoint())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogPointOfContact->getSecondPoint())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogPointOfContact.clear(); -} - void VToolPointOfContact::SetFactor(qreal factor) { VDrawTool::SetFactor(factor); @@ -189,12 +175,12 @@ void VToolPointOfContact::SetFactor(qreal factor) void VToolPointOfContact::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogPointOfContact, this, event); + ContextMenu(this, event); } void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogPointOfContact, this, event); + ContextMenu(this, event); } void VToolPointOfContact::AddToFile() @@ -238,3 +224,15 @@ void VToolPointOfContact::RemoveReferens() doc->DecrementReferens(firstPointId); doc->DecrementReferens(secondPointId); } + +void VToolPointOfContact::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogPointOfContact *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrRadius, dialogTool->getRadius()); + SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->getCenter())); + SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPoint())); + SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPoint())); +} diff --git a/src/tools/drawTools/vtoolpointofcontact.h b/src/tools/drawTools/vtoolpointofcontact.h index 390451bea..0855537c8 100644 --- a/src/tools/drawTools/vtoolpointofcontact.h +++ b/src/tools/drawTools/vtoolpointofcontact.h @@ -30,7 +30,6 @@ #define VTOOLPOINTOFCONTACT_H #include "vtoolpoint.h" -#include "../../dialogs/dialogpointofcontact.h" /** * @brief The VToolPointOfContact class tool for creation point intersection line and arc. @@ -75,8 +74,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -103,11 +101,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. @@ -131,11 +124,15 @@ protected: /** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ - virtual void RefreshDataInFile(); + virtual void RefreshDataInFile(); /** * @brief RemoveReferens decrement value of reference. */ virtual void RemoveReferens(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: /** * @brief radius string with formula radius arc. @@ -153,10 +150,6 @@ private: * @brief secondPointId id second line point. */ qint64 secondPointId; - /** - * @brief dialogPointOfContact dialog. - */ - QSharedPointer dialogPointOfContact; }; #endif // VTOOLPOINTOFCONTACT_H diff --git a/src/tools/drawTools/vtoolpointofintersection.cpp b/src/tools/drawTools/vtoolpointofintersection.cpp index d0b79999a..ba0c99d79 100644 --- a/src/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/tools/drawTools/vtoolpointofintersection.cpp @@ -27,14 +27,14 @@ *************************************************************************/ #include "vtoolpointofintersection.h" +#include "../../dialogs/dialogpointofintersection.h" const QString VToolPointOfIntersection::ToolType = QStringLiteral("pointOfIntersection"); VToolPointOfIntersection::VToolPointOfIntersection(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &firstPointId, const qint64 &secondPointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VToolPoint(doc, data, id, parent), firstPointId(firstPointId), secondPointId(secondPointId), - dialogPointOfIntersection(QSharedPointer()) + :VToolPoint(doc, data, id, parent), firstPointId(firstPointId), secondPointId(secondPointId) { ignoreFullUpdate = true; if (typeCreation == Tool::FromGui) @@ -49,19 +49,24 @@ VToolPointOfIntersection::VToolPointOfIntersection(VDomDocument *doc, VContainer void VToolPointOfIntersection::setDialog() { - Q_ASSERT(dialogPointOfIntersection.isNull() == false); + Q_CHECK_PTR(dialog); + DialogPointOfIntersection *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogPointOfIntersection->setFirstPointId(firstPointId, id); - dialogPointOfIntersection->setSecondPointId(secondPointId, id); - dialogPointOfIntersection->setPointName(p->name()); + dialogTool->setFirstPointId(firstPointId, id); + dialogTool->setSecondPointId(secondPointId, id); + dialogTool->setPointName(p->name()); } -void VToolPointOfIntersection::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data) +void VToolPointOfIntersection::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data) { - qint64 firstPointId = dialog->getFirstPointId(); - qint64 secondPointId = dialog->getSecondPointId(); - QString pointName = dialog->getPointName(); + Q_CHECK_PTR(dialog); + DialogPointOfIntersection *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + qint64 firstPointId = dialogTool->getFirstPointId(); + qint64 secondPointId = dialogTool->getSecondPointId(); + QString pointName = dialogTool->getPointName(); Create(0, pointName, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -112,26 +117,9 @@ void VToolPointOfIntersection::FullUpdateFromFile() VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); } -void VToolPointOfIntersection::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogPointOfIntersection->getPointName()); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogPointOfIntersection->getFirstPointId())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogPointOfIntersection->getSecondPointId())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogPointOfIntersection.clear(); -} - void VToolPointOfIntersection::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogPointOfIntersection, this, event); + ContextMenu(this, event); } void VToolPointOfIntersection::RemoveReferens() @@ -142,7 +130,7 @@ void VToolPointOfIntersection::RemoveReferens() void VToolPointOfIntersection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogPointOfIntersection, this, event); + ContextMenu(this, event); } void VToolPointOfIntersection::AddToFile() @@ -175,3 +163,13 @@ void VToolPointOfIntersection::RefreshDataInFile() SetAttribute(domElement, AttrSecondPoint, secondPointId); } } + +void VToolPointOfIntersection::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogPointOfIntersection *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); + SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); +} diff --git a/src/tools/drawTools/vtoolpointofintersection.h b/src/tools/drawTools/vtoolpointofintersection.h index 9c96fee9b..33e2905c6 100644 --- a/src/tools/drawTools/vtoolpointofintersection.h +++ b/src/tools/drawTools/vtoolpointofintersection.h @@ -30,7 +30,6 @@ #define VTOOLPOINTOFINTERSECTION_H #include "vtoolpoint.h" -#include "../../dialogs/dialogpointofintersection.h" /** * @brief The VToolPointOfIntersection class tool for creation point intersection two lines. @@ -63,8 +62,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -89,11 +87,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief ShowContextMenu show context menu. * @param event context menu event. @@ -117,6 +110,10 @@ protected: * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ virtual void RefreshDataInFile(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: Q_DISABLE_COPY(VToolPointOfIntersection) /** @@ -127,10 +124,6 @@ private: * @brief secondPointId id second line point. */ qint64 secondPointId; - /** - * @brief dialogPointOfIntersection dialog. - */ - QSharedPointer dialogPointOfIntersection; }; #endif // VTOOLPOINTOFINTERSECTION_H diff --git a/src/tools/drawTools/vtoolshoulderpoint.cpp b/src/tools/drawTools/vtoolshoulderpoint.cpp index f860c8c6d..9de69427e 100644 --- a/src/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/tools/drawTools/vtoolshoulderpoint.cpp @@ -28,6 +28,7 @@ #include "vtoolshoulderpoint.h" #include "../../container/calculator.h" +#include "../../dialogs/dialogshoulderpoint.h" const QString VToolShoulderPoint::ToolType = QStringLiteral("shoulder"); @@ -35,8 +36,7 @@ VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, cons const QString &typeLine, const QString &formula, const qint64 &p1Line, const qint64 &p2Line, const qint64 &pShoulder, const Tool::Sources &typeCreation, QGraphicsItem * parent) - :VToolLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), pShoulder(pShoulder), - dialogShoulderPoint(QSharedPointer()) + :VToolLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), pShoulder(pShoulder) { if (typeCreation == Tool::FromGui) { @@ -50,14 +50,16 @@ VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, cons void VToolShoulderPoint::setDialog() { - Q_ASSERT(dialogShoulderPoint.isNull() == false); + Q_CHECK_PTR(dialog); + DialogShoulderPoint *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogShoulderPoint->setTypeLine(typeLine); - dialogShoulderPoint->setFormula(formula); - dialogShoulderPoint->setP1Line(basePointId, id); - dialogShoulderPoint->setP2Line(p2Line, id); - dialogShoulderPoint->setPShoulder(pShoulder, id); - dialogShoulderPoint->setPointName(p->name()); + dialogTool->setTypeLine(typeLine); + dialogTool->setFormula(formula); + dialogTool->setP1Line(basePointId, id); + dialogTool->setP2Line(p2Line, id); + dialogTool->setPShoulder(pShoulder, id); + dialogTool->setPointName(p->name()); } QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, @@ -87,15 +89,17 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li } } -void VToolShoulderPoint::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data) +void VToolShoulderPoint::Create(DialogTool *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(); + Q_CHECK_PTR(dialog); + DialogShoulderPoint *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + QString formula = dialogTool->getFormula(); + qint64 p1Line = dialogTool->getP1Line(); + qint64 p2Line = dialogTool->getP2Line(); + qint64 pShoulder = dialogTool->getPShoulder(); + QString typeLine = dialogTool->getTypeLine(); + QString pointName = dialogTool->getPointName(); Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -165,26 +169,6 @@ void VToolShoulderPoint::FullUpdateFromFile() RefreshGeometry(); } -void VToolShoulderPoint::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogShoulderPoint->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogShoulderPoint->getTypeLine()); - SetAttribute(domElement, AttrLength, dialogShoulderPoint->getFormula()); - SetAttribute(domElement, AttrP1Line, QString().setNum(dialogShoulderPoint->getP1Line())); - SetAttribute(domElement, AttrP2Line, QString().setNum(dialogShoulderPoint->getP2Line())); - SetAttribute(domElement, AttrPShoulder, QString().setNum(dialogShoulderPoint->getPShoulder())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogShoulderPoint.clear(); -} - void VToolShoulderPoint::SetFactor(qreal factor) { VDrawTool::SetFactor(factor); @@ -193,12 +177,12 @@ void VToolShoulderPoint::SetFactor(qreal factor) void VToolShoulderPoint::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogShoulderPoint, this, event); + ContextMenu(this, event); } void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogShoulderPoint, this, event); + ContextMenu(this, event); } void VToolShoulderPoint::AddToFile() @@ -244,3 +228,16 @@ void VToolShoulderPoint::RemoveReferens() doc->DecrementReferens(pShoulder); VToolLinePoint::RemoveReferens(); } + +void VToolShoulderPoint::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogShoulderPoint *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->getP1Line())); + SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2Line())); + SetAttribute(domElement, AttrPShoulder, QString().setNum(dialogTool->getPShoulder())); +} diff --git a/src/tools/drawTools/vtoolshoulderpoint.h b/src/tools/drawTools/vtoolshoulderpoint.h index cbf79ef09..fec464fc2 100644 --- a/src/tools/drawTools/vtoolshoulderpoint.h +++ b/src/tools/drawTools/vtoolshoulderpoint.h @@ -30,7 +30,6 @@ #define VTOOLSHOULDERPOINT_H #include "vtoollinepoint.h" -#include "../../dialogs/dialogshoulderpoint.h" /** * @brief The VToolShoulderPoint class tool for creation point on shoulder. This tool for special situation, when you @@ -77,8 +76,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -106,11 +104,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. @@ -134,11 +127,15 @@ protected: /** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ - virtual void RefreshDataInFile(); + virtual void RefreshDataInFile(); /** * @brief RemoveReferens decrement value of reference. */ virtual void RemoveReferens(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: /** * @brief p2Line id second line point. @@ -148,10 +145,6 @@ private: * @brief pShoulder id shoulder line point. */ qint64 pShoulder; - /** - * @brief dialogShoulderPoint dialog. - */ - QSharedPointer dialogShoulderPoint; }; #endif // VTOOLSHOULDERPOINT_H diff --git a/src/tools/drawTools/vtoolsinglepoint.cpp b/src/tools/drawTools/vtoolsinglepoint.cpp index 067efaa23..8fbbd78f8 100644 --- a/src/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/tools/drawTools/vtoolsinglepoint.cpp @@ -27,12 +27,13 @@ *************************************************************************/ #include "vtoolsinglepoint.h" +#include "../../dialogs/dialogsinglepoint.h" const QString VToolSinglePoint::ToolType = QStringLiteral("single"); VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, QGraphicsItem * parent ) - :VToolPoint(doc, data, id, parent), dialogSinglePoint(QSharedPointer()) + :VToolPoint(doc, data, id, parent) { baseColor = Qt::red; currentColor = baseColor; @@ -53,9 +54,11 @@ VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 void VToolSinglePoint::setDialog() { - Q_ASSERT(dialogSinglePoint.isNull() == false); + Q_CHECK_PTR(dialog); + DialogSinglePoint *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogSinglePoint->setData(p->name(), p->toQPointF()); + dialogTool->setData(p->name(), p->toQPointF()); } void VToolSinglePoint::AddToFile() @@ -131,6 +134,18 @@ void VToolSinglePoint::decrementReferens() } } +void VToolSinglePoint::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogSinglePoint *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + QPointF p = dialogTool->getPoint(); + QString name = dialogTool->getName(); + SetAttribute(domElement, AttrName, name); + SetAttribute(domElement, AttrX, QString().setNum(toMM(p.x()))); + SetAttribute(domElement, AttrY, QString().setNum(toMM(p.y()))); +} + void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color) { namePoint->setBrush(color); @@ -139,7 +154,7 @@ void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color) void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) { - ContextMenu(dialogSinglePoint, this, event, false); + ContextMenu(this, event, false); } void VToolSinglePoint::FullUpdateFromFile() @@ -148,26 +163,6 @@ void VToolSinglePoint::FullUpdateFromFile() RefreshPointGeometry(point); } -void VToolSinglePoint::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QPointF p = dialogSinglePoint->getPoint(); - QString name = dialogSinglePoint->getName(); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, name); - SetAttribute(domElement, AttrX, QString().setNum(toMM(p.x()))); - SetAttribute(domElement, AttrY, QString().setNum(toMM(p.y()))); - //I don't now why but signal does not work. - doc->FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogSinglePoint.clear(); -} - void VToolSinglePoint::ChangedActivDraw(const QString &newName) { if (nameActivDraw == newName) @@ -192,5 +187,5 @@ void VToolSinglePoint::SetFactor(qreal factor) void VToolSinglePoint::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogSinglePoint, this, event, false); + ContextMenu(this, event, false); } diff --git a/src/tools/drawTools/vtoolsinglepoint.h b/src/tools/drawTools/vtoolsinglepoint.h index bb0fb187e..625a2b231 100644 --- a/src/tools/drawTools/vtoolsinglepoint.h +++ b/src/tools/drawTools/vtoolsinglepoint.h @@ -30,7 +30,6 @@ #define VTOOLSINGLEPOINT_H #include "vtoolpoint.h" -#include "../../dialogs/dialogsinglepoint.h" /** * @brief The VToolSinglePoint class tool for creation pattern base point. Obly base point can move. All object @@ -60,11 +59,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. * @param newName new name active pattern peace. @@ -115,11 +109,11 @@ protected: * @param tool tool what me delete. */ virtual void DeleteTool(QGraphicsItem *tool){Q_UNUSED(tool)} -private: /** - * @brief dialogSinglePoint dialog. + * @brief SaveDialog save options into file after change in dialog. */ - QSharedPointer dialogSinglePoint; + virtual void SaveDialog(QDomElement &domElement); +private: /** * @brief setColorLabel change color for label and label line. * @param color new color. diff --git a/src/tools/drawTools/vtoolspline.cpp b/src/tools/drawTools/vtoolspline.cpp index 7fa2c5b38..a8392d7ca 100644 --- a/src/tools/drawTools/vtoolspline.cpp +++ b/src/tools/drawTools/vtoolspline.cpp @@ -28,14 +28,14 @@ #include "vtoolspline.h" #include "../../geometry/vspline.h" +#include "../../dialogs/dialogspline.h" const QString VToolSpline::TagName = QStringLiteral("spline"); const QString VToolSpline::ToolType = QStringLiteral("simple"); VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogSpline(QSharedPointer()), - controlPoints(QVector()) + :VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector()) { ignoreFullUpdate = true; @@ -77,27 +77,32 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, const T void VToolSpline::setDialog() { - Q_ASSERT(dialogSpline.isNull() == false); + Q_CHECK_PTR(dialog); + DialogSpline *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VSpline *spl = VAbstractTool::data.GeometricObject(id); - dialogSpline->setP1(spl->GetP1().id()); - dialogSpline->setP4(spl->GetP4().id()); - dialogSpline->setAngle1(spl->GetAngle1()); - dialogSpline->setAngle2(spl->GetAngle2()); - dialogSpline->setKAsm1(spl->GetKasm1()); - dialogSpline->setKAsm2(spl->GetKasm2()); - dialogSpline->setKCurve(spl->GetKcurve()); + dialogTool->setP1(spl->GetP1().id()); + dialogTool->setP4(spl->GetP4().id()); + dialogTool->setAngle1(spl->GetAngle1()); + dialogTool->setAngle2(spl->GetAngle2()); + dialogTool->setKAsm1(spl->GetKasm1()); + dialogTool->setKAsm2(spl->GetKasm2()); + dialogTool->setKCurve(spl->GetKcurve()); } -void VToolSpline::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolSpline::Create(DialogTool *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(); + Q_CHECK_PTR(dialog); + DialogSpline *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + qint64 p1 = dialogTool->getP1(); + qint64 p4 = dialogTool->getP4(); + qreal kAsm1 = dialogTool->getKAsm1(); + qreal kAsm2 = dialogTool->getKAsm2(); + qreal angle1 = dialogTool->getAngle1(); + qreal angle2 = dialogTool->getAngle2(); + qreal kCurve = dialogTool->getKCurve(); Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -144,44 +149,6 @@ void VToolSpline::FullUpdateFromFile() RefreshGeometry(); } -void VToolSpline::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - VPointF point1 = *VAbstractTool::data.GeometricObject(dialogSpline->getP1()); - VPointF point4 = *VAbstractTool::data.GeometricObject(dialogSpline->getP4()); - VSpline spl = VSpline (point1, point4, dialogSpline->getAngle1(), dialogSpline->getAngle2(), - dialogSpline->getKAsm1(), dialogSpline->getKAsm2(), dialogSpline->getKCurve()); - - 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); - - spl = VSpline (point1, controlPoints[0]->pos(), controlPoints[1]->pos(), point4, dialogSpline->getKCurve()); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrPoint1, spl.GetP1().id()); - SetAttribute(domElement, AttrPoint4, spl.GetP4().id()); - SetAttribute(domElement, AttrAngle1, spl.GetAngle1()); - SetAttribute(domElement, AttrAngle2, spl.GetAngle2()); - SetAttribute(domElement, AttrKAsm1, spl.GetKasm1()); - SetAttribute(domElement, AttrKAsm2, spl.GetKasm2()); - SetAttribute(domElement, AttrKCurve, spl.GetKcurve()); - emit FullUpdateTree(); - emit toolhaveChange(); - } - } - dialogSpline.clear(); -} - void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position, const QPointF &pos) { @@ -205,12 +172,13 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const Sp SetAttribute(domElement, AttrKAsm2, QString().setNum(spl.GetKasm2())); SetAttribute(domElement, AttrKCurve, QString().setNum(spl.GetKcurve())); emit FullUpdateTree(); + emit toolhaveChange(); } } void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogSpline, this, event); + ContextMenu(this, event); } void VToolSpline::AddToFile() @@ -306,6 +274,39 @@ void VToolSpline::keyReleaseEvent(QKeyEvent *event) QGraphicsItem::keyReleaseEvent ( event ); } +void VToolSpline::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogSpline *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + + VPointF point1 = *VAbstractTool::data.GeometricObject(dialogTool->getP1()); + VPointF point4 = *VAbstractTool::data.GeometricObject(dialogTool->getP4()); + VSpline spl = VSpline (point1, point4, dialogTool->getAngle1(), dialogTool->getAngle2(), + dialogTool->getKAsm1(), dialogTool->getKAsm2(), dialogTool->getKCurve()); + + 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); + + spl = VSpline (point1, controlPoints[0]->pos(), controlPoints[1]->pos(), point4, dialogTool->getKCurve()); + + SetAttribute(domElement, AttrPoint1, spl.GetP1().id()); + SetAttribute(domElement, AttrPoint4, spl.GetP4().id()); + SetAttribute(domElement, AttrAngle1, spl.GetAngle1()); + SetAttribute(domElement, AttrAngle2, spl.GetAngle2()); + SetAttribute(domElement, AttrKAsm1, spl.GetKasm1()); + SetAttribute(domElement, AttrKAsm2, spl.GetKasm2()); + SetAttribute(domElement, AttrKCurve, spl.GetKcurve()); +} + void VToolSpline::RefreshGeometry() { this->setPen(QPen(currentColor, widthHairLine/factor)); diff --git a/src/tools/drawTools/vtoolspline.h b/src/tools/drawTools/vtoolspline.h index db1dac16a..fc8350083 100644 --- a/src/tools/drawTools/vtoolspline.h +++ b/src/tools/drawTools/vtoolspline.h @@ -31,7 +31,6 @@ #include "vdrawtool.h" #include -#include "../../dialogs/dialogspline.h" #include "../../widgets/vcontrolpointspline.h" #include "../../geometry/vsplinepath.h" @@ -63,8 +62,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -107,11 +105,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile (); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui ( int result ); /** * @brief ControlPointChangePosition handle change position control point. * @param indexSpline position spline in spline list. @@ -182,11 +175,11 @@ protected: * @param event key release event. */ virtual void keyReleaseEvent(QKeyEvent * event); -private: /** - * @brief dialogSpline dialog. + * @brief SaveDialog save options into file after change in dialog. */ - QSharedPointer dialogSpline; + virtual void SaveDialog(QDomElement &domElement); +private: /** * @brief controlPoints list pointers of control points. */ diff --git a/src/tools/drawTools/vtoolsplinepath.cpp b/src/tools/drawTools/vtoolsplinepath.cpp index d13d28f6b..3b0e85689 100644 --- a/src/tools/drawTools/vtoolsplinepath.cpp +++ b/src/tools/drawTools/vtoolsplinepath.cpp @@ -27,14 +27,14 @@ *************************************************************************/ #include "vtoolsplinepath.h" +#include "../../dialogs/dialogsplinepath.h" const QString VToolSplinePath::TagName = QStringLiteral("spline"); const QString VToolSplinePath::ToolType = QStringLiteral("path"); VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogSplinePath(QSharedPointer()), - controlPoints(QVector()) + :VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector()) { ignoreFullUpdate = true; const VSplinePath *splPath = data->GeometricObject(id); @@ -77,15 +77,19 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, void VToolSplinePath::setDialog() { - Q_ASSERT(dialogSplinePath.isNull() == false); + Q_CHECK_PTR(dialog); + DialogSplinePath *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VSplinePath *splPath = VAbstractTool::data.GeometricObject(id); - dialogSplinePath->SetPath(*splPath); + dialogTool->SetPath(*splPath); } -void VToolSplinePath::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data) +void VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - VSplinePath *path = new VSplinePath(dialog->GetPath()); + Q_CHECK_PTR(dialog); + DialogSplinePath *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + VSplinePath *path = new VSplinePath(dialogTool->GetPath()); Q_CHECK_PTR(path); for (qint32 i = 0; i < path->CountPoint(); ++i) { @@ -129,45 +133,6 @@ void VToolSplinePath::FullUpdateFromFile() RefreshGeometry(); } -void VToolSplinePath::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - VSplinePath splPath = dialogSplinePath->GetPath(); - for (qint32 i = 1; i<=splPath.Count(); ++i) - { - VSpline spl = splPath.GetSpline(i); - 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); - - spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(), - splPath.getKCurve()); - CorectControlPoints(spl, splPath, i); - CorectControlPoints(spl, splPath, i); - - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve())); - UpdatePathPoint(domElement, splPath); - emit FullUpdateTree(); - emit toolhaveChange(); - } - - } - } - dialogSplinePath.clear(); -} - void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position, const QPointF &pos) { @@ -189,6 +154,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve())); UpdatePathPoint(domElement, splPath); emit FullUpdateTree(); + emit toolhaveChange(); } } @@ -256,7 +222,7 @@ void VToolSplinePath::SetFactor(qreal factor) void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogSplinePath, this, event); + ContextMenu(this, event); } void VToolSplinePath::AddToFile() @@ -382,6 +348,38 @@ void VToolSplinePath::keyReleaseEvent(QKeyEvent *event) QGraphicsItem::keyReleaseEvent ( event ); } +void VToolSplinePath::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogSplinePath *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + + VSplinePath splPath = dialogTool->GetPath(); + for (qint32 i = 1; i<=splPath.Count(); ++i) + { + VSpline spl = splPath.GetSpline(i); + 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); + + spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(), + splPath.getKCurve()); + CorectControlPoints(spl, splPath, i); + CorectControlPoints(spl, splPath, i); + } + + SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve())); + UpdatePathPoint(domElement, splPath); +} + void VToolSplinePath::RefreshGeometry() { this->setPen(QPen(currentColor, widthHairLine/factor)); diff --git a/src/tools/drawTools/vtoolsplinepath.h b/src/tools/drawTools/vtoolsplinepath.h index 203b6085d..a905f4cf8 100644 --- a/src/tools/drawTools/vtoolsplinepath.h +++ b/src/tools/drawTools/vtoolsplinepath.h @@ -31,7 +31,6 @@ #include "vdrawtool.h" #include -#include "../../dialogs/dialogsplinepath.h" #include "../../widgets/vcontrolpointspline.h" /** @@ -62,8 +61,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -99,11 +97,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief ControlPointChangePosition handle change position control point. * @param indexSpline position spline in spline list. @@ -174,11 +167,11 @@ protected: * @param event key release event. */ virtual void keyReleaseEvent(QKeyEvent * event); -private: /** - * @brief dialogSplinePath dialog. + * @brief SaveDialog save options into file after change in dialog. */ - QSharedPointer dialogSplinePath; + virtual void SaveDialog(QDomElement &domElement); +private: /** * @brief controlPoints list pointers of control points. */ diff --git a/src/tools/drawTools/vtooltriangle.cpp b/src/tools/drawTools/vtooltriangle.cpp index d8c4c6b6d..b980b8d8d 100644 --- a/src/tools/drawTools/vtooltriangle.cpp +++ b/src/tools/drawTools/vtooltriangle.cpp @@ -27,6 +27,7 @@ *************************************************************************/ #include "vtooltriangle.h" +#include "../../dialogs/dialogtriangle.h" const QString VToolTriangle::ToolType = QStringLiteral("triangle"); @@ -34,7 +35,7 @@ VToolTriangle::VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 & const qint64 &axisP1Id, const qint64 &axisP2Id, const qint64 &firstPointId, const qint64 &secondPointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) :VToolPoint(doc, data, id, parent), axisP1Id(axisP1Id), axisP2Id(axisP2Id), firstPointId(firstPointId), - secondPointId(secondPointId), dialogTriangle(QSharedPointer()) + secondPointId(secondPointId) { ignoreFullUpdate = true; if (typeCreation == Tool::FromGui) @@ -49,23 +50,28 @@ VToolTriangle::VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 & void VToolTriangle::setDialog() { - Q_ASSERT(dialogTriangle.isNull() == false); + Q_CHECK_PTR(dialog); + DialogTriangle *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); const VPointF *p = VAbstractTool::data.GeometricObject(id); - dialogTriangle->setAxisP1Id(axisP1Id, id); - dialogTriangle->setAxisP2Id(axisP2Id, id); - dialogTriangle->setFirstPointId(firstPointId, id); - dialogTriangle->setSecondPointId(secondPointId, id); - dialogTriangle->setPointName(p->name()); + dialogTool->setAxisP1Id(axisP1Id, id); + dialogTool->setAxisP2Id(axisP2Id, id); + dialogTool->setFirstPointId(firstPointId, id); + dialogTool->setSecondPointId(secondPointId, id); + dialogTool->setPointName(p->name()); } -void VToolTriangle::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, +void VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - qint64 axisP1Id = dialog->getAxisP1Id(); - qint64 axisP2Id = dialog->getAxisP2Id(); - qint64 firstPointId = dialog->getFirstPointId(); - qint64 secondPointId = dialog->getSecondPointId(); - QString pointName = dialog->getPointName(); + Q_CHECK_PTR(dialog); + DialogTriangle *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + qint64 axisP1Id = dialogTool->getAxisP1Id(); + qint64 axisP2Id = dialogTool->getAxisP2Id(); + qint64 firstPointId = dialogTool->getFirstPointId(); + qint64 secondPointId = dialogTool->getSecondPointId(); + QString pointName = dialogTool->getPointName(); Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -165,29 +171,9 @@ void VToolTriangle::FullUpdateFromFile() VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); } -void VToolTriangle::FullUpdateFromGui(int result) -{ - if (result == QDialog::Accepted) - { - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrName, dialogTriangle->getPointName()); - SetAttribute(domElement, AttrAxisP1, QString().setNum(dialogTriangle->getAxisP1Id())); - SetAttribute(domElement, AttrAxisP2, QString().setNum(dialogTriangle->getAxisP2Id())); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTriangle->getFirstPointId())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTriangle->getSecondPointId())); - emit FullUpdateTree(); - emit toolhaveChange(); - } - - } - dialogTriangle.clear(); -} - void VToolTriangle::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogTriangle, this, event); + ContextMenu(this, event); } void VToolTriangle::RemoveReferens() @@ -200,7 +186,7 @@ void VToolTriangle::RemoveReferens() void VToolTriangle::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(dialogTriangle, this, event); + ContextMenu(this, event); } void VToolTriangle::AddToFile() @@ -237,3 +223,15 @@ void VToolTriangle::RefreshDataInFile() SetAttribute(domElement, AttrSecondPoint, secondPointId); } } + +void VToolTriangle::SaveDialog(QDomElement &domElement) +{ + Q_CHECK_PTR(dialog); + DialogTriangle *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + SetAttribute(domElement, AttrName, dialogTool->getPointName()); + SetAttribute(domElement, AttrAxisP1, QString().setNum(dialogTool->getAxisP1Id())); + SetAttribute(domElement, AttrAxisP2, QString().setNum(dialogTool->getAxisP2Id())); + SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); + SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); +} diff --git a/src/tools/drawTools/vtooltriangle.h b/src/tools/drawTools/vtooltriangle.h index d23c6f051..ba2f76bf4 100644 --- a/src/tools/drawTools/vtooltriangle.h +++ b/src/tools/drawTools/vtooltriangle.h @@ -30,7 +30,6 @@ #define VTOOLTRIANGLE_H #include "vtoolpoint.h" -#include "../../dialogs/dialogtriangle.h" /** * @brief The VToolTriangle class tool for what find point intersection two foots right triangle. @@ -65,8 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -103,11 +101,6 @@ public slots: * @brief FullUpdateFromFile update tool data form file. */ virtual void FullUpdateFromFile(); - /** - * @brief FullUpdateFromGui refresh tool data from change options. - * @param result result working dialog. - */ - virtual void FullUpdateFromGui(int result); /** * @brief ShowContextMenu show context menu. * @param event context menu event. @@ -131,6 +124,10 @@ protected: * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ virtual void RefreshDataInFile(); + /** + * @brief SaveDialog save options into file after change in dialog. + */ + virtual void SaveDialog(QDomElement &domElement); private: Q_DISABLE_COPY(VToolTriangle) /** @@ -149,10 +146,6 @@ private: * @brief secondPointId id second triangle point, what lies on the hypotenuse. */ qint64 secondPointId; - /** - * @brief dialogTriangle dialog. - */ - QSharedPointer dialogTriangle; }; #endif // VTOOLTRIANGLE_H diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 6a389b0f9..6a0e26e1d 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -42,8 +42,7 @@ const QString VToolDetail::NodeTypeModeling = QStringLiteral("Modeling"); VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, const Tool::Sources &typeCreation, VMainGraphicsScene *scene, QGraphicsItem *parent) - :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialogDetail(QSharedPointer()), - sceneDetails(scene) + :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialog(0), sceneDetails(scene) { VDetail detail = data->GetDetail(id); for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) @@ -80,17 +79,26 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, } } -void VToolDetail::setDialog() +VToolDetail::~VToolDetail() { - Q_ASSERT(dialogDetail.isNull() == false); - VDetail detail = VAbstractTool::data.GetDetail(id); - dialogDetail->setDetails(detail); + delete dialog; } -void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data) +void VToolDetail::setDialog() { - VDetail detail = dialog->getDetails(); + Q_CHECK_PTR(dialog); + DialogDetail *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + VDetail detail = VAbstractTool::data.GetDetail(id); + dialogTool->setDetails(detail); +} + +void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +{ + Q_CHECK_PTR(dialog); + DialogDetail *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + VDetail detail = dialogTool->getDetails(); VDetail det; for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) { @@ -176,7 +184,10 @@ void VToolDetail::FullUpdateFromGui(int result) QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - VDetail det = dialogDetail->getDetails(); + Q_CHECK_PTR(dialog); + DialogDetail *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + VDetail det = dialogTool->getDetails(); SetAttribute(domElement, AttrName, det.getName()); SetAttribute(domElement, AttrSupplement, QString().setNum(det.getSeamAllowance())); SetAttribute(domElement, AttrClosed, QString().setNum(det.getClosed())); @@ -201,7 +212,8 @@ void VToolDetail::FullUpdateFromGui(int result) emit toolhaveChange(); } } - dialogDetail.clear(); + delete dialog; + dialog = 0; } void VToolDetail::AddToFile() @@ -322,12 +334,14 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) QAction *selectedAction = menu.exec(event->screenPos()); if (selectedAction == actionOption) { - dialogDetail = QSharedPointer(new DialogDetail(getData())); + QGraphicsScene *scene = this->scene(); + QList list = scene->views(); + dialog = new DialogDetail(getData(), list.first()); connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject, - dialogDetail.data(), &DialogDetail::ChoosedObject); - connect(dialogDetail.data(), &DialogDetail::DialogClosed, this, &VToolDetail::FullUpdateFromGui); + dialog, &DialogTool::ChoosedObject); + connect(dialog, &DialogTool::DialogClosed, this, &VToolDetail::FullUpdateFromGui); setDialog(); - dialogDetail->show(); + dialog->show(); } if (selectedAction == actionRemove) { diff --git a/src/tools/vtooldetail.h b/src/tools/vtooldetail.h index f676e28c5..2ae074f72 100644 --- a/src/tools/vtooldetail.h +++ b/src/tools/vtooldetail.h @@ -40,22 +40,22 @@ class VToolDetail: public VAbstractTool, public QGraphicsPathItem { Q_OBJECT public: - /** - * @brief VToolDetail constructor. - * @param doc dom document container - * @param data container with variables - * @param id object id in container - * @param typeCreation way we create this tool. - * @param scene pointer to scene. - * @param parent parent object - */ - VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, - const Tool::Sources &typeCreation, VMainGraphicsScene *scene, - QGraphicsItem * parent = 0); + /** + * @brief VToolDetail constructor. + * @param doc dom document container + * @param data container with variables + * @param id object id in container + * @param typeCreation way we create this tool. + * @param scene pointer to scene. + * @param parent parent object + */ + VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, const Tool::Sources &typeCreation, + VMainGraphicsScene *scene, QGraphicsItem * parent = 0); + ~VToolDetail(); /** * @brief setDialog set dialog when user want change tool option. */ - virtual void setDialog(); + virtual void setDialog(); template /** * @brief CreateNode create new node for detail. @@ -79,8 +79,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -91,94 +90,94 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 &_id, const VDetail &newDetail, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation); - static const QString TagName; - static const QString TagNode; - static const QString AttrSupplement; - static const QString AttrClosed; - static const QString AttrWidth; - static const QString AttrIdObject; - static const QString AttrNodeType; - static const QString NodeTypeContour; - static const QString NodeTypeModeling; + static void Create(const qint64 &_id, const VDetail &newDetail, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static const QString TagName; + static const QString TagNode; + static const QString AttrSupplement; + static const QString AttrClosed; + static const QString AttrWidth; + static const QString AttrIdObject; + static const QString AttrNodeType; + static const QString NodeTypeContour; + static const QString NodeTypeModeling; /** * @brief Remove full delete detail. */ - void Remove(); + void Remove(); public slots: /** * @brief FullUpdateFromFile update tool data form file. */ - virtual void FullUpdateFromFile (); + virtual void FullUpdateFromFile (); /** * @brief FullUpdateFromGui refresh tool data after change in options. * @param result keep result working dialog. */ - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromGui(int result); protected: /** * @brief AddToFile add tag with informations about tool into file. */ - virtual void AddToFile (); + virtual void AddToFile (); /** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. */ - virtual void RefreshDataInFile(); + virtual void RefreshDataInFile(); /** * @brief itemChange handle detail change. * @param change change * @param value value * @return new value. */ - virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); + virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); /** * @brief mouseReleaseEvent handle mouse release events. * @param event mouse release event. */ - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); /** * @brief contextMenuEvent handle context menu events. * @param event context menu event. */ - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); /** * @brief RemoveReferens decrement value of reference. */ - virtual void RemoveReferens(); + virtual void RemoveReferens(); /** * @brief keyReleaseEvent handle key release events. * @param event key release event. */ - virtual void keyReleaseEvent(QKeyEvent * event); + virtual void keyReleaseEvent(QKeyEvent * event); private: Q_DISABLE_COPY(VToolDetail) /** - * @brief dialogDetail dialog. + * @brief dialog dialog options. */ - QSharedPointer dialogDetail; + DialogTool *dialog; /** * @brief sceneDetails pointer to the scene. */ - VMainGraphicsScene *sceneDetails; + VMainGraphicsScene *sceneDetails; /** * @brief RefreshGeometry refresh item on scene. */ - void RefreshGeometry (); + void RefreshGeometry (); /** * @brief AddNode add node to the file. * @param domElement tag in xml tree. * @param node node of detail. */ - void AddNode(QDomElement &domElement, const VNodeDetail &node); + void AddNode(QDomElement &domElement, const VNodeDetail &node); template /** * @brief InitTool initial node item on scene * @param scene pointer to scene. * @param node node of detail. */ - void InitTool(VMainGraphicsScene *scene, const VNodeDetail &node); + void InitTool(VMainGraphicsScene *scene, const VNodeDetail &node); }; #endif // VTOOLDETAIL_H diff --git a/src/tools/vtooluniondetails.cpp b/src/tools/vtooluniondetails.cpp index 2a17f780a..dfd52c65b 100644 --- a/src/tools/vtooluniondetails.cpp +++ b/src/tools/vtooluniondetails.cpp @@ -402,14 +402,16 @@ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const q point->setY(line.p2().y()); } -void VToolUnionDetails::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data) +void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - VDetail d1 = data->GetDetail(dialog->getD1()); - VDetail d2 = data->GetDetail(dialog->getD2()); - ptrdiff_t indexD1 = dialog->getIndexD1(); - ptrdiff_t indexD2 = dialog->getIndexD2(); - Create(0, d1, d2, dialog->getD1(), dialog->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse, + Q_CHECK_PTR(dialog); + DialogUnionDetails *dialogTool = qobject_cast(dialog); + Q_CHECK_PTR(dialogTool); + VDetail d1 = data->GetDetail(dialogTool->getD1()); + VDetail d2 = data->GetDetail(dialogTool->getD2()); + ptrdiff_t indexD1 = dialogTool->getIndexD1(); + ptrdiff_t indexD2 = dialogTool->getIndexD2(); + Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse, Tool::FromGui); } diff --git a/src/tools/vtooluniondetails.h b/src/tools/vtooluniondetails.h index d7c9bbabf..98c4b3eac 100644 --- a/src/tools/vtooluniondetails.h +++ b/src/tools/vtooluniondetails.h @@ -64,8 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet.