1 #include <cpPlugins/Interface/ParametersListWidget.h>
2 #include <cpPlugins/Interface/ui_ParametersListWidget.h>
6 // -------------------------------------------------------------------------
7 cpPlugins::Interface::ParametersListWidget::
8 ParametersListWidget( const std::string& list_name, QWidget* parent )
10 m_UI( new Ui::ParametersListWidget )
12 this->m_UI->setupUi( this );
15 QTableWidget* table = this->m_UI->ValuesTable;
16 table->setColumnCount( 1 );
17 table->setRowCount( 1 );
20 header << list_name.c_str( );
21 table->setHorizontalHeaderLabels( header );
22 table->setShowGrid( true );
23 table->setSelectionBehavior( QAbstractItemView::SelectRows );
27 this->m_UI->AddValueButton, SIGNAL( clicked( ) ),
28 this, SLOT( _changeValuesCount( ) )
31 this->m_UI->RemoveValueButton, SIGNAL( clicked( ) ),
32 this, SLOT( _changeValuesCount( ) )
36 // -------------------------------------------------------------------------
37 cpPlugins::Interface::ParametersListWidget::
38 ~ParametersListWidget( )
43 // -------------------------------------------------------------------------
44 std::vector< std::string > cpPlugins::Interface::ParametersListWidget::
45 GetStringValues( ) const
47 std::vector< std::string > values;
49 QTableWidget* table = this->m_UI->ValuesTable;
50 for( int i = 0; i < table->rowCount( ); ++i )
51 values.push_back( table->item( i, 0 )->text( ).toStdString( ) );
55 // -------------------------------------------------------------------------
56 std::vector< int > cpPlugins::Interface::ParametersListWidget::
59 std::vector< int > values;
61 QTableWidget* table = this->m_UI->ValuesTable;
62 for( int i = 0; i < table->rowCount( ); ++i )
64 const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( );
66 double v = std::strtod( text, &ptr );
67 if( *ptr == '\0' && ptr != text )
68 values.push_back( int( v ) );
74 // -------------------------------------------------------------------------
75 std::vector< unsigned int > cpPlugins::Interface::ParametersListWidget::
76 GetUintValues( ) const
78 std::vector< unsigned int > values;
80 QTableWidget* table = this->m_UI->ValuesTable;
81 for( int i = 0; i < table->rowCount( ); ++i )
83 const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( );
85 double v = std::strtod( text, &ptr );
86 if( *ptr == '\0' && ptr != text && v >= double( 0 ) )
87 values.push_back( ( unsigned int )( v ) );
93 // -------------------------------------------------------------------------
94 std::vector< double > cpPlugins::Interface::ParametersListWidget::
95 GetDoubleValues( ) const
97 std::vector< double > values;
99 QTableWidget* table = this->m_UI->ValuesTable;
100 for( int i = 0; i < table->rowCount( ); ++i )
102 const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( );
104 double v = std::strtod( text, &ptr );
105 if( *ptr == '\0' && ptr != text )
106 values.push_back( v );
112 // -------------------------------------------------------------------------
113 void cpPlugins::Interface::ParametersListWidget::
114 _changeValuesCount( )
116 QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
119 QTableWidget* table = this->m_UI->ValuesTable;
121 if( btn == this->m_UI->RemoveValueButton )
123 std::set< int > to_delete;
124 QList< QTableWidgetItem* > lst = table->selectedItems( );
125 QList< QTableWidgetItem* >::iterator i = lst.begin( );
126 for( ; i != lst.end( ); ++i )
127 to_delete.insert( ( *i )->row( ) );
129 std::set< int >::const_reverse_iterator d = to_delete.rbegin( );
130 for( ; d != to_delete.rend( ); ++d )
131 table->removeRow( *d );
134 table->insertRow( table->rowCount( ) );