From 205cca7eecc72b1ceb209aa84b61c2efb779e8d4 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 29 Oct 2014 11:14:36 +0200 Subject: [PATCH] Find neighbor node for undo deletion tool. --HG-- branch : develop --- src/app/dialogs/app/dialoghistory.cpp | 15 +++++---------- src/app/undocommands/deltool.cpp | 23 +++++++++++++++++++++-- src/app/xml/vpattern.cpp | 17 +++++++++++++++++ src/app/xml/vpattern.h | 1 + src/app/xml/vtoolrecord.cpp | 4 ++++ src/app/xml/vtoolrecord.h | 1 + 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/app/dialogs/app/dialoghistory.cpp b/src/app/dialogs/app/dialoghistory.cpp index 39e0a34b6..d32535e67 100644 --- a/src/app/dialogs/app/dialoghistory.cpp +++ b/src/app/dialogs/app/dialoghistory.cpp @@ -150,18 +150,13 @@ void DialogHistory::UpdateHistory() void DialogHistory::FillTable() { ui->tableWidget->clear(); - const QVector *history = doc->getHistory(); - SCASSERT(history != nullptr); + QVector history = doc->getLocalHistory(); qint32 currentRow = -1; qint32 count = 0; - ui->tableWidget->setRowCount(history->size());//Make row count max possible number - for (qint32 i = 0; i< history->size(); ++i) + ui->tableWidget->setRowCount(history.size());//Make row count max possible number + for (qint32 i = 0; i< history.size(); ++i) { - const VToolRecord tool = history->at(i); - if (tool.getNameDraw() != doc->GetNameActivPP()) - { - continue; - } + const VToolRecord tool = history.at(i); const QString historyRecord = Record(tool); if (historyRecord.isEmpty() ==false) { @@ -417,7 +412,7 @@ void DialogHistory::InitialTable() */ void DialogHistory::ShowPoint() { - QVector *history = doc->getHistory(); + const QVector *history = doc->getHistory(); if (history->size()>0) { QTableWidgetItem *item = ui->tableWidget->item(0, 1); diff --git a/src/app/undocommands/deltool.cpp b/src/app/undocommands/deltool.cpp index f7634f82d..b9c072da2 100644 --- a/src/app/undocommands/deltool.cpp +++ b/src/app/undocommands/deltool.cpp @@ -33,10 +33,29 @@ //--------------------------------------------------------------------------------------------------------------------- DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), cursor(doc->getCursor()) + : VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), cursor(NULL_ID) { setText(tr("Delete tool")); nodeId = id; + + QVector history = doc->getLocalHistory(); + for (qint32 i = 0; i< history.size(); ++i) + { + const VToolRecord tool = history.at(i); + if (nodeId == tool.getId()) + { + if (i == 0) + { + cursor = NULL_ID; + } + else + { + const VToolRecord tool = history.at(i-1); + cursor = tool.getId(); + } + } + } + QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { @@ -57,7 +76,7 @@ DelTool::~DelTool() //--------------------------------------------------------------------------------------------------------------------- void DelTool::undo() { - if (cursor <= 0) + if (cursor == NULL_ID) { parentNode.appendChild(xml); } diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 56eebc8aa..3cd182be0 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -2754,3 +2754,20 @@ QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const } return recTool; } + + +//--------------------------------------------------------------------------------------------------------------------- +QVector VPattern::getLocalHistory() +{ + QVector historyPP; + for (qint32 i = 0; i< history.size(); ++i) + { + const VToolRecord tool = history.at(i); + if (tool.getNameDraw() != GetNameActivPP()) + { + continue; + } + historyPP.append(tool); + } + return historyPP; +} diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 94d31040c..c55c7901b 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -72,6 +72,7 @@ public: QHash* getTools(); VDataTool* getTool(const quint32 &id); QVector *getHistory(); + QVector getLocalHistory(); quint32 getCursor() const; void setCursor(const quint32 &value); void setCurrentData(); diff --git a/src/app/xml/vtoolrecord.cpp b/src/app/xml/vtoolrecord.cpp index 9e95347d2..036d88583 100644 --- a/src/app/xml/vtoolrecord.cpp +++ b/src/app/xml/vtoolrecord.cpp @@ -71,3 +71,7 @@ VToolRecord &VToolRecord::operator=(const VToolRecord &record) VToolRecord::VToolRecord(const VToolRecord &record) :id(record.getId()), typeTool(record.getTypeTool()), nameDraw(record.getNameDraw()) {} + +//--------------------------------------------------------------------------------------------------------------------- +VToolRecord::~VToolRecord() +{} diff --git a/src/app/xml/vtoolrecord.h b/src/app/xml/vtoolrecord.h index f21276a0c..5cf185f5a 100644 --- a/src/app/xml/vtoolrecord.h +++ b/src/app/xml/vtoolrecord.h @@ -50,6 +50,7 @@ public: void setTypeTool(const Tool &value); QString getNameDraw() const; void setNameDraw(const QString &value); + ~VToolRecord(); private: /** @brief id tool id. */ quint32 id;