Speed up bulk removing pieces.
Optimizations for 'do' and 'undo' operations. --HG-- branch : develop
This commit is contained in:
parent
0bd69403d7
commit
82792dba6c
|
@ -35,6 +35,7 @@
|
||||||
#include "../vtools/tools/vtoolseamallowance.h"
|
#include "../vtools/tools/vtoolseamallowance.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QTimer>
|
||||||
#include <QUndoStack>
|
#include <QUndoStack>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -54,7 +55,8 @@ VWidgetDetails::VWidgetDetails(VContainer *data, VAbstractPattern *doc, QWidget
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
ui(new Ui::VWidgetDetails),
|
ui(new Ui::VWidgetDetails),
|
||||||
m_doc(doc),
|
m_doc(doc),
|
||||||
m_data(data)
|
m_data(data),
|
||||||
|
m_updateListTimer(new QTimer(this))
|
||||||
{
|
{
|
||||||
ui->setupUi(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::cellClicked, this, &VWidgetDetails::InLayoutStateChanged);
|
||||||
connect(ui->tableWidget, &QTableWidget::customContextMenuRequested, this, &VWidgetDetails::ShowContextMenu);
|
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()
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -68,6 +68,7 @@ private:
|
||||||
Ui::VWidgetDetails *ui;
|
Ui::VWidgetDetails *ui;
|
||||||
VAbstractPattern *m_doc;
|
VAbstractPattern *m_doc;
|
||||||
VContainer *m_data;
|
VContainer *m_data;
|
||||||
|
QTimer *m_updateListTimer;
|
||||||
|
|
||||||
void FillTable(const QHash<quint32, VPiece> *details);
|
void FillTable(const QHash<quint32, VPiece> *details);
|
||||||
void ToggleSectionDetails(bool select);
|
void ToggleSectionDetails(bool select);
|
||||||
|
|
|
@ -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)
|
if (domElement.isNull() || domElement.isElement() == false)
|
||||||
{
|
{
|
||||||
throw VExceptionBadId(tr("Couldn't get node"), nodeId);
|
throw VExceptionBadId(tr("Couldn't get node"), nodeId);
|
||||||
|
|
|
@ -135,7 +135,7 @@ public:
|
||||||
|
|
||||||
QDomNode ParentNodeById(const quint32 &nodeId);
|
QDomNode ParentNodeById(const quint32 &nodeId);
|
||||||
QDomElement CloneNodeById(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);
|
static bool SafeCopy(const QString &source, const QString &destination, QString &error);
|
||||||
|
|
||||||
|
@ -144,6 +144,8 @@ public:
|
||||||
|
|
||||||
void TestUniqueId() const;
|
void TestUniqueId() const;
|
||||||
|
|
||||||
|
void RefreshElementIdCache();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool setTagText(const QString &tag, const QString &text);
|
bool setTagText(const QString &tag, const QString &text);
|
||||||
bool setTagText(const QDomElement &domElement, const QString &text);
|
bool setTagText(const QDomElement &domElement, const QString &text);
|
||||||
|
@ -152,9 +154,6 @@ protected:
|
||||||
|
|
||||||
static void ValidateVersion(const QString &version);
|
static void ValidateVersion(const QString &version);
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void RefreshElementIdCache();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void CacheRefreshed();
|
void CacheRefreshed();
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ void DeletePiece::undo()
|
||||||
{
|
{
|
||||||
qCDebug(vUndo, "Undo.");
|
qCDebug(vUndo, "Undo.");
|
||||||
|
|
||||||
UndoDeleteAfterSibling(m_parentNode, m_siblingId);
|
UndoDeleteAfterSibling(m_parentNode, m_siblingId, VAbstractPattern::TagDetail);
|
||||||
|
|
||||||
VAbstractPattern::AddTool(nodeId, m_tool);
|
VAbstractPattern::AddTool(nodeId, m_tool);
|
||||||
m_data.UpdatePiece(nodeId, m_detail);
|
m_data.UpdatePiece(nodeId, m_detail);
|
||||||
|
|
|
@ -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)
|
if (siblingId == NULL_ID)
|
||||||
{
|
{
|
||||||
|
@ -70,8 +70,9 @@ void VUndoCommand::UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &s
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const QDomElement refElement = doc->NodeById(siblingId);
|
const QDomElement refElement = doc->NodeById(siblingId, tagName);
|
||||||
parentNode.insertAfter(xml, refElement);
|
parentNode.insertAfter(xml, refElement);
|
||||||
|
doc->RefreshElementIdCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,8 @@ protected:
|
||||||
quint32 nodeId;
|
quint32 nodeId;
|
||||||
bool redoFlag;
|
bool redoFlag;
|
||||||
virtual void RedoFullParsing();
|
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 IncrementReferences(const QVector<quint32> &nodes) const;
|
||||||
void DecrementReferences(const QVector<quint32> &nodes) const;
|
void DecrementReferences(const QVector<quint32> &nodes) const;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user