Fix for undo command DeletePatternPiece.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-15 11:04:49 +03:00
parent d66a4b98fe
commit cf880a04cd
10 changed files with 81 additions and 74 deletions

View file

@ -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<void (QComboBox::*)(int)>(&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);

View file

@ -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();
}
}
}

View file

@ -34,6 +34,8 @@
#include "../../undocommands/deletepatternpiece.h"
#include "../../geometry/vpointf.h"
#include <QMessageBox>
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<DialogSinglePoint>(this, event);
if (doc->CountPP() > 1)
{
ContextMenu<DialogSinglePoint>(this, event);
}
else
{
ContextMenu<DialogSinglePoint>(this, event, false);
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -277,5 +296,12 @@ void VToolSinglePoint::SetFactor(qreal factor)
*/
void VToolSinglePoint::ShowContextMenu(QGraphicsSceneContextMenuEvent *event)
{
ContextMenu<DialogSinglePoint>(this, event, false);
if (doc->CountPP() > 1)
{
ContextMenu<DialogSinglePoint>(this, event);
}
else
{
ContextMenu<DialogSinglePoint>(this, event, false);
}
}

View file

@ -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:

View file

@ -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();
}

View file

@ -53,7 +53,6 @@ private:
QString namePP;
bool redoFlag;
QString mPath;
int CountPP();
};
#endif // ADDPATTERNPIECE_H

View file

@ -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();
}

View file

@ -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

View file

@ -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();
}

View file

@ -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);