QtMobility Reference Documentation

QOrientableSensorBase Class Reference

The QOrientableSensorBase class is the base class for all sensors that react to screen orientation changes. More...

 #include <QOrientableSensorBase>

Inherited by: QAccelerometer, QCompass, QGyroscope, QMagnetometer, and QRotationSensor.

Public Types

enum AxesOrientationMode { FixedOrientation, AutomaticOrientation, UserOrientation }

Properties

Public Functions

QOrientableSensorBase ()
virtual ~QOrientableSensorBase ()
AxesOrientationMode axesOrientationMode () const
int currentOrientation () const
void setAxesOrientationMode ( AxesOrientationMode axesOrientationMode )
void setCurrentOrientation ( int currentOrientation )
void setUserOrientation ( int userOrientation )
int userOrientation () const

Signals

void axesOrientationModeChanged ( AxesOrientationMode axesOrientationMode )
void currentOrientationChanged ( int currentOrientation )
void userOrientationChanged ( int userOrientation )

Detailed Description

The QOrientableSensorBase class is the base class for all sensors that react to screen orientation changes.

All sensors based on this class support changing the reporting of the reading values based on the orientation of the screen. This is controlled by the axesOrientationMode property, which controls how the orientation affects the reading values.

In the default mode, QOrientableSensorBase::FixedOrientation, the reading values remain unaffected by the orientation. In the QOrientableSensorBase::AutomaticOrientation mode, the reading values are automatically rotated by taking the current screen orientation into account. And finally, in the QOrientableSensorBase::UserOrientation mode, the reading values are rotated according to a user-specified orientation.

The functionality of this is only available if it is supported by the backend, which can be checked by calling QSensor::isFeatureSupported() with the QSensor::AxesOrientation flag.

The orientation here is always the screen orientation, not the device orientation. The orientation values range from 0 to 270 degrees. The orientation is applied in clockwise direction. Note that when rotating a device by 90 degrees counter-clockwise, the screen orientation compensates for that by rotating 90 degrees to the right.

Member Type Documentation

enum QOrientableSensorBase::AxesOrientationMode

Describes how reading values are affected by the screen orientation.

ConstantValueDescription
QOrientableSensorBase::FixedOrientation0No automatic rotation is applied to the reading values.
QOrientableSensorBase::AutomaticOrientation1The reading values are automatically rotated based on the screen orientation.
QOrientableSensorBase::UserOrientation2The reading values are rotated based on the angle of the userOrientation property.

See also QOrientableSensorBase::axesOrientationMode.

Property Documentation

axesOrientationMode : AxesOrientationMode

This property holds the mode that affects how the screen orientation changes reading values.

When set to FixedOrientation, which is the default mode, no automatic rotation is applied to the reading. This is the only mode available for backends that do not support the QSensor::AxesOrientation feature.

When set to AutomaticOrientation, the reading values are automatically rotated when the screen orientation changes. In effect, the screen orientation is canceled out.

As an example, assume the device is rotated by 180 degrees and therefore the screen orientation also is rotated by 180 degrees from the native orientation. Without automatic axes orientation, the reading values would now be changed: Both the X and the Y values would be negated, forcing an application developer to manually cancel out the negation in application code. Automatic axes orientation does this automatically, in this mode the X and Y values would be the same as with the default screen orientation.

This automatic rotation of the axes is handy is some usecases, for example in a bubble level application that measures how level a surface is by looking at the X axis value of an accelerometer. When the device and screen orientation change by 90 degrees, an application developer does not need to change anything, he can continue using the X axis value even though the device is rotated. Without automatic axes orientation, the application developer would need to look at the Y values instead, thereby adding code to the application that reads from a different axis depending on the screen orientation.

The UserOrientation mode is quite similar to AutomaticOrientation, only that the screen orientation is manually controlled instead of automatically determined. The angle of the userOrientation property is then used for rotating the reading values.

Since the rotation of the reading values is based on the screen orientation, Z values will never change, as the Z axis is perpendicular to the screen. As screen orientation changes in 90 degree steps, rotating the reading values is also done in steps of 90 degrees.

Access functions:

AxesOrientationMode axesOrientationMode () const
void setAxesOrientationMode ( AxesOrientationMode axesOrientationMode )

Notifier signal:

void axesOrientationModeChanged ( AxesOrientationMode axesOrientationMode )

currentOrientation : const int

This property holds the current orientation that is used for rotating the reading values.

This might not be the same as the screen orientation. For example, in the FixedOrientation mode, the reading values are not rotated, and therefore the property is 0.

In the UserOrientation mode, the readings are rotated based on the userOrientation property, and therefore this property is equal to the userOrientation property.

In the AutomaticOrientation mode, the readings are rotated based on the screen orientation, and therefore this property will be equal to the current screen orientation.

This property is set by the backend.

Access functions:

int currentOrientation () const

Notifier signal:

void currentOrientationChanged ( int currentOrientation )

userOrientation : int

This property holds the angle used for rotating the reading values in the UserOrientation mode.

When the axesOrientationMode property is set to UserOrientation, the angle for rotating the reading values is taken from this property. In other modes, the property has no effect.

The default is 0. The only valid values are 0, 90, 180 and 270, as those are the only possible screen orientations.

Access functions:

int userOrientation () const
void setUserOrientation ( int userOrientation )

Notifier signal:

void userOrientationChanged ( int userOrientation )

Member Function Documentation

QOrientableSensorBase::QOrientableSensorBase ()

Constructs a QOrientableSensorBase.

QOrientableSensorBase::~QOrientableSensorBase () [virtual]

Destroys a QOrientableSensorBase.

void QOrientableSensorBase::axesOrientationModeChanged ( AxesOrientationMode axesOrientationMode ) [signal]

void QOrientableSensorBase::currentOrientationChanged ( int currentOrientation ) [signal]

void QOrientableSensorBase::setCurrentOrientation ( int currentOrientation )

Sets the current screen orientation to currentOrientation. This is to be called from the backend whenever the screen orientation or the userOrientation property changes.

See also currentOrientation().

void QOrientableSensorBase::userOrientationChanged ( int userOrientation ) [signal]

X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.