#include #ifdef cpPlugins_Interface_QT4 #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( ) ); } #endif // cpPlugins_Interface_QT4 // eof - $RCSfile$