1 #include <cpPlugins/QT/OpenFileDialog.h>
2 #include <cpPlugins/Pipeline/Parameters.h>
4 // -------------------------------------------------------------------------
5 cpPlugins::QT::OpenFileDialog::
6 OpenFileDialog( QWidget* parent )
7 : QFileDialog( parent ),
12 this, SIGNAL( accepted( ) ), this, SLOT( _dlg_Accepted( ) )
14 this->setWindowTitle( "Open an(some) file(s)" );
17 // -------------------------------------------------------------------------
18 cpPlugins::QT::OpenFileDialog::
23 // -------------------------------------------------------------------------
24 void cpPlugins::QT::OpenFileDialog::
26 cpPlugins::Pipeline::Parameters* params, const std::string& name
31 this->m_Parameters = NULL;
36 auto param_type = params->GetType( name );
38 param_type != cpPlugins::Pipeline::Parameters::OpenFileName &&
39 param_type != cpPlugins::Pipeline::Parameters::OpenFileNameList
42 this->m_Parameters = NULL;
47 this->m_Parameters = params;
51 auto extensions = this->m_Parameters->GetAcceptedFileExtensions( name );
52 if( extensions != "" )
53 filters << extensions.c_str( );
54 filters << "Any file (*)";
55 if( param_type == cpPlugins::Pipeline::Parameters::OpenFileName )
56 this->setFileMode( QFileDialog::ExistingFile );
58 this->setFileMode( QFileDialog::ExistingFiles );
59 this->setNameFilters( filters );
60 this->setAcceptMode( QFileDialog::AcceptOpen );
61 if( param_type == cpPlugins::Pipeline::Parameters::OpenFileName )
63 auto file = this->m_Parameters->GetOpenFileName( this->m_Name );
66 QFileInfo info( file.c_str( ) );
67 this->setDirectory( info.canonicalPath( ) );
71 auto files = this->m_Parameters->GetOpenFileNameList( this->m_Name );
72 if( files.size( ) > 0 )
74 QFileInfo info( files[ 0 ].c_str( ) );
75 this->setDirectory( info.canonicalPath( ) );
78 this->setDirectory( "." );
83 // -------------------------------------------------------------------------
84 void cpPlugins::QT::OpenFileDialog::
87 if( this->m_Parameters != NULL )
89 auto files = this->selectedFiles( );
90 auto param_type = this->m_Parameters->GetType( this->m_Name );
91 if( param_type == cpPlugins::Pipeline::Parameters::OpenFileNameList )
93 this->m_Parameters->ClearOpenFileNameList( this->m_Name );
94 for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt )
95 this->m_Parameters->AddToOpenFileNameList(
96 this->m_Name, fIt->toStdString( )
100 this->m_Parameters->SetOpenFileName(
101 this->m_Name, files[ 0 ].toStdString( )