From 9fc540162c7a51fa85b900307dcdcab5bc854f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0pirk?= Date: Fri, 13 Oct 2023 11:48:22 +0200 Subject: [PATCH] keep graph channel style after reset --- libshvvisu/src/timeline/graph.cpp | 16 +++++++++++++--- libshvvisu/src/timeline/graphwidget.cpp | 7 +------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index c1f6bfe66..ce407f3ca 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -147,6 +147,11 @@ void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sor QColor("orange"), QColor(0x6d, 0xa1, 0x3a), // green }; + QMap orig_styles; + for (int i = 0; i < channelCount(); ++i) { + auto *ch = channelAt(i); + orig_styles[ch->shvPath()] = ch->style(); + } clearChannels(); if(!m_model) return; @@ -168,9 +173,14 @@ 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); + if (orig_styles.contains(ch->shvPath())) { + ch->setStyle(orig_styles[ch->shvPath()]); + } + else { + GraphChannel::Style style = ch->style(); + style.setColor(colors.value(channel_ix % colors.count())); + ch->setStyle(style); + } } resetChannelsRanges(); } diff --git a/libshvvisu/src/timeline/graphwidget.cpp b/libshvvisu/src/timeline/graphwidget.cpp index 0bac7ee1c..40e5d6a6a 100644 --- a/libshvvisu/src/timeline/graphwidget.cpp +++ b/libshvvisu/src/timeline/graphwidget.cpp @@ -759,12 +759,7 @@ void GraphWidget::showGraphContextMenu(const QPoint &mouse_pos) menu.addAction(tr("Hide channels without changes"), this, [this]() { m_graph->hideFlatChannels(); }); - menu.addAction(tr("Reset channels to defaults"), this, [this]() { - m_graph->createChannelsFromModel(); - auto graph_filter = m_graph->channelFilter(); - graph_filter.setMatchingPaths(m_graph->channelPaths()); - m_graph->setChannelFilter(graph_filter); - }); + menu.addAction(tr("Reset channels to defaults"), m_graph, &Graph::reset); if (m_graph->isYAxisVisible()) { menu.addAction(tr("Hide Y axis"), this, [this]() { m_graph->setYAxisVisible(false);