1 #include <cpPlugins/Interface/ParametersListWidget.h>
3 #ifdef cpPlugins_Interface_QT4
5 #include <cpPlugins/Interface/ui_ParametersListWidget.h>
9 // -------------------------------------------------------------------------
10 cpPlugins::Interface::ParametersListWidget::
11 ParametersListWidget( const std::string& list_name, QWidget* parent )
13 m_UI( new Ui::ParametersListWidget )
15 this->m_UI->setupUi( this );
18 QTableWidget* table = this->m_UI->ValuesTable;
19 table->setColumnCount( 1 );
20 table->setRowCount( 1 );
23 header << list_name.c_str( );
24 table->setHorizontalHeaderLabels( header );
25 table->setShowGrid( true );
26 table->setSelectionBehavior( QAbstractItemView::SelectRows );
30 this->m_UI->AddValueButton, SIGNAL( clicked( ) ),
31 this, SLOT( _changeValuesCount( ) )
34 this->m_UI->RemoveValueButton, SIGNAL( clicked( ) ),
35 this, SLOT( _changeValuesCount( ) )
39 // -------------------------------------------------------------------------
40 cpPlugins::Interface::ParametersListWidget::
41 ~ParametersListWidget( )
46 // -------------------------------------------------------------------------
47 std::vector< std::string > cpPlugins::Interface::ParametersListWidget::
48 GetStringValues( ) const
50 std::vector< std::string > values;
52 QTableWidget* table = this->m_UI->ValuesTable;
53 for( int i = 0; i < table->rowCount( ); ++i )
54 values.push_back( table->item( i, 0 )->text( ).toStdString( ) );
58 // -------------------------------------------------------------------------
59 std::vector< int > cpPlugins::Interface::ParametersListWidget::
62 std::vector< int > values;
64 QTableWidget* table = this->m_UI->ValuesTable;
65 for( int i = 0; i < table->rowCount( ); ++i )
67 const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( );
69 double v = std::strtod( text, &ptr );
70 if( *ptr == '\0' && ptr != text )
71 values.push_back( int( v ) );
77 // -------------------------------------------------------------------------
78 std::vector< unsigned int > cpPlugins::Interface::ParametersListWidget::
79 GetUintValues( ) const
81 std::vector< unsigned int > values;
83 QTableWidget* table = this->m_UI->ValuesTable;
84 for( int i = 0; i < table->rowCount( ); ++i )
86 const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( );
88 double v = std::strtod( text, &ptr );
89 if( *ptr == '\0' && ptr != text && v >= double( 0 ) )
90 values.push_back( ( unsigned int )( v ) );
96 // -------------------------------------------------------------------------
97 std::vector< double > cpPlugins::Interface::ParametersListWidget::
98 GetDoubleValues( ) const
100 std::vector< double > values;
102 QTableWidget* table = this->m_UI->ValuesTable;
103 for( int i = 0; i < table->rowCount( ); ++i )
105 const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( );
107 double v = std::strtod( text, &ptr );
108 if( *ptr == '\0' && ptr != text )
109 values.push_back( v );
115 // -------------------------------------------------------------------------
116 void cpPlugins::Interface::ParametersListWidget::
117 _changeValuesCount( )
119 QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
122 QTableWidget* table = this->m_UI->ValuesTable;
124 if( btn == this->m_UI->RemoveValueButton )
126 std::set< int > to_delete;
127 QList< QTableWidgetItem* > lst = table->selectedItems( );
128 QList< QTableWidgetItem* >::iterator i = lst.begin( );
129 for( ; i != lst.end( ); ++i )
130 to_delete.insert( ( *i )->row( ) );
132 std::set< int >::const_reverse_iterator d = to_delete.rbegin( );
133 for( ; d != to_delete.rend( ); ++d )
134 table->removeRow( *d );
137 table->insertRow( table->rowCount( ) );
140 #endif // cpPlugins_Interface_QT4