dialog_mcap.cpp
Go to the documentation of this file.
1 #include "dialog_mcap.h"
2 #include "ui_dialog_mcap.h"
3 
4 #include <QSettings>
5 #include <QDialogButtonBox>
6 #include <QPushButton>
7 #include <QElapsedTimer>
8 
9 const QString DialogMCAP::prefix = "DialogLoadMCAP::";
10 
11 DialogMCAP::DialogMCAP(const std::unordered_map<int, mcap::ChannelPtr>& channels,
12  const std::unordered_map<int, mcap::SchemaPtr>& schemas,
13  std::optional<mcap::LoadParams> default_parameters,
14  QWidget* parent)
15  : QDialog(parent), ui(new Ui::dialog_mcap)
16 {
17  ui->setupUi(this);
18 
19  ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
20  ui->tableWidget->horizontalHeader()->setSectionResizeMode(
21  1, QHeaderView::ResizeToContents);
22  ui->tableWidget->horizontalHeader()->setSectionResizeMode(
23  2, QHeaderView::ResizeToContents);
24 
25  ui->tableWidget->setRowCount(channels.size());
26 
27  QSettings settings;
28  restoreGeometry(settings.value(prefix + "geometry").toByteArray());
29 
30  mcap::LoadParams params;
31  if (!default_parameters)
32  {
33  params.selected_topics = settings.value(prefix + "selected").toStringList();
34  params.clamp_large_arrays = settings.value(prefix + "clamp", true).toBool();
35  params.max_array_size = settings.value(prefix + "max_array", 500).toInt();
36  params.use_timestamp = settings.value(prefix + "use_timestamp", false).toBool();
37  }
38  else
39  {
40  params = *default_parameters;
41  }
42 
43  if (params.clamp_large_arrays)
44  {
45  ui->radioClamp->setChecked(true);
46  }
47  else
48  {
49  ui->radioSkip->setChecked(true);
50  }
51  ui->spinBox->setValue(params.max_array_size);
52  ui->checkBoxUseTimestamp->setChecked(params.use_timestamp);
53 
54  int row = 0;
55  for (const auto& [id, channel] : channels)
56  {
57  auto topic = QString::fromStdString(channel->topic);
58  auto const& schema = schemas.at(channel->schemaId);
59 
60  ui->tableWidget->setItem(row, 0, new QTableWidgetItem(topic));
61  ui->tableWidget->setItem(row, 1,
62  new QTableWidgetItem(QString::fromStdString(schema->name)));
63  ui->tableWidget->setItem(
64  row, 2, new QTableWidgetItem(QString::fromStdString(schema->encoding)));
65 
66  if (params.selected_topics.contains(topic))
67  {
68  ui->tableWidget->selectRow(row);
69  }
70  row++;
71  }
72  ui->tableWidget->sortByColumn(0, Qt::SortOrder::DescendingOrder);
73 }
74 
76 {
77  delete ui;
78 }
79 
81 {
82  mcap::LoadParams params;
83  params.max_array_size = ui->spinBox->value();
84  params.clamp_large_arrays = ui->radioClamp->isChecked();
85  params.use_timestamp = ui->checkBoxUseTimestamp->isChecked();
86 
87  QItemSelectionModel* select = ui->tableWidget->selectionModel();
88  QStringList selected_topics;
89  for (QModelIndex index : select->selectedRows())
90  {
91  params.selected_topics.push_back(ui->tableWidget->item(index.row(), 0)->text());
92  }
93  return params;
94 }
95 
97 {
98  bool enabled = !ui->tableWidget->selectionModel()->selectedRows().empty();
99  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enabled);
100 }
101 
103 {
104  QSettings settings;
105  settings.setValue(prefix + "geometry", saveGeometry());
106 
107  bool clamp_checked = ui->radioClamp->isChecked();
108  int max_array = ui->spinBox->value();
109  bool use_timestamp = ui->checkBoxUseTimestamp->isChecked();
110 
111  settings.setValue(prefix + "clamp", clamp_checked);
112  settings.setValue(prefix + "max_array", max_array);
113  settings.setValue(prefix + "use_timestamp", use_timestamp);
114 
115  QItemSelectionModel* select = ui->tableWidget->selectionModel();
116  QStringList selected_topics;
117  for (QModelIndex index : select->selectedRows())
118  {
119  selected_topics.push_back(ui->tableWidget->item(index.row(), 0)->text());
120  }
121  settings.setValue(prefix + "selected", selected_topics);
122 
123  QDialog::accept();
124 }
DialogMCAP::DialogMCAP
DialogMCAP(const std::unordered_map< int, mcap::ChannelPtr > &channels, const std::unordered_map< int, mcap::SchemaPtr > &schemas, std::optional< mcap::LoadParams > default_parameters, QWidget *parent=nullptr)
Definition: dialog_mcap.cpp:11
DialogMCAP::~DialogMCAP
~DialogMCAP()
Definition: dialog_mcap.cpp:75
sol::function_detail::select
void select(lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:19973
mcap::LoadParams
Definition: dataload_params.h:8
dialog_mcap.h
DialogMCAP::ui
Ui::dialog_mcap * ui
Definition: dialog_mcap.h:32
mcap::LoadParams::max_array_size
unsigned max_array_size
Definition: dataload_params.h:11
mcap::LoadParams::clamp_large_arrays
bool clamp_large_arrays
Definition: dataload_params.h:12
start_test_publisher.topic
topic
Definition: start_test_publisher.py:22
Ui
Definition: cheatsheet_dialog.h:6
DialogMCAP::accept
void accept() override
Definition: dialog_mcap.cpp:102
DialogMCAP::getParams
mcap::LoadParams getParams() const
Definition: dialog_mcap.cpp:80
DialogMCAP::prefix
static const QString prefix
Definition: dialog_mcap.h:34
mcap::LoadParams::selected_topics
QStringList selected_topics
Definition: dataload_params.h:10
mcap::LoadParams::use_timestamp
bool use_timestamp
Definition: dataload_params.h:13
DialogMCAP::on_tableWidget_itemSelectionChanged
void on_tableWidget_itemSelectionChanged()
Definition: dialog_mcap.cpp:96


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:44