Luke
Luke

Reputation: 2400

Manual rectangular selection of items in QCustomPlot

I'm working on a simple GUI with plot where you can set some x and y ranges. How can I select all items from all graphs on the plot that are within those ranges? I was trying to reproduce the same algorithms that are run on mouse rectangular multi range selection but I have not succeed. I hope there is some easier way that I am missing.

Example:enter image description here

Lets say that A and B are a pair of QCPRanges:

QCPRange A = QCPRange(2,4);
QCPRange B = QCPRange(1,8);

I would like to mark points on the plot that are within A and B ranges.

I am looking for some clues and tips to follow, not really a full copy-paste ready code.

Upvotes: 1

Views: 730

Answers (1)

Luke
Luke

Reputation: 2400

I achieved what I wanted by:

  1. getting all records from all graphs by iterating all data() for each graph in plot->getAllGraphs();

  2. checking QCPRanges if they contain every single data point

  3. building QCPDataRanges based on indexes which meet QCPRanges requirements

  4. building QCPSelection out of QCPDataRanges.

  5. setting appropriate selection for every graph in the loop.

Note: To make it work interaction QCP::iMultiSelect must be set for the plot. Also you need to setSelectable(QCP::stMultipleDataRanges) for every graph. Otherwise you might get an unwanted behavior as a result of selection.

Not really the most optimized way in the world but I couldn't think of anything better without rewriting part of the lib. Any better ways are welcome

Upvotes: 1

Related Questions