From c40585750e9aa4aac5621a5277911972f4959dbd Mon Sep 17 00:00:00 2001 From: Vladyslav Goncharuk Date: Fri, 31 May 2024 18:20:55 +0300 Subject: [PATCH] [ISSUE #190][PLOT_VIEW] Undo filtering with "F" doesn`t work This patch extends the logic of filtering of the selected plot. Signed-off-by: Vladyslav Goncharuk --- .../plotView/src/CCustomPlotExtended.cpp | 90 ++++++++++--------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/dltmessageanalyzerplugin/src/components/plotView/src/CCustomPlotExtended.cpp b/dltmessageanalyzerplugin/src/components/plotView/src/CCustomPlotExtended.cpp index 11c6d98e..7db43429 100644 --- a/dltmessageanalyzerplugin/src/components/plotView/src/CCustomPlotExtended.cpp +++ b/dltmessageanalyzerplugin/src/components/plotView/src/CCustomPlotExtended.cpp @@ -498,19 +498,22 @@ std::pair CCustomPlotExtended::getAxisRectType(QCPAxisR void CCustomPlotExtended::filterGraphBySelectedItem() { - int numberOfVisibleGraphs = 0; - QCPPlottableLegendItem* pSelectedLegendItem = nullptr; - const QCPLegend* pSelectedLegend = nullptr; + bool bReplot = false; + bool isSelectedItemAvailable =false; for(const auto& axisRectPair : mPlotAxisRectDataMap) { - bool leaveCycle = false; + QCPPlottableLegendItem* pSelectedLegendItem = nullptr; + int numberOfVisibleGraphs = 0; + int numberOfGraphs = 0; const auto* pLegend = axisRectPair.second.pLegend; if(nullptr != pLegend) { - for (int i = 0; i < pLegend->itemCount(); ++i) + numberOfGraphs = pLegend->itemCount(); + + for (int i = 0; i < numberOfGraphs; ++i) { QCPPlottableLegendItem* pItem = qobject_cast(pLegend->item(i)); if (nullptr != pItem) @@ -520,69 +523,69 @@ void CCustomPlotExtended::filterGraphBySelectedItem() ++numberOfVisibleGraphs; } - if(nullptr == pSelectedLegendItem || nullptr == pSelectedLegend) + if(nullptr == pSelectedLegendItem) { if(false == pItem->plottable()->selection().isEmpty()) { pSelectedLegendItem = pItem; - pSelectedLegend = pLegend; + isSelectedItemAvailable = true; } } - - if(numberOfVisibleGraphs > 1 && - nullptr != pSelectedLegendItem && - nullptr != pSelectedLegend) - { - leaveCycle = true; - break; - } } } - if(true == leaveCycle) + enum class eAction { - break; - } - } - } + eApplyFiltrer, + eRemoveFiltrer, + eDoNothing + }; - bool bReplot = false; + eAction action = eAction::eDoNothing; - if(nullptr != pSelectedLegend) - { - bool bFilterOut = numberOfVisibleGraphs > 1; + if(numberOfGraphs != numberOfVisibleGraphs && numberOfVisibleGraphs > 1 && nullptr == pSelectedLegendItem) + action = eAction::eDoNothing; + else if(numberOfVisibleGraphs > 1 && numberOfVisibleGraphs > 1 && nullptr != pSelectedLegendItem) + action = eAction::eApplyFiltrer; + else if(numberOfGraphs > 1 && numberOfVisibleGraphs == 1 && nullptr != pSelectedLegendItem) + action = eAction::eRemoveFiltrer; - for (int i = 0; i < pSelectedLegend->itemCount(); ++i) - { - QCPPlottableLegendItem* pItem = qobject_cast(pSelectedLegend->item(i)); - - if(nullptr != pItem) + for (int i = 0; i < pLegend->itemCount(); ++i) { - if(true == bFilterOut) - { - if(true == pItem->plottable()->visible() && pItem != pSelectedLegendItem) - { - changeLegendItemVisibility(pItem); - bReplot = true; - } - } - else + QCPPlottableLegendItem* pItem = qobject_cast(pLegend->item(i)); + + if(nullptr != pItem) { - if(false == pItem->plottable()->visible()) + switch(action) { - changeLegendItemVisibility(pItem); - bReplot = true; + case eAction::eApplyFiltrer: + if(true == pItem->plottable()->visible() && pItem != pSelectedLegendItem) + { + changeLegendItemVisibility(pItem); + bReplot = true; + } + break; + case eAction::eRemoveFiltrer: + if(false == pItem->plottable()->visible()) + { + changeLegendItemVisibility(pItem); + bReplot = true; + } + break; + case eAction::eDoNothing: + // do nothing + break; } } } } } - else + + if(false == isSelectedItemAvailable) { for(const auto& axisRectPair : mPlotAxisRectDataMap) { const auto* pLegend = axisRectPair.second.pLegend; - if(nullptr != pLegend) { for (int i = 0; i < pLegend->itemCount(); ++i) @@ -599,6 +602,7 @@ void CCustomPlotExtended::filterGraphBySelectedItem() } } } + } if(true == bReplot)