aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2025-01-16 01:58:22 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2025-01-16 01:58:22 -0500
commita5ae79be08125b31bb6b8d9703090a98c6fd2e30 (patch)
tree569ee612c9de85b2bb423efa485688ef1d43852e /SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp
parent21966b4f924b0a1933d9662e75ff253bd154fdb7 (diff)
parent81a21e6ce040e7740de86340c8ea4dba30e69bc3 (diff)
Update upstream source from tag 'upstream/3.4.13+dfsg'
Update to upstream version '3.4.13+dfsg' with Debian dir bf81ee0219cb8e4562a4751df17d75814772d2d6
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp46
1 files changed, 37 insertions, 9 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp
index 4d964c8..e349525 100644
--- a/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp
@@ -170,9 +170,12 @@ int FunctionsEditor::getCurrentFunctionRow() const
void FunctionsEditor::functionDeselected(int row)
{
model->setName(row, ui->nameEdit->text());
+ model->setUndefinedArgs(row, ui->undefArgsCheck->isChecked());
+ if (!ui->undefArgsCheck->isChecked())
+ model->setArguments(row, getCurrentArgList());
+
model->setLang(row, ui->langCombo->currentText());
model->setType(row, getCurrentFunctionType());
- model->setUndefinedArgs(row, ui->undefArgsCheck->isChecked());
model->setAllDatabases(row, ui->allDatabasesRadio->isChecked());
model->setCode(row, ui->mainCodeEdit->toPlainText());
model->setDeterministic(row, ui->deterministicCheck->isChecked());
@@ -189,9 +192,6 @@ void FunctionsEditor::functionDeselected(int row)
model->setFinalCode(row, QString());
}
- if (!ui->undefArgsCheck->isChecked())
- model->setArguments(row, getCurrentArgList());
-
if (ui->selDatabasesRadio->isChecked())
model->setDatabases(row, getCurrentDatabases());
@@ -416,8 +416,10 @@ void FunctionsEditor::updateCurrentFunctionState()
}
QString name = ui->nameEdit->text();
- bool nameOk = model->isAllowedName(row, name) && !name.trimmed().isEmpty();
- setValidState(ui->nameEdit, nameOk, tr("Enter a non-empty, unique name of the function."));
+ QStringList argList = getCurrentArgList();
+ bool undefArgs = ui->undefArgsCheck->isChecked();
+ bool nameOk = model->isAllowedName(row, name, argList, undefArgs) && !name.trimmed().isEmpty();
+ setValidState(ui->nameEdit, nameOk, tr("Enter a unique, non-empty function name. Duplicate names are allowed if the number of input parameters differs."));
bool langOk = ui->langCombo->currentIndex() >= 0;
ui->initCodeGroup->setEnabled(langOk);
@@ -488,8 +490,8 @@ void FunctionsEditor::updateCurrentFunctionState()
currentHighlighterLang = lang;
}
- updateArgsState();
- model->setValid(row, langOk && codeOk && finalCodeOk && nameOk);
+ bool argsOk = updateArgsState();
+ model->setValid(row, langOk && codeOk && finalCodeOk && nameOk && argsOk);
updateState();
}
@@ -576,7 +578,7 @@ void FunctionsEditor::moveFunctionArgDown()
ui->argsList->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::Clear|QItemSelectionModel::SelectCurrent);
}
-void FunctionsEditor::updateArgsState()
+bool FunctionsEditor::updateArgsState()
{
bool argsEnabled = !ui->undefArgsCheck->isChecked();
QModelIndexList indexes = ui->argsList->selectionModel()->selectedIndexes();
@@ -596,6 +598,32 @@ void FunctionsEditor::updateArgsState()
actionMap[ARG_MOVE_UP]->setEnabled(argsEnabled && canMoveUp);
actionMap[ARG_MOVE_DOWN]->setEnabled(argsEnabled && canMoveDown);
ui->argsList->setEnabled(argsEnabled);
+
+ if (argsEnabled)
+ {
+ bool argsOk = true;
+ QSet<QString> usedNames;
+ for (int rowIdx = 0; rowIdx < ui->argsList->model()->rowCount(); rowIdx++)
+ {
+ QListWidgetItem* item = ui->argsList->item(rowIdx);
+ QString argName = item->text().toLower();
+ if (argName.isEmpty())
+ {
+ argsOk = false;
+ break;
+ }
+ if (usedNames.contains(argName))
+ {
+ argsOk = false;
+ break;
+ }
+ usedNames << argName;
+ }
+ setValidState(ui->argsList, argsOk, tr("Function argument cannot be empty and it cannot have duplicated name."));
+ return argsOk;
+ }
+ else
+ return true;
}
void FunctionsEditor::applyFilter(const QString& value)