Keep information about sibling node before delete detail.
--HG-- branch : develop
This commit is contained in:
parent
205cca7eec
commit
9ad3285769
|
@ -51,6 +51,7 @@ static const quint32 null_id = 0;
|
|||
#define SceneSize 50000
|
||||
#define DefPointRadius 2.0//mm
|
||||
#define NULL_ID null_id//use this value for initialization variables that keeps id values. 0 mean uknown id value.
|
||||
#define NULL_ID_STR "0"
|
||||
|
||||
extern const QString nameRegExp;
|
||||
extern const QString degreeSymbol;
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DeleteDetail::DeleteDetail(VPattern *doc, quint32 id, QUndoCommand *parent)
|
||||
: VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode())
|
||||
: VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID)
|
||||
{
|
||||
setText(tr("Delete tool"));
|
||||
nodeId = id;
|
||||
|
@ -41,6 +41,16 @@ DeleteDetail::DeleteDetail(VPattern *doc, quint32 id, QUndoCommand *parent)
|
|||
{
|
||||
xml = domElement.cloneNode().toElement();
|
||||
parentNode = domElement.parentNode();
|
||||
QDomNode previousDetail = domElement.previousSibling();
|
||||
if (previousDetail.isNull())
|
||||
{
|
||||
siblingId = NULL_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Better save id of previous detail instead of reference to node.
|
||||
siblingId = doc->GetParametrUInt(previousDetail.toElement(), VPattern::AttrId, NULL_ID_STR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -56,7 +66,7 @@ DeleteDetail::~DeleteDetail()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DeleteDetail::undo()
|
||||
{
|
||||
parentNode.appendChild(xml);
|
||||
UndoDeleteAfterSibling(parentNode, siblingId);
|
||||
emit NeedFullParsing();
|
||||
}
|
||||
|
||||
|
@ -68,14 +78,15 @@ void DeleteDetail::redo()
|
|||
{
|
||||
parentNode.removeChild(domElement);
|
||||
|
||||
//When UnionDetail delete detail we can't use FullParsing. So we hide detail on scene directly.
|
||||
// UnionDetails delete two old details and create one new.
|
||||
// So when UnionDetail delete detail we can't use FullParsing. So we hide detail on scene directly.
|
||||
QHash<quint32, VDataTool*>* tools = doc->getTools();
|
||||
SCASSERT(tools != nullptr);
|
||||
VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(nodeId));
|
||||
SCASSERT(toolDet != nullptr);
|
||||
toolDet->hide();
|
||||
|
||||
emit NeedFullParsing();
|
||||
emit NeedFullParsing(); // Doesn't work when UnionDetail delete detail.
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
private:
|
||||
Q_DISABLE_COPY(DeleteDetail)
|
||||
QDomNode parentNode;
|
||||
quint32 siblingId;
|
||||
};
|
||||
|
||||
#endif // DELETEDETAIL_H
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent)
|
||||
: VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), cursor(NULL_ID)
|
||||
: VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID)
|
||||
{
|
||||
setText(tr("Delete tool"));
|
||||
nodeId = id;
|
||||
|
@ -46,12 +46,12 @@ DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent)
|
|||
{
|
||||
if (i == 0)
|
||||
{
|
||||
cursor = NULL_ID;
|
||||
siblingId = NULL_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
const VToolRecord tool = history.at(i-1);
|
||||
cursor = tool.getId();
|
||||
siblingId = tool.getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,18 +76,7 @@ DelTool::~DelTool()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DelTool::undo()
|
||||
{
|
||||
if (cursor == NULL_ID)
|
||||
{
|
||||
parentNode.appendChild(xml);
|
||||
}
|
||||
else
|
||||
{
|
||||
QDomElement refElement = doc->elementById(QString().setNum(cursor));
|
||||
if (refElement.isElement())
|
||||
{
|
||||
parentNode.insertAfter(xml, refElement);
|
||||
}
|
||||
}
|
||||
UndoDeleteAfterSibling(parentNode, siblingId);
|
||||
emit NeedFullParsing();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
private:
|
||||
Q_DISABLE_COPY(DelTool)
|
||||
QDomNode parentNode;
|
||||
quint32 cursor;
|
||||
quint32 siblingId;
|
||||
};
|
||||
|
||||
#endif // DELTOOL_H
|
||||
|
|
|
@ -49,3 +49,24 @@ void VUndoCommand::RedoFullParsing()
|
|||
}
|
||||
redoFlag = true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VUndoCommand::UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const
|
||||
{
|
||||
if (siblingId == NULL_ID)
|
||||
{
|
||||
parentNode.appendChild(xml);
|
||||
}
|
||||
else
|
||||
{
|
||||
const QDomElement refElement = doc->elementById(QString().setNum(siblingId));
|
||||
if (refElement.isElement())
|
||||
{
|
||||
parentNode.insertAfter(xml, refElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<<"Can't find sibling node.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ protected:
|
|||
quint32 nodeId;
|
||||
bool redoFlag;
|
||||
void RedoFullParsing();
|
||||
void UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const;
|
||||
private:
|
||||
Q_DISABLE_COPY(VUndoCommand)
|
||||
};
|
||||
|
|
|
@ -211,6 +211,7 @@ bool VPattern::GetActivDrawElement(QDomElement &element) const
|
|||
}
|
||||
}
|
||||
}
|
||||
element = QDomElement();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user