Speed up bulk removing pieces.

Optimizations for 'do' and 'undo' operations.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-10-30 15:25:25 +02:00
parent 0bd69403d7
commit 82792dba6c
7 changed files with 25 additions and 12 deletions

View File

@ -35,6 +35,7 @@
#include "../vtools/tools/vtoolseamallowance.h"
#include <QMenu>
#include <QTimer>
#include <QUndoStack>
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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -68,6 +68,7 @@ private:
Ui::VWidgetDetails *ui;
VAbstractPattern *m_doc;
VContainer *m_data;
QTimer *m_updateListTimer;
void FillTable(const QHash<quint32, VPiece> *details);
void ToggleSectionDetails(bool select);

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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<quint32> &nodes) const;
void DecrementReferences(const QVector<quint32> &nodes) const;