From 3577628501b5a25b34216d63641df4348f648953 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 3 Aug 2020 12:56:01 +0300 Subject: [PATCH] Issue #3237: Use for names of objects letters, digits, '_' and space --- src/XGUI/XGUI_ObjectsBrowser.cpp | 1 - src/XGUI/XGUI_Tools.cpp | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 1938f9b79..4c5cfc9ad 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -131,7 +131,6 @@ void XGUI_DataTree::commitData(QWidget* theEditor) if (XGUI_Tools::canRename(aObj, aName)) { SessionPtr aMgr = ModelAPI_Session::get(); aMgr->startOperation("Rename"); - std::wstring aaa = aName.toStdWString(); aObj->data()->setName(aName.toStdWString()); aMgr->finishOperation(); } diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 96fa5f4b8..e04bc4547 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -182,6 +182,20 @@ bool isAscii(const QString& theStr) return true; } +//****************************************************************** +bool isValidName(const QString& theName) +{ + QChar aChar; + for (int i = 0; i < theName.size(); i++) { + aChar = theName[i]; + if (!aChar.isLetterOrNumber()) { + if ((aChar != "_") && (!aChar.isSpace())) + return false; + } + } + return true; +} + //****************************************************************** bool canRename(const ObjectPtr& theObject, const QString& theName) { @@ -205,6 +219,9 @@ bool canRename(const ObjectPtr& theObject, const QString& theName) } } else { + if (!isValidName(theName)) + return false; + DocumentPtr aDoc = theObject->document(); ObjectPtr aObj = aDoc->objectByName(aType, theName.toStdWString()); -- 2.39.2