diff --git a/src/app/valentina/dialogs/vwidgetdetails.cpp b/src/app/valentina/dialogs/vwidgetdetails.cpp index 54429d240..71948902d 100644 --- a/src/app/valentina/dialogs/vwidgetdetails.cpp +++ b/src/app/valentina/dialogs/vwidgetdetails.cpp @@ -35,6 +35,7 @@ #include "../vtools/tools/vtoolseamallowance.h" #include +#include #include namespace @@ -54,7 +55,8 @@ VWidgetDetails::VWidgetDetails(VContainer *data, VAbstractPattern *doc, QWidget : QWidget(parent), ui(new Ui::VWidgetDetails), m_doc(doc), - m_data(data) + m_data(data), + m_updateListTimer(new QTimer(this)) { ui->setupUi(this); @@ -66,6 +68,12 @@ VWidgetDetails::VWidgetDetails(VContainer *data, VAbstractPattern *doc, QWidget connect(ui->tableWidget, &QTableWidget::cellClicked, this, &VWidgetDetails::InLayoutStateChanged); connect(ui->tableWidget, &QTableWidget::customContextMenuRequested, this, &VWidgetDetails::ShowContextMenu); + + m_updateListTimer->setSingleShot(true); + connect(m_updateListTimer, &QTimer::timeout, this, [this]() + { + FillTable(m_data->DataPieces()); + }); } //--------------------------------------------------------------------------------------------------------------------- @@ -77,7 +85,10 @@ VWidgetDetails::~VWidgetDetails() //--------------------------------------------------------------------------------------------------------------------- void VWidgetDetails::UpdateList() { - FillTable(m_data->DataPieces()); + // The filling table is a very expensive operation. This optimization will postpone it. + // Each time a new request happen we will wait 800 ms before calling it. If at this time a new request will arrive + // we will wait 800 ms more. And so on, until nothing happens within 800ms. + m_updateListTimer->start(800); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/vwidgetdetails.h b/src/app/valentina/dialogs/vwidgetdetails.h index 29261b004..083cde8dc 100644 --- a/src/app/valentina/dialogs/vwidgetdetails.h +++ b/src/app/valentina/dialogs/vwidgetdetails.h @@ -68,6 +68,7 @@ private: Ui::VWidgetDetails *ui; VAbstractPattern *m_doc; VContainer *m_data; + QTimer *m_updateListTimer; void FillTable(const QHash *details); void ToggleSectionDetails(bool select); diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index 231a4e70f..22dd8cf27 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -939,9 +939,9 @@ QDomElement VDomDocument::CloneNodeById(const quint32 &nodeId) } //--------------------------------------------------------------------------------------------------------------------- -QDomElement VDomDocument::NodeById(const quint32 &nodeId) +QDomElement VDomDocument::NodeById(const quint32 &nodeId, const QString &tagName) { - QDomElement domElement = elementById(nodeId); + QDomElement domElement = elementById(nodeId, tagName); if (domElement.isNull() || domElement.isElement() == false) { throw VExceptionBadId(tr("Couldn't get node"), nodeId); diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index 751d1493b..9a8cab0b7 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -135,7 +135,7 @@ public: QDomNode ParentNodeById(const quint32 &nodeId); QDomElement CloneNodeById(const quint32 &nodeId); - QDomElement NodeById(const quint32 &nodeId); + QDomElement NodeById(const quint32 &nodeId, const QString &tagName = QString()); static bool SafeCopy(const QString &source, const QString &destination, QString &error); @@ -144,6 +144,8 @@ public: void TestUniqueId() const; + void RefreshElementIdCache(); + protected: bool setTagText(const QString &tag, const QString &text); bool setTagText(const QDomElement &domElement, const QString &text); @@ -152,9 +154,6 @@ protected: static void ValidateVersion(const QString &version); -protected slots: - void RefreshElementIdCache(); - private slots: void CacheRefreshed(); diff --git a/src/libs/vtools/undocommands/deletepiece.cpp b/src/libs/vtools/undocommands/deletepiece.cpp index 4a1f90958..fb423de5f 100644 --- a/src/libs/vtools/undocommands/deletepiece.cpp +++ b/src/libs/vtools/undocommands/deletepiece.cpp @@ -91,7 +91,7 @@ void DeletePiece::undo() { qCDebug(vUndo, "Undo."); - UndoDeleteAfterSibling(m_parentNode, m_siblingId); + UndoDeleteAfterSibling(m_parentNode, m_siblingId, VAbstractPattern::TagDetail); VAbstractPattern::AddTool(nodeId, m_tool); m_data.UpdatePiece(nodeId, m_detail); diff --git a/src/libs/vtools/undocommands/vundocommand.cpp b/src/libs/vtools/undocommands/vundocommand.cpp index 2b43f96f1..5d6f036d2 100644 --- a/src/libs/vtools/undocommands/vundocommand.cpp +++ b/src/libs/vtools/undocommands/vundocommand.cpp @@ -62,7 +62,7 @@ void VUndoCommand::RedoFullParsing() } //--------------------------------------------------------------------------------------------------------------------- -void VUndoCommand::UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const +void VUndoCommand::UndoDeleteAfterSibling(QDomNode &parentNode, quint32 siblingId, const QString &tagName) const { if (siblingId == NULL_ID) { @@ -70,8 +70,9 @@ void VUndoCommand::UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &s } else { - const QDomElement refElement = doc->NodeById(siblingId); + const QDomElement refElement = doc->NodeById(siblingId, tagName); parentNode.insertAfter(xml, refElement); + doc->RefreshElementIdCache(); } } diff --git a/src/libs/vtools/undocommands/vundocommand.h b/src/libs/vtools/undocommands/vundocommand.h index 687823e29..37491251e 100644 --- a/src/libs/vtools/undocommands/vundocommand.h +++ b/src/libs/vtools/undocommands/vundocommand.h @@ -81,7 +81,8 @@ protected: quint32 nodeId; bool redoFlag; virtual void RedoFullParsing(); - void UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const; + void UndoDeleteAfterSibling(QDomNode &parentNode, quint32 siblingId, + const QString &tagName = QString()) const; void IncrementReferences(const QVector &nodes) const; void DecrementReferences(const QVector &nodes) const;