Improved editing custom measurement and increment.

Fixed case when a user input empty string. In this case return auto generated
name. Fixed case when the name is not unique. In this case find unique with
index "new_name" + "_number".

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2017-04-14 10:35:44 +03:00
parent 6d271423e0
commit 1e06446189
4 changed files with 87 additions and 61 deletions

View File

@ -1280,15 +1280,8 @@ void TMainWindow::Fx()
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::AddCustom()
{
qint32 num = 1;
QString name;
do
{
name = CustomMSign + qApp->TrVars()->InternalVarToUser(measurement_) + QString().number(num);
num++;
} while (data->IsUnique(name) == false);
qint32 currentRow;
const QString name = GetCustomName();
qint32 currentRow = -1;
if (ui->tableWidget->currentRow() == -1)
{
@ -1489,7 +1482,7 @@ void TMainWindow::ShowMData()
ShowMDiagram(meash->GetName());
// Don't block all signal for QLineEdit. Need for correct handle with clear button.
disconnect(ui->lineEditName, &QLineEdit::editingFinished, this, &TMainWindow::SaveMName);
disconnect(ui->lineEditName, &QLineEdit::textEdited, this, &TMainWindow::SaveMName);
ui->plainTextEditDescription->blockSignals(true);
if (meash->IsCustom())
{
@ -1504,7 +1497,7 @@ void TMainWindow::ShowMData()
ui->lineEditFullName->setText(qApp->TrVars()->GuiText(meash->GetName()));
ui->lineEditName->setText(nameField->text());
}
connect(ui->lineEditName, &QLineEdit::editingFinished, this, &TMainWindow::SaveMName);
connect(ui->lineEditName, &QLineEdit::textEdited, this, &TMainWindow::SaveMName);
ui->plainTextEditDescription->blockSignals(false);
if (mType == MeasurementsType::Standard)
@ -1614,7 +1607,7 @@ void TMainWindow::DeployFormula()
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveMName()
void TMainWindow::SaveMName(const QString &text)
{
const int row = ui->tableWidget->currentRow();
@ -1640,13 +1633,24 @@ void TMainWindow::SaveMName()
return;
}
QString newName = ui->lineEditName->text();
QString newName = text;
if (meash->IsCustom())
{
newName = CustomMSign + newName;
newName.isEmpty() ? newName = GetCustomName() : newName = CustomMSign + newName;
if (data->IsUnique(newName))
if (not data->IsUnique(newName))
{
qint32 num = 2;
QString name = newName;
do
{
name = name + QLatin1String("_") + QString().number(num);
num++;
} while (not data->IsUnique(name));
newName = name;
}
m->SetMName(nameField->text(), newName);
MeasurementsWasSaved(false);
RefreshData();
@ -1657,11 +1661,6 @@ void TMainWindow::SaveMName()
ui->tableWidget->blockSignals(false);
}
else
{
ui->lineEditName->setText(ClearCustomName(nameField->text()));
}
}
else
{
qCWarning(tMainWindow, "%s", qUtf8Printable(tr("The name of known measurement forbidden to change.")));
}
@ -2146,11 +2145,9 @@ void TMainWindow::InitWindow()
ui->actionImportFromPattern->setEnabled(true);
ui->actionSaveAs->setEnabled(true);
#if QT_VERSION > QT_VERSION_CHECK(5, 1, 0)
ui->lineEditName->setValidator( new QRegularExpressionValidator(QRegularExpression(NameRegExp()), this));
#else
ui->lineEditName->setValidator( new QRegExpValidator(QRegExp(NameRegExp()), this));
#endif
ui->lineEditName->setValidator(new QRegularExpressionValidator(QRegularExpression(
QLatin1String("^$|")+NameRegExp()),
this));
connect(ui->toolButtonRemove, &QToolButton::clicked, this, &TMainWindow::Remove);
connect(ui->toolButtonTop, &QToolButton::clicked, this, &TMainWindow::MoveTop);
@ -2158,7 +2155,7 @@ void TMainWindow::InitWindow()
connect(ui->toolButtonDown, &QToolButton::clicked, this, &TMainWindow::MoveDown);
connect(ui->toolButtonBottom, &QToolButton::clicked, this, &TMainWindow::MoveBottom);
connect(ui->lineEditName, &QLineEdit::editingFinished, this, &TMainWindow::SaveMName);
connect(ui->lineEditName, &QLineEdit::textEdited, this, &TMainWindow::SaveMName);
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMDescription);
connect(ui->lineEditFullName, &QLineEdit::textEdited, this, &TMainWindow::SaveMFullName);
@ -2492,6 +2489,20 @@ void TMainWindow::RefreshTable()
}
}
//---------------------------------------------------------------------------------------------------------------------
QString TMainWindow::GetCustomName() const
{
qint32 num = 1;
QString name;
do
{
name = CustomMSign + qApp->TrVars()->InternalVarToUser(measurement_) + QString().number(num);
num++;
} while (data->IsUnique(name) == false);
return name;
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::Controls()
{

View File

@ -117,7 +117,7 @@ private slots:
void DeployFormula();
void SaveMName();
void SaveMName(const QString &text);
void SaveMValue();
void SaveMBaseValue(double value);
void SaveMSizeIncrease(double value);
@ -181,6 +181,7 @@ private:
void RefreshData();
void RefreshTable();
QString GetCustomName() const;
QString ClearCustomName(const QString &name) const;
bool EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label);

View File

@ -92,11 +92,8 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile);
ui->tabWidget->setCurrentIndex(0);
#if QT_VERSION > QT_VERSION_CHECK(5, 1, 0)
ui->lineEditName->setValidator( new QRegularExpressionValidator(QRegularExpression(NameRegExp()), this));
#else
ui->lineEditName->setValidator( new QRegExpValidator(QRegExp(NameRegExp()), this));
#endif
ui->lineEditName->setValidator( new QRegularExpressionValidator(QRegularExpression(
QLatin1String("^$|")+NameRegExp()), this));
connect(ui->tableWidgetIncrement, &QTableWidget::itemSelectionChanged, this,
&DialogIncrements::ShowIncrementDetails);
@ -107,7 +104,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
connect(ui->toolButtonDown, &QToolButton::clicked, this, &DialogIncrements::MoveDown);
connect(ui->pushButtonGrow, &QPushButton::clicked, this, &DialogIncrements::DeployFormula);
connect(ui->toolButtonExpr, &QToolButton::clicked, this, &DialogIncrements::Fx);
connect(ui->lineEditName, &QLineEdit::editingFinished, this, &DialogIncrements::SaveIncrName);
connect(ui->lineEditName, &QLineEdit::textEdited, this, &DialogIncrements::SaveIncrName);
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrDescription);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrFormula);
connect(ui->lineEditFind, &QLineEdit::textEdited, RECEIVER(this)[this](const QString &term){search->Find(term);});
@ -300,6 +297,19 @@ void DialogIncrements::AddCell(QTableWidget *table, const QString &text, int row
table->setItem(row, column, item);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogIncrements::GetCustomName() const
{
qint32 num = 1;
QString name;
do
{
name = CustomIncrSign + qApp->TrVars()->InternalVarToUser(increment_) + QString().number(num);
num++;
} while (not data->IsUnique(name));
return name;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogIncrements::ClearIncrementName(const QString &name) const
{
@ -467,15 +477,9 @@ void DialogIncrements::FullUpdateFromFile()
void DialogIncrements::AddIncrement()
{
qCDebug(vDialog, "Add a new increment");
qint32 num = 1;
QString name;
do
{
name = CustomIncrSign + qApp->TrVars()->InternalVarToUser(increment_) + QString().number(num);
num++;
} while (data->IsUnique(name)==false);
qint32 currentRow;
const QString name = GetCustomName();
qint32 currentRow = -1;
if (ui->tableWidgetIncrement->currentRow() == -1)
{
@ -554,7 +558,7 @@ void DialogIncrements::MoveDown()
}
//---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::SaveIncrName()
void DialogIncrements::SaveIncrName(const QString &text)
{
const int row = ui->tableWidgetIncrement->currentRow();
@ -564,20 +568,28 @@ void DialogIncrements::SaveIncrName()
}
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
const QString newName = CustomIncrSign + ui->lineEditName->text();
if (data->IsUnique(newName))
QString newName = text;
newName.isEmpty() ? newName = GetCustomName() : newName = CustomIncrSign + newName;
if (not data->IsUnique(newName))
{
qint32 num = 2;
QString name = newName;
do
{
name = name + QLatin1String("_") + QString().number(num);
num++;
} while (not data->IsUnique(name));
newName = name;
}
doc->SetIncrementName(nameField->text(), newName);
FullUpdateTree(Document::LiteParse);
ui->tableWidgetIncrement->blockSignals(true);
ui->tableWidgetIncrement->selectRow(row);
ui->tableWidgetIncrement->blockSignals(false);
}
else
{
ui->lineEditName->setText(ClearIncrementName(nameField->text()));
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::SaveIncrDescription()

View File

@ -66,7 +66,7 @@ private slots:
void RemoveIncrement();
void MoveUp();
void MoveDown();
void SaveIncrName();
void SaveIncrName(const QString &text);
void SaveIncrDescription();
void SaveIncrFormula();
void DeployFormula();
@ -105,7 +105,9 @@ private:
void AddCell(QTableWidget *table, const QString &text, int row, int column, int aligment, bool ok = true);
QString GetCustomName() const;
QString ClearIncrementName(const QString &name) const;
bool EvalIncrementFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label);
void Controls();
void EnableDetails(bool enabled);