diff options
| author | 2025-01-16 01:58:22 -0500 | |
|---|---|---|
| committer | 2025-01-16 01:58:22 -0500 | |
| commit | a5ae79be08125b31bb6b8d9703090a98c6fd2e30 (patch) | |
| tree | 569ee612c9de85b2bb423efa485688ef1d43852e /SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp | |
| parent | 21966b4f924b0a1933d9662e75ff253bd154fdb7 (diff) | |
| parent | 81a21e6ce040e7740de86340c8ea4dba30e69bc3 (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/functionseditormodel.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp index 46ae8d9..13ec34f 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp @@ -266,16 +266,17 @@ QStringList FunctionsEditorModel::getFunctionNames() const void FunctionsEditorModel::validateNames() { - StrHash<QList<int>> counter; + QHash<UniqueFunctionName, QList<int>> counter; int row = 0; for (Function*& func : functionList) { func->valid &= true; - counter[func->data.name] << row++; + UniqueFunctionName uniqueName = func->toUniqueName(); + counter[uniqueName] << row++; } - QHashIterator<QString,QList<int>> cntIt = counter.iterator(); + QHashIterator<UniqueFunctionName, QList<int>> cntIt(counter); while (cntIt.hasNext()) { cntIt.next(); @@ -294,11 +295,18 @@ void FunctionsEditorModel::validateNames() } } -bool FunctionsEditorModel::isAllowedName(int rowToSkip, const QString& nameToValidate) +bool FunctionsEditorModel::isAllowedName(int rowToSkip, const QString& nameToValidate, const QStringList& argList, bool undefinedArgs) { - QStringList names = getFunctionNames(); + QList<UniqueFunctionName> names = getUniqueFunctionNames(); names.removeAt(rowToSkip); - return !names.contains(nameToValidate, Qt::CaseInsensitive); + + UniqueFunctionName validatedName; + validatedName.name = nameToValidate.toLower(); + validatedName.undefArg = undefinedArgs; + if (!undefinedArgs) + validatedName.arguments = argList; + + return !names.contains(validatedName); } int FunctionsEditorModel::rowCount(const QModelIndex& parent) const @@ -347,6 +355,15 @@ void FunctionsEditorModel::emitDataChanged(int row) emit dataChanged(idx, idx); } +QList<FunctionsEditorModel::UniqueFunctionName> FunctionsEditorModel::getUniqueFunctionNames() const +{ + QList<UniqueFunctionName> names; + for (Function* func : functionList) + names << func->toUniqueName(); + + return names; +} + FunctionsEditorModel::Function::Function() { } @@ -356,3 +373,29 @@ FunctionsEditorModel::Function::Function(FunctionManager::ScriptFunction* other) data = FunctionManager::ScriptFunction(*other); originalName = data.name; } + +FunctionsEditorModel::UniqueFunctionName FunctionsEditorModel::Function::toUniqueName() const +{ + UniqueFunctionName uniqName; + uniqName.name = data.name.toLower(); + uniqName.undefArg = data.undefinedArgs; + if (!data.undefinedArgs) + uniqName.arguments = data.arguments; + + return uniqName; +} + +int FunctionsEditorModel::UniqueFunctionName::argCount() const +{ + return undefArg ? -1 : arguments.size(); +} + +bool FunctionsEditorModel::UniqueFunctionName::operator==(const UniqueFunctionName &other) const +{ + return name == other.name && argCount() == other.argCount(); +} + +int qHash(FunctionsEditorModel::UniqueFunctionName fnName) +{ + return qHash(fnName.name) ^ fnName.argCount(); +} |
