From a6bafb77e1cad9fa2eef981514c8cc2ac6c1ee2d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 23 Jul 2017 16:52:57 +0300 Subject: [PATCH] Resolved issue #734. Optimization. Stop increments/variables table from updating immediately. --HG-- branch : develop --- ChangeLog.txt | 1 + .../valentina/dialogs/dialogincrements.cpp | 101 +++++++++++++++--- src/app/valentina/dialogs/dialogincrements.h | 14 +-- src/app/valentina/dialogs/dialogincrements.ui | 36 +++++-- src/app/valentina/xml/vpattern.cpp | 71 ++++++++++++ src/app/valentina/xml/vpattern.h | 2 + src/libs/ifc/xml/vabstractpattern.h | 2 +- src/libs/vpatterndb/vcontainer.cpp | 15 +++ src/libs/vpatterndb/vcontainer.h | 1 + 9 files changed, 215 insertions(+), 28 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 01e93a2c2..3e071ef2c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -11,6 +11,7 @@ - [#669] Improve export: export labels as text in DXF. - [#716] Command line option to create *tiled* export. - [#660] New export: Export details without layout. +- [#734] Optimization. Stop increments/variables table from updating immediately. # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index 968f7cf0b..7f57d3694 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -59,7 +59,8 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par data(data), doc(doc), formulaBaseHeight(0), - search() + search(), + hasChanges(false) { ui->setupUi(this); @@ -87,7 +88,6 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par FillRadiusesArcs(); FillAnglesCurves(); - connect(this, &DialogIncrements::FullUpdateTree, this->doc, &VPattern::LiteParseTree); connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); ui->tabWidget->setCurrentIndex(0); @@ -109,6 +109,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par connect(ui->lineEditFind, &QLineEdit::textEdited, this, [this](const QString &term){search->Find(term);}); connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this](){search->FindPrevious();}); connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this](){search->FindNext();}); + connect(ui->pushButtonRefresh, &QPushButton::clicked, this, &DialogIncrements::RefreshPattern); connect(search.data(), &VTableSearch::HasResult, this, [this] (bool state) { @@ -378,7 +379,10 @@ void DialogIncrements::Controls() { if (ui->tableWidgetIncrement->rowCount() > 0) { - ui->toolButtonRemove->setEnabled(true); + const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(ui->tableWidgetIncrement->currentRow(), 0); + SCASSERT(nameField != nullptr) + + ui->toolButtonRemove->setEnabled(not IncrementUsed(nameField->text())); } else { @@ -451,10 +455,15 @@ void DialogIncrements::EnableDetails(bool enabled) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief FullUpdateFromFile update information in tables form file - */ -void DialogIncrements::FullUpdateFromFile() +void DialogIncrements::LocalUpdateTree() +{ + doc->LiteParseIncrements(); + + UpdateTree(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::UpdateTree() { ui->tableWidgetLines->clearContents(); ui->tableWidgetSplines->clearContents(); @@ -473,6 +482,49 @@ void DialogIncrements::FullUpdateFromFile() search->RefreshList(ui->lineEditFind->text()); } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogIncrements::IncrementUsed(const QString &name) const +{ + const QStringList expressions = doc->ListExpressions(); + + for(int i = 0; i < expressions.size(); ++i) + { + if (expressions.at(i).indexOf(name) != -1) + { + return true; + } + } + return false; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief FullUpdateFromFile update information in tables form file + */ +void DialogIncrements::FullUpdateFromFile() +{ + hasChanges = false; + + UpdateTree(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::RefreshPattern() +{ + if (hasChanges) + { + const int row = ui->tableWidgetIncrement->currentRow(); + + doc->LiteParseTree(Document::LiteParse); + + ui->tableWidgetIncrement->blockSignals(true); + ui->tableWidgetIncrement->selectRow(row); + ui->tableWidgetIncrement->blockSignals(false); + + hasChanges = false; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief clickedToolButtonAdd create new row in table @@ -496,7 +548,9 @@ void DialogIncrements::AddIncrement() doc->AddEmptyIncrementAfter(nameField->text(), name); } - FullUpdateTree(Document::LiteParse); + hasChanges = true; + LocalUpdateTree(); + ui->tableWidgetIncrement->selectRow(currentRow); } @@ -516,7 +570,8 @@ void DialogIncrements::RemoveIncrement() const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); doc->RemoveIncrement(nameField->text()); - FullUpdateTree(Document::LiteParse); + hasChanges = true; + LocalUpdateTree(); if (ui->tableWidgetIncrement->rowCount() > 0) { @@ -540,7 +595,10 @@ void DialogIncrements::MoveUp() const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); doc->MoveUpIncrement(nameField->text()); - FullUpdateTree(Document::LiteParse); + + hasChanges = true; + LocalUpdateTree(); + ui->tableWidgetIncrement->selectRow(row-1); } @@ -556,7 +614,10 @@ void DialogIncrements::MoveDown() const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); doc->MoveDownIncrement(nameField->text()); - FullUpdateTree(Document::LiteParse); + + hasChanges = true; + LocalUpdateTree(); + ui->tableWidgetIncrement->selectRow(row+1); } @@ -587,7 +648,10 @@ void DialogIncrements::SaveIncrName(const QString &text) } doc->SetIncrementName(nameField->text(), newName); - FullUpdateTree(Document::LiteParse); + + hasChanges = true; + LocalUpdateTree(); + ui->tableWidgetIncrement->blockSignals(true); ui->tableWidgetIncrement->selectRow(row); ui->tableWidgetIncrement->blockSignals(false); @@ -606,7 +670,7 @@ void DialogIncrements::SaveIncrDescription() const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); doc->SetIncrementDescription(nameField->text(), ui->plainTextEditDescription->toPlainText()); - FullUpdateTree(Document::LiteParse); + LocalUpdateTree(); const QTextCursor cursor = ui->plainTextEditDescription->textCursor(); ui->tableWidgetIncrement->blockSignals(true); @@ -666,7 +730,8 @@ void DialogIncrements::SaveIncrFormula() return; } - FullUpdateTree(Document::LiteParse); + hasChanges = true; + LocalUpdateTree(); const QTextCursor cursor = ui->plainTextEditFormula->textCursor(); ui->tableWidgetIncrement->blockSignals(true); @@ -734,7 +799,10 @@ void DialogIncrements::Fx() // Because of the bug need to take QTableWidgetItem twice time. Previous update "killed" the pointer. const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); doc->SetIncrementFormula(nameField->text(), dialog->GetFormula()); - FullUpdateTree(Document::LiteParse); + + hasChanges = true; + LocalUpdateTree(); + ui->tableWidgetIncrement->selectRow(row); } delete dialog; @@ -743,6 +811,8 @@ void DialogIncrements::Fx() //--------------------------------------------------------------------------------------------------------------------- void DialogIncrements::closeEvent(QCloseEvent *event) { + RefreshPattern(); + ui->plainTextEditFormula->blockSignals(true); ui->lineEditName->blockSignals(true); ui->plainTextEditDescription->blockSignals(true); @@ -819,6 +889,7 @@ void DialogIncrements::ShowIncrementDetails() ui->lineEditName->blockSignals(true); ui->lineEditName->setText(ClearIncrementName(incr->GetName())); ui->lineEditName->blockSignals(false); + ui->lineEditName->setReadOnly(IncrementUsed(incr->GetName())); ui->plainTextEditDescription->blockSignals(true); ui->plainTextEditDescription->setPlainText(incr->GetDescription()); diff --git a/src/app/valentina/dialogs/dialogincrements.h b/src/app/valentina/dialogs/dialogincrements.h index 39cec4a7d..63a85bee4 100644 --- a/src/app/valentina/dialogs/dialogincrements.h +++ b/src/app/valentina/dialogs/dialogincrements.h @@ -50,12 +50,6 @@ public: DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent = nullptr); virtual ~DialogIncrements() Q_DECL_OVERRIDE; -signals: - /** - * @brief FullUpdateTree signal update data for dom document - */ - void FullUpdateTree(const Document &parse); - protected: virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE; virtual void changeEvent ( QEvent * event) Q_DECL_OVERRIDE; @@ -72,6 +66,7 @@ private slots: void DeployFormula(); void Fx(); void FullUpdateFromFile(); + void RefreshPattern(); private: Q_DISABLE_COPY(DialogIncrements) @@ -89,6 +84,8 @@ private: QSharedPointer search; + bool hasChanges; + template void FillTable(const QMap &varTable, QTableWidget *table); @@ -111,6 +108,11 @@ private: bool EvalIncrementFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label); void Controls(); void EnableDetails(bool enabled); + + void LocalUpdateTree(); + void UpdateTree(); + + bool IncrementUsed(const QString &name) const; }; #endif // DIALOGINCREMENTS_H diff --git a/src/app/valentina/dialogs/dialogincrements.ui b/src/app/valentina/dialogs/dialogincrements.ui index 287243e7e..7d3979836 100644 --- a/src/app/valentina/dialogs/dialogincrements.ui +++ b/src/app/valentina/dialogs/dialogincrements.ui @@ -7,7 +7,7 @@ 0 0 979 - 680 + 729 @@ -188,9 +188,6 @@ Details - - QFormLayout::ExpandingFieldsGrow - @@ -427,14 +424,14 @@ - + Description: - + false @@ -447,6 +444,33 @@ + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Refresh a pattern with all changes you made + + + Refresh + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index ffe9a8197..5f44ca99c 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -417,6 +417,77 @@ bool VPattern::SaveDocument(const QString &fileName, QString &error) return saved; } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::LiteParseIncrements() +{ + try + { + emit SetEnabledGUI(true); + + VContainer::ClearUniqueIncrementNames(); + data->ClearVariables(VarType::Increment); + + const QDomNodeList tags = elementsByTagName(TagIncrements); + if (not tags.isEmpty()) + { + const QDomNode domElement = tags.at(0); + if (not domElement.isNull()) + { + ParseIncrementsElement(domElement); + } + } + } + catch (const VExceptionUndo &e) + { + Q_UNUSED(e) + /* If user want undo last operation before undo we need finish broken redo operation. For those we post event + * myself. Later in method customEvent call undo.*/ + QApplication::postEvent(this, new UndoEvent()); + return; + } + catch (const VExceptionObjectError &e) + { + qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")), //-V807 + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + emit SetEnabledGUI(false); + return; + } + catch (const VExceptionConversionError &e) + { + qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + emit SetEnabledGUI(false); + return; + } + catch (const VExceptionEmptyParameter &e) + { + qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + emit SetEnabledGUI(false); + return; + } + catch (const VExceptionWrongId &e) + { + qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + emit SetEnabledGUI(false); + return; + } + catch (VException &e) + { + qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + emit SetEnabledGUI(false); + return; + } + catch (const std::bad_alloc &) + { + qCCritical(vXML, "%s", qUtf8Printable(tr("Error parsing file (std::bad_alloc)."))); + emit SetEnabledGUI(false); + return; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief LiteParseTree lite parse file. diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 9dc6cab3f..c88599b77 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -94,6 +94,8 @@ public: bool IsReadOnly() const; void SetReadOnly(bool rOnly); + void LiteParseIncrements(); + static const QString AttrReadOnly; public slots: diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index f4dad163e..60f98c158 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -68,6 +68,7 @@ public: virtual ~VAbstractPattern() Q_DECL_EQ_DEFAULT; QStringList ListMeasurements() const; + QStringList ListExpressions() const; virtual void CreateEmptyFile()=0; @@ -387,7 +388,6 @@ private: Q_DISABLE_COPY(VAbstractPattern) QStringList ListIncrements() const; - QStringList ListExpressions() const; QStringList ListPointExpressions() const; QStringList ListArcExpressions() const; QStringList ListElArcExpressions() const; diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index b6f9f1a4c..598ebc8d3 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -693,6 +693,21 @@ void VContainer::ClearUniqueNames() uniqueNames.clear(); } +//--------------------------------------------------------------------------------------------------------------------- +void VContainer::ClearUniqueIncrementNames() +{ + const QList list = uniqueNames.toList(); + ClearUniqueNames(); + + for(int i = 0; i < list.size(); ++i) + { + if (not list.at(i).startsWith('#')) + { + uniqueNames.insert(list.at(i)); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetSize set value of size diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 856dce1e9..b02b8c405 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -170,6 +170,7 @@ public: void ClearCalculationGObjects(); void ClearVariables(const VarType &type = VarType::Unknown); static void ClearUniqueNames(); + static void ClearUniqueIncrementNames(); static void SetSize(qreal size); static void SetHeight(qreal height);