#include "engine.h"
-const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED";
-const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";
-const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12;
+const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED"; ///< GPS setting
+const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";///< Auto centering setting
+const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12; ///< Default zoom level when GPS available
+const qreal USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE = 0.003;///< Min value for user move latitude
+const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
SituareEngine::SituareEngine(QMainWindow *parent)
: QObject(parent),
settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
}
-void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- if (m_automaticUpdateIntervalTimer) {
-
- if (enabled && m_gps->isRunning()) {
- m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
- m_automaticUpdateIntervalTimer->start();
- }
- else
- m_automaticUpdateIntervalTimer->stop();
- }
-}
-
void SituareEngine::automaticUpdateIntervalTimerTimeout()
{
qDebug() << __PRETTY_FUNCTION__;
if (m_gps->isRunning() && m_userMoved) {
- qDebug() << __PRETTY_FUNCTION__ << "requestUpdateLocation()";
- //requestUpdateLocation();
+ requestUpdateLocation();
m_userMoved = false;
}
}
else {
m_gps->stop();
enableAutoCentering(false);
- enableAutomaticLocationUpdate(false);
+ }
+}
+
+void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (m_automaticUpdateIntervalTimer) {
+
+ if (enabled && m_gps->isRunning()) {
+ m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
+ m_automaticUpdateIntervalTimer->start();
+ }
+ else
+ m_automaticUpdateIntervalTimer->stop();
}
}
{
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()) >
+ USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE) ||
+ (fabs(m_lastUpdatedGPSPosition.y() - position.y()) >
+ USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE)) {
- 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::setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy)
{
* @return true if moved engouh, false otherwise
*/
bool isUserMoved();
- * @brief Read settings and determine whether to use GPS and autocentering.
- * When values does not found on the settings, GPS and autocentering are enabled as a default.
- */
+
+ /**
+ * @brief Read settings and determine whether to use GPS and autocentering.
+ * When values does not found on the settings, GPS and autocentering are enabled as a default.
+ */
void initializeGpsAndAutocentering();
/**
void signalsFromSituareService();
private slots:
-
+ /**
+ * @brief Automatic update interval timer timeout.
+ *
+ * Requests update location if user has moved.
+ */
void automaticUpdateIntervalTimerTimeout();
/**
- * @brief Set auto centering feature enabled / disabled
- */
+ * @brief Set auto centering feature enabled / disabled
+ *
+ * @param enabled true if enabled, false otherwise
+ */
void changeAutoCenteringSetting(bool enabled);
/**
- * @brief Slot for disabling automatic centering when map is scrolled manually
- */
+ * @brief Slot for disabling automatic centering when map is scrolled manually
+ */
void disableAutoCentering();
/**
void enableGPS(bool enabled);
/**
+ * @brief Enables automatic location update.
+ *
+ * @param enabled true if
+ */
+ void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
+
+ /**
* @brief Sets zoom level to default when first GPS location is received if autocentering
* is enabled.
*
*/
void saveGPSPosition(QPointF position);
- /**
- * @brief Enables automatic location update.
- *
- * @param enabled true if
- */
- void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = -1);
-
/*******************************************************************************
* SIGNALS
******************************************************************************/
m_settingsDialog = new SettingsDialog(this);
m_settingsDialog->hide();
- connect(m_settingsDialog, SIGNAL(automaticLocationUpdateIntervalSet(int)),
- this, SIGNAL(automaticLocationUpdateIntervalSet(int)));
+ connect(m_settingsDialog, SIGNAL(enableAutomaticLocationUpdate(bool,int)),
+ this, SIGNAL(enableAutomaticLocationUpdate(bool,int)));
createMenus();
setWindowTitle(tr("Situare"));
#include "common.h"
#include "settingsdialog.h"
+const QString SETTINGS_AUTOMATIC_UPDATE_INTERVAL = "SETTINGS_AUTOMATIC_UPDATE_INTERVAL";
+const int MINIMUM_UPDATE_INTERVAL_SECS = 30;
+const int MAXIMUM_UPDATE_INTERVAL_HOURS = 1;
+
SettingsDialog::SettingsDialog(QWidget *parent)
- : QDialog(parent)
+ : QDialog(parent),
+ m_automaticLocationUpdateOldValue(false),
+ m_automaticLocationUpdateIntervalOldValue(QTime(0, 0, MINIMUM_UPDATE_INTERVAL_SECS))
{
qDebug() << __PRETTY_FUNCTION__;
setWindowTitle(tr("Settings"));
m_automaticLocationUpdate = new QCheckBox(tr("Use automatic location update"));
m_automaticLocationUpdateInterval = new QTimeEdit();
- m_automaticLocationUpdateInterval->setTimeRange(QTime(0, 0, 5), QTime(1, 0));
- m_automaticLocationUpdateInterval->setDisplayFormat("mm:ss");
+ m_automaticLocationUpdateInterval->setTimeRange(QTime(0, 0, MINIMUM_UPDATE_INTERVAL_SECS),
+ QTime(MAXIMUM_UPDATE_INTERVAL_HOURS, 0));
+ m_automaticLocationUpdateInterval->setDisplayFormat("hh:mm:ss");
m_automaticLocationUpdateInterval->setDisabled(true);
QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
this, SLOT(toggleAutomaticLocationUpdate(bool)));
connect(saveButton, SIGNAL(clicked()), this, SLOT(saveValues()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+ connect(this, SIGNAL(rejected()), this, SLOT(rejectValues()));
QFormLayout *form = new QFormLayout();
form->setRowWrapPolicy(QFormLayout::WrapAllRows);
form->addWidget(m_automaticLocationUpdate);
- form->addRow("Update interval", m_automaticLocationUpdateInterval);
+ form->addRow(tr("Update interval"), m_automaticLocationUpdateInterval);
groupBox->setLayout(form);
scrollArea->setWidget(groupBox);
setLayout(gridLayout);
scrollArea->show();
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ QString automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, "")
+ .toString();
+ if (!automaticUpdateInterval.isEmpty()) {
+ m_automaticLocationUpdateInterval->setTime(QTime::fromString(automaticUpdateInterval));
+ m_automaticLocationUpdateIntervalOldValue = m_automaticLocationUpdateInterval->time();
+ }
+}
+
+SettingsDialog::~SettingsDialog()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL,
+ m_automaticLocationUpdateInterval->time());
+}
+
+void SettingsDialog::rejectValues()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_automaticLocationUpdate->setChecked(m_automaticLocationUpdateOldValue);
+ m_automaticLocationUpdateInterval->setTime(m_automaticLocationUpdateIntervalOldValue);
}
void SettingsDialog::saveValues()
{
qDebug() << __PRETTY_FUNCTION__;
+ m_automaticLocationUpdateOldValue = m_automaticLocationUpdate->isChecked();
+ m_automaticLocationUpdateIntervalOldValue = m_automaticLocationUpdateInterval->time();
+
if (m_automaticLocationUpdate->isChecked()) {
QTime time = QTime();
- emit automaticLocationUpdateIntervalSet(time.msecsTo(
+ emit enableAutomaticLocationUpdate(true, time.msecsTo(
m_automaticLocationUpdateInterval->time()));
}
else {
- emit automaticLocationUpdateIntervalSet(-1);
+ emit enableAutomaticLocationUpdate(false);
}
accept();
}
void SettingsDialog::toggleAutomaticLocationUpdate(bool value)
{
qDebug() << __PRETTY_FUNCTION__;
+
m_automaticLocationUpdateInterval->setEnabled(value);
}
Copyright (C) 2010 Ixonos Plc. Authors:
Katri Kaikkonen - katri.kaikkonen@ixonos.com
+ Jussi Laitinen - jussi.laitinen@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
#define SETTINGSDIALOG_H
#include <QDialog>
+#include <QTime>
class QCheckBox;
class QTimeEdit;
/**
-* @brief Settings Dialog NOTE: dialog deletes itself after saving or closing settings
+* @brief Settings Dialog.
*
* @class SettingsDialog settingsdialog.h "ui/settingsdialog.h"
*/
SettingsDialog(QWidget *parent = 0);
/**
- * @brief Disables Situare related settings from settings dialog
+ * @brief Destructor.
*
+ * Saves automatic update interval in settings.
*/
- void enableSituareSettings(bool enabled);
+ ~SettingsDialog();
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
+ public:
+ /**
+ * @brief Enables Situare related settings from settings dialog
+ *
+ */
+ void enableSituareSettings(bool enabled);
+
+
private slots:
/**
- * @brief Saves settings to file
+ * @brief Saves settings to file.
*/
void saveValues();
- void toggleAutomaticLocationUpdate(bool value);
+ /**
+ * @brief Rejects changes made to settings.
+ */
+ void rejectValues();
+
+ /**
+ * @brief Toggles automatic location update state.
+ *
+ * Enables and disabled automatic location update interval time edit.
+ *
+ * @param value true if settings are enabled, false otherwise
+ */
+ void toggleAutomaticLocationUpdate(bool enabled);
signals:
- void automaticLocationUpdateIntervalSet(int updateIntervalMsecs);
+ /**
+ * @brief Signal for enabling automatic location update.
+ *
+ * @param enabled true if enabled, false otherwise
+ * @param updateIntervalMsecs update interval in milliseconds
+ */
+ void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
/*******************************************************************************
* DATA MEMBERS
private:
QCheckBox *m_automaticLocationUpdate; ///< Pointer to CheckBox
QTimeEdit *m_automaticLocationUpdateInterval; ///< Pointer to QTimeEdit
+ bool m_automaticLocationUpdateOldValue; ///< Automatic location update state
+ QTime m_automaticLocationUpdateIntervalOldValue;///< Automatic location update interval value
};
#endif // SETTINGSDIALOG_H