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

Method itemChange

src/backend/worksheet/WorksheetElement.cpp:1005–1052  ·  view source on GitHub ↗

called when any property changes (like position)

Source from the content-addressed store, hash-verified

1003
1004// called when any property changes (like position)
1005QVariant WorksheetElementPrivate::itemChange(GraphicsItemChange change, const QVariant& value) {
1006 if (suppressItemChangeEvent || !(this->flags() & QGraphicsItem::ItemIsMovable))
1007 return value;
1008
1009 if (change == QGraphicsItem::ItemPositionChange) {
1010 auto currPos = pos();
1011 auto newPos = value.toPointF();
1012 switch (position.positionLimit) {
1013 case WorksheetElement::PositionLimit::X:
1014 newPos.setY(currPos.y());
1015 break;
1016 case WorksheetElement::PositionLimit::Y:
1017 newPos.setX(currPos.x());
1018 break;
1019 case WorksheetElement::PositionLimit::None:
1020 default:
1021 break;
1022 }
1023
1024 // don't use setPosition here, because then all small changes are on the undo stack
1025 // setPosition is used then in mouseReleaseEvent
1026 if (coordinateBindingEnabled) {
1027 DEBUG(Q_FUNC_INFO << ", coordinate binding enabled")
1028 if (!q->cSystem->isValid())
1029 return QGraphicsItem::itemChange(change, value);
1030 auto pos = q->align(newPos, m_boundingRectangle, horizontalAlignment, verticalAlignment, false);
1031
1032 positionLogical = q->cSystem->mapSceneToLogical(mapParentToPlotArea(pos), AbstractCoordinateSystem::MappingFlag::SuppressPageClipping);
1033 Q_EMIT q->positionLogicalChanged(positionLogical);
1034 Q_EMIT q->objectPositionChanged();
1035 } else {
1036 DEBUG(Q_FUNC_INFO << ", coordinate binding disabled")
1037 auto tempPosition = position;
1038 tempPosition.point = q->align(newPos, boundingRect(), horizontalAlignment, verticalAlignment, false);
1039 // in percentage
1040 auto parentRect = q->parentRect();
1041 tempPosition.point.setX((tempPosition.point.x() - parentRect.x()) / parentRect.width());
1042 tempPosition.point.setY((tempPosition.point.y() - parentRect.y()) / parentRect.height());
1043
1044 // Q_EMIT the signals in order to notify the UI.
1045 Q_EMIT q->positionChanged(tempPosition);
1046 Q_EMIT q->objectPositionChanged();
1047 }
1048 return QGraphicsItem::itemChange(change, newPos);
1049 }
1050
1051 return QGraphicsItem::itemChange(change, value);
1052}
1053
1054/*!
1055 * \brief WorksheetElementPrivate::mapParentToPlotArea

Callers

nothing calls this directly

Calls 11

setYMethod · 0.80
setXMethod · 0.80
xMethod · 0.80
alignMethod · 0.80
parentRectMethod · 0.80
heightMethod · 0.80
flagsMethod · 0.45
yMethod · 0.45
isValidMethod · 0.45
mapSceneToLogicalMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected