Profile: add helper function to get the sample entry for a mouse position

This seems quite useful to have.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-11-19 22:31:28 +00:00
parent 21658383e5
commit 639e079131
2 changed files with 15 additions and 0 deletions

View file

@ -1060,6 +1060,20 @@ bool ProfileWidget2::isAddOrPlanner()
return currentState == PLAN || currentState == ADD; return currentState == PLAN || currentState == ADD;
} }
struct plot_data *ProfileWidget2::getEntryFromPos(QPointF pos)
{
// find the time stamp corresponding to the mouse position
int seconds = timeAxis->valueAt(pos);
struct plot_data *entry;
for (int i = 0; i < plotInfo.nr; i++) {
entry = plotInfo.entry + i;
if (entry->sec >= seconds)
break;
}
return entry;
}
void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
{ {
if (currentState == ADD || currentState == PLAN) { if (currentState == ADD || currentState == PLAN) {

View file

@ -134,6 +134,7 @@ private: /*methods*/
void addItemsToScene(); void addItemsToScene();
void setupItemOnScene(); void setupItemOnScene();
void disconnectTemporaryConnections(); void disconnectTemporaryConnections();
struct plot_data *getEntryFromPos(QPointF pos);
private: private:
DivePlotDataModel *dataModel; DivePlotDataModel *dataModel;