00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <QVBoxLayout>
00038 #include <QHBoxLayout>
00039 #include <QGroupBox>
00040 #include <QPushButton>
00041 #include <QFormLayout>
00042 #include <QLineEdit>
00043 #include <QMessageBox>
00044 #include <QString>
00045 #include <QHeaderView>
00046 #include "double_list_widget.h"
00047
00048 namespace moveit_setup_assistant
00049 {
00050
00051
00052
00053
00054 DoubleListWidget::DoubleListWidget( QWidget *parent, moveit_setup_assistant::MoveItConfigDataPtr config_data,
00055 QString long_name, QString short_name , bool add_ok_cancel)
00056 : QWidget( parent ), long_name_( long_name ), short_name_( short_name ), config_data_( config_data )
00057 {
00058
00059 QVBoxLayout *layout = new QVBoxLayout( );
00060
00061
00062 title_ = new QLabel( "", this );
00063 QFont group_title_font( "Arial", 12, QFont::Bold );
00064 title_->setFont(group_title_font);
00065 layout->addWidget( title_ );
00066
00067
00068 QHBoxLayout *hlayout = new QHBoxLayout();
00069
00070
00071 QVBoxLayout *column1 = new QVBoxLayout();
00072
00073
00074 column1_label_ = new QLabel( QString("Available ").append( short_name_ ).append( 's' ), this );
00075 column1->addWidget( column1_label_ );
00076
00077
00078 data_table_ = new QTableWidget( this );
00079 data_table_->setColumnCount(1);
00080 data_table_->setSortingEnabled(true);
00081 column1->addWidget( data_table_ );
00082 connect( data_table_->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), this,
00083 SLOT( previewSelectedLeft( QItemSelection, QItemSelection ) ) );
00084
00085
00086 QStringList data_header_list;
00087 data_header_list.append( QString( " Names" ).prepend( short_name_ ));
00088 data_table_->setHorizontalHeaderLabels( data_header_list );
00089 data_table_->horizontalHeader()->setDefaultAlignment(Qt::AlignHCenter);
00090
00091
00092 hlayout->addLayout( column1 );
00093
00094
00095 QVBoxLayout *column2 = new QVBoxLayout();
00096 column2->setSizeConstraint( QLayout::SetFixedSize );
00097
00098
00099 QPushButton *btn_right = new QPushButton( ">", this);
00100 btn_right->setMaximumSize(25, 80);
00101 connect( btn_right, SIGNAL( clicked() ), this, SLOT( selectDataButtonClicked() ) );
00102 column2->addWidget( btn_right );
00103
00104
00105 QPushButton *btn_left = new QPushButton( "<", this);
00106 btn_left->setMaximumSize(25, 80);
00107 connect( btn_left, SIGNAL( clicked() ), this, SLOT( deselectDataButtonClicked() ) );
00108 column2->addWidget( btn_left );
00109
00110
00111 hlayout->addLayout( column2 );
00112
00113
00114 QVBoxLayout *column3 = new QVBoxLayout();
00115
00116
00117 column2_label_ = new QLabel( QString("Selected ").append( short_name_ ).append( "s" ), this );
00118 column3->addWidget( column2_label_ );
00119
00120
00121 selected_data_table_ = new QTableWidget( this );
00122 selected_data_table_->setColumnCount(1);
00123 selected_data_table_->setSortingEnabled(true);
00124 column3->addWidget( selected_data_table_ );
00125 connect( selected_data_table_->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), this,
00126 SLOT( previewSelectedRight( QItemSelection, QItemSelection ) ) );
00127
00128
00129 selected_data_table_->setHorizontalHeaderLabels( data_header_list );
00130
00131
00132 hlayout->addLayout( column3 );
00133
00134
00135 layout->addLayout( hlayout );
00136
00137 if (add_ok_cancel)
00138 {
00139
00140 QHBoxLayout *controls_layout = new QHBoxLayout();
00141 controls_layout->setContentsMargins( 0, 25, 0, 15 );
00142
00143
00144 QWidget *spacer = new QWidget( this );
00145 spacer->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
00146 controls_layout->addWidget( spacer );
00147
00148
00149 QPushButton *btn_save = new QPushButton( "&Save", this );
00150
00151 connect( btn_save, SIGNAL(clicked()), this, SIGNAL( doneEditing() ) );
00152 controls_layout->addWidget( btn_save );
00153 controls_layout->setAlignment(btn_save, Qt::AlignRight);
00154
00155
00156 QPushButton *btn_cancel = new QPushButton( "&Cancel", this );
00157
00158 connect( btn_cancel, SIGNAL(clicked()), this, SIGNAL( cancelEditing() ) );
00159 controls_layout->addWidget( btn_cancel );
00160 controls_layout->setAlignment(btn_cancel, Qt::AlignRight);
00161
00162
00163 layout->addLayout( controls_layout );
00164 }
00165
00166
00167 this->setLayout(layout);
00168 }
00169
00170
00171
00172
00173 void DoubleListWidget::setAvailable( const std::vector<std::string> &items )
00174 {
00175 setTable( items, data_table_ );
00176
00177
00178 data_table_->resizeColumnToContents(0);
00179 selected_data_table_->setColumnWidth( 0, data_table_->columnWidth( 0 ) );
00180 }
00181
00182
00183
00184
00185 void DoubleListWidget::setSelected( const std::vector<std::string> &items )
00186 {
00187 setTable( items, selected_data_table_ );
00188 }
00189
00190 void DoubleListWidget::clearContents()
00191 {
00192 selected_data_table_->clearContents();
00193 data_table_->clearContents();
00194 }
00195
00196 void DoubleListWidget::setColumnNames( const QString &col1, const QString &col2)
00197 {
00198 column1_label_->setText(col1);
00199 column2_label_->setText(col2);
00200 }
00201
00202
00203
00204
00205 void DoubleListWidget::setTable( const std::vector<std::string> &items, QTableWidget *table )
00206 {
00207
00208 table->setUpdatesEnabled(false);
00209 table->setDisabled(true);
00210 table->clearContents();
00211
00212
00213 table->setRowCount( items.size() );
00214
00215
00216 int row = 0;
00217 for( std::vector<std::string>::const_iterator data_it = items.begin(); data_it != items.end(); ++data_it )
00218 {
00219
00220
00221 if( *data_it == "ASSUMED_FIXED_ROOT_JOINT" )
00222 continue;
00223
00224
00225 QTableWidgetItem* data_name = new QTableWidgetItem( data_it->c_str() );
00226 data_name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
00227
00228
00229 table->setItem( row, 0, data_name );
00230
00231
00232 ++row;
00233 }
00234
00235 table->setRowCount( row );
00236
00237
00238 table->setUpdatesEnabled(true);
00239 table->setDisabled(false);
00240 }
00241
00242
00243
00244
00245 void DoubleListWidget::selectDataButtonClicked()
00246 {
00247
00248 QList<QTableWidgetItem*> selected = data_table_->selectedItems();
00249
00250
00251 for(int i = 0; i < selected.size(); i++)
00252 {
00253 std::string name = selected[i]->text().toStdString();
00254 bool alreadyExists = false;
00255 int rowToAdd = 0;
00256
00257
00258 for(int r = 0; r < selected_data_table_->rowCount(); r++)
00259 {
00260 QTableWidgetItem* item = selected_data_table_->item(r, 0);
00261
00262 if(item->text().toStdString() == name)
00263 {
00264 alreadyExists = true;
00265 break;
00266 }
00267 rowToAdd = r + 1;
00268 }
00269
00270
00271 if(!alreadyExists)
00272 {
00273 selected_data_table_->setRowCount(selected_data_table_->rowCount() + 1);
00274 QTableWidgetItem* newItem = new QTableWidgetItem(name.c_str());
00275 newItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
00276 selected_data_table_->setItem(rowToAdd, 0, newItem);
00277 }
00278 }
00279
00280 Q_EMIT( selectionUpdated() );
00281 }
00282
00283
00284
00285
00286 void DoubleListWidget::deselectDataButtonClicked()
00287 {
00288
00289 QList<QTableWidgetItem*> deselected = selected_data_table_->selectedItems();
00290
00291
00292 for(int i = 0; i < deselected.size(); i++)
00293 {
00294 selected_data_table_->removeRow(deselected[i]->row());
00295 }
00296
00297 Q_EMIT( selectionUpdated() );
00298 }
00299
00300
00301
00302
00303 void DoubleListWidget::previewSelectedLeft( const QItemSelection& selected, const QItemSelection& deselected )
00304 {
00305 const QList<QTableWidgetItem*> selected_items = data_table_->selectedItems();
00306 previewSelected(selected_items);
00307 }
00308
00309
00310
00311
00312 void DoubleListWidget::previewSelectedRight( const QItemSelection& selected, const QItemSelection& deselected )
00313 {
00314 const QList<QTableWidgetItem*> selected_items = selected_data_table_->selectedItems();
00315 previewSelected(selected_items);
00316 }
00317
00318
00319
00320
00321 void DoubleListWidget::previewSelected( const QList<QTableWidgetItem*>& selected )
00322 {
00323
00324 if( !selected.size() )
00325 return;
00326
00327 std::vector<std::string> selected_vector;
00328
00329
00330 for(int i = 0; i < selected.size(); ++i)
00331 {
00332 selected_vector.push_back( selected[i]->text().toStdString() );
00333
00334 }
00335
00336
00337 Q_EMIT( previewSelected( selected_vector ) );
00338 }
00339
00340 }