8 #include "ui_curvelist_panel.h" 11 #include <QLayoutItem> 16 #include <QHeaderView> 17 #include <QFontDatabase> 18 #include <QMessageBox> 19 #include <QApplication> 22 #include <QStandardItem> 23 #include <QWheelEvent> 24 #include <QItemSelectionModel> 26 #include <QTreeWidget> 36 , _plot_data(mapped_plot_data)
39 , _transforms_map(mapped_math_plots)
40 , _column_width_dirty(true)
44 setFocusPolicy(Qt::ClickFocus);
49 auto layout1 =
new QHBoxLayout();
50 ui->listPlaceholder1->setLayout(layout1);
52 layout1->setMargin(0);
54 auto layout2 =
new QHBoxLayout();
55 ui->listPlaceholder2->setLayout(layout2);
57 layout2->setMargin(0);
61 int point_size = settings.value(
"FilterableListWidget/table_point_size", 9).toInt();
64 ui->splitter->setStretchFactor(0, 5);
65 ui->splitter->setStretchFactor(1, 1);
67 connect(
_custom_view->selectionModel(), &QItemSelectionModel::selectionChanged,
this,
70 connect(
_custom_view->verticalScrollBar(), &QScrollBar::valueChanged,
this,
73 connect(
_tree_view->verticalScrollBar(), &QScrollBar::valueChanged,
this,
89 ui->labelNumberDisplayed->setText(
"0 of 0");
94 QString plot_id = QString::fromStdString(plot_name);
102 auto FindInPlotData = [&](
auto& plot_data,
const std::string& plot_name) {
103 auto it = plot_data.find(plot_name);
104 if (it != plot_data.end())
106 auto& plot = it->second;
109 group_name = QString::fromStdString(plot.group()->name());
142 QColor default_color = view->palette().color(QPalette::Text);
145 std::function<void(QTreeWidgetItem*, QColor, bool)> ChangeColorAndStyle;
146 ChangeColorAndStyle = [&](QTreeWidgetItem* cell, QColor
color,
bool italic) {
147 cell->setForeground(0, color);
148 auto font = cell->font(0);
150 cell->setFont(0, font);
151 for (
int c = 0; c < cell->childCount(); c++)
153 ChangeColorAndStyle(cell->child(c),
color,
italic);
158 for (
int c = 0; c < view->invisibleRootItem()->childCount(); c++)
160 ChangeColorAndStyle(view->invisibleRootItem()->child(c), default_color,
false);
164 auto ChangeGroupVisitor = [&](QTreeWidgetItem* cell) {
173 color_var.isValid() ? color_var.value<QColor>() : default_color;
176 bool italic = (style_var.isValid() && style_var.value<
bool>());
178 ChangeColorAndStyle(cell, text_color, italic);
181 QVariant tooltip = it->second->attribute(
TOOL_TIP);
187 view->treeVisitor(ChangeGroupVisitor);
191 auto ChangeLeavesVisitor = [&](QTreeWidgetItem* cell) {
192 if (cell->childCount() == 0)
194 const std::string& curve_name =
199 auto GetTextColor = [&](
auto& plot_data,
const std::string& curve_name) {
200 auto it = plot_data.find(curve_name);
201 if (it != plot_data.end())
203 auto& series = it->second;
205 if (color_var.isValid())
207 cell->setForeground(0, color_var.value<QColor>());
214 bool italic = (style_var.isValid() && style_var.value<
bool>());
217 QFont font = cell->font(0);
218 font.setItalic(italic);
219 cell->setFont(0, font);
221 if (series.isTimeseries() ==
false)
236 view->treeVisitor(ChangeLeavesVisitor);
257 if (event->key() == Qt::Key_Delete)
269 settings.setValue(
"FilterableListWidget/table_point_size", point_size);
286 auto default_foreground =
_custom_view->palette().foreground();
288 auto FormattedNumber = [](
double value) {
289 QString num_text = QString::number(
value,
'f', 3);
290 if (num_text.contains(
'.'))
292 int idx = num_text.length() - 1;
293 while (num_text[idx] ==
'0')
298 if (num_text[idx] ==
'.')
301 return num_text +
" ";
304 auto GetValue = [&](
const std::string&
name) -> QString {
309 auto& plot_data = it->second;
313 return FormattedNumber(val.value());
322 auto& plot_data = it->second;
326 auto str_view = val.value();
327 char last_byte = str_view.data()[str_view.size() - 1];
328 if (last_byte ==
'\0')
330 return QString::fromLocal8Bit(str_view.data(), str_view.size() - 1);
334 return QString::fromLocal8Bit(str_view.data(), str_view.size());
344 const int vertical_height = tree_view->visibleRegion().boundingRect().height();
346 auto DisplayValue = [&](QTreeWidgetItem* cell) {
349 if (!curve_name.isEmpty())
351 auto rect = cell->treeWidget()->visualItemRect(cell);
353 if (rect.bottom() < 0 || cell->isHidden())
357 if (rect.top() > vertical_height)
364 QString str_value = GetValue(curve_name.toStdString());
365 cell->setText(1, str_value);
370 tree_view->setViewResizeEnabled(
false);
371 tree_view->treeVisitor(DisplayValue);
378 static const QRegExp rx(
"(\\[\\d+\\])");
380 std::vector<std::pair<int, int>> index_positions;
382 while ((pos = rx.indexIn(str, pos)) != -1)
384 QString array_index = rx.cap(1);
386 std::pair<int, int>
index = { pos + 1, array_index.size() - 2 };
387 index_positions.push_back(index);
388 pos += rx.matchedLength();
390 if (index_positions.empty())
395 QStringList out_list;
396 out_list.push_back(str);
398 for (
int i = index_positions.size() - 1; i >= 0; i--)
400 std::pair<int, int>
index = index_positions[i];
401 str.remove(index.first, index.second);
402 out_list.push_front(str);
405 return out_list.join(
"/");
410 auto parts = name.split(
'/', QString::SplitBehavior::SkipEmptyParts);
413 for (
int i = 0; i < parts.size(); i++)
416 if (i + 1 < parts.size())
432 int item_count = hc_1.second + hc_2.second;
433 int visible_count = item_count - hc_1.first - hc_2.first;
435 ui->labelNumberDisplayed->setText(QString::number(visible_count) + QString(
" of ") +
436 QString::number(item_count));
445 QMessageBox::StandardButton reply;
446 reply = QMessageBox::question(
nullptr, tr(
"Warning"),
447 tr(
"Do you really want to remove these data?\n"),
448 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
450 if (reply == QMessageBox::Yes)
461 QString curve_name = QString::fromStdString(name);
471 std::string suggested_name;
475 if (curve_names.size() > 0)
477 suggested_name = (curve_names.front());
487 const QItemSelection&)
491 bool enabled = (selected.size() == 1);
492 ui->buttonEditCustom->setEnabled(enabled);
493 ui->buttonEditCustom->setToolTip(enabled ?
"Edit the selected custom timeserie" :
494 "Select a single custom Timeserie to Edit " 501 if (selected.size() == 1)
511 selected.insert(selected.end(), custom_select.begin(), custom_select.end());
524 ui->buttonAddCustom->setIcon(
LoadSvg(
":/resources/svg/add_tab.svg", theme));
525 ui->buttonEditCustom->setIcon(
LoadSvg(
":/resources/svg/pencil-edit.svg", theme));
526 ui->pushButtonTrash->setIcon(
LoadSvg(
":/resources/svg/trash.svg", theme));
528 auto ChangeIconVisitor = [&](QTreeWidgetItem* cell) {
529 const auto& curve_name = cell->data(0,
CustomRoles::Name).toString().toStdString();
534 auto& series = it->second;
535 if (series.isTimeseries() ==
false)
554 QMessageBox msgBox(
this);
555 msgBox.setWindowTitle(
"Warning. Can't be undone.");
556 msgBox.setText(tr(
"Delete data:\n\n" 557 "[Delete All]: remove timeseries and plots.\n" 558 "[Delete Points]: reset data points, but keep plots and " 560 QPushButton* buttonAll = msgBox.addButton(tr(
"Delete All"), QMessageBox::NoRole);
561 QPushButton* buttonPoints = msgBox.addButton(tr(
"Delete Points"), QMessageBox::NoRole);
562 msgBox.addButton(QMessageBox::Cancel);
563 msgBox.setDefaultButton(QMessageBox::Cancel);
567 if (msgBox.clickedButton() == buttonAll)
571 else if (msgBox.clickedButton() == buttonPoints)
void onCustomSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void editMathPlot(const std::string &plot_name)
void changeFontSize(int point_size)
std::unordered_map< std::string, std::shared_ptr< TransformFunction > > TransformsMap
std::vector< std::string > getSelectedNames() override
CurveListPanel(PlotDataMapRef &mapped_plot_data, const TransformsMap &mapped_math_plots, QWidget *parent)
void removeCurve(const QString &name) override
QString getTreeName(QString name)
void createMathPlot(const std::string &linked_plot)
void treeVisitor(std::function< void(QTreeWidgetItem *)> visitor)
const QPixmap & LoadSvg(QString filename, QString style_name="light")
TimeseriesMap numeric
Numerical timeseries.
void setFontSize(int size)
CurveTreeView * _tree_view
bool is2ndColumnHidden() const
void requestDeleteAll(int)
QString StringifyArray(QString str)
void addItem(const QString &prefix, const QString &tree_name, const QString &plot_ID) override
void deleteCurves(const std::vector< std::string > &curve_names)
StringSeriesMap strings
Series of strings.
void on_stylesheetChanged(QString theme)
bool addCurve(const std::string &plot_name)
void refreshColumns() override
std::pair< int, int > hiddenItemsCount() override
virtual void keyPressEvent(QKeyEvent *event) override
void addCustom(const QString &item_name)
~CurveListPanel() override
void on_buttonEditCustom_clicked()
void removeSelectedCurves()
void hiddenItemsChanged()
std::unordered_map< std::string, PlotGroup::Ptr > groups
Each series can have (optionally) a group. Groups can have their own properties.
void on_checkBoxShowValues_toggled(bool show)
CurveTreeView * _custom_view
void on_pushButtonTrash_clicked(bool checked)
bool applyVisibilityFilter(const QString &filter_string) override
std::vector< std::string > getSelectedNames() const
void on_lineEditFilter_textChanged(const QString &search_string)
std::unordered_set< std::string > _tree_view_items
void update2ndColumnValues(double time)
void on_buttonAddCustom_clicked()
virtual void hideValuesColumn(bool hide) override
PlotDataMapRef & _plot_data
void removeCurve(const std::string &name)