Fix for undo command DeletePatternPiece.
--HG-- branch : feature
This commit is contained in:
parent
d66a4b98fe
commit
cf880a04cd
|
@ -166,6 +166,7 @@ void MainWindow::ActionNewPP()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
path = doc->MPath();
|
||||||
}
|
}
|
||||||
if (doc->appendPP(patternPieceName) == false)
|
if (doc->appendPP(patternPieceName) == false)
|
||||||
{
|
{
|
||||||
|
@ -195,7 +196,10 @@ void MainWindow::ActionNewPP()
|
||||||
if ( index != -1 )
|
if ( index != -1 )
|
||||||
{ // -1 for not found
|
{ // -1 for not found
|
||||||
comboBoxDraws->setCurrentIndex(index);
|
comboBoxDraws->setCurrentIndex(index);
|
||||||
currentDrawChanged( index );
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
comboBoxDraws->setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||||
&MainWindow::currentDrawChanged);
|
&MainWindow::currentDrawChanged);
|
||||||
|
@ -1590,8 +1594,13 @@ void MainWindow::FullParseFile()
|
||||||
qint32 index = comboBoxDraws->findText(patternPiece);
|
qint32 index = comboBoxDraws->findText(patternPiece);
|
||||||
if ( index != -1 )
|
if ( index != -1 )
|
||||||
{ // -1 for not found
|
{ // -1 for not found
|
||||||
comboBoxDraws->setCurrentIndex(index);
|
currentDrawChanged(index);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentDrawChanged(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (comboBoxDraws->count() > 0)
|
if (comboBoxDraws->count() > 0)
|
||||||
{
|
{
|
||||||
SetEnableTool(true);
|
SetEnableTool(true);
|
||||||
|
|
|
@ -98,9 +98,9 @@ protected:
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
QAction *actionOption = menu.addAction(tr("Options"));
|
QAction *actionOption = menu.addAction(tr("Options"));
|
||||||
QAction *actionRemove = nullptr;
|
QAction *actionRemove = nullptr;
|
||||||
|
actionRemove = menu.addAction(tr("Delete"));
|
||||||
if (showRemove)
|
if (showRemove)
|
||||||
{
|
{
|
||||||
actionRemove = menu.addAction(tr("Delete"));
|
|
||||||
if (_referens > 1)
|
if (_referens > 1)
|
||||||
{
|
{
|
||||||
actionRemove->setEnabled(false);
|
actionRemove->setEnabled(false);
|
||||||
|
@ -110,6 +110,11 @@ protected:
|
||||||
actionRemove->setEnabled(true);
|
actionRemove->setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
actionRemove->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
QAction *selectedAction = menu.exec(event->screenPos());
|
QAction *selectedAction = menu.exec(event->screenPos());
|
||||||
if (selectedAction == actionOption)
|
if (selectedAction == actionOption)
|
||||||
{
|
{
|
||||||
|
@ -130,15 +135,12 @@ protected:
|
||||||
|
|
||||||
dialog->show();
|
dialog->show();
|
||||||
}
|
}
|
||||||
if (showRemove)
|
|
||||||
{
|
|
||||||
if (selectedAction == actionRemove)
|
if (selectedAction == actionRemove)
|
||||||
{
|
{
|
||||||
DeleteTool();
|
DeleteTool();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
template <typename Item>
|
template <typename Item>
|
||||||
/**
|
/**
|
||||||
* @brief ShowItem highlight tool.
|
* @brief ShowItem highlight tool.
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
#include "../../undocommands/deletepatternpiece.h"
|
#include "../../undocommands/deletepatternpiece.h"
|
||||||
#include "../../geometry/vpointf.h"
|
#include "../../geometry/vpointf.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
const QString VToolSinglePoint::ToolType = QStringLiteral("single");
|
const QString VToolSinglePoint::ToolType = QStringLiteral("single");
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -185,8 +187,18 @@ void VToolSinglePoint::decrementReferens()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VToolSinglePoint::DeleteTool()
|
void VToolSinglePoint::DeleteTool()
|
||||||
{
|
{
|
||||||
DeletePatternPiece *deletePP = new DeletePatternPiece(doc, namePP);
|
QMessageBox msgBox;
|
||||||
connect(deletePP, &DeletePatternPiece::ClearScene, doc, &VPattern::ClearScene);
|
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);
|
connect(deletePP, &DeletePatternPiece::NeedFullParsing, doc, &VPattern::NeedFullParsing);
|
||||||
qApp->getUndoStack()->push(deletePP);
|
qApp->getUndoStack()->push(deletePP);
|
||||||
}
|
}
|
||||||
|
@ -224,9 +236,16 @@ void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color)
|
||||||
* @param event context menu event.
|
* @param event context menu event.
|
||||||
*/
|
*/
|
||||||
void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event )
|
void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event )
|
||||||
|
{
|
||||||
|
if (doc->CountPP() > 1)
|
||||||
{
|
{
|
||||||
ContextMenu<DialogSinglePoint>(this, event);
|
ContextMenu<DialogSinglePoint>(this, event);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ContextMenu<DialogSinglePoint>(this, event, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
@ -276,6 +295,13 @@ void VToolSinglePoint::SetFactor(qreal factor)
|
||||||
* @param event context menu event.
|
* @param event context menu event.
|
||||||
*/
|
*/
|
||||||
void VToolSinglePoint::ShowContextMenu(QGraphicsSceneContextMenuEvent *event)
|
void VToolSinglePoint::ShowContextMenu(QGraphicsSceneContextMenuEvent *event)
|
||||||
|
{
|
||||||
|
if (doc->CountPP() > 1)
|
||||||
|
{
|
||||||
|
ContextMenu<DialogSinglePoint>(this, event);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
ContextMenu<DialogSinglePoint>(this, event, false);
|
ContextMenu<DialogSinglePoint>(this, event, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -40,8 +40,7 @@ class VToolSinglePoint : public VToolPoint
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
VToolSinglePoint (VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
|
VToolSinglePoint (VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
|
||||||
const QString &namePP = QString(), const QString &mPath = QString(),
|
const QString &namePP, const QString &mPath, QGraphicsItem * parent = nullptr );
|
||||||
QGraphicsItem * parent = nullptr );
|
|
||||||
virtual void setDialog();
|
virtual void setDialog();
|
||||||
static const QString ToolType;
|
static const QString ToolType;
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -60,10 +59,6 @@ protected:
|
||||||
virtual void RefreshDataInFile();
|
virtual void RefreshDataInFile();
|
||||||
QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
|
QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
|
||||||
virtual void decrementReferens();
|
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 DeleteTool();
|
||||||
virtual void SaveDialog(QDomElement &domElement);
|
virtual void SaveDialog(QDomElement &domElement);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -34,6 +34,9 @@ AddPatternPiece::AddPatternPiece(const QDomElement &xml, VPattern *doc, const QS
|
||||||
QUndoCommand *parent)
|
QUndoCommand *parent)
|
||||||
: QObject(), QUndoCommand(parent), xml(xml), doc(doc), namePP(namePP), redoFlag(false), mPath(mPath)
|
: 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));
|
setText(tr("Add pattern piece %1").arg(namePP));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +47,7 @@ AddPatternPiece::~AddPatternPiece()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void AddPatternPiece::undo()
|
void AddPatternPiece::undo()
|
||||||
{
|
{
|
||||||
if (CountPP() <= 1)
|
if (doc->CountPP() <= 1)
|
||||||
{
|
{
|
||||||
emit ClearScene();
|
emit ClearScene();
|
||||||
}
|
}
|
||||||
|
@ -60,7 +63,7 @@ void AddPatternPiece::undo()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void AddPatternPiece::redo()
|
void AddPatternPiece::redo()
|
||||||
{
|
{
|
||||||
if (CountPP() == 0 && mPath.isEmpty() == false)
|
if (doc->CountPP() == 0 && mPath.isEmpty() == false)
|
||||||
{
|
{
|
||||||
doc->CreateEmptyFile(mPath);
|
doc->CreateEmptyFile(mPath);
|
||||||
}
|
}
|
||||||
|
@ -75,16 +78,3 @@ void AddPatternPiece::redo()
|
||||||
}
|
}
|
||||||
redoFlag = true;
|
redoFlag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
int AddPatternPiece::CountPP()
|
|
||||||
{
|
|
||||||
QDomElement rootElement = doc->documentElement();
|
|
||||||
if (rootElement.isNull())
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QDomNodeList elements = rootElement.elementsByTagName( VPattern::TagDraw );
|
|
||||||
return elements.count();
|
|
||||||
}
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ private:
|
||||||
QString namePP;
|
QString namePP;
|
||||||
bool redoFlag;
|
bool redoFlag;
|
||||||
QString mPath;
|
QString mPath;
|
||||||
int CountPP();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADDPATTERNPIECE_H
|
#endif // ADDPATTERNPIECE_H
|
||||||
|
|
|
@ -50,42 +50,19 @@ DeletePatternPiece::~DeletePatternPiece()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DeletePatternPiece::undo()
|
void DeletePatternPiece::undo()
|
||||||
{
|
{
|
||||||
if (CountPP() == 0)
|
|
||||||
{
|
|
||||||
doc->CreateEmptyFile(mPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
QDomElement rootElement = doc->documentElement();
|
QDomElement rootElement = doc->documentElement();
|
||||||
rootElement.insertAfter(patternPiece, previousNode);
|
rootElement.insertAfter(patternPiece, previousNode);
|
||||||
|
|
||||||
emit NeedFullParsing();
|
emit NeedFullParsing();
|
||||||
|
doc->ChangedActivPP(namePP);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DeletePatternPiece::redo()
|
void DeletePatternPiece::redo()
|
||||||
{
|
|
||||||
if (CountPP() <= 1)
|
|
||||||
{
|
|
||||||
emit ClearScene();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
QDomElement rootElement = doc->documentElement();
|
QDomElement rootElement = doc->documentElement();
|
||||||
QDomElement patternPiece = doc->GetPPElement(namePP);
|
QDomElement patternPiece = doc->GetPPElement(namePP);
|
||||||
rootElement.removeChild(patternPiece);
|
rootElement.removeChild(patternPiece);
|
||||||
emit NeedFullParsing();
|
emit NeedFullParsing();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
int DeletePatternPiece::CountPP()
|
|
||||||
{
|
|
||||||
QDomElement rootElement = doc->documentElement();
|
|
||||||
if (rootElement.isNull())
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QDomNodeList elements = rootElement.elementsByTagName( VPattern::TagDraw );
|
|
||||||
return elements.count();
|
|
||||||
}
|
|
||||||
|
|
|
@ -43,7 +43,6 @@ public:
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
signals:
|
signals:
|
||||||
void ClearScene();
|
|
||||||
void NeedFullParsing();
|
void NeedFullParsing();
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(DeletePatternPiece)
|
Q_DISABLE_COPY(DeletePatternPiece)
|
||||||
|
@ -52,7 +51,6 @@ private:
|
||||||
QDomElement patternPiece;
|
QDomElement patternPiece;
|
||||||
QString mPath;
|
QString mPath;
|
||||||
QDomNode previousNode;
|
QDomNode previousNode;
|
||||||
int CountPP();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DELETEPATTERNPIECE_H
|
#endif // DELETEPATTERNPIECE_H
|
||||||
|
|
|
@ -126,8 +126,6 @@ void VPattern::CreateEmptyFile(const QString &tablePath)
|
||||||
void VPattern::ChangeActivPP(const QString &name, const Document &parse)
|
void VPattern::ChangeActivPP(const QString &name, const Document &parse)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(name.isEmpty() == false, "ChangeActivPP", "name pattern piece is empty");
|
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;
|
this->nameActivDraw = name;
|
||||||
|
@ -137,7 +135,6 @@ void VPattern::ChangeActivPP(const QString &name, const Document &parse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
@ -194,7 +191,8 @@ bool VPattern::appendPP(const QString &name)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ChangeActivPP(name);
|
this->nameActivDraw = name;
|
||||||
|
emit ChangedActivPP(name);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -338,7 +336,7 @@ void VPattern::setCurrentData()
|
||||||
{
|
{
|
||||||
if (*mode == Draw::Calculation)
|
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;
|
quint32 id = 0;
|
||||||
if (history.size() == 0)
|
if (history.size() == 0)
|
||||||
|
@ -985,7 +983,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem
|
||||||
}
|
}
|
||||||
if (parse == Document::FullParse)
|
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);
|
scene->addItem(spoint);
|
||||||
connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
||||||
connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor);
|
connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor);
|
||||||
|
@ -1911,3 +1909,15 @@ QDomElement VPattern::GetPPElement(const QString &name)
|
||||||
}
|
}
|
||||||
return QDomElement();
|
return QDomElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int VPattern::CountPP() const
|
||||||
|
{
|
||||||
|
const QDomElement rootElement = this->documentElement();
|
||||||
|
if (rootElement.isNull())
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootElement.elementsByTagName( TagDraw ).count();
|
||||||
|
}
|
||||||
|
|
|
@ -109,6 +109,8 @@ public:
|
||||||
virtual bool SaveDocument(const QString &fileName);
|
virtual bool SaveDocument(const QString &fileName);
|
||||||
QStringList getPatternPieces() const;
|
QStringList getPatternPieces() const;
|
||||||
QDomElement GetPPElement(const QString &name);
|
QDomElement GetPPElement(const QString &name);
|
||||||
|
bool CheckNamePP(const QString& name) const;
|
||||||
|
int CountPP() const;
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* @brief ChangedActivDraw change active pattern peace.
|
* @brief ChangedActivDraw change active pattern peace.
|
||||||
|
@ -172,7 +174,6 @@ private:
|
||||||
VMainGraphicsScene *sceneDraw;
|
VMainGraphicsScene *sceneDraw;
|
||||||
VMainGraphicsScene *sceneDetail;
|
VMainGraphicsScene *sceneDetail;
|
||||||
|
|
||||||
bool CheckNamePP(const QString& name) const;
|
|
||||||
void SetActivPP(const QString& name);
|
void SetActivPP(const QString& name);
|
||||||
void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
|
void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
|
||||||
const QDomNode& node, const Document &parse);
|
const QDomNode& node, const Document &parse);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user