Salome HOME
Fix for the bug #164: default Image name.
authorrkv <rkv@opencascade.com>
Wed, 4 Dec 2013 11:51:43 +0000 (11:51 +0000)
committerrkv <rkv@opencascade.com>
Wed, 4 Dec 2013 11:51:43 +0000 (11:51 +0000)
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx

index e9c2fa388414b9f806951f713480916d85bf0c81..3c3f64f039ec95f2655f277296b8c6ef2d523a1c 100644 (file)
@@ -43,6 +43,7 @@
 #include <SUIT_Desktop.h>
 #include <QtxWorkstack.h>
 #include <QApplication>
+#include <QFileInfo>
 
 HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule,
                                                 const bool theIsEdit )
@@ -530,14 +531,27 @@ void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
       }
     }
 
-    QString anImageName;
-    if( myIsEdit )
+    // Set the image name in the dialog
+    QString anImageName = aPanel->getImageName().simplified();
+    // If edit mode and the name was not set yet then get from the edited object
+    if( myIsEdit && anImageName.isEmpty() )
     {
       if( !myEditedObject.IsNull() )
         anImageName = myEditedObject->GetName();
     }
-    else
-      anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
+    // If the name was not set then initialize it from the selected file name
+    if ( anImageName.isEmpty() )
+    {
+      anImageName = aPanel->getFileName();
+      if ( !anImageName.isEmpty() ) {
+          anImageName = QFileInfo( anImageName ).baseName();
+      }
+      // If no file name then generate a new image name
+      if ( anImageName.isEmpty() ) {
+        anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
+      }
+    }
+
     aPanel->setImageName( anImageName );
   }