Skip to content

Commit

Permalink
Add support for predefined data views
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr committed Nov 22, 2024
1 parent 28580f7 commit 679cbe8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
4 changes: 4 additions & 0 deletions libshvvisu/include/shv/visu/logview/dataviewwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ class SHVVISU_DECL_EXPORT DataViewWidget : public QWidget
~DataViewWidget() override;

void init(const QString &site_path, timeline::Graph *graph);
void setPredefinedViews(const QVector<timeline::Graph::VisualSettings> &views);
const QVector<timeline::Graph::VisualSettings> &predefinedViews();
void applyPredefinedView(const QString &name);

private:
void onShowChannelFilterClicked();
void onShowRawDataClicked();

timeline::Graph *m_graph = nullptr;
QString m_sitePath;
QVector<timeline::Graph::VisualSettings> m_predefinedViews;

Ui::DataViewWidget *ui;
};
Expand Down
3 changes: 2 additions & 1 deletion libshvvisu/include/shv/visu/timeline/channelfilterdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog
Q_OBJECT

public:
explicit ChannelFilterDialog(QWidget *parent, const QString &site_path, Graph *graph);
explicit ChannelFilterDialog(QWidget *parent, const QString &site_path, Graph *graph, const QVector<Graph::VisualSettings> &views = {});
~ChannelFilterDialog() override;

std::optional<ChannelFilter> channelFilter();
Expand Down Expand Up @@ -58,6 +58,7 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog
ChannelFilterSortFilterProxyModel *m_channelsFilterProxyModel = nullptr;
QString m_sitePath;
QString m_recentSettingsDir;
QVector<timeline::Graph::VisualSettings> m_predefinedDataViews;

QAction *m_saveViewAction = nullptr;
QAction *m_saveViewAsAction = nullptr;
Expand Down
22 changes: 21 additions & 1 deletion libshvvisu/src/logview/dataviewwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,29 @@ void DataViewWidget::init(const QString &site_path, timeline::Graph *graph)
ui->pbShowRawData->setIcon(m_graph->style().isRawDataVisible()? QIcon(QStringLiteral(":/shv/visu/images/raw.svg")): QIcon(QStringLiteral(":/shv/visu/images/raw-off.svg")));
}

void DataViewWidget::setPredefinedViews(const QVector<timeline::Graph::VisualSettings> &views)
{
m_predefinedViews = views;
}

const QVector<timeline::Graph::VisualSettings> &DataViewWidget::predefinedViews()
{
return m_predefinedViews;
}

void DataViewWidget::applyPredefinedView(const QString &name)
{
for (const auto &v: m_predefinedViews) {
if (v.name == name) {
m_graph->setVisualSettingsAndChannelFilter(v);
return;
}
}
}

void DataViewWidget::onShowChannelFilterClicked()
{
auto *channel_filter_dialog = new tl::ChannelFilterDialog(this, m_sitePath, m_graph);
auto *channel_filter_dialog = new tl::ChannelFilterDialog(this, m_sitePath, m_graph, m_predefinedViews);

if (channel_filter_dialog->exec() == QDialog::Accepted) {
m_graph->setChannelFilter(channel_filter_dialog->channelFilter());
Expand Down
34 changes: 27 additions & 7 deletions libshvvisu/src/timeline/channelfilterdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace shv::visu::timeline {

static const QString FLATLINE_VIEW_SETTINGS_FILE_EXTENSION = QStringLiteral(".fvs");

ChannelFilterDialog::ChannelFilterDialog(QWidget *parent, const QString &site_path, Graph *graph) :
ChannelFilterDialog::ChannelFilterDialog(QWidget *parent, const QString &site_path, Graph *graph, const QVector<Graph::VisualSettings> &predefined_data_views) :
QDialog(parent),
ui(new Ui::ChannelFilterDialog)
{
Expand Down Expand Up @@ -48,16 +48,19 @@ ChannelFilterDialog::ChannelFilterDialog(QWidget *parent, const QString &site_pa
ui->gbFilterSettings->setChecked(true);

m_channelsFilterModel->createNodes();
m_predefinedDataViews = predefined_data_views;

loadChannelFilterFomGraph();
reloadDataViewsCombobox();

std::optional<ChannelFilter> chf = m_graph->channelFilter();

if (chf && !chf.value().name().isEmpty())
if (chf && !chf.value().name().isEmpty()) {
ui->cbDataView->setCurrentText(chf.value().name());
else
}
else {
ui->cbDataView->setCurrentIndex(-1);
}

refreshActions();

Expand Down Expand Up @@ -97,6 +100,15 @@ void ChannelFilterDialog::applyTextFilter()
void ChannelFilterDialog::reloadDataViewsCombobox()
{
ui->cbDataView->clear();

for (const auto &v: m_predefinedDataViews) {
ui->cbDataView->addItem(v.name);
}

if (ui->cbDataView->count() > 0) {
ui->cbDataView->insertSeparator(ui->cbDataView->count());
}

ui->cbDataView->addItems(m_graph->savedVisualSettingsNames(m_sitePath));
}

Expand Down Expand Up @@ -150,9 +162,11 @@ void ChannelFilterDialog::importDataView()

void ChannelFilterDialog::refreshActions()
{
m_saveViewAction->setEnabled(!ui->cbDataView->currentText().isEmpty());
m_deleteViewAction->setEnabled(!ui->cbDataView->currentText().isEmpty());
m_resetViewAction->setEnabled(!ui->cbDataView->currentText().isEmpty());
bool is_action_enabled = (!ui->cbDataView->currentText().isEmpty() && ui->cbDataView->currentIndex() >= m_predefinedDataViews.count());

m_saveViewAction->setEnabled(is_action_enabled);
m_deleteViewAction->setEnabled(is_action_enabled);
m_resetViewAction->setEnabled(is_action_enabled);
}

void ChannelFilterDialog::saveDataView()
Expand Down Expand Up @@ -274,7 +288,13 @@ void ChannelFilterDialog::setVisibleItemsCheckState_helper(const QModelIndex &mi
void ChannelFilterDialog::onDataViewComboboxChanged(int index)
{
if (index >= 0) { //ignore event with index = -1, which is emmited from clear() method
m_graph->loadVisualSettings(m_sitePath, ui->cbDataView->currentText());
if (index < m_predefinedDataViews.count()) {
m_graph->setVisualSettingsAndChannelFilter(m_predefinedDataViews[index]);
}
else {
m_graph->loadVisualSettings(m_sitePath, ui->cbDataView->currentText());
}

loadChannelFilterFomGraph();
}
refreshActions();
Expand Down
6 changes: 5 additions & 1 deletion libshvvisu/src/timeline/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,11 @@ void Graph::setVisualSettingsAndChannelFilter(const VisualSettings &settings)
GraphChannel *channel = m_channels[j];
if (channel->shvPath() == channel_settings.shvPath) {
permitted_paths.insert(channel_settings.shvPath);
channel->setStyle(channel_settings.style);

if (!channel_settings.style.isEmpty()) {
channel->setStyle(channel_settings.style);;
}

m_channels.insert(i, m_channels.takeAt(j));
break;
}
Expand Down

0 comments on commit 679cbe8

Please sign in to comment.