From 9db1bda2d32466d92fcf87f263baed3b987dfde6 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Thu, 24 Sep 2015 18:16:28 +0200 Subject: [PATCH] ... --- appli/ImageMPR/ImageMPR.cxx | 14 +- lib/cpPlugins/Interface/CMakeLists.txt | 42 ++++++ lib/cpPlugins/Interface/Config.h.in | 19 +++ .../Interface/ParametersListWidget.cxx | 137 ++++++++++++++++++ .../Interface/ParametersListWidget.h | 51 +++++++ .../Interface/ParametersListWidget.ui | 42 ++++++ .../Interface/ParametersQtDialog.cxx | 70 +++++---- lib/cpPlugins/Interface/ProcessObject.cxx | 26 ++++ lib/cpPlugins/Interface/ProcessObject.h | 9 ++ 9 files changed, 370 insertions(+), 40 deletions(-) create mode 100644 lib/cpPlugins/Interface/Config.h.in create mode 100644 lib/cpPlugins/Interface/ParametersListWidget.cxx create mode 100644 lib/cpPlugins/Interface/ParametersListWidget.h create mode 100644 lib/cpPlugins/Interface/ParametersListWidget.ui diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index f17e719..412b9ed 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -310,18 +310,13 @@ _triggered_actionImageToImage( ) // Configure filter TPluginFilter::Pointer filter = this->m_Plugins.CreateProcessObject( name ); - TParameters parameters = filter->GetDefaultParameters( ); - bool dlg_ok = - cpPlugins::Interface::ParametersQtDialog( - parameters, filter->GetClassName( ) - ); + bool dlg_ok = filter->ExecConfigurationDialog( NULL ); if( !dlg_ok ) return; // Execute filter QApplication::setOverrideCursor( Qt::WaitCursor ); this->setEnabled( false ); - filter->SetParameters( parameters ); filter->SetInput( 0, this->m_InputImage ); std::string err = filter->Update( ); QApplication::restoreOverrideCursor( ); @@ -360,18 +355,13 @@ _triggered_actionImageToMesh( ) // Configure filter TPluginFilter::Pointer filter = this->m_Plugins.CreateProcessObject( name ); - TParameters parameters = filter->GetDefaultParameters( ); - bool dlg_ok = - cpPlugins::Interface::ParametersQtDialog( - parameters, filter->GetClassName( ) - ); + bool dlg_ok = filter->ExecConfigurationDialog( NULL ); if( !dlg_ok ) return; // Execute filter QApplication::setOverrideCursor( Qt::WaitCursor ); this->setEnabled( false ); - filter->SetParameters( parameters ); filter->SetInput( 0, this->m_InputImage ); std::string err = filter->Update( ); QApplication::restoreOverrideCursor( ); diff --git a/lib/cpPlugins/Interface/CMakeLists.txt b/lib/cpPlugins/Interface/CMakeLists.txt index 36dc3f8..6d73928 100644 --- a/lib/cpPlugins/Interface/CMakeLists.txt +++ b/lib/cpPlugins/Interface/CMakeLists.txt @@ -1,5 +1,11 @@ SET(LIBRARY_NAME cpPlugins_Interface) +CONFIGURE_FILE( + Config.h.in + ${PROJECT_BINARY_DIR}/lib/cpPlugins/Interface/Config.h + @ONLY + ) + ## =============== ## = Source code = ## =============== @@ -61,6 +67,42 @@ IF(USE_QT4) ${LIB_SOURCES_CXX} ParametersQtDialog.cxx ) + + SET( + LIB_QT_UI + ParametersListWidget.ui + ) + SET( + LIB_QT_Headers + ParametersListWidget.h + ) + SET( + LIB_QT_Sources + ParametersListWidget.cxx + ) + SET( + LIB_QT_Resources + ) + + QT4_WRAP_UI(LIB_QT_Wrapped_Headers ${LIB_QT_UI}) + QT4_WRAP_CPP(LIB_QT_Wrapped_MOC_Sources ${LIB_QT_Headers}) + QT4_ADD_RESOURCES(LIB_QT_Wrapped_Resources_Sources ${LIB_QT_Resources}) + + SET( + LIB_HEADERS_H + ${LIB_HEADERS_H} + ${LIB_QT_Wrapped_Headers} + ) + + SET( + LIB_SOURCES_CXX + ${LIB_SOURCES_CXX} + ${LIB_QT_Sources} + ${LIB_QT_Wrapped_Headers} + ${LIB_QT_Wrapped_MOC_Sources} + ${LIB_QT_Wrapped_Resources_Sources} + ) + ENDIF(USE_QT4) ## ===================== diff --git a/lib/cpPlugins/Interface/Config.h.in b/lib/cpPlugins/Interface/Config.h.in new file mode 100644 index 0000000..58a9286 --- /dev/null +++ b/lib/cpPlugins/Interface/Config.h.in @@ -0,0 +1,19 @@ +#ifndef __CPPLUGINS__INTERFACE__CONFIG__H__ +#define __CPPLUGINS__INTERFACE__CONFIG__H__ + + +#define cpPlugins_MAJOR_VERSION @prj_MAJOR_VERSION@ +#define cpPlugins_MINOR_VERSION @prj_MINOR_VERSION@ +#define cpPlugins_RELEASE_VERSION @prj_RELEASE_VERSION@ +#define cpPlugins_VERSION "@prj_VERSION@" + +#define cpPlugins_Interface_QT4_USED @QT4_FOUND@ +#if cpPlugins_Interface_QT4_USED == 1 +# define cpPlugins_Interface_QT4 +#else // cpPlugins_Interface_QT4_USED == 1 +# undef cpPlugins_Interface_QT4 +#endif // cpPlugins_Interface_QT4_USED == 1 + +#endif // __CPPLUGINS__INTERFACE__CONFIG__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/ParametersListWidget.cxx b/lib/cpPlugins/Interface/ParametersListWidget.cxx new file mode 100644 index 0000000..752bb68 --- /dev/null +++ b/lib/cpPlugins/Interface/ParametersListWidget.cxx @@ -0,0 +1,137 @@ +#include +#include + +#include + +// ------------------------------------------------------------------------- +cpPlugins::Interface::ParametersListWidget:: +ParametersListWidget( const std::string& list_name, QWidget* parent ) + : QWidget( parent ), + m_UI( new Ui::ParametersListWidget ) +{ + this->m_UI->setupUi( this ); + + // Configure table + QTableWidget* table = this->m_UI->ValuesTable; + table->setColumnCount( 1 ); + table->setRowCount( 1 ); + + QStringList header; + header << list_name.c_str( ); + table->setHorizontalHeaderLabels( header ); + table->setShowGrid( true ); + table->setSelectionBehavior( QAbstractItemView::SelectRows ); + + // Connect signals + QObject::connect( + this->m_UI->AddValueButton, SIGNAL( clicked( ) ), + this, SLOT( _changeValuesCount( ) ) + ); + QObject::connect( + this->m_UI->RemoveValueButton, SIGNAL( clicked( ) ), + this, SLOT( _changeValuesCount( ) ) + ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::ParametersListWidget:: +~ParametersListWidget( ) +{ + delete this->m_UI; +} + +// ------------------------------------------------------------------------- +std::vector< std::string > cpPlugins::Interface::ParametersListWidget:: +GetStringValues( ) const +{ + std::vector< std::string > values; + + QTableWidget* table = this->m_UI->ValuesTable; + for( int i = 0; i < table->rowCount( ); ++i ) + values.push_back( table->item( i, 0 )->text( ).toStdString( ) ); + return( values ); +} + +// ------------------------------------------------------------------------- +std::vector< int > cpPlugins::Interface::ParametersListWidget:: +GetIntValues( ) const +{ + std::vector< int > values; + + QTableWidget* table = this->m_UI->ValuesTable; + for( int i = 0; i < table->rowCount( ); ++i ) + { + const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( ); + char* ptr = 0; + double v = std::strtod( text, &ptr ); + if( *ptr == '\0' && ptr != text ) + values.push_back( int( v ) ); + + } // rof + return( values ); +} + +// ------------------------------------------------------------------------- +std::vector< unsigned int > cpPlugins::Interface::ParametersListWidget:: +GetUintValues( ) const +{ + std::vector< unsigned int > values; + + QTableWidget* table = this->m_UI->ValuesTable; + for( int i = 0; i < table->rowCount( ); ++i ) + { + const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( ); + char* ptr = 0; + double v = std::strtod( text, &ptr ); + if( *ptr == '\0' && ptr != text && v >= double( 0 ) ) + values.push_back( ( unsigned int )( v ) ); + + } // rof + return( values ); +} + +// ------------------------------------------------------------------------- +std::vector< double > cpPlugins::Interface::ParametersListWidget:: +GetDoubleValues( ) const +{ + std::vector< double > values; + + QTableWidget* table = this->m_UI->ValuesTable; + for( int i = 0; i < table->rowCount( ); ++i ) + { + const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( ); + char* ptr = 0; + double v = std::strtod( text, &ptr ); + if( *ptr == '\0' && ptr != text ) + values.push_back( v ); + + } // rof + return( values ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersListWidget:: +_changeValuesCount( ) +{ + QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) ); + if( btn == NULL ) + return; + QTableWidget* table = this->m_UI->ValuesTable; + + if( btn == this->m_UI->RemoveValueButton ) + { + std::set< int > to_delete; + QList< QTableWidgetItem* > lst = table->selectedItems( ); + QList< QTableWidgetItem* >::iterator i = lst.begin( ); + for( ; i != lst.end( ); ++i ) + to_delete.insert( ( *i )->row( ) ); + + std::set< int >::const_reverse_iterator d = to_delete.rbegin( ); + for( ; d != to_delete.rend( ); ++d ) + table->removeRow( *d ); + } + else + table->insertRow( table->rowCount( ) ); +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/ParametersListWidget.h b/lib/cpPlugins/Interface/ParametersListWidget.h new file mode 100644 index 0000000..eb186dd --- /dev/null +++ b/lib/cpPlugins/Interface/ParametersListWidget.h @@ -0,0 +1,51 @@ +#ifndef __CPPLUGINS__INTERFACE__PARAMETERSLISTWIDGET__H__ +#define __CPPLUGINS__INTERFACE__PARAMETERSLISTWIDGET__H__ + +#include +#include + +// ------------------------------------------------------------------------- +namespace Ui +{ + class ParametersListWidget; +} + +// ------------------------------------------------------------------------- +/** + */ +namespace cpPlugins +{ + namespace Interface + { + class ParametersListWidget + : public QWidget + { + Q_OBJECT; + + public: + + public: + explicit ParametersListWidget( + const std::string& list_name, QWidget* parent = 0 + ); + virtual ~ParametersListWidget( ); + + std::vector< std::string > GetStringValues( ) const; + std::vector< int > GetIntValues( ) const; + std::vector< unsigned int > GetUintValues( ) const; + std::vector< double > GetDoubleValues( ) const; + + private slots: + void _changeValuesCount( ); + + private: + Ui::ParametersListWidget* m_UI; + }; + + } // ecapseman + +} // ecapseman + +#endif // __CPPLUGINS__INTERFACE__PARAMETERSLISTWIDGET__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/ParametersListWidget.ui b/lib/cpPlugins/Interface/ParametersListWidget.ui new file mode 100644 index 0000000..688029c --- /dev/null +++ b/lib/cpPlugins/Interface/ParametersListWidget.ui @@ -0,0 +1,42 @@ + + + ParametersListWidget + + + + 0 + 0 + 230 + 310 + + + + Form + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.cxx b/lib/cpPlugins/Interface/ParametersQtDialog.cxx index 1cc5820..e6c5f57 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.cxx +++ b/lib/cpPlugins/Interface/ParametersQtDialog.cxx @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -10,7 +11,6 @@ #include #include #include -#include #include // ------------------------------------------------------------------------- @@ -92,24 +92,15 @@ ParametersQtDialog( v_double->setValue( parameters.GetValueAsReal( *nIt ) ); w_input = v_double; } - else if( pt == Parameters::RealList ) + else if( + pt == Parameters::StringList || + pt == Parameters::IntList || + pt == Parameters::UintList || + pt == Parameters::RealList + ) { - QStringList header; - header << nIt->c_str( ); - - QTableWidget* l_double = new QTableWidget( dlg ); - l_double->setColumnCount( 1 ); - l_double->setRowCount( 1 ); - l_double->setHorizontalHeaderLabels( header ); - l_double->setShowGrid( true ); - l_double->setSelectionBehavior( QAbstractItemView::SelectRows ); - l_double->setSelectionMode( QAbstractItemView::SingleSelection ); - - QObject::connect( - l_double, SIGNAL( cellDoubleClicked( int, int ) ), - l_double, SLOT( insertRow( int ) ) - ); - + cpPlugins::Interface::ParametersListWidget* l_double = + new cpPlugins::Interface::ParametersListWidget( *nIt, dlg ); w_input = l_double; } // fi @@ -180,21 +171,44 @@ ParametersQtDialog( if( v_double != NULL ) parameters.SetValueAsReal( *nIt, v_double->value( ) ); } - else if( pt == Parameters::RealList ) + else if( + pt == Parameters::StringList || + pt == Parameters::IntList || + pt == Parameters::UintList || + pt == Parameters::RealList + ) { - QTableWidget* l_double = - dlg->findChild< QTableWidget* >( nIt->c_str( ) ); + cpPlugins::Interface::ParametersListWidget* l_double = + dlg->findChild< cpPlugins::Interface::ParametersListWidget* >( + nIt->c_str( ) + ); if( l_double != NULL ) { - for( int r = 0; r < l_double->rowCount( ); ++r ) + if( pt == Parameters::StringList ) + { + std::vector< std::string > values = l_double->GetStringValues( ); + for( int r = 0; r < values.size( ); ++r ) + parameters.AddValueToStringList( *nIt, values[ r ] ); + } + else if( pt == Parameters::IntList ) + { + std::vector< int > values = l_double->GetIntValues( ); + for( int r = 0; r < values.size( ); ++r ) + parameters.AddValueToIntList( *nIt, values[ r ] ); + } + else if( pt == Parameters::UintList ) + { + std::vector< unsigned int > values = l_double->GetUintValues( ); + for( int r = 0; r < values.size( ); ++r ) + parameters.AddValueToUintList( *nIt, values[ r ] ); + } + else if( pt == Parameters::RealList ) { - double v = - std::atof( - l_double->item( r, 0 )->text( ).toStdString( ).c_str( ) - ); - parameters.AddValueToRealList( *nIt, v ); + std::vector< double > values = l_double->GetDoubleValues( ); + for( int r = 0; r < values.size( ); ++r ) + parameters.AddValueToRealList( *nIt, values[ r ] ); - } // rof + } // fi } // fi diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index 3630e49..a53476f 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -1,5 +1,9 @@ #include +#ifdef cpPlugins_Interface_QT4 +#include +#endif // cpPlugins_Interface_QT4 + // ------------------------------------------------------------------------- const cpPlugins::Interface::Parameters& cpPlugins::Interface::ProcessObject:: @@ -92,6 +96,28 @@ DisconnectOutputs( ) this->m_Outputs[ idx ]->DisconnectPipeline( ); } +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::ProcessObject:: +ExecConfigurationDialog( QWidget* parent ) +{ + bool r = false; + +#ifdef cpPlugins_Interface_QT4 + + Parameters parameters = this->m_DefaultParameters; + r = cpPlugins::Interface::ParametersQtDialog( + parameters, + this->m_ClassName + std::string( " basic configuration" ), + parent + ); + if( r ) + this->m_Parameters = parameters; + +#endif // cpPlugins_Interface_QT4 + + return( r ); +} + // ------------------------------------------------------------------------- cpPlugins::Interface::ProcessObject:: ProcessObject( ) diff --git a/lib/cpPlugins/Interface/ProcessObject.h b/lib/cpPlugins/Interface/ProcessObject.h index d201a6c..82492db 100644 --- a/lib/cpPlugins/Interface/ProcessObject.h +++ b/lib/cpPlugins/Interface/ProcessObject.h @@ -2,10 +2,17 @@ #define __CPPLUGINS__INTERFACE__PROCESSOBJECT__H__ #include +#include #include #include #include +#ifdef cpPlugins_Interface_QT4 +class QWidget; +#else +typedef char QWidget +#endif // cpPlugins_Interface_QT4 + #include namespace cpPlugins @@ -41,6 +48,8 @@ namespace cpPlugins virtual std::string Update( ); virtual void DisconnectOutputs( ); + virtual bool ExecConfigurationDialog( QWidget* parent ); + template< class T > inline T* GetInput( unsigned int idx ); -- 2.47.1