From e22530629173945fedcc4f60020681bcdf1cb2b7 Mon Sep 17 00:00:00 2001 From: Petr Date: Mon, 16 Oct 2023 08:23:17 +0200 Subject: [PATCH 01/17] used QSet instead of stringlist --- libshvvisu/src/logview/dlgloginspector.cpp | 10 ++--- libshvvisu/src/logview/dlgloginspector.h | 2 +- .../src/logview/logsortfilterproxymodel.cpp | 12 +----- libshvvisu/src/timeline/channelfilter.cpp | 36 ++++++---------- libshvvisu/src/timeline/channelfilter.h | 18 ++++---- .../src/timeline/channelfilterdialog.cpp | 6 +-- libshvvisu/src/timeline/channelfilterdialog.h | 6 +-- .../src/timeline/channelfiltermodel.cpp | 12 +++--- libshvvisu/src/timeline/channelfiltermodel.h | 8 ++-- libshvvisu/src/timeline/graph.cpp | 43 ++++++++----------- libshvvisu/src/timeline/graph.h | 2 +- libshvvisu/src/timeline/graphwidget.cpp | 2 +- 12 files changed, 65 insertions(+), 92 deletions(-) diff --git a/libshvvisu/src/logview/dlgloginspector.cpp b/libshvvisu/src/logview/dlgloginspector.cpp index 1d5c28c64..0eb07644c 100644 --- a/libshvvisu/src/logview/dlgloginspector.cpp +++ b/libshvvisu/src/logview/dlgloginspector.cpp @@ -486,7 +486,7 @@ void DlgLogInspector::parseLog(shv::chainpack::RpcValue log) m_graph->createChannelsFromModel(); - QStringList channel_paths = m_graph->channelPaths(); + QSet channel_paths = m_graph->channelPaths(); m_channelFilterDialog->init(shvPath(), channel_paths); ui->graphView->makeLayout(); applyFilters(channel_paths); @@ -547,16 +547,16 @@ void DlgLogInspector::setTimeZone(const QTimeZone &tz) } #endif -void DlgLogInspector::applyFilters(const QStringList &channel_paths) +void DlgLogInspector::applyFilters(const QSet &channel_paths) { - auto graph_filter = m_graph->channelFilter(); - graph_filter.setMatchingPaths(channel_paths); + timeline::ChannelFilter graph_filter = m_graph->channelFilter(); + graph_filter.setPermittedPaths(channel_paths); m_graph->setChannelFilter(graph_filter); } void DlgLogInspector::onChannelsFilterClicked() { - m_channelFilterDialog->setSelectedChannels(m_graph->channelFilter().matchingPaths()); + m_channelFilterDialog->setSelectedChannels(m_graph->channelFilter().permittedPaths()); if(m_channelFilterDialog->exec() == QDialog::Accepted) { applyFilters(m_channelFilterDialog->selectedChannels()); diff --git a/libshvvisu/src/logview/dlgloginspector.h b/libshvvisu/src/logview/dlgloginspector.h index ad4d8b544..a8001e426 100644 --- a/libshvvisu/src/logview/dlgloginspector.h +++ b/libshvvisu/src/logview/dlgloginspector.h @@ -54,7 +54,7 @@ class SHVVISU_DECL_EXPORT DlgLogInspector : public QDialog void setTimeZone(const QTimeZone &tz); #endif - void applyFilters(const QStringList &channel_paths); + void applyFilters(const QSet &channel_paths); void onChannelsFilterClicked(); void onGraphChannelFilterChanged(); diff --git a/libshvvisu/src/logview/logsortfilterproxymodel.cpp b/libshvvisu/src/logview/logsortfilterproxymodel.cpp index 9ee4a09a7..c94e187dc 100644 --- a/libshvvisu/src/logview/logsortfilterproxymodel.cpp +++ b/libshvvisu/src/logview/logsortfilterproxymodel.cpp @@ -53,17 +53,9 @@ bool LogSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex bool row_accepted = false; if (m_shvPathColumn >= 0) { QModelIndex ix = sourceModel()->index(source_row, m_shvPathColumn, source_parent); - row_accepted = !m_channelFilter.isValid(); - if (!row_accepted) { - for (const QString &selected_path : m_channelFilter.matchingPaths()) { - auto row_path = sourceModel()->data(ix).toString(); - if (selected_path.startsWith(row_path)) { - row_accepted = true; - break; - } - } - } + row_accepted = m_channelFilter.isPathPermitted(sourceModel()->data(ix).toString()); } + if (row_accepted && !m_fulltextFilter.pattern().isEmpty()) { bool fulltext_match = false; { diff --git a/libshvvisu/src/timeline/channelfilter.cpp b/libshvvisu/src/timeline/channelfilter.cpp index 2052ef9af..ca3bac219 100644 --- a/libshvvisu/src/timeline/channelfilter.cpp +++ b/libshvvisu/src/timeline/channelfilter.cpp @@ -4,47 +4,39 @@ namespace shv::visu::timeline { -ChannelFilter::ChannelFilter() - : m_isValid(false) +ChannelFilter::ChannelFilter(const QSet &permitted_paths) { + m_permittedPaths = permitted_paths; } -ChannelFilter::ChannelFilter(const QStringList &matching_paths) - : m_isValid(true) +QSet ChannelFilter::permittedPaths() const { - setMatchingPaths(matching_paths); + return m_permittedPaths; } -QStringList ChannelFilter::matchingPaths() const +void ChannelFilter::addPermittedPath(const QString &path) { - return m_matchingPaths; + m_permittedPaths.insert(path); } -void ChannelFilter::addMatchingPath(const QString &shv_path) +void ChannelFilter::removePermittedPath(const QString &path) { - m_isValid = true; - m_matchingPaths << shv_path; + m_permittedPaths.remove(path); } -void ChannelFilter::removeMatchingPath(const QString &shv_path) +void ChannelFilter::setPermittedPaths(const QSet &paths) { - m_isValid = true; - m_matchingPaths.removeOne(shv_path); + m_permittedPaths = paths; } -void ChannelFilter::setMatchingPaths(const QStringList &paths) +bool ChannelFilter::isPathPermitted(const QString &path) const { - m_isValid = true; - m_matchingPaths = paths; + return m_permittedPaths.contains(path); } -bool ChannelFilter::isPathMatch(const QString &path) const +bool ChannelFilter::isEmpty() const { - return m_matchingPaths.contains(path); + return m_permittedPaths.isEmpty(); } -bool ChannelFilter::isValid() const -{ - return m_isValid; -} } diff --git a/libshvvisu/src/timeline/channelfilter.h b/libshvvisu/src/timeline/channelfilter.h index 4a487e5fe..0036efbef 100644 --- a/libshvvisu/src/timeline/channelfilter.h +++ b/libshvvisu/src/timeline/channelfilter.h @@ -12,20 +12,18 @@ namespace timeline { class SHVVISU_DECL_EXPORT ChannelFilter { public: - ChannelFilter(); - ChannelFilter(const QStringList &matching_paths); + ChannelFilter(const QSet &permitted_paths = {}); - void addMatchingPath(const QString &shv_path); - void removeMatchingPath(const QString &shv_path); + void addPermittedPath(const QString &path); + void removePermittedPath(const QString &path); - QStringList matchingPaths() const; - void setMatchingPaths(const QStringList &paths); + QSet permittedPaths() const; + void setPermittedPaths(const QSet &paths); - bool isPathMatch(const QString &path) const; - bool isValid() const; + bool isPathPermitted(const QString &path) const; + bool isEmpty() const; private: - QStringList m_matchingPaths; - bool m_isValid; + QSet m_permittedPaths; }; } diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index 7dd241a8b..c49927bff 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -40,18 +40,18 @@ ChannelFilterDialog::~ChannelFilterDialog() delete ui; } -void ChannelFilterDialog::init(const QString &site_path, const QStringList &logged_paths) +void ChannelFilterDialog::init(const QString &site_path, const QSet &logged_paths) { m_sitePath = site_path; m_channelsFilterModel->createNodes(logged_paths); } -QStringList ChannelFilterDialog::selectedChannels() +QSet ChannelFilterDialog::selectedChannels() { return m_channelsFilterModel->selectedChannels(); } -void ChannelFilterDialog::setSelectedChannels(const QStringList &channels) +void ChannelFilterDialog::setSelectedChannels(const QSet &channels) { m_channelsFilterModel->setSelectedChannels(channels); } diff --git a/libshvvisu/src/timeline/channelfilterdialog.h b/libshvvisu/src/timeline/channelfilterdialog.h index c72d1e1e8..3dfcc9131 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.h +++ b/libshvvisu/src/timeline/channelfilterdialog.h @@ -23,10 +23,10 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog explicit ChannelFilterDialog(QWidget *parent = nullptr); ~ChannelFilterDialog(); - void init(const QString &site_path, const QStringList &logged_paths); + void init(const QString &site_path, const QSet &logged_paths); - QStringList selectedChannels(); - void setSelectedChannels(const QStringList &channels); + QSet selectedChannels(); + void setSelectedChannels(const QSet &channels); private: void applyTextFilter(); diff --git a/libshvvisu/src/timeline/channelfiltermodel.cpp b/libshvvisu/src/timeline/channelfiltermodel.cpp index 21517dcbd..16a5152d7 100644 --- a/libshvvisu/src/timeline/channelfiltermodel.cpp +++ b/libshvvisu/src/timeline/channelfiltermodel.cpp @@ -17,7 +17,7 @@ ChannelFilterModel::ChannelFilterModel(QObject *parent) ChannelFilterModel::~ChannelFilterModel() = default; -void ChannelFilterModel::createNodes(const QStringList &channels) +void ChannelFilterModel::createNodes(const QSet &channels) { beginResetModel(); @@ -27,17 +27,17 @@ void ChannelFilterModel::createNodes(const QStringList &channels) endResetModel(); } -QStringList ChannelFilterModel::selectedChannels() +QSet ChannelFilterModel::selectedChannels() { - QStringList channels; + QSet channels; selectedChannels_helper(&channels, invisibleRootItem()); return channels; } -void ChannelFilterModel::selectedChannels_helper(QStringList *channels, QStandardItem *it) +void ChannelFilterModel::selectedChannels_helper(QSet *channels, QStandardItem *it) { if ((it != invisibleRootItem()) && (it->data(UserData::ValidLogEntry).toBool()) && (it->checkState() == Qt::CheckState::Checked)){ - (*channels) << shvPathFromItem(it); + channels->insert(shvPathFromItem(it)); } for (int row = 0; row < it->rowCount(); row++) { @@ -46,7 +46,7 @@ void ChannelFilterModel::selectedChannels_helper(QStringList *channels, QStandar } } -void ChannelFilterModel::setSelectedChannels(const QStringList &channels) +void ChannelFilterModel::setSelectedChannels(const QSet &channels) { setChildItemsCheckedState(invisibleRootItem(), Qt::CheckState::Unchecked); diff --git a/libshvvisu/src/timeline/channelfiltermodel.h b/libshvvisu/src/timeline/channelfiltermodel.h index b2a3c7766..b17703e41 100644 --- a/libshvvisu/src/timeline/channelfiltermodel.h +++ b/libshvvisu/src/timeline/channelfiltermodel.h @@ -21,10 +21,10 @@ class SHVVISU_DECL_EXPORT ChannelFilterModel : public QStandardItemModel ChannelFilterModel(QObject *parent = nullptr); ~ChannelFilterModel() Q_DECL_OVERRIDE; - void createNodes(const QStringList &channels); + void createNodes(const QSet &channels); - QStringList selectedChannels(); - void setSelectedChannels(const QStringList &channels); + QSet selectedChannels(); + void setSelectedChannels(const QSet &channels); void setItemCheckState(const QModelIndex &mi, Qt::CheckState check_state); void fixCheckBoxesIntegrity(); protected: @@ -38,7 +38,7 @@ class SHVVISU_DECL_EXPORT ChannelFilterModel : public QStandardItemModel void createNodesForPath(const QString &path); - void selectedChannels_helper(QStringList *channels, QStandardItem *it); + void selectedChannels_helper(QSet *channels, QStandardItem *it); bool setData ( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; void setChildItemsCheckedState(QStandardItem *it, Qt::CheckState check_state); void fixChildItemsCheckBoxesIntegrity(QStandardItem *it); diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index c1f6bfe66..761ccbc71 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -105,9 +105,6 @@ QTimeZone Graph::timeZone() const bool Graph::isInitialView() const { - if (m_channelFilter.isValid()) { - return false; - } GraphChannel::Style default_style; QMap path_to_model_index; @@ -132,7 +129,7 @@ bool Graph::isInitialView() const void Graph::reset() { createChannelsFromModel(); - m_channelFilter = ChannelFilter(); + m_channelFilter = channelPaths(); Q_EMIT layoutChanged(); Q_EMIT channelFilterChanged(); } @@ -173,6 +170,7 @@ void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sor ch->setStyle(style); } resetChannelsRanges(); + m_channelFilter.setPermittedPaths(channelPaths()); } void Graph::resetChannelsRanges() @@ -265,35 +263,35 @@ void Graph::moveChannel(qsizetype channel, qsizetype new_pos) void Graph::showAllChannels() { - m_channelFilter.setMatchingPaths(channelPaths()); + m_channelFilter.setPermittedPaths(channelPaths()); emit layoutChanged(); emit channelFilterChanged(); } -QStringList Graph::channelPaths() +QSet Graph::channelPaths() { - QStringList shv_paths; + QSet ret; for (int i = 0; i < m_channels.count(); ++i) { - shv_paths << m_channels[i]->shvPath(); + ret.insert(m_channels[i]->shvPath()); } - return shv_paths; + return ret; } void Graph::hideFlatChannels() { - QStringList matching_paths = (m_channelFilter.isValid()) ? m_channelFilter.matchingPaths() : channelPaths(); + QSet matching_paths = m_channelFilter.permittedPaths(); for (qsizetype i = 0; i < m_channels.count(); ++i) { GraphChannel *ch = m_channels[i]; if(isChannelFlat(ch)) { - matching_paths.removeOne(ch->shvPath()); + matching_paths.remove(ch->shvPath()); } } - m_channelFilter.setMatchingPaths(matching_paths); + m_channelFilter.setPermittedPaths(matching_paths); emit layoutChanged(); emit channelFilterChanged(); @@ -321,14 +319,11 @@ void Graph::setChannelVisible(qsizetype channel_ix, bool is_visible) { GraphChannel *ch = channelAt(channel_ix); - if (!m_channelFilter.isValid()) { - m_channelFilter.setMatchingPaths(channelPaths()); - } if (is_visible) { - m_channelFilter.addMatchingPath(ch->shvPath()); + m_channelFilter.addPermittedPath(ch->shvPath()); } else { - m_channelFilter.removeMatchingPath(ch->shvPath()); + m_channelFilter.removePermittedPath(ch->shvPath()); } emit layoutChanged(); @@ -1180,18 +1175,14 @@ QVector Graph::visibleChannels() const if (maximized_channel >= 0) { visible_channels << maximized_channel; } - else if(m_channelFilter.isValid()) { + else { for (int i = 0; i < m_channels.count(); ++i) { QString shv_path = model()->channelInfo(m_channels[i]->modelIndex()).shvPath; - if(m_channelFilter.isPathMatch(shv_path)) { + if(m_channelFilter.isPathPermitted(shv_path)) { visible_channels << i; } } } - else { - for (int i = 0; i < m_channels.count(); ++i) - visible_channels << i; - } return visible_channels; } @@ -1199,14 +1190,14 @@ QVector Graph::visibleChannels() const void Graph::setVisualSettings(const VisualSettings &settings) { if (settings.isValid()) { - QStringList new_filter; + QSet f; createChannelsFromModel(); for (int i = 0; i < settings.channels.count(); ++i) { const VisualSettings::Channel &channel_settings = settings.channels[i]; for (int j = i; j < m_channels.count(); ++j) { GraphChannel *channel = m_channels[j]; if (channel->shvPath() == channel_settings.shvPath) { - new_filter << channel_settings.shvPath; + f.insert(channel_settings.shvPath); channel->setStyle(channel_settings.style); m_channels.insert(i, m_channels.takeAt(j)); break; @@ -1214,7 +1205,7 @@ void Graph::setVisualSettings(const VisualSettings &settings) } } - m_channelFilter.setMatchingPaths(new_filter); + m_channelFilter.setPermittedPaths(f); Q_EMIT layoutChanged(); Q_EMIT channelFilterChanged(); } diff --git a/libshvvisu/src/timeline/graph.h b/libshvvisu/src/timeline/graph.h index a0d664f1f..3ada2ab9f 100644 --- a/libshvvisu/src/timeline/graph.h +++ b/libshvvisu/src/timeline/graph.h @@ -128,7 +128,7 @@ class SHVVISU_DECL_EXPORT Graph : public QObject QString channelName(qsizetype channel) const; void showAllChannels(); - QStringList channelPaths(); + QSet channelPaths(); void hideFlatChannels(); const ChannelFilter& channelFilter() const; void setChannelFilter(const ChannelFilter &filter); diff --git a/libshvvisu/src/timeline/graphwidget.cpp b/libshvvisu/src/timeline/graphwidget.cpp index 0bac7ee1c..55db25523 100644 --- a/libshvvisu/src/timeline/graphwidget.cpp +++ b/libshvvisu/src/timeline/graphwidget.cpp @@ -762,7 +762,7 @@ void GraphWidget::showGraphContextMenu(const QPoint &mouse_pos) menu.addAction(tr("Reset channels to defaults"), this, [this]() { m_graph->createChannelsFromModel(); auto graph_filter = m_graph->channelFilter(); - graph_filter.setMatchingPaths(m_graph->channelPaths()); + graph_filter.setPermittedPaths(m_graph->channelPaths()); m_graph->setChannelFilter(graph_filter); }); if (m_graph->isYAxisVisible()) { From f71a4a3cbdebdf2466bc8a65374b1bdaed6f896f Mon Sep 17 00:00:00 2001 From: Petr Date: Mon, 16 Oct 2023 11:13:16 +0200 Subject: [PATCH 02/17] removed isInitialView() --- libshvvisu/src/timeline/graph.cpp | 32 ++++--------------------------- libshvvisu/src/timeline/graph.h | 1 - 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index 761ccbc71..4effaeb7a 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -103,29 +103,6 @@ QTimeZone Graph::timeZone() const } #endif -bool Graph::isInitialView() const -{ - GraphChannel::Style default_style; - - QMap path_to_model_index; - for (qsizetype i = 0; i < m_model->channelCount(); ++i) { - QString shv_path = m_model->channelShvPath(i); - path_to_model_index[shv_path] = i; - } - QString previous_shv_path; - for (GraphChannel *channel : m_channels) { - if (channel->style().heightMax() != default_style.heightMax()) { - return false; - } - QString channel_shv_path = m_model->channelShvPath(channel->modelIndex()); - if (channel_shv_path < previous_shv_path) { - return false; - } - previous_shv_path = channel_shv_path; - } - return true; -} - void Graph::reset() { createChannelsFromModel(); @@ -1245,12 +1222,11 @@ void Graph::resizeVerticalHeaderWidth(int delta_px) Graph::VisualSettings Graph::visualSettings() const { VisualSettings view; - if (!isInitialView()) { - for (int ix : visibleChannels()) { - const GraphChannel *channel = channelAt(ix); - view.channels << VisualSettings::Channel{ channel->shvPath(), channel->style() }; - } + for (int ix : visibleChannels()) { + const GraphChannel *channel = channelAt(ix); + view.channels << VisualSettings::Channel{ channel->shvPath(), channel->style() }; } + return view; } diff --git a/libshvvisu/src/timeline/graph.h b/libshvvisu/src/timeline/graph.h index 3ada2ab9f..78acc0977 100644 --- a/libshvvisu/src/timeline/graph.h +++ b/libshvvisu/src/timeline/graph.h @@ -116,7 +116,6 @@ class SHVVISU_DECL_EXPORT Graph : public QObject enum class SortChannels { No = 0, Yes }; void createChannelsFromModel(SortChannels sorted = SortChannels::Yes); void resetChannelsRanges(); - bool isInitialView() const; qsizetype channelCount() const; void clearChannels(); From f37986c529d1d9443852c5f547e2badb25894a2d Mon Sep 17 00:00:00 2001 From: Petr Date: Mon, 16 Oct 2023 14:40:17 +0200 Subject: [PATCH 03/17] Sorting channels i channelFilterModel --- libshvvisu/src/timeline/channelfiltermodel.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libshvvisu/src/timeline/channelfiltermodel.cpp b/libshvvisu/src/timeline/channelfiltermodel.cpp index 16a5152d7..7140569a3 100644 --- a/libshvvisu/src/timeline/channelfiltermodel.cpp +++ b/libshvvisu/src/timeline/channelfiltermodel.cpp @@ -21,9 +21,13 @@ void ChannelFilterModel::createNodes(const QSet &channels) { beginResetModel(); - for (const auto &shv_path: channels) { - createNodesForPath(shv_path); + QStringList sorted_channels = QStringList(channels.begin(), channels.end()); + sorted_channels.sort(Qt::CaseInsensitive); + + for (const auto &p: sorted_channels) { + createNodesForPath(p); } + endResetModel(); } From 0a70f1d20a20a147d819fb6c31196ab9aa56c574 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 17 Oct 2023 20:21:50 +0200 Subject: [PATCH 04/17] do not filter if filter is not valid --- libshvvisu/src/logview/dlgloginspector.cpp | 2 +- .../src/logview/logsortfilterproxymodel.cpp | 27 +++++++++---------- libshvvisu/src/timeline/channelfilter.cpp | 13 +++++++-- libshvvisu/src/timeline/channelfilter.h | 7 +++-- libshvvisu/src/timeline/graph.cpp | 10 ++++--- libshvvisu/src/timeline/graph.h | 6 +++++ 6 files changed, 42 insertions(+), 23 deletions(-) diff --git a/libshvvisu/src/logview/dlgloginspector.cpp b/libshvvisu/src/logview/dlgloginspector.cpp index 0eb07644c..5041e3bec 100644 --- a/libshvvisu/src/logview/dlgloginspector.cpp +++ b/libshvvisu/src/logview/dlgloginspector.cpp @@ -272,7 +272,7 @@ void DlgLogInspector::initVisualSettingSelector(const QString &shv_path) { ui->cbViews->clear(); - ui->cbViews->addItem(tr("Initial view")); + ui->cbViews->addItem(tr("Without filter")); for (const QString &view_name : m_graph->savedVisualSettingsNames(shv_path)) { ui->cbViews->addItem(view_name); } diff --git a/libshvvisu/src/logview/logsortfilterproxymodel.cpp b/libshvvisu/src/logview/logsortfilterproxymodel.cpp index c94e187dc..f3e6ae607 100644 --- a/libshvvisu/src/logview/logsortfilterproxymodel.cpp +++ b/libshvvisu/src/logview/logsortfilterproxymodel.cpp @@ -50,25 +50,24 @@ bool startsWithPath(const QStringView &str, const QStringView &path) bool LogSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { - bool row_accepted = false; + bool is_row_accepted = true; + if (m_shvPathColumn >= 0) { QModelIndex ix = sourceModel()->index(source_row, m_shvPathColumn, source_parent); - row_accepted = m_channelFilter.isPathPermitted(sourceModel()->data(ix).toString()); - } + is_row_accepted = (m_channelFilter.isValid()) ? m_channelFilter.isPathPermitted(sourceModel()->data(ix).toString()) : true; - if (row_accepted && !m_fulltextFilter.pattern().isEmpty()) { - bool fulltext_match = false; - { - QModelIndex ix = sourceModel()->index(source_row, m_shvPathColumn, source_parent); - fulltext_match = fulltext_match || m_fulltextFilter.matches(sourceModel()->data(ix).toString()); - } - if (m_valueColumn >= 0) { - QModelIndex ix = sourceModel()->index(source_row, m_valueColumn, source_parent); - fulltext_match = fulltext_match || m_fulltextFilter.matches(sourceModel()->data(ix).toString()); + if (is_row_accepted && !m_fulltextFilter.pattern().isEmpty()) { + bool is_fulltext_filter_matched = m_fulltextFilter.matches(sourceModel()->data(ix).toString()); + + if (m_valueColumn >= 0) { + ix = sourceModel()->index(source_row, m_valueColumn, source_parent); + is_fulltext_filter_matched = is_fulltext_filter_matched || m_fulltextFilter.matches(sourceModel()->data(ix).toString()); + } + is_row_accepted = is_row_accepted || is_fulltext_filter_matched; } - row_accepted = fulltext_match; } - return row_accepted; + + return is_row_accepted; } } diff --git a/libshvvisu/src/timeline/channelfilter.cpp b/libshvvisu/src/timeline/channelfilter.cpp index ca3bac219..cc3593390 100644 --- a/libshvvisu/src/timeline/channelfilter.cpp +++ b/libshvvisu/src/timeline/channelfilter.cpp @@ -4,9 +4,15 @@ namespace shv::visu::timeline { +ChannelFilter::ChannelFilter() +{ + +} + ChannelFilter::ChannelFilter(const QSet &permitted_paths) { m_permittedPaths = permitted_paths; + m_isValid = true; } QSet ChannelFilter::permittedPaths() const @@ -17,16 +23,19 @@ QSet ChannelFilter::permittedPaths() const void ChannelFilter::addPermittedPath(const QString &path) { m_permittedPaths.insert(path); + m_isValid = true; } void ChannelFilter::removePermittedPath(const QString &path) { m_permittedPaths.remove(path); + m_isValid = true; } void ChannelFilter::setPermittedPaths(const QSet &paths) { m_permittedPaths = paths; + m_isValid = true; } bool ChannelFilter::isPathPermitted(const QString &path) const @@ -34,9 +43,9 @@ bool ChannelFilter::isPathPermitted(const QString &path) const return m_permittedPaths.contains(path); } -bool ChannelFilter::isEmpty() const +bool ChannelFilter::isValid() const { - return m_permittedPaths.isEmpty(); + return m_isValid; } } diff --git a/libshvvisu/src/timeline/channelfilter.h b/libshvvisu/src/timeline/channelfilter.h index 0036efbef..1b027bf6a 100644 --- a/libshvvisu/src/timeline/channelfilter.h +++ b/libshvvisu/src/timeline/channelfilter.h @@ -12,7 +12,8 @@ namespace timeline { class SHVVISU_DECL_EXPORT ChannelFilter { public: - ChannelFilter(const QSet &permitted_paths = {}); + ChannelFilter(); + ChannelFilter(const QSet &permitted_paths); void addPermittedPath(const QString &path); void removePermittedPath(const QString &path); @@ -21,9 +22,11 @@ class SHVVISU_DECL_EXPORT ChannelFilter void setPermittedPaths(const QSet &paths); bool isPathPermitted(const QString &path) const; - bool isEmpty() const; + bool isValid() const; + private: QSet m_permittedPaths; + bool m_isValid = false; }; } diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index 4effaeb7a..f97502615 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -106,7 +106,6 @@ QTimeZone Graph::timeZone() const void Graph::reset() { createChannelsFromModel(); - m_channelFilter = channelPaths(); Q_EMIT layoutChanged(); Q_EMIT channelFilterChanged(); } @@ -147,7 +146,6 @@ void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sor ch->setStyle(style); } resetChannelsRanges(); - m_channelFilter.setPermittedPaths(channelPaths()); } void Graph::resetChannelsRanges() @@ -259,7 +257,7 @@ QSet Graph::channelPaths() void Graph::hideFlatChannels() { - QSet matching_paths = m_channelFilter.permittedPaths(); + QSet matching_paths = (m_channelFilter.isValid()) ? m_channelFilter.permittedPaths() : channelPaths(); for (qsizetype i = 0; i < m_channels.count(); ++i) { GraphChannel *ch = m_channels[i]; @@ -1152,7 +1150,7 @@ QVector Graph::visibleChannels() const if (maximized_channel >= 0) { visible_channels << maximized_channel; } - else { + else if (m_channelFilter.isValid()) { for (int i = 0; i < m_channels.count(); ++i) { QString shv_path = model()->channelInfo(m_channels[i]->modelIndex()).shvPath; if(m_channelFilter.isPathPermitted(shv_path)) { @@ -1160,6 +1158,10 @@ QVector Graph::visibleChannels() const } } } + else { + for (int i = 0; i < m_channels.count(); ++i) + visible_channels << i; + } return visible_channels; } diff --git a/libshvvisu/src/timeline/graph.h b/libshvvisu/src/timeline/graph.h index 78acc0977..d54f960e8 100644 --- a/libshvvisu/src/timeline/graph.h +++ b/libshvvisu/src/timeline/graph.h @@ -97,6 +97,12 @@ class SHVVISU_DECL_EXPORT Graph : public QObject QVector channels; }; + struct View { + QString name; + bool edited = false; + VisualSettings settings; + }; + Graph(QObject *parent = nullptr); virtual ~Graph(); From 6c10734a511b2c710815c3155b9c731438a9029f Mon Sep 17 00:00:00 2001 From: Petr Date: Thu, 19 Oct 2023 11:10:30 +0200 Subject: [PATCH 05/17] added dataviewwidget --- libshvvisu/CMakeLists.txt | 1 + libshvvisu/src/logview/dlgloginspector.cpp | 8 +- .../src/timeline/channelfilterdialog.cpp | 153 +++++++++++++++++- libshvvisu/src/timeline/channelfilterdialog.h | 23 ++- .../src/timeline/channelfilterdialog.ui | 91 +++++++---- libshvvisu/src/widgets/dataviewwidget.cpp | 14 ++ libshvvisu/src/widgets/dataviewwidget.h | 19 +++ libshvvisu/src/widgets/dataviewwidget.ui | 66 ++++++++ 8 files changed, 336 insertions(+), 39 deletions(-) create mode 100644 libshvvisu/src/widgets/dataviewwidget.cpp create mode 100644 libshvvisu/src/widgets/dataviewwidget.h create mode 100644 libshvvisu/src/widgets/dataviewwidget.ui diff --git a/libshvvisu/CMakeLists.txt b/libshvvisu/CMakeLists.txt index e8bcd2159..13311bd43 100644 --- a/libshvvisu/CMakeLists.txt +++ b/libshvvisu/CMakeLists.txt @@ -27,6 +27,7 @@ add_library(libshvvisu src/timeline/graphwidget.cpp src/timeline/sample.cpp src/widgets/timezonecombobox.cpp + src/widgets/dataviewwidget.cpp ) target_link_libraries(libshvvisu PUBLIC Qt::Widgets libshviotqt) diff --git a/libshvvisu/src/logview/dlgloginspector.cpp b/libshvvisu/src/logview/dlgloginspector.cpp index 5041e3bec..78f95c8aa 100644 --- a/libshvvisu/src/logview/dlgloginspector.cpp +++ b/libshvvisu/src/logview/dlgloginspector.cpp @@ -486,10 +486,10 @@ void DlgLogInspector::parseLog(shv::chainpack::RpcValue log) m_graph->createChannelsFromModel(); - QSet channel_paths = m_graph->channelPaths(); - m_channelFilterDialog->init(shvPath(), channel_paths); + //QSet channel_paths = m_graph->channelPaths(); + m_channelFilterDialog->init(shvPath(), m_graph); ui->graphView->makeLayout(); - applyFilters(channel_paths); + //applyFilters(channel_paths); } void DlgLogInspector::showInfo(const QString &msg, bool is_error) @@ -556,7 +556,7 @@ void DlgLogInspector::applyFilters(const QSet &channel_paths) void DlgLogInspector::onChannelsFilterClicked() { - m_channelFilterDialog->setSelectedChannels(m_graph->channelFilter().permittedPaths()); + m_channelFilterDialog->setFilter(ui->cbViews->currentText(), m_graph->channelFilter().permittedPaths()); if(m_channelFilterDialog->exec() == QDialog::Accepted) { applyFilters(m_channelFilterDialog->selectedChannels()); diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index c49927bff..dc02d51cc 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -27,8 +27,18 @@ ChannelFilterDialog::ChannelFilterDialog(QWidget *parent) : ui->tvChannelsFilter->setModel(m_channelsFilterProxyModel); ui->tvChannelsFilter->header()->hide(); ui->tvChannelsFilter->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); - connect(ui->tvChannelsFilter, &QTreeView::customContextMenuRequested, this, &ChannelFilterDialog::onCustomContextMenuRequested); + QMenu *view_menu = new QMenu(this); + m_resetViewAction = view_menu->addAction(tr("Clear"), this, &ChannelFilterDialog::resetView); + m_saveViewAction = view_menu->addAction(tr("Save"), this, &ChannelFilterDialog::saveView); + m_saveViewAsAction = view_menu->addAction(tr("Save as"), this, &ChannelFilterDialog::saveViewAs); + m_revertViewAction = view_menu->addAction(tr("Revert changes"), this, &ChannelFilterDialog::revertView); + m_deleteViewAction = view_menu->addAction(tr("Delete"), this, &ChannelFilterDialog::deleteView); + m_exportViewAction = view_menu->addAction(tr("Export"), this, &ChannelFilterDialog::exportView); + m_importViewAction = view_menu->addAction(tr("Import"), this, &ChannelFilterDialog::importView); + ui->pbActions->setMenu(view_menu); + + connect(ui->tvChannelsFilter, &QTreeView::customContextMenuRequested, this, &ChannelFilterDialog::onCustomContextMenuRequested); connect(ui->leMatchingFilterText, &QLineEdit::textChanged, this, &ChannelFilterDialog::onLeMatchingFilterTextChanged); connect(ui->pbClearMatchingText, &QPushButton::clicked, this, &ChannelFilterDialog::onPbClearMatchingTextClicked); connect(ui->pbCheckItems, &QPushButton::clicked, this, &ChannelFilterDialog::onPbCheckItemsClicked); @@ -40,10 +50,15 @@ ChannelFilterDialog::~ChannelFilterDialog() delete ui; } -void ChannelFilterDialog::init(const QString &site_path, const QSet &logged_paths) +void ChannelFilterDialog::init(const QString &site_path, Graph *graph) { m_sitePath = site_path; - m_channelsFilterModel->createNodes(logged_paths); + m_graph = graph; + m_channelsFilterModel->createNodes(graph->channelPaths()); + + for (const QString &view_name : m_graph->savedVisualSettingsNames(m_sitePath)) { + ui->cbLayouts->addItem(view_name); //, QVariant::fromValue(View{ view_name, false, tl::Graph::VisualSettings() })); + } } QSet ChannelFilterDialog::selectedChannels() @@ -51,8 +66,9 @@ QSet ChannelFilterDialog::selectedChannels() return m_channelsFilterModel->selectedChannels(); } -void ChannelFilterDialog::setSelectedChannels(const QSet &channels) +void ChannelFilterDialog::setFilter(const QString &filter_name, const QSet &channels) { + ui->cbLayouts->setCurrentText(filter_name); m_channelsFilterModel->setSelectedChannels(channels); } @@ -66,6 +82,135 @@ void ChannelFilterDialog::applyTextFilter() } } +void ChannelFilterDialog::deleteView() +{ +/* View current_view = ui->cbViews->currentData().value(); + m_graph->deleteVisualSettings(QString::fromStdString(m_site->shvPath()), current_view.name); + ui->cbViews->removeItem(index); + ui->cbViews->setCurrentIndex(VIEW_COMBO_NO_VIEW_INDEX); + onViewSelected(VIEW_COMBO_NO_VIEW_INDEX); + */ +} + +void ChannelFilterDialog::exportView() +{ +/* int index = ui->cbViews->currentIndex(); + if (index == VIEW_COMBO_NO_VIEW_INDEX) { + return; + } + QString file_name = QFileDialog::getSaveFileName(this, tr("Input file name"), RECENT_SETTINGS_DIR, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); + if (!file_name.isEmpty()) { + if (!file_name.endsWith(FLATLINE_VIEW_SETTINGS_FILE_EXTENSION)) { + file_name.append(FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); + } + View current_view = ui->cbViews->currentData().value(); + m_graph->saveVisualSettings(QString::fromStdString(m_site->shvPath()), current_view.name); + QSettings settings(file_name, QSettings::Format::IniFormat); + settings.setValue("fileType", FLATLINE_VIEW_SETTINGS_FILE_TYPE); + settings.setValue("settings", m_graph->visualSettings().toJson()); + RECENT_SETTINGS_DIR = QFileInfo(file_name).path(); + } + */ +} + +void ChannelFilterDialog::importView() +{ +/* QString file_name = QFileDialog::getOpenFileName(this, tr("Input file name"), RECENT_SETTINGS_DIR, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); + if (!file_name.isEmpty()) { + QString view_name = QInputDialog::getText(this, tr("Import as"), tr("Input view name")); + if (!view_name.isEmpty()) { + for (int i = 0; i < ui->cbViews->count(); ++i) { + if (ui->cbViews->itemData(i).value().name == view_name) { + QMessageBox::warning(this, tr("Error"), tr("This view already exists")); + return; + } + } + QSettings settings_file(file_name, QSettings::Format::IniFormat); + if (settings_file.value("fileType").toString() != FLATLINE_VIEW_SETTINGS_FILE_TYPE) { + QMessageBox::warning(this, tr("Error"), tr("This file is not flatline view setting file")); + return; + } + tl::Graph::VisualSettings settings = tl::Graph::VisualSettings::fromJson(settings_file.value("settings").toString()); + QSet graph_channels = m_graph->channelPaths(); + for (int i = 0; i < settings.channels.count(); ++i) { + if (!graph_channels.contains(settings.channels[i].shvPath)) { + settings.channels.removeAt(i--); + } + } + int index = ui->cbViews->count(); + ui->cbViews->addItem(view_name + "*", QVariant::fromValue(View{ view_name, true, settings })); + ui->cbViews->setCurrentIndex(index); + onViewSelected(index); + RECENT_SETTINGS_DIR = QFileInfo(file_name).path(); + } + } + */ +} + +void ChannelFilterDialog::saveView() +{ + m_graph->saveVisualSettings(m_sitePath, ui->cbLayouts->currentText()); +} + +void ChannelFilterDialog::saveViewAs() +{ +/* QString view_name = QInputDialog::getText(this, tr("Save as"), tr("Input view name")); + if (!view_name.isEmpty()) { + for (int i = 0; i < ui->cbViews->count(); ++i) { + if (ui->cbViews->itemData(i).value().name == view_name) { + QMessageBox::warning(this, tr("Error"), tr("This view already exists")); + return; + } + } + int index = ui->cbViews->currentIndex(); + View current_view = ui->cbViews->itemData(index).value(); + current_view.edited = false; + current_view.settings = tl::Graph::VisualSettings(); + ui->cbViews->setItemText(index, current_view.name); + ui->cbViews->setItemData(index, QVariant::fromValue(current_view)); + + m_graph->saveVisualSettings(QString::fromStdString(m_site->shvPath()), view_name); + index = ui->cbViews->count(); + ui->cbViews->addItem(view_name, QVariant::fromValue(View{ view_name, false, tl::Graph::VisualSettings() })); + ui->cbViews->setCurrentIndex(index); + onViewSelected(index); + } + */ +} + +void ChannelFilterDialog::revertView() +{ +/* int index = ui->cbViews->currentIndex(); + View current_view = ui->cbViews->itemData(index).value(); + + if (index == VIEW_COMBO_NO_VIEW_INDEX) { + m_graph->reset(); + } + else { + m_graph->loadVisualSettings(QString::fromStdString(m_site->shvPath()), current_view.name); + } + + current_view.edited = false; + current_view.settings = tl::Graph::VisualSettings(); + ui->cbViews->setItemText(index, current_view.name); + ui->cbViews->setItemData(index, QVariant::fromValue(current_view)); + m_revertViewAction->setEnabled(false); + */ +} + +void ChannelFilterDialog::resetView() +{ +/* int index = ui->cbViews->currentIndex(); + View current_view = ui->cbViews->itemData(index).value(); + current_view.edited = (index != VIEW_COMBO_NO_VIEW_INDEX); + m_graph->reset(); + current_view.settings = tl::Graph::VisualSettings(); + ui->cbViews->setItemText(index, current_view.name + (current_view.edited ? "*" : QString())); + ui->cbViews->setItemData(index, QVariant::fromValue(current_view)); + m_revertViewAction->setEnabled(current_view.edited); + */ +} + void ChannelFilterDialog::onCustomContextMenuRequested(QPoint pos) { QModelIndex ix = ui->tvChannelsFilter->indexAt(pos); diff --git a/libshvvisu/src/timeline/channelfilterdialog.h b/libshvvisu/src/timeline/channelfilterdialog.h index 3dfcc9131..958b5a01f 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.h +++ b/libshvvisu/src/timeline/channelfilterdialog.h @@ -1,6 +1,8 @@ #pragma once #include "../shvvisuglobal.h" +#include + #include @@ -23,14 +25,22 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog explicit ChannelFilterDialog(QWidget *parent = nullptr); ~ChannelFilterDialog(); - void init(const QString &site_path, const QSet &logged_paths); + void init(const QString &site_path, Graph *graph); QSet selectedChannels(); - void setSelectedChannels(const QSet &channels); + void setFilter(const QString &filter_name, const QSet &channels); private: void applyTextFilter(); + void saveView(); + void saveViewAs(); + void revertView(); + void resetView(); + void deleteView(); + void exportView(); + void importView(); + void setVisibleItemsCheckState(Qt::CheckState state); void setVisibleItemsCheckState_helper(const QModelIndex &mi, Qt::CheckState state); @@ -43,9 +53,18 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog void onChbFindRegexChanged(int state); Ui::ChannelFilterDialog *ui; + shv::visu::timeline::Graph *m_graph = nullptr; ChannelFilterModel *m_channelsFilterModel = nullptr; ChannelFilterSortFilterProxyModel *m_channelsFilterProxyModel = nullptr; QString m_sitePath; + + QAction *m_saveViewAction = nullptr; + QAction *m_saveViewAsAction = nullptr; + QAction *m_revertViewAction = nullptr; + QAction *m_resetViewAction = nullptr; + QAction *m_deleteViewAction = nullptr; + QAction *m_exportViewAction = nullptr; + QAction *m_importViewAction = nullptr; }; } diff --git a/libshvvisu/src/timeline/channelfilterdialog.ui b/libshvvisu/src/timeline/channelfilterdialog.ui index 605a948d2..dac0edb29 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.ui +++ b/libshvvisu/src/timeline/channelfilterdialog.ui @@ -15,42 +15,53 @@ - - - - - - - - - - - :/shv/visu/images/check-box-outline.svg:/shv/visu/images/check-box-outline.svg - - - - - - - - - - - :/shv/visu/images/checkbox-blank-outline.svg:/shv/visu/images/checkbox-blank-outline.svg - - - - + + + + + + true + + + + Layout name: + + + + + + + + 1 + 0 + + + + + + + + + + + + :/shv/visu/images/hamburger-menu.svg:/shv/visu/images/hamburger-menu.svg + + - + + + + + Matching text - - + + 0 @@ -77,6 +88,28 @@ + + + + + + + + :/shv/visu/images/check-box-outline.svg:/shv/visu/images/check-box-outline.svg + + + + + + + + + + + :/shv/visu/images/checkbox-blank-outline.svg:/shv/visu/images/checkbox-blank-outline.svg + + + diff --git a/libshvvisu/src/widgets/dataviewwidget.cpp b/libshvvisu/src/widgets/dataviewwidget.cpp new file mode 100644 index 000000000..0dfcdb308 --- /dev/null +++ b/libshvvisu/src/widgets/dataviewwidget.cpp @@ -0,0 +1,14 @@ +#include "dataviewwidget.h" +#include "ui_dataviewwidget.h" + +DataViewWidget::DataViewWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::DataViewWidget) +{ + ui->setupUi(this); +} + +DataViewWidget::~DataViewWidget() +{ + delete ui; +} diff --git a/libshvvisu/src/widgets/dataviewwidget.h b/libshvvisu/src/widgets/dataviewwidget.h new file mode 100644 index 000000000..5232330df --- /dev/null +++ b/libshvvisu/src/widgets/dataviewwidget.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace Ui { +class DataViewWidget; +} + +class DataViewWidget : public QWidget +{ + Q_OBJECT + +public: + explicit DataViewWidget(QWidget *parent = nullptr); + ~DataViewWidget(); + +private: + Ui::DataViewWidget *ui; +}; diff --git a/libshvvisu/src/widgets/dataviewwidget.ui b/libshvvisu/src/widgets/dataviewwidget.ui new file mode 100644 index 000000000..3307580e3 --- /dev/null +++ b/libshvvisu/src/widgets/dataviewwidget.ui @@ -0,0 +1,66 @@ + + + DataViewWidget + + + + 0 + 0 + 195 + 25 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Data view: + + + + + + + false + + + QComboBox::AdjustToContents + + + + + + + Channels filter + + + ... + + + + :/shv/visu/images/settings.svg:/shv/visu/images/settings.svg + + + + + + + + + + From 497cadc530a5a11a3016df4eee75e02ca6f63c14 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 24 Oct 2023 14:47:09 +0200 Subject: [PATCH 06/17] added dataviewwidget --- libshvvisu/CMakeLists.txt | 2 +- .../include/shv/visu/logview/dataviewwidget.h | 1 + libshvvisu/src/logview/dataviewwidget.cpp | 79 ++++++++ libshvvisu/src/logview/dataviewwidget.h | 39 ++++ libshvvisu/src/logview/dataviewwidget.ui | 66 +++++++ libshvvisu/src/logview/dlgloginspector.cpp | 86 +-------- libshvvisu/src/logview/dlgloginspector.h | 9 - libshvvisu/src/logview/dlgloginspector.ui | 62 ++---- libshvvisu/src/timeline/channelfilter.cpp | 5 +- .../src/timeline/channelfilterdialog.cpp | 177 +++++++++--------- libshvvisu/src/timeline/channelfilterdialog.h | 21 ++- .../src/timeline/channelfilterdialog.ui | 68 ++++--- libshvvisu/src/timeline/graph.cpp | 8 +- libshvvisu/src/timeline/graph.h | 6 - 14 files changed, 352 insertions(+), 277 deletions(-) create mode 100644 libshvvisu/include/shv/visu/logview/dataviewwidget.h create mode 100644 libshvvisu/src/logview/dataviewwidget.cpp create mode 100644 libshvvisu/src/logview/dataviewwidget.h create mode 100644 libshvvisu/src/logview/dataviewwidget.ui diff --git a/libshvvisu/CMakeLists.txt b/libshvvisu/CMakeLists.txt index 13311bd43..04cc9350c 100644 --- a/libshvvisu/CMakeLists.txt +++ b/libshvvisu/CMakeLists.txt @@ -1,5 +1,6 @@ add_library(libshvvisu images/images.qrc + src/logview/dataviewwidget.cpp src/logview/dlgloginspector.cpp src/logview/logmodel.cpp src/logview/logsortfilterproxymodel.cpp @@ -27,7 +28,6 @@ add_library(libshvvisu src/timeline/graphwidget.cpp src/timeline/sample.cpp src/widgets/timezonecombobox.cpp - src/widgets/dataviewwidget.cpp ) target_link_libraries(libshvvisu PUBLIC Qt::Widgets libshviotqt) diff --git a/libshvvisu/include/shv/visu/logview/dataviewwidget.h b/libshvvisu/include/shv/visu/logview/dataviewwidget.h new file mode 100644 index 000000000..33abf6cbc --- /dev/null +++ b/libshvvisu/include/shv/visu/logview/dataviewwidget.h @@ -0,0 +1 @@ +#include "../../../../src/logview/dataviewwidget.h" diff --git a/libshvvisu/src/logview/dataviewwidget.cpp b/libshvvisu/src/logview/dataviewwidget.cpp new file mode 100644 index 000000000..78a3da57c --- /dev/null +++ b/libshvvisu/src/logview/dataviewwidget.cpp @@ -0,0 +1,79 @@ +#include "dataviewwidget.h" +#include "ui_dataviewwidget.h" + +#include "shv/visu/timeline/graph.h" +#include "shv/visu/timeline/channelfilterdialog.h" + +#include "shv/core/log.h" + +namespace tl = shv::visu::timeline; + +namespace shv::visu::logview { + +static const int INVALID_FILTER_INDEX = 0; + +DataViewWidget::DataViewWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::DataViewWidget) +{ + ui->setupUi(this); + + connect(ui->pbShowChannelFilterDialog, &QToolButton::clicked, this, &DataViewWidget::onShowChannelFilterClicked); + connect(ui->cbDataViews, &QComboBox::currentIndexChanged, this, &DataViewWidget::onDataViewChanged); +} + +DataViewWidget::~DataViewWidget() +{ + delete ui; +} + +void DataViewWidget::init(const QString &site_path, timeline::Graph *graph) +{ + m_graph = graph; + m_sitePath = site_path; + + disableOnDataViewChangedAction(); + reloadDataViewsCombobox(); + enableOnDataViewChangedAction(); +} + +void DataViewWidget::reloadDataViewsCombobox() +{ + ui->cbDataViews->clear(); + ui->cbDataViews->addItem(tr("All channels")); + + for (const QString &view_name : m_graph->savedVisualSettingsNames(m_sitePath)) { + ui->cbDataViews->addItem(view_name); + } +} + +void DataViewWidget::onShowChannelFilterClicked() +{ + tl::ChannelFilterDialog *channel_filter_dialog = new tl::ChannelFilterDialog(this); + channel_filter_dialog->init(m_sitePath, m_graph, ui->cbDataViews->currentText()); + + if (channel_filter_dialog->exec() == QDialog::Accepted) { + shv::visu::timeline::ChannelFilter filter(channel_filter_dialog->selectedChannels()); + m_graph->setChannelFilter(filter); + } + + channel_filter_dialog->deleteLater(); + + disableOnDataViewChangedAction(); + reloadDataViewsCombobox(); + ui->cbDataViews->setCurrentText(channel_filter_dialog->selectedFilterName()); + enableOnDataViewChangedAction(); +} + +void DataViewWidget::onDataViewChanged(int index) +{ + if (m_onDataViewChangedActionEnabled) { + if (index > INVALID_FILTER_INDEX) + m_graph->loadVisualSettings(m_sitePath, ui->cbDataViews->currentText()); + else { + m_graph->setChannelFilter(timeline::ChannelFilter()); + } + } +} + +} diff --git a/libshvvisu/src/logview/dataviewwidget.h b/libshvvisu/src/logview/dataviewwidget.h new file mode 100644 index 000000000..cf363849b --- /dev/null +++ b/libshvvisu/src/logview/dataviewwidget.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include + +namespace shv { +namespace visu { +namespace logview { + +namespace Ui { +class DataViewWidget; +} + +class DataViewWidget : public QWidget +{ + Q_OBJECT + +public: + explicit DataViewWidget(QWidget *parent = nullptr); + ~DataViewWidget(); + + void init(const QString &site_path, timeline::Graph *graph); + +private: + void enableOnDataViewChangedAction() {m_onDataViewChangedActionEnabled = true;} + void disableOnDataViewChangedAction() {m_onDataViewChangedActionEnabled = false;} + void reloadDataViewsCombobox(); + + void onDataViewChanged(int index); + void onShowChannelFilterClicked(); + + timeline::Graph *m_graph = nullptr; + QString m_sitePath; + bool m_onDataViewChangedActionEnabled = true; + + Ui::DataViewWidget *ui; +}; + +}}} diff --git a/libshvvisu/src/logview/dataviewwidget.ui b/libshvvisu/src/logview/dataviewwidget.ui new file mode 100644 index 000000000..304d250e3 --- /dev/null +++ b/libshvvisu/src/logview/dataviewwidget.ui @@ -0,0 +1,66 @@ + + + shv::visu::logview::DataViewWidget + + + + 0 + 0 + 195 + 25 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Data view: + + + + + + + false + + + QComboBox::AdjustToContents + + + + + + + Channels filter + + + ... + + + + :/shv/visu/images/settings.svg:/shv/visu/images/settings.svg + + + + + + + + + + diff --git a/libshvvisu/src/logview/dlgloginspector.cpp b/libshvvisu/src/logview/dlgloginspector.cpp index 78f95c8aa..b23435da8 100644 --- a/libshvvisu/src/logview/dlgloginspector.cpp +++ b/libshvvisu/src/logview/dlgloginspector.cpp @@ -222,7 +222,7 @@ DlgLogInspector::DlgLogInspector(const QString &shv_path, QWidget *parent) : m_graph->setModel(m_graphModel); m_graphWidget->setGraph(m_graph); - m_channelFilterDialog = new shv::visu::timeline::ChannelFilterDialog(this); + ui->wDataView->init(ui->edShvPath->text(), m_graph); #if SHVVISU_HAS_TIMEZONE connect(ui->cbxTimeZone, &QComboBox::currentTextChanged, this, [this](const QString &) { @@ -237,22 +237,12 @@ DlgLogInspector::DlgLogInspector(const QString &shv_path, QWidget *parent) : connect(ui->btLoad, &QPushButton::clicked, this, &DlgLogInspector::downloadLog); connect(m_graph, &shv::visu::timeline::Graph::channelFilterChanged, this, &DlgLogInspector::onGraphChannelFilterChanged); - connect(ui->pbChannelsFilter, &QPushButton::clicked, this, &DlgLogInspector::onChannelsFilterClicked); connect(ui->btResizeColumnsToFitWidth, &QAbstractButton::clicked, this, [this]() { ui->tblData->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); }); loadSettings(); - - initVisualSettingSelector(shv_path); - ui->cbViews->setCurrentIndex(VIEW_SELECTOR_NO_VIEW_INDEX); - - connect(ui->cbViews, QOverload::of(&QComboBox::activated), this, &DlgLogInspector::onViewSelected); - - connect(ui->pbDeleteView, &QPushButton::clicked, this, &DlgLogInspector::onDeleteViewClicked); - connect(ui->pbSaveView, &QPushButton::clicked, this, &DlgLogInspector::onSaveViewClicked); - onViewSelected(VIEW_SELECTOR_NO_VIEW_INDEX); } DlgLogInspector::~DlgLogInspector() @@ -268,60 +258,6 @@ void DlgLogInspector::loadSettings() restoreGeometry(ba); } -void DlgLogInspector::initVisualSettingSelector(const QString &shv_path) -{ - ui->cbViews->clear(); - - ui->cbViews->addItem(tr("Without filter")); - for (const QString &view_name : m_graph->savedVisualSettingsNames(shv_path)) { - ui->cbViews->addItem(view_name); - } -} - -void DlgLogInspector::onSaveViewClicked() -{ - QString current_name = ui->cbViews->currentText(); - if (current_name.isEmpty() || current_name == ui->cbViews->itemText(0)) { - return; - } - if (ui->cbViews->findText(current_name) == -1) { - int index = ui->cbViews->count(); - ui->cbViews->addItem(current_name); - ui->cbViews->setCurrentIndex(index); - } - m_graph->saveVisualSettings(shvPath(), current_name); -} - -void DlgLogInspector::onDeleteViewClicked() -{ - int index = ui->cbViews->currentIndex(); - const QString ¤t_name = ui->cbViews->currentText(); - if (ui->cbViews->findText(current_name) == -1) { - ui->cbViews->setEditText(ui->cbViews->itemText(index)); - return; - } - - m_graph->deleteVisualSettings(shvPath(), current_name); - ui->cbViews->removeItem(index); - ui->cbViews->setCurrentIndex(VIEW_SELECTOR_NO_VIEW_INDEX); - onViewSelected(VIEW_SELECTOR_NO_VIEW_INDEX); -} - -void DlgLogInspector::onViewSelected(int index) -{ - if (index == VIEW_SELECTOR_NO_VIEW_INDEX) { - m_graph->reset(); - } - else { - setView(ui->cbViews->currentText()); - } -} - -void DlgLogInspector::setView(const QString &name) -{ - m_graph->loadVisualSettings(shvPath(), name); -} - void DlgLogInspector::saveSettings() { QSettings settings; @@ -485,11 +421,7 @@ void DlgLogInspector::parseLog(shv::chainpack::RpcValue log) } m_graph->createChannelsFromModel(); - - //QSet channel_paths = m_graph->channelPaths(); - m_channelFilterDialog->init(shvPath(), m_graph); ui->graphView->makeLayout(); - //applyFilters(channel_paths); } void DlgLogInspector::showInfo(const QString &msg, bool is_error) @@ -547,22 +479,6 @@ void DlgLogInspector::setTimeZone(const QTimeZone &tz) } #endif -void DlgLogInspector::applyFilters(const QSet &channel_paths) -{ - timeline::ChannelFilter graph_filter = m_graph->channelFilter(); - graph_filter.setPermittedPaths(channel_paths); - m_graph->setChannelFilter(graph_filter); -} - -void DlgLogInspector::onChannelsFilterClicked() -{ - m_channelFilterDialog->setFilter(ui->cbViews->currentText(), m_graph->channelFilter().permittedPaths()); - - if(m_channelFilterDialog->exec() == QDialog::Accepted) { - applyFilters(m_channelFilterDialog->selectedChannels()); - } -} - void DlgLogInspector::onGraphChannelFilterChanged() { m_logSortFilterProxy->setChannelFilter(m_graph->channelFilter()); diff --git a/libshvvisu/src/logview/dlgloginspector.h b/libshvvisu/src/logview/dlgloginspector.h index a8001e426..8265bd9c2 100644 --- a/libshvvisu/src/logview/dlgloginspector.h +++ b/libshvvisu/src/logview/dlgloginspector.h @@ -54,16 +54,8 @@ class SHVVISU_DECL_EXPORT DlgLogInspector : public QDialog void setTimeZone(const QTimeZone &tz); #endif - void applyFilters(const QSet &channel_paths); - void onChannelsFilterClicked(); void onGraphChannelFilterChanged(); - void initVisualSettingSelector(const QString &shv_path); - void onSaveViewClicked(); - void onDeleteViewClicked(); - void onViewSelected(int index); - void setView(const QString &name); - private: Ui::DlgLogInspector *ui; @@ -79,7 +71,6 @@ class SHVVISU_DECL_EXPORT DlgLogInspector : public QDialog shv::visu::timeline::GraphModel *m_graphModel = nullptr; shv::visu::timeline::Graph *m_graph = nullptr; shv::visu::timeline::GraphWidget *m_graphWidget = nullptr; - shv::visu::timeline::ChannelFilterDialog *m_channelFilterDialog = nullptr; }; }}} diff --git a/libshvvisu/src/logview/dlgloginspector.ui b/libshvvisu/src/logview/dlgloginspector.ui index 0f58dbfcb..72c77884b 100644 --- a/libshvvisu/src/logview/dlgloginspector.ui +++ b/libshvvisu/src/logview/dlgloginspector.ui @@ -65,7 +65,7 @@ 1999 12 - 20 + 18 @@ -116,7 +116,7 @@ 1999 12 - 19 + 17 @@ -427,47 +427,7 @@ - - - Saved views: - - - - - - - true - - - - - - - - - - - :/shv/visu/images/file-save.svg:/shv/visu/images/file-save.svg - - - - - - - - - - - :/shv/visu/images/delete.svg:/shv/visu/images/delete.svg - - - - - - - Channels filter - - + @@ -505,7 +465,7 @@ 0 0 1152 - 368 + 354 @@ -598,16 +558,22 @@ + + shv::visu::TimeZoneComboBox + QComboBox +
shv/visu/timezonecombobox.h
+
shv::visu::timeline::GraphView QScrollArea -
src/timeline/graphview.h
+
shv/visu/timeline/graphview.h
1
- shv::visu::TimeZoneComboBox - QComboBox -
src/widgets/timezonecombobox.h
+ shv::visu::logview::DataViewWidget + QWidget +
shv/visu/logview/dataviewwidget.h
+ 1
diff --git a/libshvvisu/src/timeline/channelfilter.cpp b/libshvvisu/src/timeline/channelfilter.cpp index cc3593390..1425127c5 100644 --- a/libshvvisu/src/timeline/channelfilter.cpp +++ b/libshvvisu/src/timeline/channelfilter.cpp @@ -4,10 +4,7 @@ namespace shv::visu::timeline { -ChannelFilter::ChannelFilter() -{ - -} +ChannelFilter::ChannelFilter() = default; ChannelFilter::ChannelFilter(const QSet &permitted_paths) { diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index dc02d51cc..b6d6a0fe5 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -6,11 +6,20 @@ #include +#include +#include #include #include +#include +#include namespace shv::visu::timeline { +static const int INVALID_FILTER_INDEX = 0; +static QString RECENT_SETTINGS_DIR; +static const QString FLATLINE_VIEW_SETTINGS_FILE_TYPE = QStringLiteral("FlatlineViewSettings"); +static const QString FLATLINE_VIEW_SETTINGS_FILE_EXTENSION = QStringLiteral(".fvs"); + ChannelFilterDialog::ChannelFilterDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ChannelFilterDialog) @@ -29,10 +38,9 @@ ChannelFilterDialog::ChannelFilterDialog(QWidget *parent) : ui->tvChannelsFilter->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); QMenu *view_menu = new QMenu(this); - m_resetViewAction = view_menu->addAction(tr("Clear"), this, &ChannelFilterDialog::resetView); + m_resetViewAction = view_menu->addAction(tr("Discard changes"), this, &ChannelFilterDialog::discardUserChanges); m_saveViewAction = view_menu->addAction(tr("Save"), this, &ChannelFilterDialog::saveView); m_saveViewAsAction = view_menu->addAction(tr("Save as"), this, &ChannelFilterDialog::saveViewAs); - m_revertViewAction = view_menu->addAction(tr("Revert changes"), this, &ChannelFilterDialog::revertView); m_deleteViewAction = view_menu->addAction(tr("Delete"), this, &ChannelFilterDialog::deleteView); m_exportViewAction = view_menu->addAction(tr("Export"), this, &ChannelFilterDialog::exportView); m_importViewAction = view_menu->addAction(tr("Import"), this, &ChannelFilterDialog::importView); @@ -43,6 +51,7 @@ ChannelFilterDialog::ChannelFilterDialog(QWidget *parent) : connect(ui->pbClearMatchingText, &QPushButton::clicked, this, &ChannelFilterDialog::onPbClearMatchingTextClicked); connect(ui->pbCheckItems, &QPushButton::clicked, this, &ChannelFilterDialog::onPbCheckItemsClicked); connect(ui->pbUncheckItems, &QPushButton::clicked, this, &ChannelFilterDialog::onPbUncheckItemsClicked); + connect(ui->cbDataView, &QComboBox::currentIndexChanged, this, &ChannelFilterDialog::onDataViewCurrentIndexChanged); } ChannelFilterDialog::~ChannelFilterDialog() @@ -50,15 +59,16 @@ ChannelFilterDialog::~ChannelFilterDialog() delete ui; } -void ChannelFilterDialog::init(const QString &site_path, Graph *graph) +void ChannelFilterDialog::init(const QString &site_path, Graph *graph, const QString &filter_name) { + disableOnDataViewChangedAction(); m_sitePath = site_path; m_graph = graph; m_channelsFilterModel->createNodes(graph->channelPaths()); - for (const QString &view_name : m_graph->savedVisualSettingsNames(m_sitePath)) { - ui->cbLayouts->addItem(view_name); //, QVariant::fromValue(View{ view_name, false, tl::Graph::VisualSettings() })); - } + applyPermittedChannelsFromGraph(); + reloadDataViewsComboboxAndSetlect(filter_name); + enableOnDataViewChangedAction(); } QSet ChannelFilterDialog::selectedChannels() @@ -66,149 +76,113 @@ QSet ChannelFilterDialog::selectedChannels() return m_channelsFilterModel->selectedChannels(); } -void ChannelFilterDialog::setFilter(const QString &filter_name, const QSet &channels) +QString ChannelFilterDialog::selectedFilterName() { - ui->cbLayouts->setCurrentText(filter_name); - m_channelsFilterModel->setSelectedChannels(channels); + return ui->cbDataView->currentText(); } void ChannelFilterDialog::applyTextFilter() { m_channelsFilterProxyModel->setFilterString(ui->leMatchingFilterText->text()); - if (m_channelsFilterProxyModel->rowCount() == 1){ + if (m_channelsFilterProxyModel->rowCount() == 1) { ui->tvChannelsFilter->setCurrentIndex(m_channelsFilterProxyModel->index(0, 0)); ui->tvChannelsFilter->expandRecursively(ui->tvChannelsFilter->currentIndex()); } } +void ChannelFilterDialog::reloadDataViewsComboboxAndSetlect(const QString &text) +{ + ui->cbDataView->clear(); + ui->cbDataView->addItem(tr("All channels")); + ui->cbDataView->addItems(m_graph->savedVisualSettingsNames(m_sitePath)); + + if (!text.isEmpty()) { + ui->cbDataView->setCurrentText(text); + } + else { + ui->cbDataView->setCurrentIndex(INVALID_FILTER_INDEX); + } +} + void ChannelFilterDialog::deleteView() { -/* View current_view = ui->cbViews->currentData().value(); - m_graph->deleteVisualSettings(QString::fromStdString(m_site->shvPath()), current_view.name); - ui->cbViews->removeItem(index); - ui->cbViews->setCurrentIndex(VIEW_COMBO_NO_VIEW_INDEX); - onViewSelected(VIEW_COMBO_NO_VIEW_INDEX); - */ + m_graph->deleteVisualSettings(m_sitePath, ui->cbDataView->currentText()); + disableOnDataViewChangedAction(); + reloadDataViewsComboboxAndSetlect(); + enableOnDataViewChangedAction(); } void ChannelFilterDialog::exportView() { -/* int index = ui->cbViews->currentIndex(); - if (index == VIEW_COMBO_NO_VIEW_INDEX) { - return; - } QString file_name = QFileDialog::getSaveFileName(this, tr("Input file name"), RECENT_SETTINGS_DIR, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); if (!file_name.isEmpty()) { if (!file_name.endsWith(FLATLINE_VIEW_SETTINGS_FILE_EXTENSION)) { file_name.append(FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); } - View current_view = ui->cbViews->currentData().value(); - m_graph->saveVisualSettings(QString::fromStdString(m_site->shvPath()), current_view.name); + QSettings settings(file_name, QSettings::Format::IniFormat); settings.setValue("fileType", FLATLINE_VIEW_SETTINGS_FILE_TYPE); settings.setValue("settings", m_graph->visualSettings().toJson()); RECENT_SETTINGS_DIR = QFileInfo(file_name).path(); } - */ } void ChannelFilterDialog::importView() { -/* QString file_name = QFileDialog::getOpenFileName(this, tr("Input file name"), RECENT_SETTINGS_DIR, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); + QString file_name = QFileDialog::getOpenFileName(this, tr("Input file name"), RECENT_SETTINGS_DIR, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); if (!file_name.isEmpty()) { QString view_name = QInputDialog::getText(this, tr("Import as"), tr("Input view name")); + if (!view_name.isEmpty()) { - for (int i = 0; i < ui->cbViews->count(); ++i) { - if (ui->cbViews->itemData(i).value().name == view_name) { - QMessageBox::warning(this, tr("Error"), tr("This view already exists")); - return; - } - } QSettings settings_file(file_name, QSettings::Format::IniFormat); if (settings_file.value("fileType").toString() != FLATLINE_VIEW_SETTINGS_FILE_TYPE) { QMessageBox::warning(this, tr("Error"), tr("This file is not flatline view setting file")); return; } - tl::Graph::VisualSettings settings = tl::Graph::VisualSettings::fromJson(settings_file.value("settings").toString()); + + Graph::VisualSettings visual_settings = Graph::VisualSettings::fromJson(settings_file.value("settings").toString()); QSet graph_channels = m_graph->channelPaths(); - for (int i = 0; i < settings.channels.count(); ++i) { - if (!graph_channels.contains(settings.channels[i].shvPath)) { - settings.channels.removeAt(i--); + + for (int i = 0; i < visual_settings.channels.count(); ++i) { + if (!graph_channels.contains(visual_settings.channels[i].shvPath)) { + visual_settings.channels.removeAt(i--); } } - int index = ui->cbViews->count(); - ui->cbViews->addItem(view_name + "*", QVariant::fromValue(View{ view_name, true, settings })); - ui->cbViews->setCurrentIndex(index); - onViewSelected(index); + + m_graph->saveVisualSettings(m_sitePath, view_name); + reloadDataViewsComboboxAndSetlect(view_name); + RECENT_SETTINGS_DIR = QFileInfo(file_name).path(); } } - */ } -void ChannelFilterDialog::saveView() +void ChannelFilterDialog::updateContextMenuActionsAvailability() { - m_graph->saveVisualSettings(m_sitePath, ui->cbLayouts->currentText()); + m_saveViewAction->setEnabled(ui->cbDataView->currentIndex() != INVALID_FILTER_INDEX); + m_deleteViewAction->setEnabled(ui->cbDataView->currentIndex() != INVALID_FILTER_INDEX); } -void ChannelFilterDialog::saveViewAs() +void ChannelFilterDialog::saveView() { -/* QString view_name = QInputDialog::getText(this, tr("Save as"), tr("Input view name")); - if (!view_name.isEmpty()) { - for (int i = 0; i < ui->cbViews->count(); ++i) { - if (ui->cbViews->itemData(i).value().name == view_name) { - QMessageBox::warning(this, tr("Error"), tr("This view already exists")); - return; - } - } - int index = ui->cbViews->currentIndex(); - View current_view = ui->cbViews->itemData(index).value(); - current_view.edited = false; - current_view.settings = tl::Graph::VisualSettings(); - ui->cbViews->setItemText(index, current_view.name); - ui->cbViews->setItemData(index, QVariant::fromValue(current_view)); - - m_graph->saveVisualSettings(QString::fromStdString(m_site->shvPath()), view_name); - index = ui->cbViews->count(); - ui->cbViews->addItem(view_name, QVariant::fromValue(View{ view_name, false, tl::Graph::VisualSettings() })); - ui->cbViews->setCurrentIndex(index); - onViewSelected(index); - } - */ + m_graph->setChannelFilter(selectedChannels()); + m_graph->saveVisualSettings(m_sitePath, ui->cbDataView->currentText()); } -void ChannelFilterDialog::revertView() +void ChannelFilterDialog::saveViewAs() { -/* int index = ui->cbViews->currentIndex(); - View current_view = ui->cbViews->itemData(index).value(); - - if (index == VIEW_COMBO_NO_VIEW_INDEX) { - m_graph->reset(); - } - else { - m_graph->loadVisualSettings(QString::fromStdString(m_site->shvPath()), current_view.name); + QString view_name = QInputDialog::getText(this, tr("Save as"), tr("Input view name")); + if (!view_name.isEmpty()) { + m_graph->setChannelFilter(selectedChannels()); + m_graph->saveVisualSettings(m_sitePath, view_name); + reloadDataViewsComboboxAndSetlect(view_name); } - - current_view.edited = false; - current_view.settings = tl::Graph::VisualSettings(); - ui->cbViews->setItemText(index, current_view.name); - ui->cbViews->setItemData(index, QVariant::fromValue(current_view)); - m_revertViewAction->setEnabled(false); - */ } -void ChannelFilterDialog::resetView() +void ChannelFilterDialog::discardUserChanges() { -/* int index = ui->cbViews->currentIndex(); - View current_view = ui->cbViews->itemData(index).value(); - current_view.edited = (index != VIEW_COMBO_NO_VIEW_INDEX); - m_graph->reset(); - current_view.settings = tl::Graph::VisualSettings(); - ui->cbViews->setItemText(index, current_view.name + (current_view.edited ? "*" : QString())); - ui->cbViews->setItemData(index, QVariant::fromValue(current_view)); - m_revertViewAction->setEnabled(current_view.edited); - */ + onDataViewCurrentIndexChanged(ui->cbDataView->currentIndex()); } void ChannelFilterDialog::onCustomContextMenuRequested(QPoint pos) @@ -262,6 +236,12 @@ void ChannelFilterDialog::onChbFindRegexChanged(int state) applyTextFilter(); } +void ChannelFilterDialog::applyPermittedChannelsFromGraph() +{ + shvInfo() << "setPermitted channels" << m_graph->channelFilter().isValid(); + m_channelsFilterModel->setSelectedChannels((m_graph->channelFilter().isValid()) ? m_graph->channelFilter().permittedPaths() : m_graph->channelPaths()); +} + void ChannelFilterDialog::setVisibleItemsCheckState(Qt::CheckState state) { for (int row = 0; row < m_channelsFilterProxyModel->rowCount(); row++) { @@ -284,4 +264,21 @@ void ChannelFilterDialog::setVisibleItemsCheckState_helper(const QModelIndex &mi } } +void ChannelFilterDialog::onDataViewCurrentIndexChanged(int index) +{ + if (m_onDataViewChangedActionEnabled && (index >= 0)) { + if (index == INVALID_FILTER_INDEX) { + m_graph->reset(); + shvInfo() << "chf valid" << m_graph->channelFilter().isValid(); + } + else{ + m_graph->loadVisualSettings(m_sitePath, ui->cbDataView->currentText()); + } + + shvInfo() << " load" << ui->cbDataView->currentText().toStdString() << index; + applyPermittedChannelsFromGraph(); + updateContextMenuActionsAvailability(); + } +} + } diff --git a/libshvvisu/src/timeline/channelfilterdialog.h b/libshvvisu/src/timeline/channelfilterdialog.h index 958b5a01f..48fbdad32 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.h +++ b/libshvvisu/src/timeline/channelfilterdialog.h @@ -25,25 +25,35 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog explicit ChannelFilterDialog(QWidget *parent = nullptr); ~ChannelFilterDialog(); - void init(const QString &site_path, Graph *graph); + void init(const QString &site_path, Graph *graph, const QString &filter_name); QSet selectedChannels(); - void setFilter(const QString &filter_name, const QSet &channels); + QString selectedFilterName(); + + Q_SIGNAL void selectedFilterNameChanged(const QString &filter_name); private: + void enableOnDataViewChangedAction() {m_onDataViewChangedActionEnabled = true;} + void disableOnDataViewChangedAction() {m_onDataViewChangedActionEnabled = false;} + void applyTextFilter(); + void reloadDataViewsComboboxAndSetlect(const QString &text = {}); + void saveView(); void saveViewAs(); - void revertView(); - void resetView(); + void discardUserChanges(); void deleteView(); void exportView(); void importView(); + void updateContextMenuActionsAvailability(); + void setVisibleItemsCheckState(Qt::CheckState state); void setVisibleItemsCheckState_helper(const QModelIndex &mi, Qt::CheckState state); + void applyPermittedChannelsFromGraph(); + void onDataViewCurrentIndexChanged(int index); void onCustomContextMenuRequested(QPoint pos); void onPbCheckItemsClicked(); @@ -65,6 +75,9 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog QAction *m_deleteViewAction = nullptr; QAction *m_exportViewAction = nullptr; QAction *m_importViewAction = nullptr; + + bool m_onDataViewChangedActionEnabled = true; + }; } diff --git a/libshvvisu/src/timeline/channelfilterdialog.ui b/libshvvisu/src/timeline/channelfilterdialog.ui index dac0edb29..a8c9ed67d 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.ui +++ b/libshvvisu/src/timeline/channelfilterdialog.ui @@ -6,7 +6,7 @@ 0 0 - 407 + 391 802 @@ -24,12 +24,12 @@ - Layout name: + Data view - + 1 @@ -51,8 +51,46 @@ + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 10 + 10 + + + + + + + + + + + + :/shv/visu/images/check-box-outline.svg:/shv/visu/images/check-box-outline.svg + + + + + + + + + + + :/shv/visu/images/checkbox-blank-outline.svg:/shv/visu/images/checkbox-blank-outline.svg + + + @@ -88,28 +126,6 @@ - - - - - - - - :/shv/visu/images/check-box-outline.svg:/shv/visu/images/check-box-outline.svg - - - - - - - - - - - :/shv/visu/images/checkbox-blank-outline.svg:/shv/visu/images/checkbox-blank-outline.svg - - - @@ -121,7 +137,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Ok diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index f97502615..bb31d9c4c 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -106,8 +106,7 @@ QTimeZone Graph::timeZone() const void Graph::reset() { createChannelsFromModel(); - Q_EMIT layoutChanged(); - Q_EMIT channelFilterChanged(); + setChannelFilter(ChannelFilter()); } void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sorted) @@ -146,6 +145,8 @@ void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sor ch->setStyle(style); } resetChannelsRanges(); + + emit layoutChanged(); } void Graph::resetChannelsRanges() @@ -281,6 +282,7 @@ bool Graph::isChannelFlat(GraphChannel *ch) void Graph::setChannelFilter(const ChannelFilter &filter) { m_channelFilter = filter; + emit layoutChanged(); emit channelFilterChanged(); } @@ -1170,7 +1172,6 @@ void Graph::setVisualSettings(const VisualSettings &settings) { if (settings.isValid()) { QSet f; - createChannelsFromModel(); for (int i = 0; i < settings.channels.count(); ++i) { const VisualSettings::Channel &channel_settings = settings.channels[i]; for (int j = i; j < m_channels.count(); ++j) { @@ -2279,7 +2280,6 @@ void Graph::saveVisualSettings(const QString &settings_id, const QString &name) void Graph::loadVisualSettings(const QString &settings_id, const QString &name) { - VisualSettings graph_view; QSettings settings; settings.beginGroup(USER_PROFILES_KEY); settings.beginGroup(m_settingsUserName); diff --git a/libshvvisu/src/timeline/graph.h b/libshvvisu/src/timeline/graph.h index d54f960e8..78acc0977 100644 --- a/libshvvisu/src/timeline/graph.h +++ b/libshvvisu/src/timeline/graph.h @@ -97,12 +97,6 @@ class SHVVISU_DECL_EXPORT Graph : public QObject QVector channels; }; - struct View { - QString name; - bool edited = false; - VisualSettings settings; - }; - Graph(QObject *parent = nullptr); virtual ~Graph(); From 08e4ccbc3ebed6710f5defc12793b3fe195e3d06 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 25 Oct 2023 12:23:00 +0200 Subject: [PATCH 07/17] import export visual settings --- libshvvisu/src/logview/dataviewwidget.cpp | 36 ++++++----- libshvvisu/src/logview/dataviewwidget.h | 2 +- libshvvisu/src/logview/dataviewwidget.ui | 2 +- libshvvisu/src/timeline/channelfilter.cpp | 5 ++ libshvvisu/src/timeline/channelfilter.h | 2 + .../src/timeline/channelfilterdialog.cpp | 63 ++++++++++--------- libshvvisu/src/timeline/channelfilterdialog.h | 12 +--- libshvvisu/src/timeline/graph.cpp | 44 ++++++++----- libshvvisu/src/timeline/graph.h | 10 ++- 9 files changed, 101 insertions(+), 75 deletions(-) diff --git a/libshvvisu/src/logview/dataviewwidget.cpp b/libshvvisu/src/logview/dataviewwidget.cpp index 78a3da57c..919006dfe 100644 --- a/libshvvisu/src/logview/dataviewwidget.cpp +++ b/libshvvisu/src/logview/dataviewwidget.cpp @@ -19,7 +19,7 @@ DataViewWidget::DataViewWidget(QWidget *parent) : ui->setupUi(this); connect(ui->pbShowChannelFilterDialog, &QToolButton::clicked, this, &DataViewWidget::onShowChannelFilterClicked); - connect(ui->cbDataViews, &QComboBox::currentIndexChanged, this, &DataViewWidget::onDataViewChanged); + connect(ui->cbDataView, &QComboBox::currentIndexChanged, this, &DataViewWidget::onDataViewChanged); } DataViewWidget::~DataViewWidget() @@ -32,25 +32,27 @@ void DataViewWidget::init(const QString &site_path, timeline::Graph *graph) m_graph = graph; m_sitePath = site_path; - disableOnDataViewChangedAction(); - reloadDataViewsCombobox(); - enableOnDataViewChangedAction(); + reloadDataViewsComboboxAndSetlectItem(); } -void DataViewWidget::reloadDataViewsCombobox() +void DataViewWidget::reloadDataViewsComboboxAndSetlectItem(const QString &text) { - ui->cbDataViews->clear(); - ui->cbDataViews->addItem(tr("All channels")); + ui->cbDataView->clear(); + ui->cbDataView->addItem(tr("All channels")); + ui->cbDataView->addItems(m_graph->savedVisualSettingsNames(m_sitePath)); - for (const QString &view_name : m_graph->savedVisualSettingsNames(m_sitePath)) { - ui->cbDataViews->addItem(view_name); + if (!text.isEmpty()) { + ui->cbDataView->setCurrentText(text); + } + else { + ui->cbDataView->setCurrentIndex(INVALID_FILTER_INDEX); } } void DataViewWidget::onShowChannelFilterClicked() { tl::ChannelFilterDialog *channel_filter_dialog = new tl::ChannelFilterDialog(this); - channel_filter_dialog->init(m_sitePath, m_graph, ui->cbDataViews->currentText()); + channel_filter_dialog->init(m_sitePath, m_graph, ui->cbDataView->currentText()); if (channel_filter_dialog->exec() == QDialog::Accepted) { shv::visu::timeline::ChannelFilter filter(channel_filter_dialog->selectedChannels()); @@ -60,18 +62,18 @@ void DataViewWidget::onShowChannelFilterClicked() channel_filter_dialog->deleteLater(); disableOnDataViewChangedAction(); - reloadDataViewsCombobox(); - ui->cbDataViews->setCurrentText(channel_filter_dialog->selectedFilterName()); + reloadDataViewsComboboxAndSetlectItem(channel_filter_dialog->selectedFilterName()); enableOnDataViewChangedAction(); } void DataViewWidget::onDataViewChanged(int index) { - if (m_onDataViewChangedActionEnabled) { - if (index > INVALID_FILTER_INDEX) - m_graph->loadVisualSettings(m_sitePath, ui->cbDataViews->currentText()); - else { - m_graph->setChannelFilter(timeline::ChannelFilter()); + if (m_onDataViewChangedActionEnabled && (index >= 0)) { //ignore event for index = -1, currentIndexChanged(-1) is emmited from clear() method + if (index == INVALID_FILTER_INDEX) { + m_graph->resetVisualSettingsAndChannelFilter(); + } + else{ + m_graph->loadVisualSettings(m_sitePath, ui->cbDataView->currentText()); } } } diff --git a/libshvvisu/src/logview/dataviewwidget.h b/libshvvisu/src/logview/dataviewwidget.h index cf363849b..f09c4a266 100644 --- a/libshvvisu/src/logview/dataviewwidget.h +++ b/libshvvisu/src/logview/dataviewwidget.h @@ -24,7 +24,7 @@ class DataViewWidget : public QWidget private: void enableOnDataViewChangedAction() {m_onDataViewChangedActionEnabled = true;} void disableOnDataViewChangedAction() {m_onDataViewChangedActionEnabled = false;} - void reloadDataViewsCombobox(); + void reloadDataViewsComboboxAndSetlectItem(const QString &text = {}); void onDataViewChanged(int index); void onShowChannelFilterClicked(); diff --git a/libshvvisu/src/logview/dataviewwidget.ui b/libshvvisu/src/logview/dataviewwidget.ui index 304d250e3..9a3c1dd5e 100644 --- a/libshvvisu/src/logview/dataviewwidget.ui +++ b/libshvvisu/src/logview/dataviewwidget.ui @@ -34,7 +34,7 @@ - + false diff --git a/libshvvisu/src/timeline/channelfilter.cpp b/libshvvisu/src/timeline/channelfilter.cpp index 1425127c5..99cf45de7 100644 --- a/libshvvisu/src/timeline/channelfilter.cpp +++ b/libshvvisu/src/timeline/channelfilter.cpp @@ -40,6 +40,11 @@ bool ChannelFilter::isPathPermitted(const QString &path) const return m_permittedPaths.contains(path); } +void ChannelFilter::setValid(bool is_valid) +{ + m_isValid = is_valid; +} + bool ChannelFilter::isValid() const { return m_isValid; diff --git a/libshvvisu/src/timeline/channelfilter.h b/libshvvisu/src/timeline/channelfilter.h index 1b027bf6a..6d3b4610b 100644 --- a/libshvvisu/src/timeline/channelfilter.h +++ b/libshvvisu/src/timeline/channelfilter.h @@ -22,6 +22,8 @@ class SHVVISU_DECL_EXPORT ChannelFilter void setPermittedPaths(const QSet &paths); bool isPathPermitted(const QString &path) const; + + void setValid(bool is_valid); bool isValid() const; private: diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index b6d6a0fe5..8ef8120fe 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -51,7 +51,6 @@ ChannelFilterDialog::ChannelFilterDialog(QWidget *parent) : connect(ui->pbClearMatchingText, &QPushButton::clicked, this, &ChannelFilterDialog::onPbClearMatchingTextClicked); connect(ui->pbCheckItems, &QPushButton::clicked, this, &ChannelFilterDialog::onPbCheckItemsClicked); connect(ui->pbUncheckItems, &QPushButton::clicked, this, &ChannelFilterDialog::onPbUncheckItemsClicked); - connect(ui->cbDataView, &QComboBox::currentIndexChanged, this, &ChannelFilterDialog::onDataViewCurrentIndexChanged); } ChannelFilterDialog::~ChannelFilterDialog() @@ -61,14 +60,20 @@ ChannelFilterDialog::~ChannelFilterDialog() void ChannelFilterDialog::init(const QString &site_path, Graph *graph, const QString &filter_name) { - disableOnDataViewChangedAction(); + if (m_graph != nullptr) { + shvWarning() << "Dialog is allready initialized."; + return; + } + m_sitePath = site_path; m_graph = graph; m_channelsFilterModel->createNodes(graph->channelPaths()); - applyPermittedChannelsFromGraph(); - reloadDataViewsComboboxAndSetlect(filter_name); - enableOnDataViewChangedAction(); + setPermittedChannelsFromGraph(); + reloadDataViewsComboboxAndSetlectItem(filter_name); + updateContextMenuActionsAvailability(); + + connect(ui->cbDataView, &QComboBox::currentIndexChanged, this, &ChannelFilterDialog::onDataViewChanged); } QSet ChannelFilterDialog::selectedChannels() @@ -91,7 +96,7 @@ void ChannelFilterDialog::applyTextFilter() } } -void ChannelFilterDialog::reloadDataViewsComboboxAndSetlect(const QString &text) +void ChannelFilterDialog::reloadDataViewsComboboxAndSetlectItem(const QString &text) { ui->cbDataView->clear(); ui->cbDataView->addItem(tr("All channels")); @@ -108,9 +113,7 @@ void ChannelFilterDialog::reloadDataViewsComboboxAndSetlect(const QString &text) void ChannelFilterDialog::deleteView() { m_graph->deleteVisualSettings(m_sitePath, ui->cbDataView->currentText()); - disableOnDataViewChangedAction(); - reloadDataViewsComboboxAndSetlect(); - enableOnDataViewChangedAction(); + reloadDataViewsComboboxAndSetlectItem(); } void ChannelFilterDialog::exportView() @@ -121,9 +124,14 @@ void ChannelFilterDialog::exportView() file_name.append(FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); } + ChannelFilter chf(selectedChannels()); + chf.setValid(true); + m_graph->setChannelFilter(chf); + QSettings settings(file_name, QSettings::Format::IniFormat); settings.setValue("fileType", FLATLINE_VIEW_SETTINGS_FILE_TYPE); settings.setValue("settings", m_graph->visualSettings().toJson()); + RECENT_SETTINGS_DIR = QFileInfo(file_name).path(); } } @@ -142,16 +150,10 @@ void ChannelFilterDialog::importView() } Graph::VisualSettings visual_settings = Graph::VisualSettings::fromJson(settings_file.value("settings").toString()); - QSet graph_channels = m_graph->channelPaths(); - - for (int i = 0; i < visual_settings.channels.count(); ++i) { - if (!graph_channels.contains(visual_settings.channels[i].shvPath)) { - visual_settings.channels.removeAt(i--); - } - } - + visual_settings.setIsValid(true); + m_graph->setVisualSettingsAndChannelFilter(visual_settings); m_graph->saveVisualSettings(m_sitePath, view_name); - reloadDataViewsComboboxAndSetlect(view_name); + reloadDataViewsComboboxAndSetlectItem(view_name); RECENT_SETTINGS_DIR = QFileInfo(file_name).path(); } @@ -166,7 +168,9 @@ void ChannelFilterDialog::updateContextMenuActionsAvailability() void ChannelFilterDialog::saveView() { - m_graph->setChannelFilter(selectedChannels()); + ChannelFilter chf(selectedChannels()); + chf.setValid(true); + m_graph->setChannelFilter(chf); m_graph->saveVisualSettings(m_sitePath, ui->cbDataView->currentText()); } @@ -174,15 +178,17 @@ void ChannelFilterDialog::saveViewAs() { QString view_name = QInputDialog::getText(this, tr("Save as"), tr("Input view name")); if (!view_name.isEmpty()) { - m_graph->setChannelFilter(selectedChannels()); + ChannelFilter chf(selectedChannels()); + chf.setValid(true); + m_graph->setChannelFilter(chf); m_graph->saveVisualSettings(m_sitePath, view_name); - reloadDataViewsComboboxAndSetlect(view_name); + reloadDataViewsComboboxAndSetlectItem(view_name); } } void ChannelFilterDialog::discardUserChanges() { - onDataViewCurrentIndexChanged(ui->cbDataView->currentIndex()); + onDataViewChanged(ui->cbDataView->currentIndex()); } void ChannelFilterDialog::onCustomContextMenuRequested(QPoint pos) @@ -236,9 +242,8 @@ void ChannelFilterDialog::onChbFindRegexChanged(int state) applyTextFilter(); } -void ChannelFilterDialog::applyPermittedChannelsFromGraph() +void ChannelFilterDialog::setPermittedChannelsFromGraph() { - shvInfo() << "setPermitted channels" << m_graph->channelFilter().isValid(); m_channelsFilterModel->setSelectedChannels((m_graph->channelFilter().isValid()) ? m_graph->channelFilter().permittedPaths() : m_graph->channelPaths()); } @@ -264,19 +269,17 @@ void ChannelFilterDialog::setVisibleItemsCheckState_helper(const QModelIndex &mi } } -void ChannelFilterDialog::onDataViewCurrentIndexChanged(int index) +void ChannelFilterDialog::onDataViewChanged(int index) { - if (m_onDataViewChangedActionEnabled && (index >= 0)) { + if (index >= 0) { //ignore event for index = -1, currentIndexChanged(-1) is emmited from clear() method if (index == INVALID_FILTER_INDEX) { - m_graph->reset(); - shvInfo() << "chf valid" << m_graph->channelFilter().isValid(); + m_graph->resetVisualSettingsAndChannelFilter(); } else{ m_graph->loadVisualSettings(m_sitePath, ui->cbDataView->currentText()); } - shvInfo() << " load" << ui->cbDataView->currentText().toStdString() << index; - applyPermittedChannelsFromGraph(); + setPermittedChannelsFromGraph(); updateContextMenuActionsAvailability(); } } diff --git a/libshvvisu/src/timeline/channelfilterdialog.h b/libshvvisu/src/timeline/channelfilterdialog.h index 48fbdad32..6ad024bf6 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.h +++ b/libshvvisu/src/timeline/channelfilterdialog.h @@ -33,12 +33,9 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog Q_SIGNAL void selectedFilterNameChanged(const QString &filter_name); private: - void enableOnDataViewChangedAction() {m_onDataViewChangedActionEnabled = true;} - void disableOnDataViewChangedAction() {m_onDataViewChangedActionEnabled = false;} - void applyTextFilter(); - void reloadDataViewsComboboxAndSetlect(const QString &text = {}); + void reloadDataViewsComboboxAndSetlectItem(const QString &text = {}); void saveView(); void saveViewAs(); @@ -51,9 +48,9 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog void setVisibleItemsCheckState(Qt::CheckState state); void setVisibleItemsCheckState_helper(const QModelIndex &mi, Qt::CheckState state); - void applyPermittedChannelsFromGraph(); + void setPermittedChannelsFromGraph(); - void onDataViewCurrentIndexChanged(int index); + void onDataViewChanged(int index); void onCustomContextMenuRequested(QPoint pos); void onPbCheckItemsClicked(); @@ -75,9 +72,6 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog QAction *m_deleteViewAction = nullptr; QAction *m_exportViewAction = nullptr; QAction *m_importViewAction = nullptr; - - bool m_onDataViewChangedActionEnabled = true; - }; } diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index bb31d9c4c..eccb97a2b 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -103,10 +103,9 @@ QTimeZone Graph::timeZone() const } #endif -void Graph::reset() +void Graph::resetVisualSettingsAndChannelFilter() { - createChannelsFromModel(); - setChannelFilter(ChannelFilter()); + setVisualSettingsAndChannelFilter(VisualSettings()); } void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sorted) @@ -1168,7 +1167,7 @@ QVector Graph::visibleChannels() const return visible_channels; } -void Graph::setVisualSettings(const VisualSettings &settings) +void Graph::setVisualSettingsAndChannelFilter(const VisualSettings &settings) { if (settings.isValid()) { QSet f; @@ -1186,12 +1185,18 @@ void Graph::setVisualSettings(const VisualSettings &settings) } m_channelFilter.setPermittedPaths(f); - Q_EMIT layoutChanged(); - Q_EMIT channelFilterChanged(); + m_channelFilter.setValid(true); } else { - reset(); + for (GraphChannel *ch: m_channels) { + ch->setStyle(Style()); + } + + m_channelFilter = ChannelFilter(); } + + emit layoutChanged(); + emit channelFilterChanged(); } void Graph::resizeChannelHeight(qsizetype ix, int delta_px) @@ -1207,7 +1212,7 @@ void Graph::resizeChannelHeight(qsizetype ix, int delta_px) ch_style.setHeightMax(h); ch_style.setHeightMin(h); ch->setStyle(ch_style); - Q_EMIT layoutChanged(); + emit layoutChanged(); } } } @@ -1218,19 +1223,20 @@ void Graph::resizeVerticalHeaderWidth(int delta_px) if (w > MIN_VERTICAL_HEADER_WIDTH && w < MAX_VERTICAL_HEADER_WIDTH) { m_style.setVerticalHeaderWidth(w); - Q_EMIT layoutChanged(); + emit layoutChanged(); } } Graph::VisualSettings Graph::visualSettings() const { - VisualSettings view; + VisualSettings visual_settings; for (int ix : visibleChannels()) { const GraphChannel *channel = channelAt(ix); - view.channels << VisualSettings::Channel{ channel->shvPath(), channel->style() }; + visual_settings.channels << VisualSettings::Channel{ channel->shvPath(), channel->style() }; + visual_settings.setIsValid(true); } - return view; + return visual_settings; } int Graph::maximizedChannelIndex() const @@ -2286,7 +2292,9 @@ void Graph::loadVisualSettings(const QString &settings_id, const QString &name) settings.beginGroup(SITES_KEY); settings.beginGroup(settings_id); settings.beginGroup(VIEWS_KEY); - setVisualSettings(VisualSettings::fromJson(settings.value(name).toString())); + VisualSettings vs = VisualSettings::fromJson(settings.value(name).toString()); + vs.setIsValid(true); //force set valid, because settings without channels are also valid + setVisualSettingsAndChannelFilter(vs); } void Graph::deleteVisualSettings(const QString &settings_id, const QString &name) const @@ -2343,17 +2351,25 @@ Graph::VisualSettings Graph::VisualSettings::fromJson(const QString &json) item["style"].toVariant().toMap() }); } + + settings.setIsValid(!settings.channels.isEmpty()); } else { shvWarning() << "Error on parsing user settings" << parse_error.errorString(); } } + return settings; } +void Graph::VisualSettings::setIsValid(bool is_valid) +{ + m_isValid = is_valid; +} + bool Graph::VisualSettings::isValid() const { - return channels.count(); + return m_isValid; } Graph::XAxis::XAxis() = default; diff --git a/libshvvisu/src/timeline/graph.h b/libshvvisu/src/timeline/graph.h index 78acc0977..ac050a693 100644 --- a/libshvvisu/src/timeline/graph.h +++ b/libshvvisu/src/timeline/graph.h @@ -93,8 +93,12 @@ class SHVVISU_DECL_EXPORT Graph : public QObject QString toJson() const; static VisualSettings fromJson(const QString &json); + void setIsValid(bool is_valid); bool isValid() const; QVector channels; + + protected: + bool m_isValid = false; }; Graph(QObject *parent = nullptr); @@ -111,8 +115,8 @@ class SHVVISU_DECL_EXPORT Graph : public QObject #endif void setSettingsUserName(const QString &user); - - void reset(); + + void resetVisualSettingsAndChannelFilter(); enum class SortChannels { No = 0, Yes }; void createChannelsFromModel(SortChannels sorted = SortChannels::Yes); void resetChannelsRanges(); @@ -225,7 +229,7 @@ class SHVVISU_DECL_EXPORT Graph : public QObject static QString rectToString(const QRect &r); VisualSettings visualSettings() const; - void setVisualSettings(const VisualSettings &settings); + void setVisualSettingsAndChannelFilter(const VisualSettings &settings); void resizeChannelHeight(qsizetype ix, int delta_px); void resizeVerticalHeaderWidth(int delta_px); From e66d03ca5e077e600df540077d21f33ff5bfe1bd Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 25 Oct 2023 14:45:26 +0200 Subject: [PATCH 08/17] sort channels on reset visual settings --- libshvvisu/src/timeline/graph.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index eccb97a2b..3d542d642 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -1188,10 +1188,18 @@ void Graph::setVisualSettingsAndChannelFilter(const VisualSettings &settings) m_channelFilter.setValid(true); } else { - for (GraphChannel *ch: m_channels) { - ch->setStyle(Style()); + std::sort(m_channels.begin(), m_channels.end(), [](const GraphChannel *a, const GraphChannel *b) { + return (QString::compare(a->shvPath(), b->shvPath()) < 0); + }); + + for (GraphChannel *ch : m_channels) { + GraphChannel::Style s = ch->style(); + s.setHeightMin(GraphChannel::Style::DEFAULT_HEIGHT_MIN); + ch->setStyle(s); } + resetChannelsRanges(); + m_channelFilter = ChannelFilter(); } From 3434d5a3a377836e2c9bec8b87b60f382cb74476 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 8 Nov 2023 14:23:21 +0100 Subject: [PATCH 09/17] used std::optional for channelfilter --- libshvvisu/images/images.qrc | 2 + libshvvisu/src/logview/dataviewwidget.cpp | 49 +--- libshvvisu/src/logview/dataviewwidget.h | 7 +- libshvvisu/src/logview/dataviewwidget.ui | 23 +- .../src/logview/logsortfilterproxymodel.cpp | 4 +- .../src/logview/logsortfilterproxymodel.h | 4 +- libshvvisu/src/timeline/channelfilter.cpp | 14 - libshvvisu/src/timeline/channelfilter.h | 4 - .../src/timeline/channelfilterdialog.cpp | 81 +++--- libshvvisu/src/timeline/channelfilterdialog.h | 13 +- .../src/timeline/channelfilterdialog.ui | 242 ++++++++++-------- .../src/timeline/channelfiltermodel.cpp | 2 +- libshvvisu/src/timeline/channelfiltermodel.h | 2 +- libshvvisu/src/timeline/graph.cpp | 118 ++++----- libshvvisu/src/timeline/graph.h | 15 +- libshvvisu/src/timeline/graphwidget.cpp | 3 - 16 files changed, 259 insertions(+), 324 deletions(-) diff --git a/libshvvisu/images/images.qrc b/libshvvisu/images/images.qrc index 2c41c3148..75fbc19a7 100644 --- a/libshvvisu/images/images.qrc +++ b/libshvvisu/images/images.qrc @@ -1,5 +1,7 @@ + filter.svg + filter-off.svg pencil.svg clock.svg ok.svg diff --git a/libshvvisu/src/logview/dataviewwidget.cpp b/libshvvisu/src/logview/dataviewwidget.cpp index 919006dfe..257b5f558 100644 --- a/libshvvisu/src/logview/dataviewwidget.cpp +++ b/libshvvisu/src/logview/dataviewwidget.cpp @@ -10,8 +10,6 @@ namespace tl = shv::visu::timeline; namespace shv::visu::logview { -static const int INVALID_FILTER_INDEX = 0; - DataViewWidget::DataViewWidget(QWidget *parent) : QWidget(parent), ui(new Ui::DataViewWidget) @@ -19,7 +17,6 @@ DataViewWidget::DataViewWidget(QWidget *parent) : ui->setupUi(this); connect(ui->pbShowChannelFilterDialog, &QToolButton::clicked, this, &DataViewWidget::onShowChannelFilterClicked); - connect(ui->cbDataView, &QComboBox::currentIndexChanged, this, &DataViewWidget::onDataViewChanged); } DataViewWidget::~DataViewWidget() @@ -29,53 +26,31 @@ DataViewWidget::~DataViewWidget() void DataViewWidget::init(const QString &site_path, timeline::Graph *graph) { + if (m_graph != nullptr) { + shvWarning() << "Dialog is allready initialized."; + return; + } + m_graph = graph; m_sitePath = site_path; - reloadDataViewsComboboxAndSetlectItem(); -} - -void DataViewWidget::reloadDataViewsComboboxAndSetlectItem(const QString &text) -{ - ui->cbDataView->clear(); - ui->cbDataView->addItem(tr("All channels")); - ui->cbDataView->addItems(m_graph->savedVisualSettingsNames(m_sitePath)); - - if (!text.isEmpty()) { - ui->cbDataView->setCurrentText(text); - } - else { - ui->cbDataView->setCurrentIndex(INVALID_FILTER_INDEX); - } + connect(graph, &timeline::Graph::channelFilterChanged, this, [this](){ + bool is_filter_enabled = (m_graph->channelFilter() != std::nullopt); + ui->pbShowChannelFilterDialog->setIcon(is_filter_enabled? QIcon(QStringLiteral(":/shv/visu/images/filter.svg")): QIcon(QStringLiteral(":/shv/visu/images/filter-off.svg"))); + }); } void DataViewWidget::onShowChannelFilterClicked() { tl::ChannelFilterDialog *channel_filter_dialog = new tl::ChannelFilterDialog(this); - channel_filter_dialog->init(m_sitePath, m_graph, ui->cbDataView->currentText()); + channel_filter_dialog->init(m_sitePath, m_currentVisualSettingsId, m_graph); if (channel_filter_dialog->exec() == QDialog::Accepted) { - shv::visu::timeline::ChannelFilter filter(channel_filter_dialog->selectedChannels()); - m_graph->setChannelFilter(filter); + m_graph->setChannelFilter(channel_filter_dialog->filter()); + m_currentVisualSettingsId = channel_filter_dialog->currentVisualSettingsId(); } channel_filter_dialog->deleteLater(); - - disableOnDataViewChangedAction(); - reloadDataViewsComboboxAndSetlectItem(channel_filter_dialog->selectedFilterName()); - enableOnDataViewChangedAction(); -} - -void DataViewWidget::onDataViewChanged(int index) -{ - if (m_onDataViewChangedActionEnabled && (index >= 0)) { //ignore event for index = -1, currentIndexChanged(-1) is emmited from clear() method - if (index == INVALID_FILTER_INDEX) { - m_graph->resetVisualSettingsAndChannelFilter(); - } - else{ - m_graph->loadVisualSettings(m_sitePath, ui->cbDataView->currentText()); - } - } } } diff --git a/libshvvisu/src/logview/dataviewwidget.h b/libshvvisu/src/logview/dataviewwidget.h index f09c4a266..9e1bd541e 100644 --- a/libshvvisu/src/logview/dataviewwidget.h +++ b/libshvvisu/src/logview/dataviewwidget.h @@ -22,16 +22,11 @@ class DataViewWidget : public QWidget void init(const QString &site_path, timeline::Graph *graph); private: - void enableOnDataViewChangedAction() {m_onDataViewChangedActionEnabled = true;} - void disableOnDataViewChangedAction() {m_onDataViewChangedActionEnabled = false;} - void reloadDataViewsComboboxAndSetlectItem(const QString &text = {}); - - void onDataViewChanged(int index); void onShowChannelFilterClicked(); timeline::Graph *m_graph = nullptr; QString m_sitePath; - bool m_onDataViewChangedActionEnabled = true; + QString m_currentVisualSettingsId; Ui::DataViewWidget *ui; }; diff --git a/libshvvisu/src/logview/dataviewwidget.ui b/libshvvisu/src/logview/dataviewwidget.ui index 9a3c1dd5e..e769098f1 100644 --- a/libshvvisu/src/logview/dataviewwidget.ui +++ b/libshvvisu/src/logview/dataviewwidget.ui @@ -6,7 +6,7 @@ 0 0 - 195 + 24 25 @@ -26,34 +26,17 @@ 0 - - - - Data view: - - - - - - - false - - - QComboBox::AdjustToContents - - - - Channels filter + Show filter dialog ... - :/shv/visu/images/settings.svg:/shv/visu/images/settings.svg + :/shv/visu/images/filter-off.svg:/shv/visu/images/filter-off.svg diff --git a/libshvvisu/src/logview/logsortfilterproxymodel.cpp b/libshvvisu/src/logview/logsortfilterproxymodel.cpp index f3e6ae607..ae8d88767 100644 --- a/libshvvisu/src/logview/logsortfilterproxymodel.cpp +++ b/libshvvisu/src/logview/logsortfilterproxymodel.cpp @@ -11,7 +11,7 @@ LogSortFilterProxyModel::LogSortFilterProxyModel(QObject *parent) : } -void LogSortFilterProxyModel::setChannelFilter(const shv::visu::timeline::ChannelFilter &filter) +void LogSortFilterProxyModel::setChannelFilter(const std::optional &filter) { m_channelFilter = filter; invalidateFilter(); @@ -54,7 +54,7 @@ bool LogSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex if (m_shvPathColumn >= 0) { QModelIndex ix = sourceModel()->index(source_row, m_shvPathColumn, source_parent); - is_row_accepted = (m_channelFilter.isValid()) ? m_channelFilter.isPathPermitted(sourceModel()->data(ix).toString()) : true; + is_row_accepted = (m_channelFilter == std::nullopt) ? true : m_channelFilter->isPathPermitted(sourceModel()->data(ix).toString()); if (is_row_accepted && !m_fulltextFilter.pattern().isEmpty()) { bool is_fulltext_filter_matched = m_fulltextFilter.matches(sourceModel()->data(ix).toString()); diff --git a/libshvvisu/src/logview/logsortfilterproxymodel.h b/libshvvisu/src/logview/logsortfilterproxymodel.h index 299bb45b9..cda945d09 100644 --- a/libshvvisu/src/logview/logsortfilterproxymodel.h +++ b/libshvvisu/src/logview/logsortfilterproxymodel.h @@ -18,7 +18,7 @@ class SHVVISU_DECL_EXPORT LogSortFilterProxyModel : public QSortFilterProxyModel public: explicit LogSortFilterProxyModel(QObject *parent = nullptr); - void setChannelFilter(const shv::visu::timeline::ChannelFilter &filter); + void setChannelFilter(const std::optional &filter); void setShvPathColumn(int column); void setValueColumn(int column); void setFulltextFilter(const shv::visu::timeline::FullTextFilter &filter); @@ -26,7 +26,7 @@ class SHVVISU_DECL_EXPORT LogSortFilterProxyModel : public QSortFilterProxyModel bool filterAcceptsRow(int source_rrow, const QModelIndex &source_parent) const override; private: - shv::visu::timeline::ChannelFilter m_channelFilter; + std::optional m_channelFilter; shv::visu::timeline::FullTextFilter m_fulltextFilter; int m_shvPathColumn = -1; int m_valueColumn = -1; diff --git a/libshvvisu/src/timeline/channelfilter.cpp b/libshvvisu/src/timeline/channelfilter.cpp index 99cf45de7..6220f8950 100644 --- a/libshvvisu/src/timeline/channelfilter.cpp +++ b/libshvvisu/src/timeline/channelfilter.cpp @@ -9,7 +9,6 @@ ChannelFilter::ChannelFilter() = default; ChannelFilter::ChannelFilter(const QSet &permitted_paths) { m_permittedPaths = permitted_paths; - m_isValid = true; } QSet ChannelFilter::permittedPaths() const @@ -20,19 +19,16 @@ QSet ChannelFilter::permittedPaths() const void ChannelFilter::addPermittedPath(const QString &path) { m_permittedPaths.insert(path); - m_isValid = true; } void ChannelFilter::removePermittedPath(const QString &path) { m_permittedPaths.remove(path); - m_isValid = true; } void ChannelFilter::setPermittedPaths(const QSet &paths) { m_permittedPaths = paths; - m_isValid = true; } bool ChannelFilter::isPathPermitted(const QString &path) const @@ -40,14 +36,4 @@ bool ChannelFilter::isPathPermitted(const QString &path) const return m_permittedPaths.contains(path); } -void ChannelFilter::setValid(bool is_valid) -{ - m_isValid = is_valid; -} - -bool ChannelFilter::isValid() const -{ - return m_isValid; -} - } diff --git a/libshvvisu/src/timeline/channelfilter.h b/libshvvisu/src/timeline/channelfilter.h index 6d3b4610b..2ea771b07 100644 --- a/libshvvisu/src/timeline/channelfilter.h +++ b/libshvvisu/src/timeline/channelfilter.h @@ -23,12 +23,8 @@ class SHVVISU_DECL_EXPORT ChannelFilter bool isPathPermitted(const QString &path) const; - void setValid(bool is_valid); - bool isValid() const; - private: QSet m_permittedPaths; - bool m_isValid = false; }; } diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index 8ef8120fe..b4584eb09 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -15,7 +15,6 @@ namespace shv::visu::timeline { -static const int INVALID_FILTER_INDEX = 0; static QString RECENT_SETTINGS_DIR; static const QString FLATLINE_VIEW_SETTINGS_FILE_TYPE = QStringLiteral("FlatlineViewSettings"); static const QString FLATLINE_VIEW_SETTINGS_FILE_EXTENSION = QStringLiteral(".fvs"); @@ -45,7 +44,9 @@ ChannelFilterDialog::ChannelFilterDialog(QWidget *parent) : m_exportViewAction = view_menu->addAction(tr("Export"), this, &ChannelFilterDialog::exportView); m_importViewAction = view_menu->addAction(tr("Import"), this, &ChannelFilterDialog::importView); ui->pbActions->setMenu(view_menu); + ui->gbFilterSetings->setEnabled(ui->chbFileterEnabled->isChecked()); + connect(ui->chbFileterEnabled, &QCheckBox::stateChanged, this, &ChannelFilterDialog::onChbFilterEnabledClicked); connect(ui->tvChannelsFilter, &QTreeView::customContextMenuRequested, this, &ChannelFilterDialog::onCustomContextMenuRequested); connect(ui->leMatchingFilterText, &QLineEdit::textChanged, this, &ChannelFilterDialog::onLeMatchingFilterTextChanged); connect(ui->pbClearMatchingText, &QPushButton::clicked, this, &ChannelFilterDialog::onPbClearMatchingTextClicked); @@ -58,7 +59,7 @@ ChannelFilterDialog::~ChannelFilterDialog() delete ui; } -void ChannelFilterDialog::init(const QString &site_path, Graph *graph, const QString &filter_name) +void ChannelFilterDialog::init(const QString &site_path, const QString &visual_settings_id, Graph *graph) { if (m_graph != nullptr) { shvWarning() << "Dialog is allready initialized."; @@ -69,19 +70,29 @@ void ChannelFilterDialog::init(const QString &site_path, Graph *graph, const QSt m_graph = graph; m_channelsFilterModel->createNodes(graph->channelPaths()); + ui->chbFileterEnabled->setChecked(m_graph->channelFilter() != std::nullopt); + setPermittedChannelsFromGraph(); - reloadDataViewsComboboxAndSetlectItem(filter_name); - updateContextMenuActionsAvailability(); + reloadDataViewsCombobox(); connect(ui->cbDataView, &QComboBox::currentIndexChanged, this, &ChannelFilterDialog::onDataViewChanged); + + if (ui->chbFileterEnabled->isChecked()) + ui->cbDataView->setCurrentText(visual_settings_id); + else + ui->cbDataView->setCurrentIndex(-1); } -QSet ChannelFilterDialog::selectedChannels() +std::optional ChannelFilterDialog::filter() { - return m_channelsFilterModel->selectedChannels(); + if (ui->chbFileterEnabled->isChecked()) { + return ChannelFilter(m_channelsFilterModel->selectedChannels()); + } + + return std::nullopt; } -QString ChannelFilterDialog::selectedFilterName() +QString ChannelFilterDialog::currentVisualSettingsId() { return ui->cbDataView->currentText(); } @@ -96,24 +107,17 @@ void ChannelFilterDialog::applyTextFilter() } } -void ChannelFilterDialog::reloadDataViewsComboboxAndSetlectItem(const QString &text) +void ChannelFilterDialog::reloadDataViewsCombobox() { ui->cbDataView->clear(); - ui->cbDataView->addItem(tr("All channels")); ui->cbDataView->addItems(m_graph->savedVisualSettingsNames(m_sitePath)); - - if (!text.isEmpty()) { - ui->cbDataView->setCurrentText(text); - } - else { - ui->cbDataView->setCurrentIndex(INVALID_FILTER_INDEX); - } } void ChannelFilterDialog::deleteView() { m_graph->deleteVisualSettings(m_sitePath, ui->cbDataView->currentText()); - reloadDataViewsComboboxAndSetlectItem(); + reloadDataViewsCombobox(); + ui->cbDataView->setCurrentIndex(ui->cbDataView->count() - 1); } void ChannelFilterDialog::exportView() @@ -124,9 +128,7 @@ void ChannelFilterDialog::exportView() file_name.append(FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); } - ChannelFilter chf(selectedChannels()); - chf.setValid(true); - m_graph->setChannelFilter(chf); + m_graph->setChannelFilter(filter()); QSettings settings(file_name, QSettings::Format::IniFormat); settings.setValue("fileType", FLATLINE_VIEW_SETTINGS_FILE_TYPE); @@ -150,10 +152,10 @@ void ChannelFilterDialog::importView() } Graph::VisualSettings visual_settings = Graph::VisualSettings::fromJson(settings_file.value("settings").toString()); - visual_settings.setIsValid(true); m_graph->setVisualSettingsAndChannelFilter(visual_settings); m_graph->saveVisualSettings(m_sitePath, view_name); - reloadDataViewsComboboxAndSetlectItem(view_name); + reloadDataViewsCombobox(); + ui->cbDataView->setCurrentText(view_name); RECENT_SETTINGS_DIR = QFileInfo(file_name).path(); } @@ -162,27 +164,26 @@ void ChannelFilterDialog::importView() void ChannelFilterDialog::updateContextMenuActionsAvailability() { - m_saveViewAction->setEnabled(ui->cbDataView->currentIndex() != INVALID_FILTER_INDEX); - m_deleteViewAction->setEnabled(ui->cbDataView->currentIndex() != INVALID_FILTER_INDEX); + m_saveViewAction->setEnabled(!ui->cbDataView->currentText().isEmpty()); + m_deleteViewAction->setEnabled(!ui->cbDataView->currentText().isEmpty()); + m_resetViewAction->setEnabled(!ui->cbDataView->currentText().isEmpty()); } void ChannelFilterDialog::saveView() { - ChannelFilter chf(selectedChannels()); - chf.setValid(true); - m_graph->setChannelFilter(chf); + m_graph->setChannelFilter(filter()); m_graph->saveVisualSettings(m_sitePath, ui->cbDataView->currentText()); } void ChannelFilterDialog::saveViewAs() { QString view_name = QInputDialog::getText(this, tr("Save as"), tr("Input view name")); + if (!view_name.isEmpty()) { - ChannelFilter chf(selectedChannels()); - chf.setValid(true); - m_graph->setChannelFilter(chf); + m_graph->setChannelFilter(filter()); m_graph->saveVisualSettings(m_sitePath, view_name); - reloadDataViewsComboboxAndSetlectItem(view_name); + reloadDataViewsCombobox(); + ui->cbDataView->setCurrentText(view_name); } } @@ -215,6 +216,11 @@ void ChannelFilterDialog::onCustomContextMenuRequested(QPoint pos) } } +void ChannelFilterDialog::onChbFilterEnabledClicked(int state) +{ + ui->gbFilterSetings->setEnabled(state == Qt::CheckState::Checked); +} + void ChannelFilterDialog::onPbCheckItemsClicked() { setVisibleItemsCheckState(Qt::Checked); @@ -244,7 +250,8 @@ void ChannelFilterDialog::onChbFindRegexChanged(int state) void ChannelFilterDialog::setPermittedChannelsFromGraph() { - m_channelsFilterModel->setSelectedChannels((m_graph->channelFilter().isValid()) ? m_graph->channelFilter().permittedPaths() : m_graph->channelPaths()); + std::optional f = m_graph->channelFilter(); + m_channelsFilterModel->setPermittedChannels((f == std::nullopt) ? QSet{} : f->permittedPaths()); } void ChannelFilterDialog::setVisibleItemsCheckState(Qt::CheckState state) @@ -271,14 +278,8 @@ void ChannelFilterDialog::setVisibleItemsCheckState_helper(const QModelIndex &mi void ChannelFilterDialog::onDataViewChanged(int index) { - if (index >= 0) { //ignore event for index = -1, currentIndexChanged(-1) is emmited from clear() method - if (index == INVALID_FILTER_INDEX) { - m_graph->resetVisualSettingsAndChannelFilter(); - } - else{ - m_graph->loadVisualSettings(m_sitePath, ui->cbDataView->currentText()); - } - + if (index >= 0) { //ignore event with index = -1, which is emmited from clear() method + m_graph->loadVisualSettings(m_sitePath, ui->cbDataView->currentText()); setPermittedChannelsFromGraph(); updateContextMenuActionsAvailability(); } diff --git a/libshvvisu/src/timeline/channelfilterdialog.h b/libshvvisu/src/timeline/channelfilterdialog.h index 6ad024bf6..2e338aeb5 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.h +++ b/libshvvisu/src/timeline/channelfilterdialog.h @@ -25,17 +25,13 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog explicit ChannelFilterDialog(QWidget *parent = nullptr); ~ChannelFilterDialog(); - void init(const QString &site_path, Graph *graph, const QString &filter_name); - - QSet selectedChannels(); - QString selectedFilterName(); - - Q_SIGNAL void selectedFilterNameChanged(const QString &filter_name); + void init(const QString &site_path, const QString &visual_settings_id, Graph *graph); + std::optional filter(); + QString currentVisualSettingsId(); private: void applyTextFilter(); - - void reloadDataViewsComboboxAndSetlectItem(const QString &text = {}); + void reloadDataViewsCombobox(); void saveView(); void saveViewAs(); @@ -53,6 +49,7 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog void onDataViewChanged(int index); void onCustomContextMenuRequested(QPoint pos); + void onChbFilterEnabledClicked(int state); void onPbCheckItemsClicked(); void onPbUncheckItemsClicked(); void onPbClearMatchingTextClicked(); diff --git a/libshvvisu/src/timeline/channelfilterdialog.ui b/libshvvisu/src/timeline/channelfilterdialog.ui index a8c9ed67d..79015c922 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.ui +++ b/libshvvisu/src/timeline/channelfilterdialog.ui @@ -13,123 +13,139 @@ Channels filter dialog - + - - - - - - true - - - - Data view - - - - - - - - 1 - 0 - - - - - - - - - - - - :/shv/visu/images/hamburger-menu.svg:/shv/visu/images/hamburger-menu.svg - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 10 - 10 - + + + Enabled - - - - - - - - - - - - :/shv/visu/images/check-box-outline.svg:/shv/visu/images/check-box-outline.svg - - - - - - - - - - - :/shv/visu/images/checkbox-blank-outline.svg:/shv/visu/images/checkbox-blank-outline.svg - - - - - - - Matching text - - - - - - - 0 - - - - - - 1 - 0 - - - - - - - - - - - - :/shv/visu/images/delete.svg:/shv/visu/images/delete.svg - - - - - - + - + + + + + + + + + + + + true + + + + Data view + + + + + + + + 1 + 0 + + + + + + + + + + + + :/shv/visu/images/hamburger-menu.svg:/shv/visu/images/hamburger-menu.svg + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 10 + 10 + + + + + + + + + + + + + + :/shv/visu/images/check-box-outline.svg:/shv/visu/images/check-box-outline.svg + + + + + + + + + + + :/shv/visu/images/checkbox-blank-outline.svg:/shv/visu/images/checkbox-blank-outline.svg + + + + + + + Matching text + + + + + + + 0 + + + + + + 1 + 0 + + + + + + + + + + + + :/shv/visu/images/delete.svg:/shv/visu/images/delete.svg + + + + + + + + + + + + diff --git a/libshvvisu/src/timeline/channelfiltermodel.cpp b/libshvvisu/src/timeline/channelfiltermodel.cpp index 7140569a3..481129093 100644 --- a/libshvvisu/src/timeline/channelfiltermodel.cpp +++ b/libshvvisu/src/timeline/channelfiltermodel.cpp @@ -50,7 +50,7 @@ void ChannelFilterModel::selectedChannels_helper(QSet *channels, QStand } } -void ChannelFilterModel::setSelectedChannels(const QSet &channels) +void ChannelFilterModel::setPermittedChannels(const QSet &channels) { setChildItemsCheckedState(invisibleRootItem(), Qt::CheckState::Unchecked); diff --git a/libshvvisu/src/timeline/channelfiltermodel.h b/libshvvisu/src/timeline/channelfiltermodel.h index b17703e41..dbd3947d4 100644 --- a/libshvvisu/src/timeline/channelfiltermodel.h +++ b/libshvvisu/src/timeline/channelfiltermodel.h @@ -24,7 +24,7 @@ class SHVVISU_DECL_EXPORT ChannelFilterModel : public QStandardItemModel void createNodes(const QSet &channels); QSet selectedChannels(); - void setSelectedChannels(const QSet &channels); + void setPermittedChannels(const QSet &channels); void setItemCheckState(const QModelIndex &mi, Qt::CheckState check_state); void fixCheckBoxesIntegrity(); protected: diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index 3d542d642..6891bd8df 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -105,7 +105,8 @@ QTimeZone Graph::timeZone() const void Graph::resetVisualSettingsAndChannelFilter() { - setVisualSettingsAndChannelFilter(VisualSettings()); + createChannelsFromModel(); + } void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sorted) @@ -144,8 +145,10 @@ void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sor ch->setStyle(style); } resetChannelsRanges(); + disableFiltering(); emit layoutChanged(); + emit channelFilterChanged(); } void Graph::resetChannelsRanges() @@ -238,7 +241,7 @@ void Graph::moveChannel(qsizetype channel, qsizetype new_pos) void Graph::showAllChannels() { - m_channelFilter.setPermittedPaths(channelPaths()); + disableFiltering(); emit layoutChanged(); emit channelFilterChanged(); @@ -257,16 +260,16 @@ QSet Graph::channelPaths() void Graph::hideFlatChannels() { - QSet matching_paths = (m_channelFilter.isValid()) ? m_channelFilter.permittedPaths() : channelPaths(); + QSet permitted_paths = (isFilteringEnabled()) ? m_channelFilter->permittedPaths() : channelPaths(); for (qsizetype i = 0; i < m_channels.count(); ++i) { GraphChannel *ch = m_channels[i]; if(isChannelFlat(ch)) { - matching_paths.remove(ch->shvPath()); + permitted_paths.remove(ch->shvPath()); } } - m_channelFilter.setPermittedPaths(matching_paths); + enableFilteringAndSetPermittedPaths(permitted_paths); emit layoutChanged(); emit channelFilterChanged(); @@ -278,7 +281,7 @@ bool Graph::isChannelFlat(GraphChannel *ch) return yrange.isEmpty(); } -void Graph::setChannelFilter(const ChannelFilter &filter) +void Graph::setChannelFilter(const std::optional &filter) { m_channelFilter = filter; @@ -286,7 +289,7 @@ void Graph::setChannelFilter(const ChannelFilter &filter) emit channelFilterChanged(); } -const ChannelFilter& Graph::channelFilter() const +const std::optional& Graph::channelFilter() const { return m_channelFilter; } @@ -294,12 +297,14 @@ const ChannelFilter& Graph::channelFilter() const void Graph::setChannelVisible(qsizetype channel_ix, bool is_visible) { GraphChannel *ch = channelAt(channel_ix); + if (m_channelFilter == std::nullopt) + m_channelFilter = ChannelFilter(); if (is_visible) { - m_channelFilter.addPermittedPath(ch->shvPath()); + m_channelFilter->addPermittedPath(ch->shvPath()); } else { - m_channelFilter.removePermittedPath(ch->shvPath()); + m_channelFilter->removePermittedPath(ch->shvPath()); } emit layoutChanged(); @@ -1151,10 +1156,10 @@ QVector Graph::visibleChannels() const if (maximized_channel >= 0) { visible_channels << maximized_channel; } - else if (m_channelFilter.isValid()) { + else if (isFilteringEnabled()) { for (int i = 0; i < m_channels.count(); ++i) { QString shv_path = model()->channelInfo(m_channels[i]->modelIndex()).shvPath; - if(m_channelFilter.isPathPermitted(shv_path)) { + if(m_channelFilter->isPathPermitted(shv_path)) { visible_channels << i; } } @@ -1169,39 +1174,22 @@ QVector Graph::visibleChannels() const void Graph::setVisualSettingsAndChannelFilter(const VisualSettings &settings) { - if (settings.isValid()) { - QSet f; - for (int i = 0; i < settings.channels.count(); ++i) { - const VisualSettings::Channel &channel_settings = settings.channels[i]; - for (int j = i; j < m_channels.count(); ++j) { - GraphChannel *channel = m_channels[j]; - if (channel->shvPath() == channel_settings.shvPath) { - f.insert(channel_settings.shvPath); - channel->setStyle(channel_settings.style); - m_channels.insert(i, m_channels.takeAt(j)); - break; - } + QSet permitted_paths; + + for (int i = 0; i < settings.channels.count(); ++i) { + const VisualSettings::Channel &channel_settings = settings.channels[i]; + for (int j = i; j < m_channels.count(); ++j) { + GraphChannel *channel = m_channels[j]; + if (channel->shvPath() == channel_settings.shvPath) { + permitted_paths.insert(channel_settings.shvPath); + channel->setStyle(channel_settings.style); + m_channels.insert(i, m_channels.takeAt(j)); + break; } } - - m_channelFilter.setPermittedPaths(f); - m_channelFilter.setValid(true); } - else { - std::sort(m_channels.begin(), m_channels.end(), [](const GraphChannel *a, const GraphChannel *b) { - return (QString::compare(a->shvPath(), b->shvPath()) < 0); - }); - for (GraphChannel *ch : m_channels) { - GraphChannel::Style s = ch->style(); - s.setHeightMin(GraphChannel::Style::DEFAULT_HEIGHT_MIN); - ch->setStyle(s); - } - - resetChannelsRanges(); - - m_channelFilter = ChannelFilter(); - } + enableFilteringAndSetPermittedPaths(permitted_paths); emit layoutChanged(); emit channelFilterChanged(); @@ -1241,7 +1229,6 @@ Graph::VisualSettings Graph::visualSettings() const for (int ix : visibleChannels()) { const GraphChannel *channel = channelAt(ix); visual_settings.channels << VisualSettings::Channel{ channel->shvPath(), channel->style() }; - visual_settings.setIsValid(true); } return visual_settings; @@ -2301,10 +2288,27 @@ void Graph::loadVisualSettings(const QString &settings_id, const QString &name) settings.beginGroup(settings_id); settings.beginGroup(VIEWS_KEY); VisualSettings vs = VisualSettings::fromJson(settings.value(name).toString()); - vs.setIsValid(true); //force set valid, because settings without channels are also valid setVisualSettingsAndChannelFilter(vs); } +bool Graph::isFilteringEnabled() const +{ + return (m_channelFilter != std::nullopt); +} + +void Graph::enableFilteringAndSetPermittedPaths(const QSet &paths) +{ + if (m_channelFilter == std::nullopt) + m_channelFilter = ChannelFilter(); + + m_channelFilter->setPermittedPaths(paths); +} + +void Graph::disableFiltering() +{ + m_channelFilter = std::nullopt; +} + void Graph::deleteVisualSettings(const QString &settings_id, const QString &name) const { QSettings settings; @@ -2329,19 +2333,15 @@ QStringList Graph::savedVisualSettingsNames(const QString &settings_id) const QString Graph::VisualSettings::toJson() const { - if (isValid()) { - QJsonArray settings; + QJsonArray settings; - for (int i = 0; i < channels.count(); ++i) { - settings << QJsonObject { - { "shvPath", channels[i].shvPath }, - { "style", QJsonObject::fromVariantMap(channels[i].style) } - }; + for (int i = 0; i < channels.count(); ++i) { + settings << QJsonObject { + { "shvPath", channels[i].shvPath }, + { "style", QJsonObject::fromVariantMap(channels[i].style) } + }; } - return QJsonDocument(QJsonObject{{ "channels", settings }}).toJson(QJsonDocument::Compact); - } - - return QString(); + return QJsonDocument(QJsonObject{{ "channels", settings }}).toJson(QJsonDocument::Compact); } Graph::VisualSettings Graph::VisualSettings::fromJson(const QString &json) @@ -2359,8 +2359,6 @@ Graph::VisualSettings Graph::VisualSettings::fromJson(const QString &json) item["style"].toVariant().toMap() }); } - - settings.setIsValid(!settings.channels.isEmpty()); } else { shvWarning() << "Error on parsing user settings" << parse_error.errorString(); @@ -2370,16 +2368,6 @@ Graph::VisualSettings Graph::VisualSettings::fromJson(const QString &json) return settings; } -void Graph::VisualSettings::setIsValid(bool is_valid) -{ - m_isValid = is_valid; -} - -bool Graph::VisualSettings::isValid() const -{ - return m_isValid; -} - Graph::XAxis::XAxis() = default; Graph::XAxis::XAxis(timemsec_t t, int se, LabelScale f) : tickInterval(t) diff --git a/libshvvisu/src/timeline/graph.h b/libshvvisu/src/timeline/graph.h index ac050a693..e07eaddf1 100644 --- a/libshvvisu/src/timeline/graph.h +++ b/libshvvisu/src/timeline/graph.h @@ -93,12 +93,7 @@ class SHVVISU_DECL_EXPORT Graph : public QObject QString toJson() const; static VisualSettings fromJson(const QString &json); - void setIsValid(bool is_valid); - bool isValid() const; QVector channels; - - protected: - bool m_isValid = false; }; Graph(QObject *parent = nullptr); @@ -133,8 +128,8 @@ class SHVVISU_DECL_EXPORT Graph : public QObject void showAllChannels(); QSet channelPaths(); void hideFlatChannels(); - const ChannelFilter& channelFilter() const; - void setChannelFilter(const ChannelFilter &filter); + const std::optional &channelFilter() const; + void setChannelFilter(const std::optional &filter); void setChannelVisible(qsizetype channel_ix, bool is_visible); void setChannelMaximized(qsizetype channel_ix, bool is_maximized); @@ -237,6 +232,10 @@ class SHVVISU_DECL_EXPORT Graph : public QObject void deleteVisualSettings(const QString &settings_id, const QString &name) const; QStringList savedVisualSettingsNames(const QString &settings_id) const; void loadVisualSettings(const QString &settings_id, const QString &name); + QString loadedVisualSettingsId(); + bool isFilteringEnabled() const; + void enableFilteringAndSetPermittedPaths(const QSet &paths); + void disableFiltering(); protected: void sanityXRangeZoom(); @@ -293,7 +292,7 @@ class SHVVISU_DECL_EXPORT Graph : public QObject QVector m_channelProbes; QVector m_channels; - ChannelFilter m_channelFilter; + std::optional m_channelFilter; struct SHVVISU_DECL_EXPORT XAxis { diff --git a/libshvvisu/src/timeline/graphwidget.cpp b/libshvvisu/src/timeline/graphwidget.cpp index 55db25523..ce5faba6a 100644 --- a/libshvvisu/src/timeline/graphwidget.cpp +++ b/libshvvisu/src/timeline/graphwidget.cpp @@ -761,9 +761,6 @@ void GraphWidget::showGraphContextMenu(const QPoint &mouse_pos) }); menu.addAction(tr("Reset channels to defaults"), this, [this]() { m_graph->createChannelsFromModel(); - auto graph_filter = m_graph->channelFilter(); - graph_filter.setPermittedPaths(m_graph->channelPaths()); - m_graph->setChannelFilter(graph_filter); }); if (m_graph->isYAxisVisible()) { menu.addAction(tr("Hide Y axis"), this, [this]() { From 042c2e3b27170e329512ebf0fab312f8e7c3efd3 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 8 Nov 2023 19:28:37 +0100 Subject: [PATCH 10/17] added virtual void applyCustomChannelColor(...) to graph, added filter name --- libshvvisu/images/filter-off.svg | 1 + libshvvisu/images/filter.svg | 1 + libshvvisu/src/logview/dataviewwidget.cpp | 3 +- libshvvisu/src/logview/dataviewwidget.h | 1 - libshvvisu/src/timeline/channelfilter.cpp | 8 +++- libshvvisu/src/timeline/channelfilter.h | 4 +- .../src/timeline/channelfilterdialog.cpp | 23 ++++++---- libshvvisu/src/timeline/channelfilterdialog.h | 2 +- .../src/timeline/channelfilterdialog.ui | 20 +++++++++ libshvvisu/src/timeline/graph.cpp | 42 +++++++++++-------- libshvvisu/src/timeline/graph.h | 5 ++- 11 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 libshvvisu/images/filter-off.svg create mode 100644 libshvvisu/images/filter.svg diff --git a/libshvvisu/images/filter-off.svg b/libshvvisu/images/filter-off.svg new file mode 100644 index 000000000..476c929a3 --- /dev/null +++ b/libshvvisu/images/filter-off.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/libshvvisu/images/filter.svg b/libshvvisu/images/filter.svg new file mode 100644 index 000000000..5844d0eca --- /dev/null +++ b/libshvvisu/images/filter.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/libshvvisu/src/logview/dataviewwidget.cpp b/libshvvisu/src/logview/dataviewwidget.cpp index 257b5f558..e6685d570 100644 --- a/libshvvisu/src/logview/dataviewwidget.cpp +++ b/libshvvisu/src/logview/dataviewwidget.cpp @@ -43,11 +43,10 @@ void DataViewWidget::init(const QString &site_path, timeline::Graph *graph) void DataViewWidget::onShowChannelFilterClicked() { tl::ChannelFilterDialog *channel_filter_dialog = new tl::ChannelFilterDialog(this); - channel_filter_dialog->init(m_sitePath, m_currentVisualSettingsId, m_graph); + channel_filter_dialog->init(m_sitePath, m_graph); if (channel_filter_dialog->exec() == QDialog::Accepted) { m_graph->setChannelFilter(channel_filter_dialog->filter()); - m_currentVisualSettingsId = channel_filter_dialog->currentVisualSettingsId(); } channel_filter_dialog->deleteLater(); diff --git a/libshvvisu/src/logview/dataviewwidget.h b/libshvvisu/src/logview/dataviewwidget.h index 9e1bd541e..4a62abdd1 100644 --- a/libshvvisu/src/logview/dataviewwidget.h +++ b/libshvvisu/src/logview/dataviewwidget.h @@ -26,7 +26,6 @@ class DataViewWidget : public QWidget timeline::Graph *m_graph = nullptr; QString m_sitePath; - QString m_currentVisualSettingsId; Ui::DataViewWidget *ui; }; diff --git a/libshvvisu/src/timeline/channelfilter.cpp b/libshvvisu/src/timeline/channelfilter.cpp index 6220f8950..c9640ab7c 100644 --- a/libshvvisu/src/timeline/channelfilter.cpp +++ b/libshvvisu/src/timeline/channelfilter.cpp @@ -6,9 +6,10 @@ namespace shv::visu::timeline { ChannelFilter::ChannelFilter() = default; -ChannelFilter::ChannelFilter(const QSet &permitted_paths) +ChannelFilter::ChannelFilter(const QSet &permitted_paths, const QString &name) { m_permittedPaths = permitted_paths; + m_name = name; } QSet ChannelFilter::permittedPaths() const @@ -36,4 +37,9 @@ bool ChannelFilter::isPathPermitted(const QString &path) const return m_permittedPaths.contains(path); } +QString ChannelFilter::name() +{ + return m_name; +} + } diff --git a/libshvvisu/src/timeline/channelfilter.h b/libshvvisu/src/timeline/channelfilter.h index 2ea771b07..9ca4b4817 100644 --- a/libshvvisu/src/timeline/channelfilter.h +++ b/libshvvisu/src/timeline/channelfilter.h @@ -13,7 +13,7 @@ class SHVVISU_DECL_EXPORT ChannelFilter { public: ChannelFilter(); - ChannelFilter(const QSet &permitted_paths); + ChannelFilter(const QSet &permitted_paths, const QString &name = {}); void addPermittedPath(const QString &path); void removePermittedPath(const QString &path); @@ -22,8 +22,10 @@ class SHVVISU_DECL_EXPORT ChannelFilter void setPermittedPaths(const QSet &paths); bool isPathPermitted(const QString &path) const; + QString name(); private: + QString m_name; QSet m_permittedPaths; }; diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index b4584eb09..49090ab3a 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -59,7 +59,7 @@ ChannelFilterDialog::~ChannelFilterDialog() delete ui; } -void ChannelFilterDialog::init(const QString &site_path, const QString &visual_settings_id, Graph *graph) +void ChannelFilterDialog::init(const QString &site_path, Graph *graph) { if (m_graph != nullptr) { shvWarning() << "Dialog is allready initialized."; @@ -70,23 +70,26 @@ void ChannelFilterDialog::init(const QString &site_path, const QString &visual_s m_graph = graph; m_channelsFilterModel->createNodes(graph->channelPaths()); - ui->chbFileterEnabled->setChecked(m_graph->channelFilter() != std::nullopt); + ui->chbFileterEnabled->setChecked(m_graph->isFilteringEnabled()); setPermittedChannelsFromGraph(); reloadDataViewsCombobox(); - connect(ui->cbDataView, &QComboBox::currentIndexChanged, this, &ChannelFilterDialog::onDataViewChanged); + std::optional chf = m_graph->channelFilter(); - if (ui->chbFileterEnabled->isChecked()) - ui->cbDataView->setCurrentText(visual_settings_id); + if ((chf != std::nullopt) && (!chf->name().isEmpty())) + ui->cbDataView->setCurrentText(chf->name()); else ui->cbDataView->setCurrentIndex(-1); + + updateContextMenuActionsAvailability(); + connect(ui->cbDataView, &QComboBox::currentIndexChanged, this, &ChannelFilterDialog::onDataViewChanged); } std::optional ChannelFilterDialog::filter() { if (ui->chbFileterEnabled->isChecked()) { - return ChannelFilter(m_channelsFilterModel->selectedChannels()); + return ChannelFilter(m_channelsFilterModel->selectedChannels(), ui->cbDataView->currentText()); } return std::nullopt; @@ -152,6 +155,7 @@ void ChannelFilterDialog::importView() } Graph::VisualSettings visual_settings = Graph::VisualSettings::fromJson(settings_file.value("settings").toString()); + visual_settings.name = view_name; m_graph->setVisualSettingsAndChannelFilter(visual_settings); m_graph->saveVisualSettings(m_sitePath, view_name); reloadDataViewsCombobox(); @@ -171,6 +175,11 @@ void ChannelFilterDialog::updateContextMenuActionsAvailability() void ChannelFilterDialog::saveView() { + if(ui->cbDataView->currentText().isEmpty()) { + shvWarning() << "Failed to save empty filter name."; + return; + } + m_graph->setChannelFilter(filter()); m_graph->saveVisualSettings(m_sitePath, ui->cbDataView->currentText()); } @@ -281,8 +290,8 @@ void ChannelFilterDialog::onDataViewChanged(int index) if (index >= 0) { //ignore event with index = -1, which is emmited from clear() method m_graph->loadVisualSettings(m_sitePath, ui->cbDataView->currentText()); setPermittedChannelsFromGraph(); - updateContextMenuActionsAvailability(); } + updateContextMenuActionsAvailability(); } } diff --git a/libshvvisu/src/timeline/channelfilterdialog.h b/libshvvisu/src/timeline/channelfilterdialog.h index 2e338aeb5..1b60bee9d 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.h +++ b/libshvvisu/src/timeline/channelfilterdialog.h @@ -25,7 +25,7 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog explicit ChannelFilterDialog(QWidget *parent = nullptr); ~ChannelFilterDialog(); - void init(const QString &site_path, const QString &visual_settings_id, Graph *graph); + void init(const QString &site_path, Graph *graph); std::optional filter(); QString currentVisualSettingsId(); diff --git a/libshvvisu/src/timeline/channelfilterdialog.ui b/libshvvisu/src/timeline/channelfilterdialog.ui index 79015c922..dd9163685 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.ui +++ b/libshvvisu/src/timeline/channelfilterdialog.ui @@ -14,8 +14,19 @@ Channels filter dialog + + 0 + + + + true + + + + Qt::RightToLeft + Enabled @@ -27,6 +38,15 @@ + + 9 + + + 9 + + + 9 + diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index 6891bd8df..49d39e35f 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -111,17 +111,10 @@ void Graph::resetVisualSettingsAndChannelFilter() void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sorted) { - static QVector colors { - Qt::magenta, - Qt::cyan, - Qt::blue, - QColor(0xe6, 0x3c, 0x33), //red - QColor("orange"), - QColor(0x6d, 0xa1, 0x3a), // green - }; clearChannels(); if(!m_model) return; + QList model_ixs; if(sorted == SortChannels::Yes) { // sort channels alphabetically @@ -139,11 +132,9 @@ void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sor } for(auto model_ix : model_ixs) { GraphChannel *ch = appendChannel(model_ix); - auto channel_ix = channelCount() - 1; - GraphChannel::Style style = ch->style(); - style.setColor(colors.value(channel_ix % colors.count())); - ch->setStyle(style); + applyCustomChannelColor(ch); } + resetChannelsRanges(); disableFiltering(); @@ -269,7 +260,8 @@ void Graph::hideFlatChannels() } } - enableFilteringAndSetPermittedPaths(permitted_paths); + enableFiltering(); + m_channelFilter->setPermittedPaths(permitted_paths); emit layoutChanged(); emit channelFilterChanged(); @@ -1189,7 +1181,7 @@ void Graph::setVisualSettingsAndChannelFilter(const VisualSettings &settings) } } - enableFilteringAndSetPermittedPaths(permitted_paths); + setChannelFilter(ChannelFilter(permitted_paths, settings.name)); emit layoutChanged(); emit channelFilterChanged(); @@ -2248,6 +2240,23 @@ void Graph::drawCurrentTimeMarker(QPainter *painter, time_t time) drawCenterTopText(painter, p1, text, m_style.font(), color.darker(400), color); } +void Graph::applyCustomChannelColor(GraphChannel *channel) +{ + static QVector colors { + Qt::magenta, + Qt::cyan, + Qt::blue, + QColor(0xe6, 0x3c, 0x33), //red + QColor("orange"), + QColor(0x6d, 0xa1, 0x3a), // green + }; + + auto channel_ix = channelCount() - 1; + GraphChannel::Style style = channel->style(); + style.setColor(colors.value(channel_ix % colors.count())); + channel->setStyle(style); +} + QString Graph::timeToStringTZ(timemsec_t time) const { QDateTime dt = QDateTime::fromMSecsSinceEpoch(time); @@ -2288,6 +2297,7 @@ void Graph::loadVisualSettings(const QString &settings_id, const QString &name) settings.beginGroup(settings_id); settings.beginGroup(VIEWS_KEY); VisualSettings vs = VisualSettings::fromJson(settings.value(name).toString()); + vs.name = settings_id; setVisualSettingsAndChannelFilter(vs); } @@ -2296,12 +2306,10 @@ bool Graph::isFilteringEnabled() const return (m_channelFilter != std::nullopt); } -void Graph::enableFilteringAndSetPermittedPaths(const QSet &paths) +void Graph::enableFiltering() { if (m_channelFilter == std::nullopt) m_channelFilter = ChannelFilter(); - - m_channelFilter->setPermittedPaths(paths); } void Graph::disableFiltering() diff --git a/libshvvisu/src/timeline/graph.h b/libshvvisu/src/timeline/graph.h index e07eaddf1..c05ae08de 100644 --- a/libshvvisu/src/timeline/graph.h +++ b/libshvvisu/src/timeline/graph.h @@ -94,6 +94,7 @@ class SHVVISU_DECL_EXPORT Graph : public QObject QString toJson() const; static VisualSettings fromJson(const QString &json); QVector channels; + QString name; }; Graph(QObject *parent = nullptr); @@ -234,7 +235,7 @@ class SHVVISU_DECL_EXPORT Graph : public QObject void loadVisualSettings(const QString &settings_id, const QString &name); QString loadedVisualSettingsId(); bool isFilteringEnabled() const; - void enableFilteringAndSetPermittedPaths(const QSet &paths); + void enableFiltering(); void disableFiltering(); protected: @@ -272,6 +273,8 @@ class SHVVISU_DECL_EXPORT Graph : public QObject virtual void drawCurrentTime(QPainter *painter, int channel_ix); void drawCurrentTimeMarker(QPainter *painter, time_t time); + virtual void applyCustomChannelColor(GraphChannel *channel); + QVariantMap mergeMaps(const QVariantMap &base, const QVariantMap &overlay) const; void makeXAxis(); void makeYAxis(qsizetype channel); From 088571611b02f45cf22b2f4069f4e547bbc8c4d5 Mon Sep 17 00:00:00 2001 From: Petr Date: Thu, 9 Nov 2023 10:20:05 +0100 Subject: [PATCH 11/17] refactoring --- libshvvisu/src/logview/dataviewwidget.cpp | 3 +-- .../src/logview/logsortfilterproxymodel.cpp | 2 +- .../src/timeline/channelfilterdialog.cpp | 12 +++++------- libshvvisu/src/timeline/channelfilterdialog.h | 1 - .../src/timeline/channelfiltermodel.cpp | 2 +- libshvvisu/src/timeline/channelfiltermodel.h | 2 +- libshvvisu/src/timeline/graph.cpp | 19 ++++--------------- libshvvisu/src/timeline/graph.h | 3 +-- 8 files changed, 14 insertions(+), 30 deletions(-) diff --git a/libshvvisu/src/logview/dataviewwidget.cpp b/libshvvisu/src/logview/dataviewwidget.cpp index e6685d570..8e8d2daf3 100644 --- a/libshvvisu/src/logview/dataviewwidget.cpp +++ b/libshvvisu/src/logview/dataviewwidget.cpp @@ -35,8 +35,7 @@ void DataViewWidget::init(const QString &site_path, timeline::Graph *graph) m_sitePath = site_path; connect(graph, &timeline::Graph::channelFilterChanged, this, [this](){ - bool is_filter_enabled = (m_graph->channelFilter() != std::nullopt); - ui->pbShowChannelFilterDialog->setIcon(is_filter_enabled? QIcon(QStringLiteral(":/shv/visu/images/filter.svg")): QIcon(QStringLiteral(":/shv/visu/images/filter-off.svg"))); + ui->pbShowChannelFilterDialog->setIcon(m_graph->isFilteringEnabled()? QIcon(QStringLiteral(":/shv/visu/images/filter.svg")): QIcon(QStringLiteral(":/shv/visu/images/filter-off.svg"))); }); } diff --git a/libshvvisu/src/logview/logsortfilterproxymodel.cpp b/libshvvisu/src/logview/logsortfilterproxymodel.cpp index ae8d88767..05157aa85 100644 --- a/libshvvisu/src/logview/logsortfilterproxymodel.cpp +++ b/libshvvisu/src/logview/logsortfilterproxymodel.cpp @@ -63,7 +63,7 @@ bool LogSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex ix = sourceModel()->index(source_row, m_valueColumn, source_parent); is_fulltext_filter_matched = is_fulltext_filter_matched || m_fulltextFilter.matches(sourceModel()->data(ix).toString()); } - is_row_accepted = is_row_accepted || is_fulltext_filter_matched; + is_row_accepted = is_row_accepted && is_fulltext_filter_matched; } } diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index 49090ab3a..84f3c9e3e 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -89,17 +89,12 @@ void ChannelFilterDialog::init(const QString &site_path, Graph *graph) std::optional ChannelFilterDialog::filter() { if (ui->chbFileterEnabled->isChecked()) { - return ChannelFilter(m_channelsFilterModel->selectedChannels(), ui->cbDataView->currentText()); + return ChannelFilter(m_channelsFilterModel->permittedChannels(), ui->cbDataView->currentText()); } return std::nullopt; } -QString ChannelFilterDialog::currentVisualSettingsId() -{ - return ui->cbDataView->currentText(); -} - void ChannelFilterDialog::applyTextFilter() { m_channelsFilterProxyModel->setFilterString(ui->leMatchingFilterText->text()); @@ -188,7 +183,10 @@ void ChannelFilterDialog::saveViewAs() { QString view_name = QInputDialog::getText(this, tr("Save as"), tr("Input view name")); - if (!view_name.isEmpty()) { + if (view_name.isEmpty()) { + QMessageBox::warning(this, tr("Error"), tr("Failed to save view: name is empty.")); + } + else { m_graph->setChannelFilter(filter()); m_graph->saveVisualSettings(m_sitePath, view_name); reloadDataViewsCombobox(); diff --git a/libshvvisu/src/timeline/channelfilterdialog.h b/libshvvisu/src/timeline/channelfilterdialog.h index 1b60bee9d..0ba86dfff 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.h +++ b/libshvvisu/src/timeline/channelfilterdialog.h @@ -27,7 +27,6 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog void init(const QString &site_path, Graph *graph); std::optional filter(); - QString currentVisualSettingsId(); private: void applyTextFilter(); diff --git a/libshvvisu/src/timeline/channelfiltermodel.cpp b/libshvvisu/src/timeline/channelfiltermodel.cpp index 481129093..32a1574b2 100644 --- a/libshvvisu/src/timeline/channelfiltermodel.cpp +++ b/libshvvisu/src/timeline/channelfiltermodel.cpp @@ -31,7 +31,7 @@ void ChannelFilterModel::createNodes(const QSet &channels) endResetModel(); } -QSet ChannelFilterModel::selectedChannels() +QSet ChannelFilterModel::permittedChannels() { QSet channels; selectedChannels_helper(&channels, invisibleRootItem()); diff --git a/libshvvisu/src/timeline/channelfiltermodel.h b/libshvvisu/src/timeline/channelfiltermodel.h index dbd3947d4..0f5f0b622 100644 --- a/libshvvisu/src/timeline/channelfiltermodel.h +++ b/libshvvisu/src/timeline/channelfiltermodel.h @@ -23,7 +23,7 @@ class SHVVISU_DECL_EXPORT ChannelFilterModel : public QStandardItemModel void createNodes(const QSet &channels); - QSet selectedChannels(); + QSet permittedChannels(); void setPermittedChannels(const QSet &channels); void setItemCheckState(const QModelIndex &mi, Qt::CheckState check_state); void fixCheckBoxesIntegrity(); diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index 49d39e35f..19db7a8e9 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -103,12 +103,6 @@ QTimeZone Graph::timeZone() const } #endif -void Graph::resetVisualSettingsAndChannelFilter() -{ - createChannelsFromModel(); - -} - void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sorted) { clearChannels(); @@ -132,14 +126,13 @@ void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sor } for(auto model_ix : model_ixs) { GraphChannel *ch = appendChannel(model_ix); - applyCustomChannelColor(ch); + applyCustomChannelStyle(ch); } resetChannelsRanges(); disableFiltering(); emit layoutChanged(); - emit channelFilterChanged(); } void Graph::resetChannelsRanges() @@ -235,7 +228,6 @@ void Graph::showAllChannels() disableFiltering(); emit layoutChanged(); - emit channelFilterChanged(); } QSet Graph::channelPaths() @@ -289,8 +281,7 @@ const std::optional& Graph::channelFilter() const void Graph::setChannelVisible(qsizetype channel_ix, bool is_visible) { GraphChannel *ch = channelAt(channel_ix); - if (m_channelFilter == std::nullopt) - m_channelFilter = ChannelFilter(); + enableFiltering(); if (is_visible) { m_channelFilter->addPermittedPath(ch->shvPath()); @@ -1182,9 +1173,6 @@ void Graph::setVisualSettingsAndChannelFilter(const VisualSettings &settings) } setChannelFilter(ChannelFilter(permitted_paths, settings.name)); - - emit layoutChanged(); - emit channelFilterChanged(); } void Graph::resizeChannelHeight(qsizetype ix, int delta_px) @@ -2240,7 +2228,7 @@ void Graph::drawCurrentTimeMarker(QPainter *painter, time_t time) drawCenterTopText(painter, p1, text, m_style.font(), color.darker(400), color); } -void Graph::applyCustomChannelColor(GraphChannel *channel) +void Graph::applyCustomChannelStyle(GraphChannel *channel) { static QVector colors { Qt::magenta, @@ -2315,6 +2303,7 @@ void Graph::enableFiltering() void Graph::disableFiltering() { m_channelFilter = std::nullopt; + emit channelFilterChanged(); } void Graph::deleteVisualSettings(const QString &settings_id, const QString &name) const diff --git a/libshvvisu/src/timeline/graph.h b/libshvvisu/src/timeline/graph.h index c05ae08de..39bce9fc8 100644 --- a/libshvvisu/src/timeline/graph.h +++ b/libshvvisu/src/timeline/graph.h @@ -112,7 +112,6 @@ class SHVVISU_DECL_EXPORT Graph : public QObject void setSettingsUserName(const QString &user); - void resetVisualSettingsAndChannelFilter(); enum class SortChannels { No = 0, Yes }; void createChannelsFromModel(SortChannels sorted = SortChannels::Yes); void resetChannelsRanges(); @@ -273,7 +272,7 @@ class SHVVISU_DECL_EXPORT Graph : public QObject virtual void drawCurrentTime(QPainter *painter, int channel_ix); void drawCurrentTimeMarker(QPainter *painter, time_t time); - virtual void applyCustomChannelColor(GraphChannel *channel); + virtual void applyCustomChannelStyle(GraphChannel *channel); QVariantMap mergeMaps(const QVariantMap &base, const QVariantMap &overlay) const; void makeXAxis(); From 026a30ff1a8dfc4381b082ae5d7894467068b265 Mon Sep 17 00:00:00 2001 From: Petr Date: Thu, 9 Nov 2023 10:56:45 +0100 Subject: [PATCH 12/17] added checkbox on fitler settings groupbox --- .../src/timeline/channelfilterdialog.cpp | 12 +++------- libshvvisu/src/timeline/channelfilterdialog.h | 1 - .../src/timeline/channelfilterdialog.ui | 24 +++++++------------ libshvvisu/src/timeline/graph.cpp | 5 +++- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index 84f3c9e3e..26de33667 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -44,9 +44,8 @@ ChannelFilterDialog::ChannelFilterDialog(QWidget *parent) : m_exportViewAction = view_menu->addAction(tr("Export"), this, &ChannelFilterDialog::exportView); m_importViewAction = view_menu->addAction(tr("Import"), this, &ChannelFilterDialog::importView); ui->pbActions->setMenu(view_menu); - ui->gbFilterSetings->setEnabled(ui->chbFileterEnabled->isChecked()); + ui->gbFilterSettings->setChecked(false); - connect(ui->chbFileterEnabled, &QCheckBox::stateChanged, this, &ChannelFilterDialog::onChbFilterEnabledClicked); connect(ui->tvChannelsFilter, &QTreeView::customContextMenuRequested, this, &ChannelFilterDialog::onCustomContextMenuRequested); connect(ui->leMatchingFilterText, &QLineEdit::textChanged, this, &ChannelFilterDialog::onLeMatchingFilterTextChanged); connect(ui->pbClearMatchingText, &QPushButton::clicked, this, &ChannelFilterDialog::onPbClearMatchingTextClicked); @@ -70,7 +69,7 @@ void ChannelFilterDialog::init(const QString &site_path, Graph *graph) m_graph = graph; m_channelsFilterModel->createNodes(graph->channelPaths()); - ui->chbFileterEnabled->setChecked(m_graph->isFilteringEnabled()); + ui->gbFilterSettings->setChecked(m_graph->isFilteringEnabled()); setPermittedChannelsFromGraph(); reloadDataViewsCombobox(); @@ -88,7 +87,7 @@ void ChannelFilterDialog::init(const QString &site_path, Graph *graph) std::optional ChannelFilterDialog::filter() { - if (ui->chbFileterEnabled->isChecked()) { + if (ui->gbFilterSettings->isChecked()) { return ChannelFilter(m_channelsFilterModel->permittedChannels(), ui->cbDataView->currentText()); } @@ -223,11 +222,6 @@ void ChannelFilterDialog::onCustomContextMenuRequested(QPoint pos) } } -void ChannelFilterDialog::onChbFilterEnabledClicked(int state) -{ - ui->gbFilterSetings->setEnabled(state == Qt::CheckState::Checked); -} - void ChannelFilterDialog::onPbCheckItemsClicked() { setVisibleItemsCheckState(Qt::Checked); diff --git a/libshvvisu/src/timeline/channelfilterdialog.h b/libshvvisu/src/timeline/channelfilterdialog.h index 0ba86dfff..d77b45ed7 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.h +++ b/libshvvisu/src/timeline/channelfilterdialog.h @@ -48,7 +48,6 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog void onDataViewChanged(int index); void onCustomContextMenuRequested(QPoint pos); - void onChbFilterEnabledClicked(int state); void onPbCheckItemsClicked(); void onPbUncheckItemsClicked(); void onPbClearMatchingTextClicked(); diff --git a/libshvvisu/src/timeline/channelfilterdialog.ui b/libshvvisu/src/timeline/channelfilterdialog.ui index dd9163685..f8cfe573b 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.ui +++ b/libshvvisu/src/timeline/channelfilterdialog.ui @@ -18,24 +18,18 @@ 0 - - - - true - + + + Channel filter is enabled - - Qt::RightToLeft + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - Enabled + + true - - - - - - + + false diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index 19db7a8e9..ee742475d 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -281,7 +281,10 @@ const std::optional& Graph::channelFilter() const void Graph::setChannelVisible(qsizetype channel_ix, bool is_visible) { GraphChannel *ch = channelAt(channel_ix); - enableFiltering(); + + if (!m_channelFilter && !is_visible) { + m_channelFilter = ChannelFilter(channelPaths()); + } if (is_visible) { m_channelFilter->addPermittedPath(ch->shvPath()); From f2e3badb9867c9ab24baaadb88f65d877e764755 Mon Sep 17 00:00:00 2001 From: Petr Date: Thu, 9 Nov 2023 13:37:15 +0100 Subject: [PATCH 13/17] removed duplicate data widget --- libshvvisu/src/widgets/dataviewwidget.cpp | 14 ----- libshvvisu/src/widgets/dataviewwidget.h | 19 ------- libshvvisu/src/widgets/dataviewwidget.ui | 66 ----------------------- 3 files changed, 99 deletions(-) delete mode 100644 libshvvisu/src/widgets/dataviewwidget.cpp delete mode 100644 libshvvisu/src/widgets/dataviewwidget.h delete mode 100644 libshvvisu/src/widgets/dataviewwidget.ui diff --git a/libshvvisu/src/widgets/dataviewwidget.cpp b/libshvvisu/src/widgets/dataviewwidget.cpp deleted file mode 100644 index 0dfcdb308..000000000 --- a/libshvvisu/src/widgets/dataviewwidget.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "dataviewwidget.h" -#include "ui_dataviewwidget.h" - -DataViewWidget::DataViewWidget(QWidget *parent) : - QWidget(parent), - ui(new Ui::DataViewWidget) -{ - ui->setupUi(this); -} - -DataViewWidget::~DataViewWidget() -{ - delete ui; -} diff --git a/libshvvisu/src/widgets/dataviewwidget.h b/libshvvisu/src/widgets/dataviewwidget.h deleted file mode 100644 index 5232330df..000000000 --- a/libshvvisu/src/widgets/dataviewwidget.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include - -namespace Ui { -class DataViewWidget; -} - -class DataViewWidget : public QWidget -{ - Q_OBJECT - -public: - explicit DataViewWidget(QWidget *parent = nullptr); - ~DataViewWidget(); - -private: - Ui::DataViewWidget *ui; -}; diff --git a/libshvvisu/src/widgets/dataviewwidget.ui b/libshvvisu/src/widgets/dataviewwidget.ui deleted file mode 100644 index 3307580e3..000000000 --- a/libshvvisu/src/widgets/dataviewwidget.ui +++ /dev/null @@ -1,66 +0,0 @@ - - - DataViewWidget - - - - 0 - 0 - 195 - 25 - - - - Form - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Data view: - - - - - - - false - - - QComboBox::AdjustToContents - - - - - - - Channels filter - - - ... - - - - :/shv/visu/images/settings.svg:/shv/visu/images/settings.svg - - - - - - - - - - From df20480fa4d67112d619e0f02c29e9b42738b888 Mon Sep 17 00:00:00 2001 From: Petr Date: Thu, 9 Nov 2023 15:30:39 +0100 Subject: [PATCH 14/17] fixed warnings --- .../shv/visu/timeline/channelfilterdialog.h | 1 + libshvvisu/src/logview/dataviewwidget.cpp | 2 +- .../src/logview/logsortfilterproxymodel.cpp | 2 +- .../src/timeline/channelfilterdialog.cpp | 17 +++++++------ libshvvisu/src/timeline/graph.cpp | 24 +++++++++++-------- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h b/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h index d77b45ed7..a634a8617 100644 --- a/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h +++ b/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h @@ -59,6 +59,7 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog ChannelFilterModel *m_channelsFilterModel = nullptr; ChannelFilterSortFilterProxyModel *m_channelsFilterProxyModel = nullptr; QString m_sitePath; + QString m_recentSettingsDir; QAction *m_saveViewAction = nullptr; QAction *m_saveViewAsAction = nullptr; diff --git a/libshvvisu/src/logview/dataviewwidget.cpp b/libshvvisu/src/logview/dataviewwidget.cpp index be31e7fb5..488256e31 100644 --- a/libshvvisu/src/logview/dataviewwidget.cpp +++ b/libshvvisu/src/logview/dataviewwidget.cpp @@ -41,7 +41,7 @@ void DataViewWidget::init(const QString &site_path, timeline::Graph *graph) void DataViewWidget::onShowChannelFilterClicked() { - tl::ChannelFilterDialog *channel_filter_dialog = new tl::ChannelFilterDialog(this); + auto *channel_filter_dialog = new tl::ChannelFilterDialog(this); channel_filter_dialog->init(m_sitePath, m_graph); if (channel_filter_dialog->exec() == QDialog::Accepted) { diff --git a/libshvvisu/src/logview/logsortfilterproxymodel.cpp b/libshvvisu/src/logview/logsortfilterproxymodel.cpp index 3856b876f..519e086d8 100644 --- a/libshvvisu/src/logview/logsortfilterproxymodel.cpp +++ b/libshvvisu/src/logview/logsortfilterproxymodel.cpp @@ -54,7 +54,7 @@ bool LogSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex if (m_shvPathColumn >= 0) { QModelIndex ix = sourceModel()->index(source_row, m_shvPathColumn, source_parent); - is_row_accepted = (m_channelFilter == std::nullopt) ? true : m_channelFilter->isPathPermitted(sourceModel()->data(ix).toString()); + is_row_accepted = (m_channelFilter) ? m_channelFilter.value().isPathPermitted(sourceModel()->data(ix).toString()) : true; if (is_row_accepted && !m_fulltextFilter.pattern().isEmpty()) { bool is_fulltext_filter_matched = m_fulltextFilter.matches(sourceModel()->data(ix).toString()); diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index 1c6f21bbe..628658fc7 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -15,7 +15,6 @@ namespace shv::visu::timeline { -static QString RECENT_SETTINGS_DIR; static const QString FLATLINE_VIEW_SETTINGS_FILE_TYPE = QStringLiteral("FlatlineViewSettings"); static const QString FLATLINE_VIEW_SETTINGS_FILE_EXTENSION = QStringLiteral(".fvs"); @@ -36,7 +35,7 @@ ChannelFilterDialog::ChannelFilterDialog(QWidget *parent) : ui->tvChannelsFilter->header()->hide(); ui->tvChannelsFilter->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); - QMenu *view_menu = new QMenu(this); + auto *view_menu = new QMenu(this); m_resetViewAction = view_menu->addAction(tr("Discard changes"), this, &ChannelFilterDialog::discardUserChanges); m_saveViewAction = view_menu->addAction(tr("Save"), this, &ChannelFilterDialog::saveView); m_saveViewAsAction = view_menu->addAction(tr("Save as"), this, &ChannelFilterDialog::saveViewAs); @@ -76,8 +75,8 @@ void ChannelFilterDialog::init(const QString &site_path, Graph *graph) std::optional chf = m_graph->channelFilter(); - if ((chf != std::nullopt) && (!chf->name().isEmpty())) - ui->cbDataView->setCurrentText(chf->name()); + if (chf && !chf.value().name().isEmpty()) + ui->cbDataView->setCurrentText(chf.value().name()); else ui->cbDataView->setCurrentIndex(-1); @@ -119,7 +118,7 @@ void ChannelFilterDialog::deleteView() void ChannelFilterDialog::exportView() { - QString file_name = QFileDialog::getSaveFileName(this, tr("Input file name"), RECENT_SETTINGS_DIR, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); + QString file_name = QFileDialog::getSaveFileName(this, tr("Input file name"), m_recentSettingsDir, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); if (!file_name.isEmpty()) { if (!file_name.endsWith(FLATLINE_VIEW_SETTINGS_FILE_EXTENSION)) { file_name.append(FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); @@ -131,13 +130,13 @@ void ChannelFilterDialog::exportView() settings.setValue("fileType", FLATLINE_VIEW_SETTINGS_FILE_TYPE); settings.setValue("settings", m_graph->visualSettings().toJson()); - RECENT_SETTINGS_DIR = QFileInfo(file_name).path(); + m_recentSettingsDir = QFileInfo(file_name).path(); } } void ChannelFilterDialog::importView() { - QString file_name = QFileDialog::getOpenFileName(this, tr("Input file name"), RECENT_SETTINGS_DIR, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); + QString file_name = QFileDialog::getOpenFileName(this, tr("Input file name"), m_recentSettingsDir, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); if (!file_name.isEmpty()) { QString view_name = QInputDialog::getText(this, tr("Import as"), tr("Input view name")); @@ -155,7 +154,7 @@ void ChannelFilterDialog::importView() reloadDataViewsCombobox(); ui->cbDataView->setCurrentText(view_name); - RECENT_SETTINGS_DIR = QFileInfo(file_name).path(); + m_recentSettingsDir = QFileInfo(file_name).path(); } } } @@ -252,7 +251,7 @@ void ChannelFilterDialog::onChbFindRegexChanged(int state) void ChannelFilterDialog::setPermittedChannelsFromGraph() { std::optional f = m_graph->channelFilter(); - m_channelsFilterModel->setPermittedChannels((f == std::nullopt) ? QSet{} : f->permittedPaths()); + m_channelsFilterModel->setPermittedChannels((f) ? f.value().permittedPaths() : QSet{}); } void ChannelFilterDialog::setVisibleItemsCheckState(Qt::CheckState state) diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index c30e93380..526444378 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -18,12 +18,12 @@ #include +namespace shv::visu::timeline { + static const QString USER_PROFILES_KEY = QStringLiteral("userProfiles"); static const QString SITES_KEY = QStringLiteral("sites"); static const QString VIEWS_KEY = QStringLiteral("channelViews"); -namespace shv::visu::timeline { - const QString Graph::DEFAULT_USER_PROFILE = QStringLiteral("default"); static const int VALUE_NOT_AVILABLE_Y = std::numeric_limits::max(); @@ -243,7 +243,7 @@ QSet Graph::channelPaths() void Graph::hideFlatChannels() { - QSet permitted_paths = (isFilteringEnabled()) ? m_channelFilter->permittedPaths() : channelPaths(); + QSet permitted_paths = (m_channelFilter) ? m_channelFilter.value().permittedPaths() : channelPaths(); for (qsizetype i = 0; i < m_channels.count(); ++i) { GraphChannel *ch = m_channels[i]; @@ -253,7 +253,9 @@ void Graph::hideFlatChannels() } enableFiltering(); - m_channelFilter->setPermittedPaths(permitted_paths); + + if (m_channelFilter) + m_channelFilter.value().setPermittedPaths(permitted_paths); emit layoutChanged(); emit channelFilterChanged(); @@ -286,11 +288,13 @@ void Graph::setChannelVisible(qsizetype channel_ix, bool is_visible) m_channelFilter = ChannelFilter(channelPaths()); } - if (is_visible) { - m_channelFilter->addPermittedPath(ch->shvPath()); - } - else { - m_channelFilter->removePermittedPath(ch->shvPath()); + if (m_channelFilter) { + if (is_visible) { + m_channelFilter.value().addPermittedPath(ch->shvPath()); + } + else { + m_channelFilter.value().removePermittedPath(ch->shvPath()); + } } emit layoutChanged(); @@ -1151,7 +1155,7 @@ QVector Graph::visibleChannels() const else if (isFilteringEnabled()) { for (int i = 0; i < m_channels.count(); ++i) { QString shv_path = model()->channelInfo(m_channels[i]->modelIndex()).shvPath; - if(m_channelFilter->isPathPermitted(shv_path)) { + if(m_channelFilter && m_channelFilter.value().isPathPermitted(shv_path)) { visible_channels << i; } } From fc8f05f21df14e383230e6cc4fd2442c1a1acf8c Mon Sep 17 00:00:00 2001 From: Petr Date: Thu, 9 Nov 2023 15:44:11 +0100 Subject: [PATCH 15/17] added missing include for optional --- libshvvisu/include/shv/visu/logview/logsortfilterproxymodel.h | 1 + libshvvisu/include/shv/visu/timeline/channelfilterdialog.h | 2 +- libshvvisu/include/shv/visu/timeline/graph.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libshvvisu/include/shv/visu/logview/logsortfilterproxymodel.h b/libshvvisu/include/shv/visu/logview/logsortfilterproxymodel.h index cda945d09..72d3771db 100644 --- a/libshvvisu/include/shv/visu/logview/logsortfilterproxymodel.h +++ b/libshvvisu/include/shv/visu/logview/logsortfilterproxymodel.h @@ -5,6 +5,7 @@ #include "../timeline/fulltextfilter.h" #include +#include namespace shv { namespace visu { diff --git a/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h b/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h index a634a8617..75b5c9039 100644 --- a/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h +++ b/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h @@ -3,8 +3,8 @@ #include "../shvvisuglobal.h" #include - #include +#include namespace shv { namespace visu { diff --git a/libshvvisu/include/shv/visu/timeline/graph.h b/libshvvisu/include/shv/visu/timeline/graph.h index 39bce9fc8..00f575249 100644 --- a/libshvvisu/include/shv/visu/timeline/graph.h +++ b/libshvvisu/include/shv/visu/timeline/graph.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include From 7b2be640fa34b704aa08e447b2805431af752bbb Mon Sep 17 00:00:00 2001 From: Petr Date: Thu, 9 Nov 2023 15:56:47 +0100 Subject: [PATCH 16/17] added qOverload for combobox signal --- libshvvisu/src/timeline/channelfilterdialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index 628658fc7..fbbe6a058 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -81,7 +81,7 @@ void ChannelFilterDialog::init(const QString &site_path, Graph *graph) ui->cbDataView->setCurrentIndex(-1); updateContextMenuActionsAvailability(); - connect(ui->cbDataView, &QComboBox::currentIndexChanged, this, &ChannelFilterDialog::onDataViewChanged); + connect(ui->cbDataView, qOverload(&QComboBox::currentIndexChanged), this, &ChannelFilterDialog::onDataViewChanged); } std::optional ChannelFilterDialog::filter() From 29ea2ad58c46e8970f4d5b94b8fd7dfdbae68cb7 Mon Sep 17 00:00:00 2001 From: Petr Date: Thu, 9 Nov 2023 17:02:02 +0100 Subject: [PATCH 17/17] refactoring, removed enableFiltering(), disableFiltering(), use only 1 color for basic applyCustomChannelStyle() function --- .../shv/visu/timeline/channelfilterdialog.h | 21 +++-- libshvvisu/include/shv/visu/timeline/graph.h | 4 +- libshvvisu/src/logview/dataviewwidget.cpp | 7 +- .../src/timeline/channelfilterdialog.cpp | 85 +++++++++---------- libshvvisu/src/timeline/graph.cpp | 39 ++------- 5 files changed, 60 insertions(+), 96 deletions(-) diff --git a/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h b/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h index 75b5c9039..0ae932e67 100644 --- a/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h +++ b/libshvvisu/include/shv/visu/timeline/channelfilterdialog.h @@ -22,30 +22,29 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog Q_OBJECT public: - explicit ChannelFilterDialog(QWidget *parent = nullptr); + explicit ChannelFilterDialog(QWidget *parent, const QString &site_path, Graph *graph); ~ChannelFilterDialog(); - void init(const QString &site_path, Graph *graph); - std::optional filter(); + std::optional channelFilter(); private: void applyTextFilter(); void reloadDataViewsCombobox(); - void saveView(); - void saveViewAs(); + void saveDataView(); + void saveDataViewAs(); void discardUserChanges(); - void deleteView(); - void exportView(); - void importView(); + void deleteDataView(); + void exportDataView(); + void importDataView(); - void updateContextMenuActionsAvailability(); + void refreshActions(); void setVisibleItemsCheckState(Qt::CheckState state); void setVisibleItemsCheckState_helper(const QModelIndex &mi, Qt::CheckState state); - void setPermittedChannelsFromGraph(); + void loadChannelFilterFomGraph(); - void onDataViewChanged(int index); + void onDataViewComboboxChanged(int index); void onCustomContextMenuRequested(QPoint pos); void onPbCheckItemsClicked(); diff --git a/libshvvisu/include/shv/visu/timeline/graph.h b/libshvvisu/include/shv/visu/timeline/graph.h index 00f575249..b94a29158 100644 --- a/libshvvisu/include/shv/visu/timeline/graph.h +++ b/libshvvisu/include/shv/visu/timeline/graph.h @@ -234,9 +234,7 @@ class SHVVISU_DECL_EXPORT Graph : public QObject QStringList savedVisualSettingsNames(const QString &settings_id) const; void loadVisualSettings(const QString &settings_id, const QString &name); QString loadedVisualSettingsId(); - bool isFilteringEnabled() const; - void enableFiltering(); - void disableFiltering(); + bool isChannelFilterValid() const; protected: void sanityXRangeZoom(); diff --git a/libshvvisu/src/logview/dataviewwidget.cpp b/libshvvisu/src/logview/dataviewwidget.cpp index 488256e31..146812c69 100644 --- a/libshvvisu/src/logview/dataviewwidget.cpp +++ b/libshvvisu/src/logview/dataviewwidget.cpp @@ -35,17 +35,16 @@ void DataViewWidget::init(const QString &site_path, timeline::Graph *graph) m_sitePath = site_path; connect(graph, &timeline::Graph::channelFilterChanged, this, [this](){ - ui->pbShowChannelFilterDialog->setIcon(m_graph->isFilteringEnabled()? QIcon(QStringLiteral(":/shv/visu/images/filter.svg")): QIcon(QStringLiteral(":/shv/visu/images/filter-off.svg"))); + ui->pbShowChannelFilterDialog->setIcon(m_graph->isChannelFilterValid()? QIcon(QStringLiteral(":/shv/visu/images/filter.svg")): QIcon(QStringLiteral(":/shv/visu/images/filter-off.svg"))); }); } void DataViewWidget::onShowChannelFilterClicked() { - auto *channel_filter_dialog = new tl::ChannelFilterDialog(this); - channel_filter_dialog->init(m_sitePath, m_graph); + auto *channel_filter_dialog = new tl::ChannelFilterDialog(this, m_sitePath, m_graph); if (channel_filter_dialog->exec() == QDialog::Accepted) { - m_graph->setChannelFilter(channel_filter_dialog->filter()); + m_graph->setChannelFilter(channel_filter_dialog->channelFilter()); } channel_filter_dialog->deleteLater(); diff --git a/libshvvisu/src/timeline/channelfilterdialog.cpp b/libshvvisu/src/timeline/channelfilterdialog.cpp index fbbe6a058..504bb41c3 100644 --- a/libshvvisu/src/timeline/channelfilterdialog.cpp +++ b/libshvvisu/src/timeline/channelfilterdialog.cpp @@ -18,12 +18,15 @@ namespace shv::visu::timeline { static const QString FLATLINE_VIEW_SETTINGS_FILE_TYPE = QStringLiteral("FlatlineViewSettings"); static const QString FLATLINE_VIEW_SETTINGS_FILE_EXTENSION = QStringLiteral(".fvs"); -ChannelFilterDialog::ChannelFilterDialog(QWidget *parent) : +ChannelFilterDialog::ChannelFilterDialog(QWidget *parent, const QString &site_path, Graph *graph) : QDialog(parent), ui(new Ui::ChannelFilterDialog) { ui->setupUi(this); + m_sitePath = site_path; + m_graph = graph; + m_channelsFilterModel = new ChannelFilterModel(this); m_channelsFilterProxyModel = new ChannelFilterSortFilterProxyModel(this); @@ -37,40 +40,19 @@ ChannelFilterDialog::ChannelFilterDialog(QWidget *parent) : auto *view_menu = new QMenu(this); m_resetViewAction = view_menu->addAction(tr("Discard changes"), this, &ChannelFilterDialog::discardUserChanges); - m_saveViewAction = view_menu->addAction(tr("Save"), this, &ChannelFilterDialog::saveView); - m_saveViewAsAction = view_menu->addAction(tr("Save as"), this, &ChannelFilterDialog::saveViewAs); - m_deleteViewAction = view_menu->addAction(tr("Delete"), this, &ChannelFilterDialog::deleteView); - m_exportViewAction = view_menu->addAction(tr("Export"), this, &ChannelFilterDialog::exportView); - m_importViewAction = view_menu->addAction(tr("Import"), this, &ChannelFilterDialog::importView); + m_saveViewAction = view_menu->addAction(tr("Save"), this, &ChannelFilterDialog::saveDataView); + m_saveViewAsAction = view_menu->addAction(tr("Save as"), this, &ChannelFilterDialog::saveDataViewAs); + m_deleteViewAction = view_menu->addAction(tr("Delete"), this, &ChannelFilterDialog::deleteDataView); + m_exportViewAction = view_menu->addAction(tr("Export"), this, &ChannelFilterDialog::exportDataView); + m_importViewAction = view_menu->addAction(tr("Import"), this, &ChannelFilterDialog::importDataView); ui->pbActions->setMenu(view_menu); ui->gbFilterSettings->setChecked(false); - connect(ui->tvChannelsFilter, &QTreeView::customContextMenuRequested, this, &ChannelFilterDialog::onCustomContextMenuRequested); - connect(ui->leMatchingFilterText, &QLineEdit::textChanged, this, &ChannelFilterDialog::onLeMatchingFilterTextChanged); - connect(ui->pbClearMatchingText, &QPushButton::clicked, this, &ChannelFilterDialog::onPbClearMatchingTextClicked); - connect(ui->pbCheckItems, &QPushButton::clicked, this, &ChannelFilterDialog::onPbCheckItemsClicked); - connect(ui->pbUncheckItems, &QPushButton::clicked, this, &ChannelFilterDialog::onPbUncheckItemsClicked); -} - -ChannelFilterDialog::~ChannelFilterDialog() -{ - delete ui; -} - -void ChannelFilterDialog::init(const QString &site_path, Graph *graph) -{ - if (m_graph != nullptr) { - shvWarning() << "Dialog is allready initialized."; - return; - } - - m_sitePath = site_path; - m_graph = graph; m_channelsFilterModel->createNodes(graph->channelPaths()); - ui->gbFilterSettings->setChecked(m_graph->isFilteringEnabled()); + ui->gbFilterSettings->setChecked(m_graph->isChannelFilterValid()); - setPermittedChannelsFromGraph(); + loadChannelFilterFomGraph(); reloadDataViewsCombobox(); std::optional chf = m_graph->channelFilter(); @@ -80,11 +62,22 @@ void ChannelFilterDialog::init(const QString &site_path, Graph *graph) else ui->cbDataView->setCurrentIndex(-1); - updateContextMenuActionsAvailability(); - connect(ui->cbDataView, qOverload(&QComboBox::currentIndexChanged), this, &ChannelFilterDialog::onDataViewChanged); + refreshActions(); + + connect(ui->cbDataView, qOverload(&QComboBox::currentIndexChanged), this, &ChannelFilterDialog::onDataViewComboboxChanged); + connect(ui->tvChannelsFilter, &QTreeView::customContextMenuRequested, this, &ChannelFilterDialog::onCustomContextMenuRequested); + connect(ui->leMatchingFilterText, &QLineEdit::textChanged, this, &ChannelFilterDialog::onLeMatchingFilterTextChanged); + connect(ui->pbClearMatchingText, &QPushButton::clicked, this, &ChannelFilterDialog::onPbClearMatchingTextClicked); + connect(ui->pbCheckItems, &QPushButton::clicked, this, &ChannelFilterDialog::onPbCheckItemsClicked); + connect(ui->pbUncheckItems, &QPushButton::clicked, this, &ChannelFilterDialog::onPbUncheckItemsClicked); +} + +ChannelFilterDialog::~ChannelFilterDialog() +{ + delete ui; } -std::optional ChannelFilterDialog::filter() +std::optional ChannelFilterDialog::channelFilter() { if (ui->gbFilterSettings->isChecked()) { return ChannelFilter(m_channelsFilterModel->permittedChannels(), ui->cbDataView->currentText()); @@ -109,14 +102,14 @@ void ChannelFilterDialog::reloadDataViewsCombobox() ui->cbDataView->addItems(m_graph->savedVisualSettingsNames(m_sitePath)); } -void ChannelFilterDialog::deleteView() +void ChannelFilterDialog::deleteDataView() { m_graph->deleteVisualSettings(m_sitePath, ui->cbDataView->currentText()); reloadDataViewsCombobox(); ui->cbDataView->setCurrentIndex(ui->cbDataView->count() - 1); } -void ChannelFilterDialog::exportView() +void ChannelFilterDialog::exportDataView() { QString file_name = QFileDialog::getSaveFileName(this, tr("Input file name"), m_recentSettingsDir, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); if (!file_name.isEmpty()) { @@ -124,7 +117,7 @@ void ChannelFilterDialog::exportView() file_name.append(FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); } - m_graph->setChannelFilter(filter()); + m_graph->setChannelFilter(channelFilter()); QSettings settings(file_name, QSettings::Format::IniFormat); settings.setValue("fileType", FLATLINE_VIEW_SETTINGS_FILE_TYPE); @@ -134,7 +127,7 @@ void ChannelFilterDialog::exportView() } } -void ChannelFilterDialog::importView() +void ChannelFilterDialog::importDataView() { QString file_name = QFileDialog::getOpenFileName(this, tr("Input file name"), m_recentSettingsDir, "*" + FLATLINE_VIEW_SETTINGS_FILE_EXTENSION); if (!file_name.isEmpty()) { @@ -159,25 +152,25 @@ void ChannelFilterDialog::importView() } } -void ChannelFilterDialog::updateContextMenuActionsAvailability() +void ChannelFilterDialog::refreshActions() { m_saveViewAction->setEnabled(!ui->cbDataView->currentText().isEmpty()); m_deleteViewAction->setEnabled(!ui->cbDataView->currentText().isEmpty()); m_resetViewAction->setEnabled(!ui->cbDataView->currentText().isEmpty()); } -void ChannelFilterDialog::saveView() +void ChannelFilterDialog::saveDataView() { if(ui->cbDataView->currentText().isEmpty()) { shvWarning() << "Failed to save empty filter name."; return; } - m_graph->setChannelFilter(filter()); + m_graph->setChannelFilter(channelFilter()); m_graph->saveVisualSettings(m_sitePath, ui->cbDataView->currentText()); } -void ChannelFilterDialog::saveViewAs() +void ChannelFilterDialog::saveDataViewAs() { QString view_name = QInputDialog::getText(this, tr("Save as"), tr("Input view name")); @@ -185,7 +178,7 @@ void ChannelFilterDialog::saveViewAs() QMessageBox::warning(this, tr("Error"), tr("Failed to save view: name is empty.")); } else { - m_graph->setChannelFilter(filter()); + m_graph->setChannelFilter(channelFilter()); m_graph->saveVisualSettings(m_sitePath, view_name); reloadDataViewsCombobox(); ui->cbDataView->setCurrentText(view_name); @@ -194,7 +187,7 @@ void ChannelFilterDialog::saveViewAs() void ChannelFilterDialog::discardUserChanges() { - onDataViewChanged(ui->cbDataView->currentIndex()); + onDataViewComboboxChanged(ui->cbDataView->currentIndex()); } void ChannelFilterDialog::onCustomContextMenuRequested(QPoint pos) @@ -248,7 +241,7 @@ void ChannelFilterDialog::onChbFindRegexChanged(int state) applyTextFilter(); } -void ChannelFilterDialog::setPermittedChannelsFromGraph() +void ChannelFilterDialog::loadChannelFilterFomGraph() { std::optional f = m_graph->channelFilter(); m_channelsFilterModel->setPermittedChannels((f) ? f.value().permittedPaths() : QSet{}); @@ -276,13 +269,13 @@ void ChannelFilterDialog::setVisibleItemsCheckState_helper(const QModelIndex &mi } } -void ChannelFilterDialog::onDataViewChanged(int index) +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()); - setPermittedChannelsFromGraph(); + loadChannelFilterFomGraph(); } - updateContextMenuActionsAvailability(); + refreshActions(); } } diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index 526444378..21e01136d 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -130,9 +130,7 @@ void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sor } resetChannelsRanges(); - disableFiltering(); - - emit layoutChanged(); + setChannelFilter(std::nullopt); } void Graph::resetChannelsRanges() @@ -225,9 +223,7 @@ void Graph::moveChannel(qsizetype channel, qsizetype new_pos) void Graph::showAllChannels() { - disableFiltering(); - - emit layoutChanged(); + setChannelFilter(std::nullopt); } QSet Graph::channelPaths() @@ -252,7 +248,8 @@ void Graph::hideFlatChannels() } } - enableFiltering(); + if (m_channelFilter == std::nullopt) + m_channelFilter = ChannelFilter(); if (m_channelFilter) m_channelFilter.value().setPermittedPaths(permitted_paths); @@ -1152,7 +1149,7 @@ QVector Graph::visibleChannels() const if (maximized_channel >= 0) { visible_channels << maximized_channel; } - else if (isFilteringEnabled()) { + else if (isChannelFilterValid()) { for (int i = 0; i < m_channels.count(); ++i) { QString shv_path = model()->channelInfo(m_channels[i]->modelIndex()).shvPath; if(m_channelFilter && m_channelFilter.value().isPathPermitted(shv_path)) { @@ -2243,18 +2240,8 @@ void Graph::drawCurrentTimeMarker(QPainter *painter, time_t time) void Graph::applyCustomChannelStyle(GraphChannel *channel) { - static QVector colors { - Qt::magenta, - Qt::cyan, - Qt::blue, - QColor(0xe6, 0x3c, 0x33), //red - QColor("orange"), - QColor(0x6d, 0xa1, 0x3a), // green - }; - - auto channel_ix = channelCount() - 1; GraphChannel::Style style = channel->style(); - style.setColor(colors.value(channel_ix % colors.count())); + style.setColor(Qt::cyan); channel->setStyle(style); } @@ -2302,23 +2289,11 @@ void Graph::loadVisualSettings(const QString &settings_id, const QString &name) setVisualSettingsAndChannelFilter(vs); } -bool Graph::isFilteringEnabled() const +bool Graph::isChannelFilterValid() const { return (m_channelFilter != std::nullopt); } -void Graph::enableFiltering() -{ - if (m_channelFilter == std::nullopt) - m_channelFilter = ChannelFilter(); -} - -void Graph::disableFiltering() -{ - m_channelFilter = std::nullopt; - emit channelFilterChanged(); -} - void Graph::deleteVisualSettings(const QString &settings_id, const QString &name) const { QSettings settings;