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