Fix issue #784. Bug in Table of Variables.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-12-12 17:13:18 +02:00
parent 8b4fc33649
commit 5b0a557b21
2 changed files with 72 additions and 65 deletions

View File

@ -622,6 +622,74 @@ void DialogIncrements::CacheRename(const QString &name, const QString &newName)
renameList.append(qMakePair(name, newName));
}
//---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::ShowTableIncrementDetails(QTableWidget *table)
{
QLineEdit *lineEditName = nullptr;
QPlainTextEdit *plainTextEditDescription = nullptr;
QPlainTextEdit *plainTextEditFormula = nullptr;
QLabel *labelCalculatedValue = nullptr;
if (table == ui->tableWidgetIncrement)
{
lineEditName = ui->lineEditName;
plainTextEditDescription = ui->plainTextEditDescription;
plainTextEditFormula = ui->plainTextEditFormula;
labelCalculatedValue = ui->labelCalculatedValue;
}
else if (table == ui->tableWidgetPC)
{
lineEditName = ui->lineEditNamePC;
plainTextEditDescription = ui->plainTextEditDescriptionPC;
plainTextEditFormula = ui->plainTextEditFormulaPC;
labelCalculatedValue = ui->labelCalculatedValuePC;
}
else
{
return;
}
if (table->rowCount() > 0 && table->currentRow() != -1)
{
EnableDetails(table, true);
// name
const QTableWidgetItem *nameField = table->item(table->currentRow(), 0);
QSharedPointer<VIncrement> incr;
try
{
incr = data->GetVariable<VIncrement>(nameField->text());
}
catch(const VExceptionBadId &e)
{
Q_UNUSED(e)
EnableDetails(table, false);
return;
}
lineEditName->blockSignals(true);
lineEditName->setText(ClearIncrementName(incr->GetName()));
lineEditName->blockSignals(false);
plainTextEditDescription->blockSignals(true);
plainTextEditDescription->setPlainText(incr->GetDescription());
plainTextEditDescription->blockSignals(false);
EvalIncrementFormula(incr->GetFormula(), false, incr->GetData(), labelCalculatedValue);
plainTextEditFormula->blockSignals(true);
QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
plainTextEditFormula->setPlainText(formula);
plainTextEditFormula->blockSignals(false);
}
else
{
EnableDetails(table, false);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief FullUpdateFromFile update information in tables form file
@ -1229,6 +1297,7 @@ void DialogIncrements::Fx()
LocalUpdateTree();
table->selectRow(row);
ShowTableIncrementDetails(table);
}
}
@ -1330,71 +1399,7 @@ void DialogIncrements::resizeEvent(QResizeEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::ShowIncrementDetails()
{
QTableWidget *table = qobject_cast<QTableWidget *>(sender());
QLineEdit *lineEditName = nullptr;
QPlainTextEdit *plainTextEditDescription = nullptr;
QPlainTextEdit *plainTextEditFormula = nullptr;
QLabel *labelCalculatedValue = nullptr;
if (table == ui->tableWidgetIncrement)
{
lineEditName = ui->lineEditName;
plainTextEditDescription = ui->plainTextEditDescription;
plainTextEditFormula = ui->plainTextEditFormula;
labelCalculatedValue = ui->labelCalculatedValue;
}
else if (table == ui->tableWidgetPC)
{
lineEditName = ui->lineEditNamePC;
plainTextEditDescription = ui->plainTextEditDescriptionPC;
plainTextEditFormula = ui->plainTextEditFormulaPC;
labelCalculatedValue = ui->labelCalculatedValuePC;
}
else
{
return;
}
if (table->rowCount() > 0)
{
EnableDetails(table, true);
// name
const QTableWidgetItem *nameField = table->item(table->currentRow(), 0);
QSharedPointer<VIncrement> incr;
try
{
incr = data->GetVariable<VIncrement>(nameField->text());
}
catch(const VExceptionBadId &e)
{
Q_UNUSED(e)
EnableDetails(table, false);
return;
}
lineEditName->blockSignals(true);
lineEditName->setText(ClearIncrementName(incr->GetName()));
lineEditName->blockSignals(false);
plainTextEditDescription->blockSignals(true);
plainTextEditDescription->setPlainText(incr->GetDescription());
plainTextEditDescription->blockSignals(false);
EvalIncrementFormula(incr->GetFormula(), false, incr->GetData(), labelCalculatedValue);
plainTextEditFormula->blockSignals(true);
QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
plainTextEditFormula->setPlainText(formula);
plainTextEditFormula->blockSignals(false);
}
else
{
EnableDetails(table, false);
}
ShowTableIncrementDetails(qobject_cast<QTableWidget *>(sender()));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -133,6 +133,8 @@ private:
bool IncrementUsed(const QString &name) const;
void CacheRename(const QString &name, const QString &newName);
void ShowTableIncrementDetails(QTableWidget *table);
};
#endif // DIALOGINCREMENTS_H