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

View File

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

View File

@ -48,7 +48,7 @@ AddToCalc::~AddToCalc()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void AddToCalc::undo() void AddToCalc::undo()
{ {
doc->ChangeActivPP(nameActivDraw); doc->ChangeActivPP(nameActivDraw);//User will not see this change
doc->setCursor(cursor); doc->setCursor(cursor);
QDomElement calcElement; QDomElement calcElement;
@ -80,12 +80,13 @@ void AddToCalc::undo()
} }
emit NeedFullParsing(); emit NeedFullParsing();
VAbstractTool::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); VAbstractTool::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void AddToCalc::redo() void AddToCalc::redo()
{ {
doc->ChangeActivPP(nameActivDraw); doc->ChangeActivPP(nameActivDraw);//User will not see this change
doc->setCursor(cursor); doc->setCursor(cursor);
QDomElement calcElement; QDomElement calcElement;
@ -118,3 +119,14 @@ void AddToCalc::redo()
RedoFullParsing(); RedoFullParsing();
VAbstractTool::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); 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 ~AddToCalc();
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();
protected:
virtual void RedoFullParsing();
private: private:
Q_DISABLE_COPY(AddToCalc) Q_DISABLE_COPY(AddToCalc)
const QString nameActivDraw; const QString nameActivDraw;

View File

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

View File

@ -44,6 +44,7 @@ private:
Q_DISABLE_COPY(DelTool) Q_DISABLE_COPY(DelTool)
QDomNode parentNode; QDomNode parentNode;
quint32 siblingId; quint32 siblingId;
const QString nameActivDraw;
}; };
#endif // DELTOOL_H #endif // DELTOOL_H

View File

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

View File

@ -64,7 +64,7 @@ protected:
VPattern *doc; VPattern *doc;
quint32 nodeId; quint32 nodeId;
bool redoFlag; bool redoFlag;
void RedoFullParsing(); virtual void RedoFullParsing();
void UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const; void UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const;
private: private:
Q_DISABLE_COPY(VUndoCommand) Q_DISABLE_COPY(VUndoCommand)

View File

@ -37,7 +37,6 @@ extern const int DEBUG_VERSION;
extern const QString APP_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. // Change version number in version.cpp also.
#define VER_FILEVERSION 0,2,8,0 #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 Minor() const;
QString Patch() const; QString Patch() const;
static void RemoveAllChild(QDomElement &domElement); static void RemoveAllChild(QDomElement &domElement);
QDomNode ParentNodeById(const quint32 &nodeId);
QDomElement CloneNodeById(const quint32 &nodeId);
QDomElement NodeById(const quint32 &nodeId);
protected: protected:
/** @brief data container with data. */ /** @brief data container with data. */
VContainer *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; QVector<VToolRecord> historyPP;
for (qint32 i = 0; i< history.size(); ++i) for (qint32 i = 0; i< history.size(); ++i)
@ -2755,3 +2755,45 @@ QVector<VToolRecord> VPattern::getLocalHistory()
} }
return historyPP; 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(); QHash<quint32, VDataTool*>* getTools();
VDataTool* getTool(const quint32 &id); VDataTool* getTool(const quint32 &id);
QVector<VToolRecord> *getHistory(); QVector<VToolRecord> *getHistory();
QVector<VToolRecord> getLocalHistory(); QVector<VToolRecord> getLocalHistory() const;
quint32 getCursor() const; quint32 getCursor() const;
void setCursor(const quint32 &value); void setCursor(const quint32 &value);
void setCurrentData(); void setCurrentData();
@ -183,6 +183,8 @@ public:
void SetVersion(); void SetVersion();
QString GenerateLabel(const LabelType &type)const; QString GenerateLabel(const LabelType &type)const;
quint32 SiblingNodeId(const quint32 &nodeId) const;
signals: signals:
/** /**
* @brief ChangedActivDraw change active pattern peace. * @brief ChangedActivDraw change active pattern peace.
@ -219,6 +221,7 @@ signals:
void UndoCommand(); void UndoCommand();
void SetEnabledGUI(bool enabled); void SetEnabledGUI(bool enabled);
void CheckLayout(); void CheckLayout();
void SetCurrentPP(const QString &patterPiece);
public slots: public slots:
void LiteParseTree(const Document &parse); void LiteParseTree(const Document &parse);
void haveLiteChange(); void haveLiteChange();