Skip to content

Commit

Permalink
Merge pull request #199 from svlad-90/dev/vladyslav-goncharuk/ISSUE-190
Browse files Browse the repository at this point in the history
[ISSUE #190][PLOT_VIEW] Undo filtering with "F" doesn`t work
  • Loading branch information
svlad-90 authored May 31, 2024
2 parents bd71ef3 + c405857 commit be913cd
Showing 1 changed file with 47 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,19 +498,22 @@ std::pair<bool, ePlotViewAxisType> 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<QCPPlottableLegendItem*>(pLegend->item(i));
if (nullptr != pItem)
Expand All @@ -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<QCPPlottableLegendItem*>(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<QCPPlottableLegendItem*>(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)
Expand All @@ -599,6 +602,7 @@ void CCustomPlotExtended::filterGraphBySelectedItem()
}
}
}

}

if(true == bReplot)
Expand Down

0 comments on commit be913cd

Please sign in to comment.