Salome HOME
Name validator is added to the Calculation Case dialog.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationDlg.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();
 }