سؤال

I know that it is possible to use affine transformations with Qt. But is it also possible to set a complete custom global transformation method?

Use case: Drawing projected geographic points (lat, long) or retrieve mouse events etc. in geographic corrdinates (in the context of a QGraphicsScene/View).

At the moment I use it like that (little bit pseudo code):

MyPoint pt = myProjection(geographicPoint);
QPoint(pt.x, pt.y);

// or, to make it shorter, but essentially it's the same
QPoint p  = myProjection(geoPoint);

geoPoint = myBackProjection(mouseEvent.getPoint());

And I'd like to do "register" my transformation methods somewhere so that the QGraphicsView (or whoever is responsible) internally uses these methods before it draws something on the screen.

Or does that neither make sense (because it would introduce problems where I don't expect them, e.g. in calculating distances) nor is it possible?

هل كانت مفيدة؟

المحلول

QGraphicsView uses a QTransform matrix, which is a 3x3 matrix. Therefore you can only do linear transformations. In Qt5/QtQuick or with QtQuick3d you may be able to achieve this with a QML ShaderProgram.

In "pure" Qt4 you would have to derive your own custom class from QGraphicsView, or QAbstractScrollArea or QGraphicsScene and override the paint methods.

نصائح أخرى

A good approach would be to encapsulate this transform in your QGraphicsItem shape() method. Suppose you have a point defined as a pair of latitude and longitude, it would store pairs of lat lon, but its shape method would return projected values (usually in pixel equivalents).

If you feel like it, you could even subclass QPoint to make it geographically aware, thus creating it with latlon, but exposing projected values in its x, y properties.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top