[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Thu Mar 6 20:16:02 CET 2008
SVN commit 783010 by fenton:
Fix Log Axis Mouse Zoom.
Move all point/rect projection calculations to PlotItem.
M +18 -75 plotitem.cpp
M +3 -15 plotitem.h
M +3 -39 plotrenderitem.cpp
M +0 -7 plotrenderitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #783009:783010
@@ -1280,7 +1280,23 @@
}
-QPointF PlotItem::mapPointToProjection(const QPointF &point) {
+QRectF PlotItem::mapToProjection(const QRectF &rect) {
+ QRectF projRect;
+
+ // Invert and convert points.
+ QPointF topLeft = mapToProjection(rect.bottomLeft());
+ QPointF bottomRight = mapToProjection(rect.topRight());
+
+ projRect.setTopLeft(topLeft);
+
+ projRect.setWidth(bottomRight.x() - topLeft.x());
+ projRect.setHeight(bottomRight.y() - topLeft.y());
+
+ return projRect;
+}
+
+
+QPointF PlotItem::mapToProjection(const QPointF &point) {
QRectF pr = plotRect();
double xpos, ypos;
@@ -1312,7 +1328,7 @@
}
-QPointF PlotItem::mapPointToPlot(const QPointF &point) const {
+QPointF PlotItem::mapToPlot(const QPointF &point) const {
return QPointF(mapXToPlot(point.x()), mapYToPlot(point.y()));
}
@@ -1369,79 +1385,6 @@
}
-QPointF PlotItem::mapFromAxisToProjection(const QPointF &point) const {
- return projectionAxisTransform().map(point);
-}
-
-
-QPointF PlotItem::mapToAxisFromProjection(const QPointF &point) const {
- return projectionAxisTransform().inverted().map(point);
-}
-
-
-QRectF PlotItem::mapFromAxisToProjection(const QRectF &rect) const {
- return projectionAxisTransform().mapRect(rect);
-}
-
-
-QRectF PlotItem::mapToAxisFromProjection(const QRectF &rect) const {
- return projectionAxisTransform().inverted().mapRect(rect);
-}
-
-
-QTransform PlotItem::projectionAxisTransform() const {
- QTransform t;
-
- QRectF rect = plotAxisRect();
- QRectF v = QRectF(rect.bottomLeft(), rect.topRight());
-
- QPolygonF from_ = QPolygonF(v);
- from_.pop_back(); //get rid of last closed point
-
- QPolygonF to_ = QPolygonF(projectionRect());
- to_.pop_back(); //get rid of last closed point
-
- QTransform::quadToQuad(from_, to_, t);
- return t;
-}
-
-
-QPointF PlotItem::mapFromPlotToProjection(const QPointF &point) const {
- return projectionPlotTransform().map(point);
-}
-
-
-QPointF PlotItem::mapToPlotFromProjection(const QPointF &point) const {
- return projectionPlotTransform().inverted().map(point);
-}
-
-
-QRectF PlotItem::mapFromPlotToProjection(const QRectF &rect) const {
- return projectionPlotTransform().mapRect(rect);
-}
-
-
-QRectF PlotItem::mapToPlotFromProjection(const QRectF &rect) const {
- return projectionPlotTransform().inverted().mapRect(rect);
-}
-
-
-QTransform PlotItem::projectionPlotTransform() const {
- QTransform t;
-
- QRectF rect = plotRect();
- QRectF v = QRectF(rect.bottomLeft(), rect.topRight());
-
- QPolygonF from_ = QPolygonF(v);
- from_.pop_back(); //get rid of last closed point
-
- QPolygonF to_ = QPolygonF(projectionRect());
- to_.pop_back(); //get rid of last closed point
-
- QTransform::quadToQuad(from_, to_, t);
- return t;
-}
-
QFont PlotItem::rightLabelFont() const {
return _rightLabelFont;
}
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #783009:783010
@@ -228,21 +228,13 @@
PlotMarkers yAxisPlotMarkers() { return _yAxisPlotMarkers; }
void setYAxisPlotMarkers(const PlotMarkers &plotMarkers) { _yAxisPlotMarkers = plotMarkers; }
- QPointF mapPointToPlot(const QPointF &point) const;
qreal mapXToPlot(const qreal &x) const;
qreal mapYToPlot(const qreal &y) const;
- QPointF mapPointToProjection(const QPointF &point);
+ QPointF mapToPlot(const QPointF &point) const;
- QPointF mapFromAxisToProjection(const QPointF &point) const;
- QPointF mapToAxisFromProjection(const QPointF &point) const;
- QRectF mapFromAxisToProjection(const QRectF &rect) const;
- QRectF mapToAxisFromProjection(const QRectF &rect) const;
+ QPointF mapToProjection(const QPointF &point);
+ QRectF mapToProjection(const QRectF &rect);
- QPointF mapFromPlotToProjection(const QPointF &point) const;
- QPointF mapToPlotFromProjection(const QPointF &point) const;
- QRectF mapFromPlotToProjection(const QRectF &rect) const;
- QRectF mapToPlotFromProjection(const QRectF &rect) const;
-
void updateScale();
qreal xMin() { return _xMin; }
@@ -340,10 +332,6 @@
private Q_SLOTS:
void calculateProjectionRect();
- protected:
- virtual QTransform projectionAxisTransform() const;
- virtual QTransform projectionPlotTransform() const;
-
private:
QHash<PlotRenderItem::RenderType, PlotRenderItem*> _renderers;
bool _isTiedZoom;
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #783009:783010
@@ -530,7 +530,7 @@
}
updateCursor(event->pos());
- const QRectF projection = mapToProjection(_selectionRect.rect());
+ const QRectF projection = plotItem()->mapToProjection(_selectionRect.rect());
_selectionRect.reset();
zoomFixedExpression(projection);
@@ -541,7 +541,7 @@
ViewItem::hoverMoveEvent(event);
updateCursor(event->pos());
- const QPointF p = plotItem()->mapPointToProjection(event->pos());
+ const QPointF p = plotItem()->mapToProjection(event->pos());
QString message = QString("(%1, %2)").arg(QString::number(p.x(), 'G')).arg(QString::number(p.y()));
kstApp->mainWindow()->statusBar()->showMessage(message);
}
@@ -552,7 +552,7 @@
updateCursor(event->pos());
- const QPointF p = plotItem()->mapPointToProjection(event->pos());
+ const QPointF p = plotItem()->mapToProjection(event->pos());
QString message = QString("(%1, %2)").arg(QString::number(p.x())).arg(QString::number(p.y()));
kstApp->mainWindow()->statusBar()->showMessage(message);
}
@@ -567,42 +567,6 @@
}
-QTransform PlotRenderItem::projectionTransform() const {
- QTransform t;
-
- QRectF v = QRectF(rect().bottomLeft(), rect().topRight());
-
- QPolygonF from_ = QPolygonF(v);
- from_.pop_back(); //get rid of last closed point
-
- QPolygonF to_ = QPolygonF(projectionRect());
- to_.pop_back(); //get rid of last closed point
-
- QTransform::quadToQuad(from_, to_, t);
- return t;
-}
-
-
-QPointF PlotRenderItem::mapToProjection(const QPointF &point) const {
- return projectionTransform().map(point);
-}
-
-
-QPointF PlotRenderItem::mapFromProjection(const QPointF &point) const {
- return projectionTransform().inverted().map(point);
-}
-
-
-QRectF PlotRenderItem::mapToProjection(const QRectF &rect) const {
- return projectionTransform().mapRect(rect);
-}
-
-
-QRectF PlotRenderItem::mapFromProjection(const QRectF &rect) const {
- return projectionTransform().inverted().mapRect(rect);
-}
-
-
void PlotRenderItem::zoomFixedExpression(const QRectF &projection) {
qDebug() << "zoomFixedExpression" << endl;
ZoomCommand *cmd = new ZoomFixedExpressionCommand(this, projection);
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.h #783009:783010
@@ -82,11 +82,6 @@
QString rightLabel() const;
QString topLabel() const;
- QPointF mapToProjection(const QPointF &point) const;
- QPointF mapFromProjection(const QPointF &point) const;
- QRectF mapToProjection(const QRectF &rect) const;
- QRectF mapFromProjection(const QRectF &rect) const;
-
Q_SIGNALS:
void projectionRectChanged();
@@ -122,8 +117,6 @@
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
- virtual QTransform projectionTransform() const;
-
virtual QPainterPath shape() const;
virtual QRectF boundingRect() const;
virtual QSizeF sizeOfGrip() const;
More information about the Kst
mailing list