#include "map/mapengine.h"
#include "situareservice/situareservice.h"
#include "ui/mainwindow.h"
+#include <cmath>
#include "engine.h"
SituareEngine::SituareEngine(QMainWindow *parent)
: QObject(parent),
m_autoCenteringEnabled(false),
- m_loggedIn(false)
+ m_loggedIn(false),
+ m_automaticUpdateIntervalTimer(0),
+ m_lastUpdatedGPSPosition(QPointF()),
+ m_userMoved(false)
{
qDebug() << __PRETTY_FUNCTION__;
m_ui = new MainWindow;
settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
}
-void SituareEngine::automaticLocationUpdateIntervalSet(int updateIntervalMsecs)
+void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
{
qDebug() << __PRETTY_FUNCTION__;
if (m_automaticUpdateIntervalTimer) {
- m_automaticUpdateIntervalTimer->stop();
-
- if ((updateIntervalMsecs > 0) && m_gps->isRunning()) {
+ if (enabled && m_gps->isRunning()) {
m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
m_automaticUpdateIntervalTimer->start();
}
+ else
+ m_automaticUpdateIntervalTimer->stop();
}
}
{
qDebug() << __PRETTY_FUNCTION__;
- if (m_gps->isRunning());
+ if (m_gps->isRunning() && m_userMoved) {
+ qDebug() << __PRETTY_FUNCTION__ << "requestUpdateLocation()";
//requestUpdateLocation();
+ m_userMoved = false;
+ }
}
void SituareEngine::changeAutoCenteringSetting(bool enabled)
else {
m_gps->stop();
enableAutoCentering(false);
- automaticLocationUpdateIntervalSet(-1);
+ enableAutomaticLocationUpdate(false);
}
}
m_facebookAuthenticator->start();
}
+bool SituareEngine::isUserMoved()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_userMoved;
+}
+
void SituareEngine::loginActionPressed()
{
qDebug() << __PRETTY_FUNCTION__;
m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
}
+void SituareEngine::saveGPSPosition(QPointF position)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ qDebug() << __PRETTY_FUNCTION__ << m_lastUpdatedGPSPosition.x() << m_lastUpdatedGPSPosition.y();
+ qDebug() << __PRETTY_FUNCTION__ << position.x() << position.y();
+ qDebug() << __PRETTY_FUNCTION__ << "=" << fabs(m_lastUpdatedGPSPosition.x() - position.x()) <<
+ fabs(m_lastUpdatedGPSPosition.y() - position.y());
+
+ if ((fabs(m_lastUpdatedGPSPosition.x() - position.x()) > 0.003) ||
+ (fabs(m_lastUpdatedGPSPosition.y() - position.y()) > 0.001)) {
+ qDebug() << __PRETTY_FUNCTION__ << "m_userMoved = true";
+ m_lastUpdatedGPSPosition = position;
+ m_userMoved = true;
+ }
+}
+
void SituareEngine::signalsFromFacebookAuthenticator()
{
qDebug() << __PRETTY_FUNCTION__;
connect(m_gps, SIGNAL(error(QString)),
m_ui, SLOT(gpsError(QString)));
+
+ connect(m_gps, SIGNAL(position(QPointF,qreal)),
+ this, SLOT(saveGPSPosition(QPointF)));
}
void SituareEngine::signalsFromMainWindow()
connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
this, SLOT(requestUpdateLocation(QString,bool)));
- connect(m_ui, SIGNAL(automaticLocationUpdateIntervalSet(int)),
- this, SLOT(automaticLocationUpdateIntervalSet(int)));
+ connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
+ this, SLOT(enableAutomaticLocationUpdate(bool, int)));
// signals from user info tab
connect(m_ui, SIGNAL(refreshUserData()),
#include <QObject>
#include <QTime>
+#include <QPointF>
class QMainWindow;
private:
/**
+ * @brief Checks if user is moved enough for position auto update.
+ *
+ * @return true if moved engouh, false otherwise
+ */
+ bool isUserMoved();
+
+ /**
* @brief Connect signals coming from Facdebook authenticator
*/
void signalsFromFacebookAuthenticator();
private slots:
- void automaticLocationUpdateIntervalSet(int updateIntervalMsecs);
-
void automaticUpdateIntervalTimerTimeout();
/**
*/
void invalidCredentials();
+ /**
+ * @brief Saves GPS position.
+ *
+ * Saves GPS position if it has changed enough and sets m_userMoved flag.
+ *
+ * @param position geo coordinates
+ */
+ void saveGPSPosition(QPointF position);
+
+ /**
+ * @brief Enables automatic location update.
+ *
+ * @param enabled true if
+ */
+ void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = -1);
+
/*******************************************************************************
* SIGNALS
******************************************************************************/
MapEngine *m_mapEngine; ///< MapEngine
SituareService *m_situareService; ///< Instance of the situare server communication service
- QTimer *m_automaticUpdateIntervalTimer;
-
+ QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
+ QPointF m_lastUpdatedGPSPosition; ///< Last updated GPS position
+ bool m_userMoved; ///< Flag for user moving
};
#endif // ENGINE_H