]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/QT/SaveFileDialog.cxx
d42af9508122739ad61027e5a7296caf97d69a9a
[cpPlugins.git] / lib / cpPlugins / QT / SaveFileDialog.cxx
1 #include <cpPlugins/QT/SaveFileDialog.h>
2 #include <cpPlugins/Pipeline/Parameters.h>
3
4 // -------------------------------------------------------------------------
5 cpPlugins::QT::SaveFileDialog::
6 SaveFileDialog( QWidget* parent )
7   : QFileDialog( parent ),
8     m_Parameters( NULL ),
9     m_Name( "" )
10 {
11   this->connect(
12     this, SIGNAL( accepted( ) ), this, SLOT( _dlg_Accepted( ) )
13     );
14   this->setWindowTitle( "Save a file" );
15 }
16
17 // -------------------------------------------------------------------------
18 cpPlugins::QT::SaveFileDialog::
19 ~SaveFileDialog( )
20 {
21 }
22
23 // -------------------------------------------------------------------------
24 void cpPlugins::QT::SaveFileDialog::
25 SetParameters(
26   cpPlugins::Pipeline::Parameters* params, const std::string& name
27   )
28 {
29   if( params == NULL )
30   {
31     this->m_Parameters = NULL;
32     this->m_Name = "";
33     return;
34
35   } // fi
36   auto param_type = params->GetType( name );
37   if( param_type != cpPlugins::Pipeline::Parameters::SaveFileName )
38   {
39     this->m_Parameters = NULL;
40     this->m_Name = "";
41     return;
42
43   } // fi
44   this->m_Parameters = params;
45   this->m_Name = name;
46
47   QStringList filters;
48   auto extensions = this->m_Parameters->GetAcceptedFileExtensions( name );
49   if( extensions != "" )
50     filters << extensions.c_str( );
51   filters << "Any file (*)";
52   this->setFileMode( QFileDialog::AnyFile );
53   this->setNameFilters( filters );
54   this->setAcceptMode( QFileDialog::AcceptOpen );
55   auto file = this->m_Parameters->GetSaveFileName( this->m_Name );
56   if( file == "" )
57     file = ".";
58   QFileInfo info( file.c_str( ) );
59   this->setDirectory( info.canonicalPath( ) );
60 }
61
62 // -------------------------------------------------------------------------
63 void cpPlugins::QT::SaveFileDialog::
64 _dlg_Accepted( )
65 {
66   if( this->m_Parameters != NULL )
67   {
68     auto files = this->selectedFiles( );
69     this->m_Parameters->SetSaveFileName(
70       this->m_Name, files[ 0 ].toStdString( )
71       );
72
73   } // fi
74 }
75
76 // eof - $RCSfile$