Skip to content

Commit

Permalink
keep graph channel style after reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Špirk committed Oct 13, 2023
1 parent bb93ec5 commit 9fc5401
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
16 changes: 13 additions & 3 deletions libshvvisu/src/timeline/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ void Graph::createChannelsFromModel(shv::visu::timeline::Graph::SortChannels sor
QColor("orange"),
QColor(0x6d, 0xa1, 0x3a), // green
};
QMap<QString, GraphChannel::Style> orig_styles;
for (int i = 0; i < channelCount(); ++i) {
auto *ch = channelAt(i);
orig_styles[ch->shvPath()] = ch->style();
}
clearChannels();
if(!m_model)
return;
Expand All @@ -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();
}
Expand Down
7 changes: 1 addition & 6 deletions libshvvisu/src/timeline/graphwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9fc5401

Please sign in to comment.