! Returns the item at the pixel position \a pos. Items that only consist of single lines (e.g. \ref QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is returned. If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are cons
| 13925 | \see plottableAt, layoutElementAt |
| 13926 | */ |
| 13927 | QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const |
| 13928 | { |
| 13929 | QCPAbstractItem *resultItem = 0; |
| 13930 | double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value |
| 13931 | |
| 13932 | foreach (QCPAbstractItem *item, mItems) |
| 13933 | { |
| 13934 | if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable |
| 13935 | continue; |
| 13936 | if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it |
| 13937 | { |
| 13938 | double currentDistance = item->selectTest(pos, false); |
| 13939 | if (currentDistance >= 0 && currentDistance < resultDistance) |
| 13940 | { |
| 13941 | resultItem = item; |
| 13942 | resultDistance = currentDistance; |
| 13943 | } |
| 13944 | } |
| 13945 | } |
| 13946 | |
| 13947 | return resultItem; |
| 13948 | } |
| 13949 | |
| 13950 | /*! |
| 13951 | Returns whether this QCustomPlot contains the \a item. |
nothing calls this directly
no outgoing calls
no test coverage detected