Go to the documentation of this file.00001 #include <QFile>
00002 #include <QTextStream>
00003 #include <QSettings>
00004 #include <QFileInfo>
00005 #include <QDir>
00006 #include <QFileDialog>
00007 #include <QTableWidget>
00008 #include <QTableWidgetItem>
00009 #include <QSettings>
00010 #include <QHeaderView>
00011 #include <QDebug>
00012
00013 #include "dialog_select_ros_topics.h"
00014 #include "rule_editing.h"
00015 #include "ui_dialog_select_ros_topics.h"
00016
00017
00018 DialogSelectRosTopics::DialogSelectRosTopics(const std::vector<std::pair<QString, QString>>& topic_list,
00019 QStringList default_selected_topics,
00020 QWidget *parent) :
00021 QDialog(parent),
00022 ui(new Ui::dialogSelectRosTopics)
00023 {
00024
00025 auto flags = this->windowFlags();
00026 this->setWindowFlags( flags | Qt::WindowStaysOnTopHint);
00027
00028 ui->setupUi(this);
00029
00030 QSettings settings( "IcarusTechnology", "PlotJuggler");
00031 ui->checkBoxEnableRules->setChecked( settings.value("DialogSelectRosTopics.enableRules", true ).toBool());
00032 ui->checkBoxUseHeaderStamp->setChecked( settings.value("DialogSelectRosTopics.useHeaderStamp", true ).toBool());
00033 restoreGeometry(settings.value("DialogSelectRosTopics.geometry").toByteArray());
00034
00035 if( default_selected_topics.isEmpty())
00036 {
00037 QString default_topics = settings.value("DialogSelectRosTopics.selectedItems", "" ).toString();
00038 default_selected_topics = default_topics.split(' ', QString::SkipEmptyParts);
00039 }
00040
00041 QStringList labels;
00042 labels.push_back("Topic name");
00043 labels.push_back("Datatype");
00044
00045 ui->listRosTopics->setHorizontalHeaderLabels(labels);
00046 ui->listRosTopics->verticalHeader()->setVisible(false);
00047
00048 updateTopicList(topic_list);
00049
00050 if( ui->listRosTopics->rowCount() == 1)
00051 {
00052 ui->listRosTopics->selectRow(0);
00053 }
00054 else{
00055 for(int row=0; row < ui->listRosTopics->rowCount(); row++ )
00056 {
00057 const QTableWidgetItem *item = ui->listRosTopics->item(row,0);
00058 if(default_selected_topics.contains( item->text() ) ){
00059 ui->listRosTopics->selectRow(row);
00060 }
00061 }
00062 }
00063 }
00064
00065 void DialogSelectRosTopics::updateTopicList(std::vector<std::pair<QString, QString> > topic_list)
00066 {
00067
00068 for (const auto& it: topic_list)
00069 {
00070 const QString& topic_name = it.first ;
00071 const QString& type_name = it.second ;
00072
00073 bool found = false;
00074 for(int r=0; r < ui->listRosTopics->rowCount(); r++ )
00075 {
00076 const QTableWidgetItem *item = ui->listRosTopics->item(r,0);
00077 if( item->text() == topic_name){
00078 found = true;
00079 break;
00080 }
00081 }
00082
00083 if( !found )
00084 {
00085 int new_row = ui->listRosTopics->rowCount();
00086 ui->listRosTopics->setRowCount( new_row+1 );
00087
00088
00089 ui->listRosTopics->setItem(new_row, 1, new QTableWidgetItem( type_name ));
00090 ui->listRosTopics->setItem(new_row, 0, new QTableWidgetItem( topic_name ));
00091 }
00092 }
00093
00094 ui->listRosTopics->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
00095 ui->listRosTopics->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
00096 ui->listRosTopics->sortByColumn(0, Qt::AscendingOrder);
00097
00098 }
00099
00100
00101 DialogSelectRosTopics::~DialogSelectRosTopics()
00102 {
00103 delete ui;
00104 }
00105
00106 QStringList DialogSelectRosTopics::getSelectedItems()
00107 {
00108 return _topic_list;
00109 }
00110
00111
00112 const QCheckBox *DialogSelectRosTopics::checkBoxUseHeaderStamp()
00113 {
00114 return ui->checkBoxUseHeaderStamp;
00115 }
00116
00117 const QCheckBox* DialogSelectRosTopics::checkBoxUseRenamingRules()
00118 {
00119 return ui->checkBoxEnableRules;
00120 }
00121
00122
00123 void DialogSelectRosTopics::on_buttonBox_accepted()
00124 {
00125 QModelIndexList selected_indexes = ui->listRosTopics->selectionModel()->selectedIndexes();
00126 QString selected_topics;
00127
00128 foreach(QModelIndex index, selected_indexes)
00129 {
00130 if(index.column() == 0){
00131 _topic_list.push_back( index.data(Qt::DisplayRole).toString() );
00132 selected_topics.append( _topic_list.back() ).append(" ");
00133 }
00134 }
00135 QSettings settings( "IcarusTechnology", "PlotJuggler");
00136 settings.setValue("DialogSelectRosTopics.enableRules", ui->checkBoxEnableRules->isChecked() );
00137 settings.setValue("DialogSelectRosTopics.useHeaderStamp", ui->checkBoxUseHeaderStamp->isChecked() );
00138 settings.setValue("DialogSelectRosTopics.geometry", saveGeometry());
00139 settings.setValue("DialogSelectRosTopics.selectedItems", selected_topics );
00140 }
00141
00142 void DialogSelectRosTopics::on_listRosTopics_itemSelectionChanged()
00143 {
00144 QModelIndexList indexes = ui->listRosTopics->selectionModel()->selectedIndexes();
00145
00146 ui->buttonBox->setEnabled( indexes.size() > 0) ;
00147 }
00148
00149
00150 void DialogSelectRosTopics::on_checkBoxEnableRules_toggled(bool checked)
00151 {
00152 ui->pushButtonEditRules->setEnabled( checked );
00153 }
00154
00155 void DialogSelectRosTopics::on_pushButtonEditRules_pressed()
00156 {
00157 RuleEditing* rule_editing = new RuleEditing(this);
00158 rule_editing->exec();
00159 }
00160
00161 void DialogSelectRosTopics::closeEvent(QCloseEvent *event)
00162 {
00163 QSettings settings( "IcarusTechnology", "PlotJuggler");
00164 settings.setValue("DialogSelectRosTopics.geometry", saveGeometry());
00165 }
00166
00167 nonstd::optional<double> FlatContainedContainHeaderStamp(const RosIntrospection::RenamedValues& renamed_value)
00168 {
00169 const char* ID = "/header/stamp";
00170 const int renamed_count = renamed_value.size();
00171 const int OFF = strlen(ID);
00172
00173
00174 static std::map<const RosIntrospection::RenamedValues*,int> first_indexes;
00175
00176 int first_index = first_indexes[&renamed_value];
00177
00178 if( first_index >= 0 && first_index < renamed_count)
00179 {
00180 const RosIntrospection::SString& field_name = renamed_value[first_index].first;
00181 if( field_name.size() > OFF &&
00182 strcmp( &field_name.data()[ field_name.size() -OFF], ID) == 0)
00183 {
00184 const RosIntrospection::VarNumber& var_value = renamed_value[first_index].second;
00185 return var_value.convert<double>();
00186 }
00187 }
00188
00189 for(int i=0; i< renamed_count; i++ )
00190 {
00191 if( i == first_index ) continue;
00192
00193 const RosIntrospection::SString& field_name = renamed_value[i].first;
00194 if( field_name.size() > OFF &&
00195 strcmp( &field_name.data()[ field_name.size() -OFF], ID) == 0)
00196 {
00197 first_indexes[&renamed_value] = i;
00198 const RosIntrospection::VarNumber& var_value = renamed_value[i].second;
00199 return var_value.convert<double>();
00200 }
00201 }
00202 return nonstd::optional<double>();
00203 }