]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Name validator is added to the Calculation Case dialog.
authorrkv <rkv@opencascade.com>
Wed, 30 Oct 2013 07:11:46 +0000 (07:11 +0000)
committerrkv <rkv@opencascade.com>
Wed, 30 Oct 2013 07:11:46 +0000 (07:11 +0000)
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_CalculationDlg.cxx
src/HYDROGUI/HYDROGUI_CalculationDlg.h
src/HYDROGUI/HYDROGUI_NameValidator.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_NameValidator.h [new file with mode: 0644]

index 2e227bad5b968599403bdc491407d360d626a268..c88b7ba182c939eb5a98e21ae1efab676504986c 100644 (file)
@@ -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
index 733ab5d5e9c447789b8c911226832ef355ec8f9f..1713e060600131042317f98638f32c8998e9f567 100644 (file)
@@ -28,6 +28,7 @@
 #include "HYDROGUI_DataModel.h"
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_DataObject.h"
+#include "HYDROGUI_NameValidator.h"
 
 #include <HYDROData_Document.h>
 #include <HYDROData_Entity.h>
 #include <SUIT_Session.h>
 #include <SUIT_Study.h>
 
+#include <LightApp_Application.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+
 #include <QGroupBox>
 #include <QLabel>
 #include <QLayout>
@@ -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();
 }
index 55a98ca1cf9fccb1e3918cf651f9f2971de90e74..37206ede90ca26759bd3511c617c2a76407e077d 100644 (file)
@@ -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 (file)
index 0000000..5c66304
--- /dev/null
@@ -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 (file)
index 0000000..05ddc8b
--- /dev/null
@@ -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 <HYDROData_Entity.h>
+#include <QValidator>
+
+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