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:
parent
6d271423e0
commit
1e06446189
|
@ -1280,15 +1280,8 @@ void TMainWindow::Fx()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TMainWindow::AddCustom()
|
void TMainWindow::AddCustom()
|
||||||
{
|
{
|
||||||
qint32 num = 1;
|
const QString name = GetCustomName();
|
||||||
QString name;
|
qint32 currentRow = -1;
|
||||||
do
|
|
||||||
{
|
|
||||||
name = CustomMSign + qApp->TrVars()->InternalVarToUser(measurement_) + QString().number(num);
|
|
||||||
num++;
|
|
||||||
} while (data->IsUnique(name) == false);
|
|
||||||
|
|
||||||
qint32 currentRow;
|
|
||||||
|
|
||||||
if (ui->tableWidget->currentRow() == -1)
|
if (ui->tableWidget->currentRow() == -1)
|
||||||
{
|
{
|
||||||
|
@ -1489,7 +1482,7 @@ void TMainWindow::ShowMData()
|
||||||
ShowMDiagram(meash->GetName());
|
ShowMDiagram(meash->GetName());
|
||||||
|
|
||||||
// Don't block all signal for QLineEdit. Need for correct handle with clear button.
|
// 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);
|
ui->plainTextEditDescription->blockSignals(true);
|
||||||
if (meash->IsCustom())
|
if (meash->IsCustom())
|
||||||
{
|
{
|
||||||
|
@ -1504,7 +1497,7 @@ void TMainWindow::ShowMData()
|
||||||
ui->lineEditFullName->setText(qApp->TrVars()->GuiText(meash->GetName()));
|
ui->lineEditFullName->setText(qApp->TrVars()->GuiText(meash->GetName()));
|
||||||
ui->lineEditName->setText(nameField->text());
|
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);
|
ui->plainTextEditDescription->blockSignals(false);
|
||||||
|
|
||||||
if (mType == MeasurementsType::Standard)
|
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();
|
const int row = ui->tableWidget->currentRow();
|
||||||
|
|
||||||
|
@ -1640,13 +1633,24 @@ void TMainWindow::SaveMName()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString newName = ui->lineEditName->text();
|
QString newName = text;
|
||||||
|
|
||||||
if (meash->IsCustom())
|
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);
|
m->SetMName(nameField->text(), newName);
|
||||||
MeasurementsWasSaved(false);
|
MeasurementsWasSaved(false);
|
||||||
RefreshData();
|
RefreshData();
|
||||||
|
@ -1657,11 +1661,6 @@ void TMainWindow::SaveMName()
|
||||||
ui->tableWidget->blockSignals(false);
|
ui->tableWidget->blockSignals(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
ui->lineEditName->setText(ClearCustomName(nameField->text()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
qCWarning(tMainWindow, "%s", qUtf8Printable(tr("The name of known measurement forbidden to change.")));
|
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->actionImportFromPattern->setEnabled(true);
|
||||||
ui->actionSaveAs->setEnabled(true);
|
ui->actionSaveAs->setEnabled(true);
|
||||||
|
|
||||||
#if QT_VERSION > QT_VERSION_CHECK(5, 1, 0)
|
ui->lineEditName->setValidator(new QRegularExpressionValidator(QRegularExpression(
|
||||||
ui->lineEditName->setValidator( new QRegularExpressionValidator(QRegularExpression(NameRegExp()), this));
|
QLatin1String("^$|")+NameRegExp()),
|
||||||
#else
|
this));
|
||||||
ui->lineEditName->setValidator( new QRegExpValidator(QRegExp(NameRegExp()), this));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
connect(ui->toolButtonRemove, &QToolButton::clicked, this, &TMainWindow::Remove);
|
connect(ui->toolButtonRemove, &QToolButton::clicked, this, &TMainWindow::Remove);
|
||||||
connect(ui->toolButtonTop, &QToolButton::clicked, this, &TMainWindow::MoveTop);
|
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->toolButtonDown, &QToolButton::clicked, this, &TMainWindow::MoveDown);
|
||||||
connect(ui->toolButtonBottom, &QToolButton::clicked, this, &TMainWindow::MoveBottom);
|
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->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMDescription);
|
||||||
connect(ui->lineEditFullName, &QLineEdit::textEdited, this, &TMainWindow::SaveMFullName);
|
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()
|
void TMainWindow::Controls()
|
||||||
{
|
{
|
||||||
|
|
|
@ -117,7 +117,7 @@ private slots:
|
||||||
|
|
||||||
void DeployFormula();
|
void DeployFormula();
|
||||||
|
|
||||||
void SaveMName();
|
void SaveMName(const QString &text);
|
||||||
void SaveMValue();
|
void SaveMValue();
|
||||||
void SaveMBaseValue(double value);
|
void SaveMBaseValue(double value);
|
||||||
void SaveMSizeIncrease(double value);
|
void SaveMSizeIncrease(double value);
|
||||||
|
@ -181,6 +181,7 @@ private:
|
||||||
void RefreshData();
|
void RefreshData();
|
||||||
void RefreshTable();
|
void RefreshTable();
|
||||||
|
|
||||||
|
QString GetCustomName() const;
|
||||||
QString ClearCustomName(const QString &name) const;
|
QString ClearCustomName(const QString &name) const;
|
||||||
|
|
||||||
bool EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label);
|
bool EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label);
|
||||||
|
|
|
@ -92,11 +92,8 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
|
||||||
connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile);
|
connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile);
|
||||||
|
|
||||||
ui->tabWidget->setCurrentIndex(0);
|
ui->tabWidget->setCurrentIndex(0);
|
||||||
#if QT_VERSION > QT_VERSION_CHECK(5, 1, 0)
|
ui->lineEditName->setValidator( new QRegularExpressionValidator(QRegularExpression(
|
||||||
ui->lineEditName->setValidator( new QRegularExpressionValidator(QRegularExpression(NameRegExp()), this));
|
QLatin1String("^$|")+NameRegExp()), this));
|
||||||
#else
|
|
||||||
ui->lineEditName->setValidator( new QRegExpValidator(QRegExp(NameRegExp()), this));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
connect(ui->tableWidgetIncrement, &QTableWidget::itemSelectionChanged, this,
|
connect(ui->tableWidgetIncrement, &QTableWidget::itemSelectionChanged, this,
|
||||||
&DialogIncrements::ShowIncrementDetails);
|
&DialogIncrements::ShowIncrementDetails);
|
||||||
|
@ -107,7 +104,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
|
||||||
connect(ui->toolButtonDown, &QToolButton::clicked, this, &DialogIncrements::MoveDown);
|
connect(ui->toolButtonDown, &QToolButton::clicked, this, &DialogIncrements::MoveDown);
|
||||||
connect(ui->pushButtonGrow, &QPushButton::clicked, this, &DialogIncrements::DeployFormula);
|
connect(ui->pushButtonGrow, &QPushButton::clicked, this, &DialogIncrements::DeployFormula);
|
||||||
connect(ui->toolButtonExpr, &QToolButton::clicked, this, &DialogIncrements::Fx);
|
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->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrDescription);
|
||||||
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrFormula);
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrFormula);
|
||||||
connect(ui->lineEditFind, &QLineEdit::textEdited, RECEIVER(this)[this](const QString &term){search->Find(term);});
|
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);
|
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
|
QString DialogIncrements::ClearIncrementName(const QString &name) const
|
||||||
{
|
{
|
||||||
|
@ -467,15 +477,9 @@ void DialogIncrements::FullUpdateFromFile()
|
||||||
void DialogIncrements::AddIncrement()
|
void DialogIncrements::AddIncrement()
|
||||||
{
|
{
|
||||||
qCDebug(vDialog, "Add a new increment");
|
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)
|
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();
|
const int row = ui->tableWidgetIncrement->currentRow();
|
||||||
|
|
||||||
|
@ -564,20 +568,28 @@ void DialogIncrements::SaveIncrName()
|
||||||
}
|
}
|
||||||
|
|
||||||
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
|
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);
|
doc->SetIncrementName(nameField->text(), newName);
|
||||||
FullUpdateTree(Document::LiteParse);
|
FullUpdateTree(Document::LiteParse);
|
||||||
ui->tableWidgetIncrement->blockSignals(true);
|
ui->tableWidgetIncrement->blockSignals(true);
|
||||||
ui->tableWidgetIncrement->selectRow(row);
|
ui->tableWidgetIncrement->selectRow(row);
|
||||||
ui->tableWidgetIncrement->blockSignals(false);
|
ui->tableWidgetIncrement->blockSignals(false);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ui->lineEditName->setText(ClearIncrementName(nameField->text()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DialogIncrements::SaveIncrDescription()
|
void DialogIncrements::SaveIncrDescription()
|
||||||
|
|
|
@ -66,7 +66,7 @@ private slots:
|
||||||
void RemoveIncrement();
|
void RemoveIncrement();
|
||||||
void MoveUp();
|
void MoveUp();
|
||||||
void MoveDown();
|
void MoveDown();
|
||||||
void SaveIncrName();
|
void SaveIncrName(const QString &text);
|
||||||
void SaveIncrDescription();
|
void SaveIncrDescription();
|
||||||
void SaveIncrFormula();
|
void SaveIncrFormula();
|
||||||
void DeployFormula();
|
void DeployFormula();
|
||||||
|
@ -105,7 +105,9 @@ private:
|
||||||
|
|
||||||
void AddCell(QTableWidget *table, const QString &text, int row, int column, int aligment, bool ok = true);
|
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;
|
QString ClearIncrementName(const QString &name) const;
|
||||||
|
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user