Sorry, my description of the error was not accurate. I have a graph in a plot and deselect it by clicking in an empty spot. Thus the graph is unselected. The selection decorator is a QCPSelectionDecoratorBracket, which is, where exactly the error occurs.
It is generated from the call chain
double QCPAbstractPlottable1D<DataType>::dataMainKey called from
QCPSelectionDecoratorBracket::getPixelCoordinates called from
The critial section is:
foreach (const QCPDataRange &dataRange, selection.dataRanges())
// determine position and (if tangent mode is enabled) angle of brackets:
int openBracketDir = (mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed()) ? 1 : -1;
int closeBracketDir = -openBracketDir;
QPointF openBracketPos = getPixelCoordinates(interface1d, dataRange.begin());
QPointF closeBracketPos = getPixelCoordinates(interface1d, dataRange.end()-1);
In the last line, an empty QCPDataRange yields an index of -1. The emptyness is not cheched for.
But this is only part of the problem. Let selection be an empty QCPDataSelection. isEmpty() checks the QList<QCPDataRange> for elements. If there are none, the selection is empty. selection.enforceType(QCP::stDataRange) now takes selection.span(), which returns an empty QCPDataRange for an empty selection, and inserts that in mDataRange.
So now, selection.isEmpty() returns false, because its mDataRange does contain an (empty) QCPDataRange. This is not the answer I would expect!
My bugfix for void QCPDataSelection::enforceType(QCP::SelectionType type) is (only the relevant case is shown here)
QCPDataRange range = span();
mDataRanges << range;