src/location/qgeoareamonitor.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include "qgeoareamonitor.h"
       
    42 
       
    43 #if defined(Q_OS_SYMBIAN) && defined(QT_LOCATION_S60_MONITORING)
       
    44 #include "qgeoareamonitor_s60_p.h"
       
    45 #elif defined(Q_WS_MAEMO_5)
       
    46 #include "qgeoareamonitor_maemo_p.h"
       
    47 #endif
       
    48 
       
    49 /*!
       
    50     \class QGeoAreaMonitor
       
    51     \brief The QGeoAreaMonitor class enables the detection of proximity
       
    52     changes for a specified set of coordinates.
       
    53     \ingroup location
       
    54 
       
    55     A QGeoAreaMonitor emits signals when the current position is in
       
    56     range, or has moved out of range, of a specified circular area.
       
    57     The area is specified by a coordinate (the center point) and a
       
    58     radius (in meters).
       
    59 
       
    60     For example:
       
    61 
       
    62     \code
       
    63         public:
       
    64             MyClass::MyClass()
       
    65             {
       
    66                 QGeoAreaMonitor *monitor = QGeoAreaMonitor::createDefaultMonitor();
       
    67                 connect(monitor, SIGNAL(areaEntered(QGeoPositionInfo)),
       
    68                         this, SLOT(areaEntered(QGeoPositionInfo)));
       
    69                 connect(monitor, SIGNAL(areaExited(QGeoPositionInfo)),
       
    70                         this, SLOT(areaExited(QGeoPositionInfo)));
       
    71 
       
    72                 QGeoCoordinate bigBenLocation(51.50104, -0.124632);
       
    73                 monitor->setCenter(bigBenLocation);
       
    74                 monitor->setRadius(100);
       
    75             }
       
    76 
       
    77         public Q_SLOTS:
       
    78             void areaEntered(const QGeoPositionInfo &update)
       
    79             {
       
    80                 qDebug() << "Now within 100 meters, current position is" << update.coordinate();
       
    81             }
       
    82 
       
    83             void areaExited(const QGeoPositionInfo &update)
       
    84             {
       
    85                 qDebug() << "No longer within 100 meters, current position is" << update.coordinate();
       
    86             }
       
    87     \endcode
       
    88 */
       
    89 
       
    90 QTM_BEGIN_NAMESPACE
       
    91 
       
    92 class QGeoAreaMonitorPrivate
       
    93 {
       
    94 public:
       
    95     QGeoCoordinate coord;
       
    96     qreal radius;
       
    97 };
       
    98 
       
    99 
       
   100 /*!
       
   101     Creates a monitor with the given \a parent.
       
   102 */
       
   103 QGeoAreaMonitor::QGeoAreaMonitor(QObject *parent)
       
   104         : QObject(parent),
       
   105         d(new QGeoAreaMonitorPrivate)
       
   106 {
       
   107     d->radius = qreal(0.0);
       
   108 }
       
   109 
       
   110 /*!
       
   111     Destroys the monitor.
       
   112 */
       
   113 QGeoAreaMonitor::~QGeoAreaMonitor()
       
   114 {
       
   115     delete d;
       
   116 }
       
   117 
       
   118 /*!
       
   119     \property QGeoAreaMonitor::center
       
   120     \brief holds the center of the area to be monitored.
       
   121 
       
   122     When the center is set, if the radius has already been set and
       
   123     the current position is within the monitored area, areaEntered()
       
   124     is emitted immediately.
       
   125 
       
   126     By default, contains an invalid coordinate.
       
   127 
       
   128     Note: Subclass implementations must call the base implementation of
       
   129     setCenter() so that center() returns the correct value.
       
   130 */
       
   131 void QGeoAreaMonitor::setCenter(const QGeoCoordinate &coordinate)
       
   132 {
       
   133     d->coord = coordinate;
       
   134 }
       
   135 
       
   136 QGeoCoordinate QGeoAreaMonitor::center() const
       
   137 {
       
   138     return d->coord;
       
   139 }
       
   140 
       
   141 /*!
       
   142     \property QGeoAreaMonitor::radius
       
   143     \brief holds the radius of the area to be monitored, in meters.
       
   144 
       
   145     If the specified radius is less than the minimum supported radius, the
       
   146     radius is set to the minimum radius.
       
   147 
       
   148     When this property is set, if the center coordinate has already been set and
       
   149     the current position is within the monitored area, areaEntered()
       
   150     is emitted immediately.
       
   151 
       
   152     By default, this property is 0.
       
   153 
       
   154     Note: Subclass implementations must call the base implementation of
       
   155     setRadius() so that radius() returns the correct value.
       
   156 */
       
   157 void QGeoAreaMonitor::setRadius(qreal radius)
       
   158 {
       
   159     d->radius = radius;
       
   160 }
       
   161 
       
   162 qreal QGeoAreaMonitor::radius() const
       
   163 {
       
   164     return d->radius;
       
   165 }
       
   166 
       
   167 /*!
       
   168     Creates and returns a monitor with the given \a parent that
       
   169     monitors areas using resources on the underlying system.
       
   170 
       
   171     Returns 0 if the system has no support for position monitoring.
       
   172 */
       
   173 QGeoAreaMonitor *QGeoAreaMonitor::createDefaultMonitor(QObject *parent)
       
   174 {
       
   175 #if defined(Q_OS_SYMBIAN) && defined(QT_LOCATION_S60_MONITORING)
       
   176     QGeoAreaMonitor *ret = NULL;
       
   177     TRAPD(error, ret = QGeoAreaMonitorS60::NewL(parent));
       
   178     return ret;
       
   179 #elif defined(Q_WS_MAEMO_5)
       
   180     QGeoAreaMonitorMaemo *ret = new QGeoAreaMonitorMaemo(parent);
       
   181     return ret;
       
   182 #else
       
   183     Q_UNUSED(parent);
       
   184 #endif
       
   185     return 0;
       
   186 }
       
   187 
       
   188 /*!
       
   189     \fn void QGeoAreaMonitor::areaEntered(const QGeoPositionInfo &update);
       
   190 
       
   191     Emitted when the current position has moved from a position outside the
       
   192     monitored area to a position within the monitored area.
       
   193 
       
   194     The \a update holds the new position.
       
   195 */
       
   196 
       
   197 /*!
       
   198     \fn void QGeoAreaMonitor::areaExited(const QGeoPositionInfo &update);
       
   199 
       
   200     Emitted when the current position has moved from a position within the
       
   201     monitored area to a position outside the monitored area.
       
   202 
       
   203     The \a update holds the new position.
       
   204 */
       
   205 
       
   206 QTM_END_NAMESPACE