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