Undo current pattern piece.

--HG--
branch : develop
This commit is contained in:
dismine 2014-11-10 16:49:39 +02:00
parent ba44e4e84d
commit d8d5fbe646
13 changed files with 132 additions and 76 deletions

View File

@ -115,6 +115,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile);
connect(doc, &VPattern::SetEnabledGUI, this, &MainWindow::SetEnabledGUI);
connect(doc, &VPattern::CheckLayout, this, &MainWindow::Layout);
connect(doc, &VPattern::SetCurrentPP, this, &MainWindow::GlobalChangePP);
qApp->setCurrentDocument(doc);
connect(qApp->getUndoStack(), &QUndoStack::cleanChanged, this, &MainWindow::PatternWasModified);
@ -1484,7 +1485,23 @@ void MainWindow::FullParseFile()
comboBoxDraws->blockSignals(false);
ui->actionPattern_properties->setEnabled(true);
qint32 index = comboBoxDraws->findText(patternPiece);
GlobalChangePP(patternPiece);
if (comboBoxDraws->count() > 0)
{
SetEnableTool(true);
}
else
{
SetEnableTool(false);
}
SetEnableWidgets(true);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::GlobalChangePP(const QString &patternPiece)
{
const qint32 index = comboBoxDraws->findText(patternPiece);
try
{
if ( index != -1 )
@ -1508,19 +1525,8 @@ void MainWindow::FullParseFile()
SetEnabledGUI(false);
return;
}
if (comboBoxDraws->count() > 0)
{
SetEnableTool(true);
}
else
{
SetEnableTool(false);
}
SetEnableWidgets(true);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::SetEnabledGUI(bool enabled)
{

View File

@ -127,6 +127,7 @@ public slots:
void ClickEndVisualization();
void Layout();
void UpdateGradation();
void GlobalChangePP(const QString &patternPiece);
signals:
/**
* @brief ModelChosen emit after calculation all details.

View File

@ -48,7 +48,7 @@ AddToCalc::~AddToCalc()
//---------------------------------------------------------------------------------------------------------------------
void AddToCalc::undo()
{
doc->ChangeActivPP(nameActivDraw);
doc->ChangeActivPP(nameActivDraw);//User will not see this change
doc->setCursor(cursor);
QDomElement calcElement;
@ -80,12 +80,13 @@ void AddToCalc::undo()
}
emit NeedFullParsing();
VAbstractTool::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
}
//---------------------------------------------------------------------------------------------------------------------
void AddToCalc::redo()
{
doc->ChangeActivPP(nameActivDraw);
doc->ChangeActivPP(nameActivDraw);//User will not see this change
doc->setCursor(cursor);
QDomElement calcElement;
@ -118,3 +119,14 @@ void AddToCalc::redo()
RedoFullParsing();
VAbstractTool::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
}
//---------------------------------------------------------------------------------------------------------------------
void AddToCalc::RedoFullParsing()
{
if (redoFlag)
{
emit NeedFullParsing();
doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
}
redoFlag = true;
}

View File

@ -39,6 +39,8 @@ public:
virtual ~AddToCalc();
virtual void undo();
virtual void redo();
protected:
virtual void RedoFullParsing();
private:
Q_DISABLE_COPY(AddToCalc)
const QString nameActivDraw;

View File

@ -33,40 +33,14 @@
//---------------------------------------------------------------------------------------------------------------------
DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID)
: VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID),
nameActivDraw(doc->GetNameActivPP())
{
setText(tr("Delete tool"));
nodeId = id;
QVector<VToolRecord> history = doc->getLocalHistory();
for (qint32 i = 0; i< history.size(); ++i)
{
const VToolRecord tool = history.at(i);
if (nodeId == tool.getId())
{
if (i == 0)
{
siblingId = NULL_ID;
}
else
{
const VToolRecord tool = history.at(i-1);
siblingId = tool.getId();
}
}
}
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
xml = domElement.cloneNode().toElement();
parentNode = domElement.parentNode();
}
else
{
qDebug()<<"Can't get tool by id = "<<nodeId<<Q_FUNC_INFO;
return;
}
siblingId = doc->SiblingNodeId(nodeId);
parentNode = doc->ParentNodeById(nodeId);
xml = doc->CloneNodeById(nodeId);
}
//---------------------------------------------------------------------------------------------------------------------
@ -78,20 +52,14 @@ void DelTool::undo()
{
UndoDeleteAfterSibling(parentNode, siblingId);
emit NeedFullParsing();
doc->SetCurrentPP(nameActivDraw);
}
//---------------------------------------------------------------------------------------------------------------------
void DelTool::redo()
{
QDomElement domElement = doc->elementById(QString().setNum(nodeId));
if (domElement.isElement())
{
parentNode.removeChild(domElement);
emit NeedFullParsing();
}
else
{
qDebug()<<"Can't get tool by id = "<<nodeId<<Q_FUNC_INFO;
return;
}
QDomElement domElement = doc->NodeById(nodeId);
parentNode.removeChild(domElement);
emit NeedFullParsing();
doc->SetCurrentPP(nameActivDraw);
}

View File

@ -42,8 +42,9 @@ public:
virtual void redo();
private:
Q_DISABLE_COPY(DelTool)
QDomNode parentNode;
quint32 siblingId;
QDomNode parentNode;
quint32 siblingId;
const QString nameActivDraw;
};
#endif // DELTOOL_H

View File

@ -59,14 +59,7 @@ void VUndoCommand::UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &s
}
else
{
const QDomElement refElement = doc->elementById(QString().setNum(siblingId));
if (refElement.isElement())
{
parentNode.insertAfter(xml, refElement);
}
else
{
qDebug()<<"Can't find sibling node.";
}
const QDomElement refElement = doc->NodeById(siblingId);
parentNode.insertAfter(xml, refElement);
}
}

View File

@ -60,12 +60,12 @@ signals:
void NeedFullParsing();
void NeedLiteParsing(const Document &parse);
protected:
QDomElement xml;
VPattern *doc;
quint32 nodeId;
bool redoFlag;
void RedoFullParsing();
void UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const;
QDomElement xml;
VPattern *doc;
quint32 nodeId;
bool redoFlag;
virtual void RedoFullParsing();
void UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const;
private:
Q_DISABLE_COPY(VUndoCommand)
};

View File

@ -37,7 +37,6 @@ extern const int DEBUG_VERSION;
extern const QString APP_VERSION;
// Don't forget change version number in manifest file /src/app/share/resources/valentina.exe.manifest.
// Change version number in version.cpp also.
#define VER_FILEVERSION 0,2,8,0

View File

@ -600,3 +600,28 @@ void VDomDocument::RemoveAllChild(QDomElement &domElement)
}
}
}
//---------------------------------------------------------------------------------------------------------------------
QDomNode VDomDocument::ParentNodeById(const quint32 &nodeId)
{
QDomElement domElement = NodeById(nodeId);
return domElement.parentNode();
}
//---------------------------------------------------------------------------------------------------------------------
QDomElement VDomDocument::CloneNodeById(const quint32 &nodeId)
{
QDomElement domElement = NodeById(nodeId);
return domElement.cloneNode().toElement();
}
//---------------------------------------------------------------------------------------------------------------------
QDomElement VDomDocument::NodeById(const quint32 &nodeId)
{
QDomElement domElement = elementById(QString().setNum(nodeId));
if (domElement.isNull() || domElement.isElement() == false)
{
throw VExceptionBadId(tr("Couldn't get node"), nodeId);
}
return domElement;
}

View File

@ -109,6 +109,10 @@ public:
QString Minor() const;
QString Patch() const;
static void RemoveAllChild(QDomElement &domElement);
QDomNode ParentNodeById(const quint32 &nodeId);
QDomElement CloneNodeById(const quint32 &nodeId);
QDomElement NodeById(const quint32 &nodeId);
protected:
/** @brief data container with data. */
VContainer *data;

View File

@ -2741,7 +2741,7 @@ QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const
//---------------------------------------------------------------------------------------------------------------------
QVector<VToolRecord> VPattern::getLocalHistory()
QVector<VToolRecord> VPattern::getLocalHistory() const
{
QVector<VToolRecord> historyPP;
for (qint32 i = 0; i< history.size(); ++i)
@ -2755,3 +2755,45 @@ QVector<VToolRecord> VPattern::getLocalHistory()
}
return historyPP;
}
//---------------------------------------------------------------------------------------------------------------------
quint32 VPattern::SiblingNodeId(const quint32 &nodeId) const
{
quint32 siblingId = NULL_ID;
const QVector<VToolRecord> history = getLocalHistory();
for (qint32 i = 0; i < history.size(); ++i)
{
const VToolRecord tool = history.at(i);
if (nodeId == tool.getId())
{
if (i == 0)
{
siblingId = NULL_ID;
}
else
{
for (qint32 j = i; j > 0; --j)
{
const VToolRecord tool = history.at(j-1);
switch ( tool.getTypeTool() )
{
case Tool::Detail:
case Tool::UnionDetails:
case Tool::NodeArc:
case Tool::NodePoint:
case Tool::NodeSpline:
case Tool::NodeSplinePath:
continue;
break;
default:
siblingId = tool.getId();
j = 0;// break loop
break;
}
}
}
}
}
return siblingId;
}

View File

@ -72,7 +72,7 @@ public:
QHash<quint32, VDataTool*>* getTools();
VDataTool* getTool(const quint32 &id);
QVector<VToolRecord> *getHistory();
QVector<VToolRecord> getLocalHistory();
QVector<VToolRecord> getLocalHistory() const;
quint32 getCursor() const;
void setCursor(const quint32 &value);
void setCurrentData();
@ -183,6 +183,8 @@ public:
void SetVersion();
QString GenerateLabel(const LabelType &type)const;
quint32 SiblingNodeId(const quint32 &nodeId) const;
signals:
/**
* @brief ChangedActivDraw change active pattern peace.
@ -219,6 +221,7 @@ signals:
void UndoCommand();
void SetEnabledGUI(bool enabled);
void CheckLayout();
void SetCurrentPP(const QString &patterPiece);
public slots:
void LiteParseTree(const Document &parse);
void haveLiteChange();