MCPcopy Create free account
hub / github.com/KDE/labplot / mouseMoveEvent

Method mouseMoveEvent

src/backend/worksheet/InfoElement.cpp:1119–1168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1117}
1118
1119void InfoElementPrivate::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
1120 const auto eventPos = mapToParent(event->pos());
1121 // DEBUG("EventPos: " << eventPos.x() << " Y: " << eventPos.y());
1122 const auto delta = eventPos - oldMousePos;
1123 if (delta == QPointF(0, 0))
1124 return;
1125
1126 if (!q->cSystem->isValid())
1127 return;
1128 const auto eventLogicPos = q->cSystem->mapSceneToLogical(eventPos, AbstractCoordinateSystem::MappingFlag::SuppressPageClipping);
1129 const auto delta_logic = eventLogicPos - q->cSystem->mapSceneToLogical(oldMousePos);
1130
1131 if (!q->m_title)
1132 return;
1133 if (q->markerpoints.isEmpty())
1134 return;
1135
1136 // TODO: find better method to do this. It's inefficient.
1137 // Finding which curve should be used to find the new values
1138 double x = positionLogical;
1139 int activeIndex = 0;
1140 for (int i = 1; i < q->markerPointsCount(); i++) {
1141 if (q->markerpoints[i].curve->name().compare(connectionLineCurveName) == 0) {
1142 // not possible to use index, because when the number of elements in the columns of the curves are not the same there is a problem
1143 x = q->markerpoints[i].customPoint->positionLogical().x(); // q->markerpoints[i].curve->xColumn()->valueAt(m_index)
1144 activeIndex = i;
1145 break;
1146 }
1147 }
1148 x += delta_logic.x();
1149 auto xColumn = q->markerpoints[activeIndex].curve->xColumn();
1150 if (!xColumn)
1151 return;
1152 int xindex = xColumn->indexForValue(x, false);
1153 double x_new = NAN;
1154 if (xColumn->isNumeric())
1155 x_new = xColumn->valueAt(xindex);
1156 else
1157 x_new = xColumn->dateTimeAt(xindex).toMSecsSinceEpoch();
1158
1159 auto pointPos = q->markerpoints[activeIndex].customPoint->positionLogical().x();
1160 if (abs(x_new - pointPos) > 0) {
1161 if ((xColumn->rowCount() - 1 == xindex && pointPos > x_new) || (xindex == 0 && pointPos < x_new)) {
1162 q->setPositionLogical(x_new);
1163 } else {
1164 oldMousePos = eventPos;
1165 q->setPositionLogical(x);
1166 }
1167 }
1168}
1169
1170void InfoElementPrivate::keyPressEvent(QKeyEvent* event) {
1171 if (m_suppressKeyPressEvents) {

Callers

nothing calls this directly

Calls 13

markerPointsCountMethod · 0.80
xMethod · 0.80
QPointFClass · 0.50
isValidMethod · 0.45
mapSceneToLogicalMethod · 0.45
isEmptyMethod · 0.45
nameMethod · 0.45
indexForValueMethod · 0.45
isNumericMethod · 0.45
valueAtMethod · 0.45
dateTimeAtMethod · 0.45
rowCountMethod · 0.45

Tested by

no test coverage detected