From f99b39f1b9dbf6939a1c605331c250dd8d59e897 Mon Sep 17 00:00:00 2001 From: rkv Date: Wed, 30 Oct 2013 07:11:46 +0000 Subject: [PATCH] Name validator is added to the Calculation Case dialog. --- src/HYDROGUI/CMakeLists.txt | 2 + src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 26 +++++++- src/HYDROGUI/HYDROGUI_CalculationDlg.h | 5 ++ src/HYDROGUI/HYDROGUI_NameValidator.cxx | 76 ++++++++++++++++++++++++ src/HYDROGUI/HYDROGUI_NameValidator.h | 53 +++++++++++++++++ 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 src/HYDROGUI/HYDROGUI_NameValidator.cxx create mode 100644 src/HYDROGUI/HYDROGUI_NameValidator.h diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 2e227bad..c88b7ba1 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -23,6 +23,7 @@ set(PROJECT_HEADERS HYDROGUI_ImportImageOp.h HYDROGUI_InputPanel.h HYDROGUI_Module.h + HYDROGUI_NameValidator.h HYDROGUI_ObjSelector.h HYDROGUI_ObserveImageOp.h HYDROGUI_OCCDisplayer.h @@ -74,6 +75,7 @@ set(PROJECT_SOURCES HYDROGUI_ImportImageOp.cxx HYDROGUI_InputPanel.cxx HYDROGUI_Module.cxx + HYDROGUI_NameValidator.cxx HYDROGUI_ObjSelector.cxx HYDROGUI_ObserveImageOp.cxx HYDROGUI_OCCDisplayer.cxx diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 733ab5d5..1713e060 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -28,6 +28,7 @@ #include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_DataObject.h" +#include "HYDROGUI_NameValidator.h" #include #include @@ -41,6 +42,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -79,6 +84,11 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { // myObjectName = new QLineEdit( myObjectNameGroup ); myObjectName = new QLineEdit( aPage ); + myValidator = new HYDROGUI_NameValidator(module(), myObjectName); + myObjectName->setValidator( myValidator ); + + connect( myValidator, SIGNAL( emptyName() ), this, SLOT( onEmptyName() ) ); + connect( myValidator, SIGNAL( alreadyExists( QString ) ), this, SLOT( onAlreadyExists( QString ) ) ); //QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup ); //aNameLayout->setMargin( 5 ); @@ -132,6 +142,20 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { return aPage; } +void HYDROGUI_CalculationDlg::onEmptyName() +{ + QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" ); + QString aMessage = QObject::tr( "INCORRECT_OBJECT_NAME" ); + SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage ); +} + +void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName ) +{ + QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" ); + QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ); + SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage ); +} + QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { QWizardPage* aPage = new QWizardPage( wizard() ); QFrame* aFrame = new QFrame( aPage ); @@ -206,13 +230,13 @@ QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase ) { myEditedObject = theCase; + myValidator->setEditedObject( theCase ); HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" ); myBrowser->setRoot(anobj); LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj, myEditedObject, "", true ); - myBrowser->updateTree(); myBrowser->openLevels(); } diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index 55a98ca1..37206ede 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -32,6 +32,7 @@ class QLineEdit; class QListWidget; class QComboBox; class HYDROGUI_DataBrowser; +class HYDROGUI_NameValidator; class HYDROGUI_CalculationDlg : public HYDROGUI_Wizard { @@ -52,6 +53,9 @@ public: void setSelectedGeomObjects( const QStringList& theObjects ); QStringList getSelectedGeomObjects() const; + public slots: + void onEmptyName(); + void onAlreadyExists( QString theName ); private: QWizardPage* createObjectsPage(); @@ -59,6 +63,7 @@ private: QGroupBox* myObjectNameGroup; QLineEdit* myObjectName; + HYDROGUI_NameValidator* myValidator; QListWidget* myGeomObjects; diff --git a/src/HYDROGUI/HYDROGUI_NameValidator.cxx b/src/HYDROGUI/HYDROGUI_NameValidator.cxx new file mode 100644 index 00000000..5c663041 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_NameValidator.cxx @@ -0,0 +1,76 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_NameValidator.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_Module.h" + +HYDROGUI_NameValidator::HYDROGUI_NameValidator( HYDROGUI_Module* theModule, QObject* parent ) +: QValidator( parent ), myModule( theModule ) +{ +} + +HYDROGUI_NameValidator::~HYDROGUI_NameValidator() +{ +} + +QValidator::State HYDROGUI_NameValidator::validate( QString & theName, int & thePos ) const +{ + State aRes = Acceptable; + QString aName = theName.simplified(); + + if ( aName.isEmpty() ) + { + aRes = Intermediate; + } + else if( !myEditedObject.IsNull() && myEditedObject->GetName() != theName ) + { + // check that there are no other objects with the same name in the document + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( myModule, aName ); + if ( !anObject.IsNull() ) + { + aRes = Intermediate; + } + } + + return aRes; +} + +void HYDROGUI_NameValidator::fixup( QString & theName ) const +{ + theName = theName.simplified(); + if ( theName.isEmpty() ) + { + emit emptyName(); + } + else + { + emit alreadyExists( theName ); + } + + theName = myEditedObject->GetName(); +} + +void HYDROGUI_NameValidator::setEditedObject( const Handle(HYDROData_Entity) theObj ) +{ + myEditedObject = theObj; +} diff --git a/src/HYDROGUI/HYDROGUI_NameValidator.h b/src/HYDROGUI/HYDROGUI_NameValidator.h new file mode 100644 index 00000000..05ddc8b7 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_NameValidator.h @@ -0,0 +1,53 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_NAMEVALIDATOR_H +#define HYDROGUI_NAMEVALIDATOR_H + +#include +#include + +class HYDROGUI_Module; + +class HYDROGUI_NameValidator : public QValidator +{ + Q_OBJECT + +public: + HYDROGUI_NameValidator( HYDROGUI_Module* theModule, QObject* parent = 0 ); + virtual ~HYDROGUI_NameValidator(); + + State validate ( QString & theName, int & thePos ) const override; + void fixup ( QString & input ) const override; + + void setEditedObject( const Handle(HYDROData_Entity) theObj ); + +signals: + void emptyName() const; + void alreadyExists( QString theName ) const; + +private: + HYDROGUI_Module* myModule; + Handle(HYDROData_Entity) myEditedObject; +}; + +#endif -- 2.39.2