#ifdef cpPlugins_Interface_QT4
#include <queue>
#include <map>
+#include <sstream>
#include <vector>
+#include <QApplication>
#include <QDialogButtonBox>
#include <QDir>
#include <QFileDialog>
#include <QTreeWidget>
#include <QVBoxLayout>
-#endif // cpPlugins_Interface_QT4
+#include <cpPlugins/Interface/ParametersQtDialog.h>
#include <itkGDCMSeriesFileNames.h>
-// -------------------------------------------------------------------------
-bool cpPlugins::IO::DicomSeriesReader::
-ExecConfigurationDialog( QWidget* parent )
+/**
+ */
+class cpPlugins_IO_DicomSeriesReader_ParametersQtDialog
+ : public cpPlugins::Interface::ParametersQtDialog
{
- bool r = false;
-
-#ifdef cpPlugins_Interface_QT4
+public:
+ cpPlugins_IO_DicomSeriesReader_ParametersQtDialog(
+ QWidget* parent = 0, Qt::WindowFlags f = 0
+ )
+ : cpPlugins::Interface::ParametersQtDialog( parent, f )
+ {
+ }
+ virtual ~cpPlugins_IO_DicomSeriesReader_ParametersQtDialog( )
+ {
+ }
- // DICOM series analyzer
- itk::GDCMSeriesFileNames::GlobalWarningDisplayOff( );
- itk::GDCMSeriesFileNames::Pointer series =
- itk::GDCMSeriesFileNames::New( );
-
- typedef std::map< std::string, TStringList > _TSeries;
- typedef std::map< std::string, _TSeries > _TFilenames;
- _TSeries found_series;
- _TFilenames found_filenames;
-
- // Show dialog and check if it was accepted
- QFileDialog dialog( parent );
- dialog.setFileMode( QFileDialog::DirectoryOnly );
- dialog.setDirectory( QFileDialog::tr( "." ) );
- if( dialog.exec( ) )
- {
- std::string dir_name = dialog.selectedFiles( ).begin( )->toStdString( );
- std::queue< std::string > q;
- q.push( dir_name );
- while( !( q.empty( ) ) )
+protected:
+ virtual void _dlg_OpenMultipleFiles( )
{
- dir_name = q.front( );
- q.pop( );
-
- // Get DICOM information
- series->SetUseSeriesDetails( true );
- series->AddSeriesRestriction( "0008|0021" );
- series->SetDirectory( dir_name );
- const TStringList& seriesUID = series->GetSeriesUIDs( );
- if( seriesUID.size( ) > 0 )
+ // DICOM series analyzer
+ itk::GDCMSeriesFileNames::GlobalWarningDisplayOff( );
+ itk::GDCMSeriesFileNames::Pointer series =
+ itk::GDCMSeriesFileNames::New( );
+
+ // Show dialog and check if it was accepted
+ QWidget* parent = dynamic_cast< QWidget* >( this->parent( ) );
+ QFileDialog dialog( parent );
+ dialog.setFileMode( QFileDialog::DirectoryOnly );
+ dialog.setDirectory( QFileDialog::tr( "." ) );
+ if( !dialog.exec( ) )
+ return;
+
+ // Prepare dialog
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+ if( parent != NULL )
+ parent->setEnabled( false );
+
+ QDialog* tree_dialog = new QDialog( parent );
+ QTreeWidget* tree_widget = new QTreeWidget( tree_dialog );
+ QList< QTreeWidgetItem* > tree_items;
+ std::map<
+ std::string,
+ std::map< std::string, std::vector< std::string > >
+ > found_files;
+
+ std::string main_dir_name =
+ dialog.selectedFiles( ).begin( )->toStdString( );
+ std::queue< std::string > q;
+ q.push( main_dir_name );
+ while( !( q.empty( ) ) )
{
- TStringList::const_iterator sIt = seriesUID.begin( );
- for( ; sIt != seriesUID.end( ); ++sIt )
+ std::string dir_name = q.front( );
+ q.pop( );
+
+ // Get DICOM information
+ series->SetUseSeriesDetails( true );
+ series->AddSeriesRestriction( "0008|0021" );
+ series->SetDirectory( dir_name );
+ const std::vector< std::string >& seriesUID = series->GetSeriesUIDs( );
+ if( seriesUID.size( ) > 0 )
{
- TStringList filenames = series->GetFileNames( *sIt );
- if( filenames.size( ) > 0 )
+ QTreeWidgetItem* new_item = new QTreeWidgetItem(
+ ( QTreeWidgetItem* )( NULL ),
+ QStringList( dir_name.c_str( ) )
+ );
+ QTreeWidgetItem* new_leaf = NULL;
+ std::vector< std::string >::const_iterator sIt = seriesUID.begin( );
+ for( ; sIt != seriesUID.end( ); ++sIt )
{
- found_series[ dir_name ].push_back( *sIt );
- found_filenames[ dir_name ][ *sIt ] = filenames;
-
- } // fi
-
- } // rof
-
- } // fi
-
- // Update queue
- QDir dir( dir_name.c_str( ) );
- QFileInfoList contents = dir.entryInfoList( );
- QFileInfoList::const_iterator i = contents.begin( );
- for( ; i != contents.end( ); ++i )
- {
- if( i->isDir( ) )
- {
- std::string new_dir_name = i->absoluteFilePath( ).toStdString( );
- if( new_dir_name.size( ) > dir_name.size( ) )
- q.push( new_dir_name );
+ std::vector< std::string > filenames = series->GetFileNames( *sIt );
+ if( filenames.size( ) > 0 )
+ {
+ std::stringstream ss;
+ ss << "(" << filenames.size( ) << "): " << *sIt;
+ new_leaf =
+ new QTreeWidgetItem(
+ new_item, QStringList( ss.str( ).c_str( ) )
+ );
+ new_item->addChild( new_leaf );
+ found_files[ dir_name ][ *sIt ] = filenames;
+
+ } // fi
+
+ } // rof
+
+ if( new_leaf != NULL )
+ tree_items.append( new_item );
+ else
+ delete new_item;
} // fi
- } // rof
-
- } // elihw
-
- } // fi
+ // Update queue
+ QDir dir( dir_name.c_str( ) );
+ QFileInfoList contents = dir.entryInfoList( );
+ QFileInfoList::const_iterator i = contents.begin( );
+ for( ; i != contents.end( ); ++i )
+ {
+ if( i->isDir( ) )
+ {
+ std::string new_dir_name = i->absoluteFilePath( ).toStdString( );
+ if( new_dir_name.size( ) > dir_name.size( ) )
+ q.push( new_dir_name );
- // Show second dialog
- if( found_series.size( ) > 0 )
- {
- QDialog* tree_dialog = new QDialog( parent );
+ } // fi
- QLabel* title = new QLabel( tree_dialog );
- title->setText( "Choose a DICOM series" );
- QGridLayout* mainLayout = new QGridLayout( tree_dialog );
- QVBoxLayout* toolsLayout = new QVBoxLayout( );
- toolsLayout->addWidget( title );
- mainLayout->addLayout( toolsLayout, 0, 0, 1, 1 );
+ } // rof
- QTreeWidget* tree = new QTreeWidget( tree_dialog );
- QList< QTreeWidgetItem* > tree_items;
+ } // elihw
- _TSeries::const_iterator fsIt = found_series.begin( );
- for( ; fsIt != found_series.end( ); ++fsIt )
- {
- QTreeWidgetItem* new_item =
- new QTreeWidgetItem(
- ( QTreeWidgetItem* )( NULL ), QStringList( fsIt->first.c_str( ) )
- );
- TStringList::const_iterator sId = fsIt->second.begin( );
- for( ; sId != fsIt->second.end( ); ++sId )
+ // Show second dialog
+ if( tree_items.size( ) == 0 )
{
- QTreeWidgetItem* new_leaf =
- new QTreeWidgetItem( new_item, QStringList( sId->c_str( ) ) );
- new_item->addChild( new_leaf );
+ delete tree_widget;
+ delete tree_dialog;
+ return;
- } // rof
- tree_items.append( new_item );
+ } // fi
- } // rof
- tree->insertTopLevelItems( 0, tree_items );
- toolsLayout->addWidget( tree );
+ QLabel* title = new QLabel( tree_dialog );
+ title->setText( "Choose a DICOM series" );
+ QGridLayout* mainLayout = new QGridLayout( tree_dialog );
+ QVBoxLayout* toolsLayout = new QVBoxLayout( );
+ toolsLayout->addWidget( title );
+ mainLayout->addLayout( toolsLayout, 0, 0, 1, 1 );
+
+ tree_widget->insertTopLevelItems( 0, tree_items );
+ toolsLayout->addWidget( tree_widget );
+
+ QDialogButtonBox* bb = new QDialogButtonBox(
+ QDialogButtonBox::Ok | QDialogButtonBox::Cancel
+ );
+ tree_dialog->connect(
+ bb, SIGNAL( accepted( ) ), tree_dialog, SLOT( accept( ) )
+ );
+ tree_dialog->connect(
+ bb, SIGNAL( rejected( ) ), tree_dialog, SLOT( reject( ) )
+ );
+ toolsLayout->addWidget( bb );
+
+ QApplication::restoreOverrideCursor( );
+ if( parent != NULL )
+ parent->setEnabled( true );
- QDialogButtonBox* bb = new QDialogButtonBox(
- QDialogButtonBox::Ok | QDialogButtonBox::Cancel
- );
- tree_dialog->connect( bb, SIGNAL( accepted( ) ), tree_dialog, SLOT( accept( ) ) );
- tree_dialog->connect( bb, SIGNAL( rejected( ) ), tree_dialog, SLOT( reject( ) ) );
- toolsLayout->addWidget( bb );
+ if( tree_dialog->exec( ) == 0 )
+ return;
- if( tree_dialog->exec( ) == 1 )
- {
- QTreeWidgetItem* item = tree->currentItem( );
- QTreeWidgetItem* parent = item->parent( );
- if( parent != NULL )
+ QTreeWidgetItem* item = tree_widget->currentItem( );
+ if( item != NULL )
{
- std::string serie_dir = parent->text( 0 ).toStdString( );
- std::string serie_id = item->text( 0 ).toStdString( );
-
- this->m_Parameters->ClearStringList( "FileNames" );
- const TStringList& filenames = found_filenames[ serie_dir ][ serie_id ];
- for( unsigned int f = 0; f < filenames.size( ); ++f )
- this->m_Parameters->AddToStringList( "FileNames", filenames[ f ] );
+ QTreeWidgetItem* item_parent = item->parent( );
+ if( item_parent != NULL )
+ {
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+ if( parent != NULL )
+ parent->setEnabled( false );
+
+ std::string serie_dir = item_parent->text( 0 ).toStdString( );
+ std::string serie_id = item->text( 0 ).toStdString( );
+ serie_id = serie_id.substr( serie_id.find_first_of( " " ) + 1 );
+ this->m_Parameters->ClearOpenFileNameList( "FileNames" );
+ const std::vector< std::string >& names =
+ found_files[ serie_dir ][ serie_id ];
+ for( unsigned int f = 0; f < names.size( ); ++f )
+ this->m_Parameters->AddToOpenFileNameList( "FileNames", names[ f ] );
+ this->updateView( );
+
+ QApplication::restoreOverrideCursor( );
+ if( parent != NULL )
+ parent->setEnabled( true );
- r = true;
+ } // fi
} // fi
-
- } // fi
-
- } // fi
-
- itk::GDCMSeriesFileNames::GlobalWarningDisplayOn( );
+ itk::GDCMSeriesFileNames::GlobalWarningDisplayOn( );
+ }
+};
#endif // cpPlugins_Interface_QT4
- return( r );
-}
-
// -------------------------------------------------------------------------
cpPlugins::IO::DicomSeriesReader::
DicomSeriesReader( )
: Superclass( )
{
+#ifdef cpPlugins_Interface_QT4
+ if( QApplication::instance( ) != NULL )
+ {
+ this->m_ParametersDialog =
+ new cpPlugins_IO_DicomSeriesReader_ParametersQtDialog( );
+ this->m_ParametersDialog->setParameters( this->m_Parameters );
+
+ } // fi
+#endif // cpPlugins_Interface_QT4
}
// -------------------------------------------------------------------------