Salome HOME
refs #550: fix crash when myObject is NULL
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageDlg.cxx
index 4286978d8d517ba799d5f2e9e5985419a104a463..2a65913e0af635fdbfcb97f1b48283a3c3d2421e 100644 (file)
@@ -1,12 +1,8 @@
-// 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
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -66,15 +62,15 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   myFileName = new QLineEdit( myFileNameGroup );
   myFileName->setReadOnly( true );
 
-  QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
-  aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
+  myBrowseBtn = new QToolButton( myFileNameGroup );
+  myBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
 
   QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
   aFileNameLayout->setMargin( 5 );
   aFileNameLayout->setSpacing( 5 );
   aFileNameLayout->addWidget( aFileNameLabel );
   aFileNameLayout->addWidget( myFileName );
-  aFileNameLayout->addWidget( aBrowseBtn );
+  aFileNameLayout->addWidget( myBrowseBtn );
 
   // Image name
   myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ), this );
@@ -343,7 +339,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   addWidget( myTransformGroup );
   addStretch();
 
-  connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
+  connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
 
   connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
            this, SLOT( onModeActivated( int ) ) );
@@ -701,20 +697,29 @@ HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsf
 void HYDROGUI_ImportImageDlg::onBrowse()
 {
   QString aFilter( tr( "IMAGE_FILTER" ) );
-  QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
-  if( !aFileName.isEmpty() )
+  QStringList aFileNamesList = SUIT_FileDlg::getOpenFileNames( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
+  emit filesSelected( aFileNamesList );
+}
+
+void HYDROGUI_ImportImageDlg::ActivateFile( const QString& theFileName, bool isEnableFilesChoice )
+{
+  myFileName->setEnabled( isEnableFilesChoice );
+  myBrowseBtn->setEnabled( isEnableFilesChoice );
+
+  if( !theFileName.isEmpty() )
   {
-    QImage anImage( aFileName );
+    QImage anImage( theFileName );
     if( anImage.isNull() )
     {
       QString aTitle = QObject::tr( "INPUT_VALID_DATA" );
       QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_IMPORTED" ).
-        arg( aFileName ).arg( QFileInfo( aFileName ).suffix() );
+        arg( theFileName ).arg( QFileInfo( theFileName ).suffix() );
       SUIT_MessageBox::warning( module()->getApp()->desktop(), aTitle, aMessage );
     }
     else
     {
-      setFileName( aFileName );
+      setFileName( theFileName );
+      setImageName( "" );
       emit createPreview( anImage );
     }
   }