diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 4c2690c71..4583238f2 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -166,6 +166,7 @@ void MainWindow::ActionNewPP() { return; } + path = doc->MPath(); } if (doc->appendPP(patternPieceName) == false) { @@ -195,7 +196,10 @@ void MainWindow::ActionNewPP() if ( index != -1 ) { // -1 for not found comboBoxDraws->setCurrentIndex(index); - currentDrawChanged( index ); + } + else + { + comboBoxDraws->setCurrentIndex(0); } connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::currentDrawChanged); @@ -1590,8 +1594,13 @@ void MainWindow::FullParseFile() qint32 index = comboBoxDraws->findText(patternPiece); if ( index != -1 ) { // -1 for not found - comboBoxDraws->setCurrentIndex(index); + currentDrawChanged(index); } + else + { + currentDrawChanged(0); + } + if (comboBoxDraws->count() > 0) { SetEnableTool(true); diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index d138e71ce..ec15a3987 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -98,9 +98,9 @@ protected: QMenu menu; QAction *actionOption = menu.addAction(tr("Options")); QAction *actionRemove = nullptr; + actionRemove = menu.addAction(tr("Delete")); if (showRemove) { - actionRemove = menu.addAction(tr("Delete")); if (_referens > 1) { actionRemove->setEnabled(false); @@ -110,6 +110,11 @@ protected: actionRemove->setEnabled(true); } } + else + { + actionRemove->setEnabled(false); + } + QAction *selectedAction = menu.exec(event->screenPos()); if (selectedAction == actionOption) { @@ -130,12 +135,9 @@ protected: dialog->show(); } - if (showRemove) + if (selectedAction == actionRemove) { - if (selectedAction == actionRemove) - { - DeleteTool(); - } + DeleteTool(); } } } diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index db965984f..52d624d44 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -34,6 +34,8 @@ #include "../../undocommands/deletepatternpiece.h" #include "../../geometry/vpointf.h" +#include + const QString VToolSinglePoint::ToolType = QStringLiteral("single"); //--------------------------------------------------------------------------------------------------------------------- @@ -185,8 +187,18 @@ void VToolSinglePoint::decrementReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::DeleteTool() { - DeletePatternPiece *deletePP = new DeletePatternPiece(doc, namePP); - connect(deletePP, &DeletePatternPiece::ClearScene, doc, &VPattern::ClearScene); + QMessageBox msgBox; + msgBox.setText(tr("Confirm the deletion.")); + msgBox.setInformativeText(tr("Do you really want delete?")); + msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setIcon(QMessageBox::Question); + if (msgBox.exec() == QMessageBox::Cancel) + { + return; + } + + DeletePatternPiece *deletePP = new DeletePatternPiece(doc, nameActivDraw); connect(deletePP, &DeletePatternPiece::NeedFullParsing, doc, &VPattern::NeedFullParsing); qApp->getUndoStack()->push(deletePP); } @@ -225,7 +237,14 @@ void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color) */ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) { - ContextMenu(this, event); + if (doc->CountPP() > 1) + { + ContextMenu(this, event); + } + else + { + ContextMenu(this, event, false); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -277,5 +296,12 @@ void VToolSinglePoint::SetFactor(qreal factor) */ void VToolSinglePoint::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event, false); + if (doc->CountPP() > 1) + { + ContextMenu(this, event); + } + else + { + ContextMenu(this, event, false); + } } diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index 99fdfaead..a36388202 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -40,8 +40,7 @@ class VToolSinglePoint : public VToolPoint Q_OBJECT public: VToolSinglePoint (VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - const QString &namePP = QString(), const QString &mPath = QString(), - QGraphicsItem * parent = nullptr ); + const QString &namePP, const QString &mPath, QGraphicsItem * parent = nullptr ); virtual void setDialog(); static const QString ToolType; public slots: @@ -60,10 +59,6 @@ protected: virtual void RefreshDataInFile(); QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void decrementReferens(); - /** - * @brief DeleteTool delete tool from file and scene. This tool can't be deleted by now. - * @param tool tool what me delete. - */ virtual void DeleteTool(); virtual void SaveDialog(QDomElement &domElement); private: diff --git a/src/app/undocommands/addpatternpiece.cpp b/src/app/undocommands/addpatternpiece.cpp index 8c1d41bd8..915e72b11 100644 --- a/src/app/undocommands/addpatternpiece.cpp +++ b/src/app/undocommands/addpatternpiece.cpp @@ -34,6 +34,9 @@ AddPatternPiece::AddPatternPiece(const QDomElement &xml, VPattern *doc, const QS QUndoCommand *parent) : QObject(), QUndoCommand(parent), xml(xml), doc(doc), namePP(namePP), redoFlag(false), mPath(mPath) { + Q_ASSERT(xml.isNull() == false); + Q_ASSERT(namePP.isEmpty() == false); + Q_ASSERT(mPath.isEmpty() == false); setText(tr("Add pattern piece %1").arg(namePP)); } @@ -44,7 +47,7 @@ AddPatternPiece::~AddPatternPiece() //--------------------------------------------------------------------------------------------------------------------- void AddPatternPiece::undo() { - if (CountPP() <= 1) + if (doc->CountPP() <= 1) { emit ClearScene(); } @@ -60,7 +63,7 @@ void AddPatternPiece::undo() //--------------------------------------------------------------------------------------------------------------------- void AddPatternPiece::redo() { - if (CountPP() == 0 && mPath.isEmpty() == false) + if (doc->CountPP() == 0 && mPath.isEmpty() == false) { doc->CreateEmptyFile(mPath); } @@ -75,16 +78,3 @@ void AddPatternPiece::redo() } redoFlag = true; } - -//--------------------------------------------------------------------------------------------------------------------- -int AddPatternPiece::CountPP() -{ - QDomElement rootElement = doc->documentElement(); - if (rootElement.isNull()) - { - return 0; - } - - const QDomNodeList elements = rootElement.elementsByTagName( VPattern::TagDraw ); - return elements.count(); -} diff --git a/src/app/undocommands/addpatternpiece.h b/src/app/undocommands/addpatternpiece.h index 8267cb64e..661d7de92 100644 --- a/src/app/undocommands/addpatternpiece.h +++ b/src/app/undocommands/addpatternpiece.h @@ -53,7 +53,6 @@ private: QString namePP; bool redoFlag; QString mPath; - int CountPP(); }; #endif // ADDPATTERNPIECE_H diff --git a/src/app/undocommands/deletepatternpiece.cpp b/src/app/undocommands/deletepatternpiece.cpp index a04508023..15d55da60 100644 --- a/src/app/undocommands/deletepatternpiece.cpp +++ b/src/app/undocommands/deletepatternpiece.cpp @@ -50,42 +50,19 @@ DeletePatternPiece::~DeletePatternPiece() //--------------------------------------------------------------------------------------------------------------------- void DeletePatternPiece::undo() { - if (CountPP() == 0) - { - doc->CreateEmptyFile(mPath); - } QDomElement rootElement = doc->documentElement(); rootElement.insertAfter(patternPiece, previousNode); emit NeedFullParsing(); + doc->ChangedActivPP(namePP); } //--------------------------------------------------------------------------------------------------------------------- void DeletePatternPiece::redo() -{ - if (CountPP() <= 1) - { - emit ClearScene(); - } - else - { - QDomElement rootElement = doc->documentElement(); - QDomElement patternPiece = doc->GetPPElement(namePP); - rootElement.removeChild(patternPiece); - emit NeedFullParsing(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -int DeletePatternPiece::CountPP() { QDomElement rootElement = doc->documentElement(); - if (rootElement.isNull()) - { - return 0; - } - - const QDomNodeList elements = rootElement.elementsByTagName( VPattern::TagDraw ); - return elements.count(); + QDomElement patternPiece = doc->GetPPElement(namePP); + rootElement.removeChild(patternPiece); + emit NeedFullParsing(); } diff --git a/src/app/undocommands/deletepatternpiece.h b/src/app/undocommands/deletepatternpiece.h index cc62b0183..fa5d14cd6 100644 --- a/src/app/undocommands/deletepatternpiece.h +++ b/src/app/undocommands/deletepatternpiece.h @@ -43,7 +43,6 @@ public: virtual void undo(); virtual void redo(); signals: - void ClearScene(); void NeedFullParsing(); private: Q_DISABLE_COPY(DeletePatternPiece) @@ -52,7 +51,6 @@ private: QDomElement patternPiece; QString mPath; QDomNode previousNode; - int CountPP(); }; #endif // DELETEPATTERNPIECE_H diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 6b02f4b73..4151e75e7 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -126,15 +126,12 @@ void VPattern::CreateEmptyFile(const QString &tablePath) void VPattern::ChangeActivPP(const QString &name, const Document &parse) { Q_ASSERT_X(name.isEmpty() == false, "ChangeActivPP", "name pattern piece is empty"); - if (this->nameActivDraw != name) + if (CheckNamePP(name)) { - if (CheckNamePP(name)) + this->nameActivDraw = name; + if (parse == Document::FullParse) { - this->nameActivDraw = name; - if (parse == Document::FullParse) - { - emit ChangedActivPP(name); - } + emit ChangedActivPP(name); } } } @@ -194,7 +191,8 @@ bool VPattern::appendPP(const QString &name) } else { - ChangeActivPP(name); + this->nameActivDraw = name; + emit ChangedActivPP(name); } return true; } @@ -338,7 +336,7 @@ void VPattern::setCurrentData() { if (*mode == Draw::Calculation) { - if (patternPieces.size() > 1)//don't need upadate data if we have only one pattern piece + if (CountPP() > 1)//don't need upadate data if we have only one pattern piece { quint32 id = 0; if (history.size() == 0) @@ -985,7 +983,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem } if (parse == Document::FullParse) { - spoint = new VToolSinglePoint(this, data, id, Source::FromFile); + spoint = new VToolSinglePoint(this, data, id, Source::FromFile, nameActivDraw, MPath()); scene->addItem(spoint); connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); @@ -1911,3 +1909,15 @@ QDomElement VPattern::GetPPElement(const QString &name) } return QDomElement(); } + +//--------------------------------------------------------------------------------------------------------------------- +int VPattern::CountPP() const +{ + const QDomElement rootElement = this->documentElement(); + if (rootElement.isNull()) + { + return 0; + } + + return rootElement.elementsByTagName( TagDraw ).count(); +} diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 0b8d3b867..f1497e878 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -109,6 +109,8 @@ public: virtual bool SaveDocument(const QString &fileName); QStringList getPatternPieces() const; QDomElement GetPPElement(const QString &name); + bool CheckNamePP(const QString& name) const; + int CountPP() const; signals: /** * @brief ChangedActivDraw change active pattern peace. @@ -172,7 +174,6 @@ private: VMainGraphicsScene *sceneDraw; VMainGraphicsScene *sceneDetail; - bool CheckNamePP(const QString& name) const; void SetActivPP(const QString& name); void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, const QDomNode& node, const Document &parse);