Resolved issue #734. Optimization. Stop increments/variables table from

updating immediately.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-07-23 16:52:57 +03:00
parent 51f89c9799
commit a6bafb77e1
9 changed files with 215 additions and 28 deletions

View File

@ -11,6 +11,7 @@
- [#669] Improve export: export labels as text in DXF. - [#669] Improve export: export labels as text in DXF.
- [#716] Command line option to create *tiled* export. - [#716] Command line option to create *tiled* export.
- [#660] New export: Export details without layout. - [#660] New export: Export details without layout.
- [#734] Optimization. Stop increments/variables table from updating immediately.
# Version 0.5.1 # Version 0.5.1
- [#683] Tool Seam allowance's dialog is off screen on small resolutions. - [#683] Tool Seam allowance's dialog is off screen on small resolutions.

View File

@ -59,7 +59,8 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
data(data), data(data),
doc(doc), doc(doc),
formulaBaseHeight(0), formulaBaseHeight(0),
search() search(),
hasChanges(false)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -87,7 +88,6 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
FillRadiusesArcs(); FillRadiusesArcs();
FillAnglesCurves(); FillAnglesCurves();
connect(this, &DialogIncrements::FullUpdateTree, this->doc, &VPattern::LiteParseTree);
connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile);
ui->tabWidget->setCurrentIndex(0); 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->lineEditFind, &QLineEdit::textEdited, this, [this](const QString &term){search->Find(term);});
connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this](){search->FindPrevious();}); connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this](){search->FindPrevious();});
connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this](){search->FindNext();}); 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) connect(search.data(), &VTableSearch::HasResult, this, [this] (bool state)
{ {
@ -378,7 +379,10 @@ void DialogIncrements::Controls()
{ {
if (ui->tableWidgetIncrement->rowCount() > 0) 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 else
{ {
@ -451,10 +455,15 @@ void DialogIncrements::EnableDetails(bool enabled)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** void DialogIncrements::LocalUpdateTree()
* @brief FullUpdateFromFile update information in tables form file {
*/ doc->LiteParseIncrements();
void DialogIncrements::FullUpdateFromFile()
UpdateTree();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::UpdateTree()
{ {
ui->tableWidgetLines->clearContents(); ui->tableWidgetLines->clearContents();
ui->tableWidgetSplines->clearContents(); ui->tableWidgetSplines->clearContents();
@ -473,6 +482,49 @@ void DialogIncrements::FullUpdateFromFile()
search->RefreshList(ui->lineEditFind->text()); 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 * @brief clickedToolButtonAdd create new row in table
@ -496,7 +548,9 @@ void DialogIncrements::AddIncrement()
doc->AddEmptyIncrementAfter(nameField->text(), name); doc->AddEmptyIncrementAfter(nameField->text(), name);
} }
FullUpdateTree(Document::LiteParse); hasChanges = true;
LocalUpdateTree();
ui->tableWidgetIncrement->selectRow(currentRow); ui->tableWidgetIncrement->selectRow(currentRow);
} }
@ -516,7 +570,8 @@ void DialogIncrements::RemoveIncrement()
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
doc->RemoveIncrement(nameField->text()); doc->RemoveIncrement(nameField->text());
FullUpdateTree(Document::LiteParse); hasChanges = true;
LocalUpdateTree();
if (ui->tableWidgetIncrement->rowCount() > 0) if (ui->tableWidgetIncrement->rowCount() > 0)
{ {
@ -540,7 +595,10 @@ void DialogIncrements::MoveUp()
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
doc->MoveUpIncrement(nameField->text()); doc->MoveUpIncrement(nameField->text());
FullUpdateTree(Document::LiteParse);
hasChanges = true;
LocalUpdateTree();
ui->tableWidgetIncrement->selectRow(row-1); ui->tableWidgetIncrement->selectRow(row-1);
} }
@ -556,7 +614,10 @@ void DialogIncrements::MoveDown()
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
doc->MoveDownIncrement(nameField->text()); doc->MoveDownIncrement(nameField->text());
FullUpdateTree(Document::LiteParse);
hasChanges = true;
LocalUpdateTree();
ui->tableWidgetIncrement->selectRow(row+1); ui->tableWidgetIncrement->selectRow(row+1);
} }
@ -587,7 +648,10 @@ void DialogIncrements::SaveIncrName(const QString &text)
} }
doc->SetIncrementName(nameField->text(), newName); doc->SetIncrementName(nameField->text(), newName);
FullUpdateTree(Document::LiteParse);
hasChanges = true;
LocalUpdateTree();
ui->tableWidgetIncrement->blockSignals(true); ui->tableWidgetIncrement->blockSignals(true);
ui->tableWidgetIncrement->selectRow(row); ui->tableWidgetIncrement->selectRow(row);
ui->tableWidgetIncrement->blockSignals(false); ui->tableWidgetIncrement->blockSignals(false);
@ -606,7 +670,7 @@ void DialogIncrements::SaveIncrDescription()
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
doc->SetIncrementDescription(nameField->text(), ui->plainTextEditDescription->toPlainText()); doc->SetIncrementDescription(nameField->text(), ui->plainTextEditDescription->toPlainText());
FullUpdateTree(Document::LiteParse); LocalUpdateTree();
const QTextCursor cursor = ui->plainTextEditDescription->textCursor(); const QTextCursor cursor = ui->plainTextEditDescription->textCursor();
ui->tableWidgetIncrement->blockSignals(true); ui->tableWidgetIncrement->blockSignals(true);
@ -666,7 +730,8 @@ void DialogIncrements::SaveIncrFormula()
return; return;
} }
FullUpdateTree(Document::LiteParse); hasChanges = true;
LocalUpdateTree();
const QTextCursor cursor = ui->plainTextEditFormula->textCursor(); const QTextCursor cursor = ui->plainTextEditFormula->textCursor();
ui->tableWidgetIncrement->blockSignals(true); 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. // Because of the bug need to take QTableWidgetItem twice time. Previous update "killed" the pointer.
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
doc->SetIncrementFormula(nameField->text(), dialog->GetFormula()); doc->SetIncrementFormula(nameField->text(), dialog->GetFormula());
FullUpdateTree(Document::LiteParse);
hasChanges = true;
LocalUpdateTree();
ui->tableWidgetIncrement->selectRow(row); ui->tableWidgetIncrement->selectRow(row);
} }
delete dialog; delete dialog;
@ -743,6 +811,8 @@ void DialogIncrements::Fx()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::closeEvent(QCloseEvent *event) void DialogIncrements::closeEvent(QCloseEvent *event)
{ {
RefreshPattern();
ui->plainTextEditFormula->blockSignals(true); ui->plainTextEditFormula->blockSignals(true);
ui->lineEditName->blockSignals(true); ui->lineEditName->blockSignals(true);
ui->plainTextEditDescription->blockSignals(true); ui->plainTextEditDescription->blockSignals(true);
@ -819,6 +889,7 @@ void DialogIncrements::ShowIncrementDetails()
ui->lineEditName->blockSignals(true); ui->lineEditName->blockSignals(true);
ui->lineEditName->setText(ClearIncrementName(incr->GetName())); ui->lineEditName->setText(ClearIncrementName(incr->GetName()));
ui->lineEditName->blockSignals(false); ui->lineEditName->blockSignals(false);
ui->lineEditName->setReadOnly(IncrementUsed(incr->GetName()));
ui->plainTextEditDescription->blockSignals(true); ui->plainTextEditDescription->blockSignals(true);
ui->plainTextEditDescription->setPlainText(incr->GetDescription()); ui->plainTextEditDescription->setPlainText(incr->GetDescription());

View File

@ -50,12 +50,6 @@ public:
DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent = nullptr); DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent = nullptr);
virtual ~DialogIncrements() Q_DECL_OVERRIDE; virtual ~DialogIncrements() Q_DECL_OVERRIDE;
signals:
/**
* @brief FullUpdateTree signal update data for dom document
*/
void FullUpdateTree(const Document &parse);
protected: protected:
virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE; virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE;
virtual void changeEvent ( QEvent * event) Q_DECL_OVERRIDE; virtual void changeEvent ( QEvent * event) Q_DECL_OVERRIDE;
@ -72,6 +66,7 @@ private slots:
void DeployFormula(); void DeployFormula();
void Fx(); void Fx();
void FullUpdateFromFile(); void FullUpdateFromFile();
void RefreshPattern();
private: private:
Q_DISABLE_COPY(DialogIncrements) Q_DISABLE_COPY(DialogIncrements)
@ -89,6 +84,8 @@ private:
QSharedPointer<VTableSearch> search; QSharedPointer<VTableSearch> search;
bool hasChanges;
template <typename T> template <typename T>
void FillTable(const QMap<QString, T> &varTable, QTableWidget *table); void FillTable(const QMap<QString, T> &varTable, QTableWidget *table);
@ -111,6 +108,11 @@ private:
bool EvalIncrementFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label); bool EvalIncrementFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label);
void Controls(); void Controls();
void EnableDetails(bool enabled); void EnableDetails(bool enabled);
void LocalUpdateTree();
void UpdateTree();
bool IncrementUsed(const QString &name) const;
}; };
#endif // DIALOGINCREMENTS_H #endif // DIALOGINCREMENTS_H

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>979</width> <width>979</width>
<height>680</height> <height>729</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
@ -188,9 +188,6 @@
<string>Details</string> <string>Details</string>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item alignment="Qt::AlignLeft"> <item alignment="Qt::AlignLeft">
@ -427,14 +424,14 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="6" column="0"> <item row="7" column="0">
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
<property name="text"> <property name="text">
<string>Description:</string> <string>Description:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="7" column="1">
<widget class="QPlainTextEdit" name="plainTextEditDescription"> <widget class="QPlainTextEdit" name="plainTextEditDescription">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
@ -447,6 +444,33 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonRefresh">
<property name="toolTip">
<string>Refresh a pattern with all changes you made</string>
</property>
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

View File

@ -417,6 +417,77 @@ bool VPattern::SaveDocument(const QString &fileName, QString &error)
return saved; 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. * @brief LiteParseTree lite parse file.

View File

@ -94,6 +94,8 @@ public:
bool IsReadOnly() const; bool IsReadOnly() const;
void SetReadOnly(bool rOnly); void SetReadOnly(bool rOnly);
void LiteParseIncrements();
static const QString AttrReadOnly; static const QString AttrReadOnly;
public slots: public slots:

View File

@ -68,6 +68,7 @@ public:
virtual ~VAbstractPattern() Q_DECL_EQ_DEFAULT; virtual ~VAbstractPattern() Q_DECL_EQ_DEFAULT;
QStringList ListMeasurements() const; QStringList ListMeasurements() const;
QStringList ListExpressions() const;
virtual void CreateEmptyFile()=0; virtual void CreateEmptyFile()=0;
@ -387,7 +388,6 @@ private:
Q_DISABLE_COPY(VAbstractPattern) Q_DISABLE_COPY(VAbstractPattern)
QStringList ListIncrements() const; QStringList ListIncrements() const;
QStringList ListExpressions() const;
QStringList ListPointExpressions() const; QStringList ListPointExpressions() const;
QStringList ListArcExpressions() const; QStringList ListArcExpressions() const;
QStringList ListElArcExpressions() const; QStringList ListElArcExpressions() const;

View File

@ -693,6 +693,21 @@ void VContainer::ClearUniqueNames()
uniqueNames.clear(); uniqueNames.clear();
} }
//---------------------------------------------------------------------------------------------------------------------
void VContainer::ClearUniqueIncrementNames()
{
const QList<QString> 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 * @brief SetSize set value of size

View File

@ -170,6 +170,7 @@ public:
void ClearCalculationGObjects(); void ClearCalculationGObjects();
void ClearVariables(const VarType &type = VarType::Unknown); void ClearVariables(const VarType &type = VarType::Unknown);
static void ClearUniqueNames(); static void ClearUniqueNames();
static void ClearUniqueIncrementNames();
static void SetSize(qreal size); static void SetSize(qreal size);
static void SetHeight(qreal height); static void SetHeight(qreal height);