Added comments to settingsdialog, engine and mainwindow.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 31 May 2010 10:00:51 +0000 (13:00 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 31 May 2010 10:00:51 +0000 (13:00 +0300)
src/engine/engine.cpp
src/engine/engine.h
src/ui/mainwindow.cpp
src/ui/settingsdialog.cpp
src/ui/settingsdialog.h

index 40e46fa..c5f6264 100644 (file)
 
 #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),
@@ -108,28 +110,12 @@ SituareEngine::~SituareEngine()
     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;
     }
 }
@@ -176,7 +162,21 @@ void SituareEngine::enableGPS(bool enabled)
     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();
     }
 }
 
@@ -319,17 +319,15 @@ 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()) >
+         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)
 {
index 9d55404..814aad7 100644 (file)
@@ -148,9 +148,11 @@ private:
     * @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();
 
     /**
@@ -184,17 +186,23 @@ private:
     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();
 
     /**
@@ -214,6 +222,13 @@ private slots:
     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.
      *
@@ -237,13 +252,6 @@ private slots:
     */
     void saveGPSPosition(QPointF position);
 
-    /**
-    * @brief Enables automatic location update.
-    *
-    * @param enabled true if
-    */
-    void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = -1);
-
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
index 1922a57..31dfb72 100644 (file)
@@ -75,8 +75,8 @@ MainWindow::MainWindow(QWidget *parent)
 
     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"));
index 5cfa180..aaf1471 100644 (file)
 #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"));
@@ -38,8 +44,9 @@ SettingsDialog::SettingsDialog(QWidget *parent)
     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);
@@ -50,11 +57,12 @@ SettingsDialog::SettingsDialog(QWidget *parent)
             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);
@@ -64,19 +72,47 @@ SettingsDialog::SettingsDialog(QWidget *parent)
     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();
 }
@@ -91,5 +127,6 @@ void SettingsDialog::enableSituareSettings(bool enabled)
 void SettingsDialog::toggleAutomaticLocationUpdate(bool value)
 {
     qDebug() << __PRETTY_FUNCTION__;
+
     m_automaticLocationUpdateInterval->setEnabled(value);
 }
index 60745bb..fc89357 100644 (file)
@@ -3,6 +3,7 @@
    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"
 */
@@ -45,24 +47,51 @@ public:
     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
@@ -70,6 +99,8 @@ signals:
 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