Modifying RoutingPanel buttons functionality
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 26 Aug 2010 07:43:36 +0000 (10:43 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 26 Aug 2010 07:43:36 +0000 (10:43 +0300)
 - Changed RoutingPanel buttons checkable

 - Handlers for RoutingPanel buttons toggling

 - Route to location button clears the route line when unchecked

src/engine/engine.cpp
src/map/mapengine.cpp
src/map/mapengine.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/routingpanel.cpp
src/ui/routingpanel.h

index 4b7b821..4f0359e 100644 (file)
@@ -671,6 +671,9 @@ void SituareEngine::signalsFromMainWindow()
             m_mapEngine,
             SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&)));
 
+    connect(m_ui, SIGNAL(clearRoute()),
+            m_mapEngine, SLOT(clearRoute()));
+
     // signals from distence indicator button
     connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
             this, SLOT(changeAutoCenteringSetting(bool)));
index 8c2a706..0675e1f 100644 (file)
@@ -177,6 +177,17 @@ void MapEngine::centerToCoordinates(GeoCoordinate coordinate)
     scrollToPosition(SceneCoordinate(coordinate));
 }
 
+void MapEngine::clearRoute()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_mapRouteItem) {
+        m_mapScene->removeItem(m_mapRouteItem);
+        delete m_mapRouteItem;
+        m_mapRouteItem = 0;
+    }
+}
+
 QPoint MapEngine::convertSceneCoordinateToTileNumber(int zoomLevel, SceneCoordinate coordinate)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -463,17 +474,9 @@ void MapEngine::setRoute(Route &route)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_route = route;
-
-    // delete old route track (if exists)
-    if (m_mapRouteItem) {
-        m_mapScene->removeItem(m_mapRouteItem);
-        delete m_mapRouteItem;
-        m_mapRouteItem = 0;
-    }
+    clearRoute();
 
-    // create new route track
-    m_mapRouteItem = new MapRouteItem(&m_route);
+    m_mapRouteItem = new MapRouteItem(&route);
     m_mapScene->addItem(m_mapRouteItem);
 
     centerAndZoomTo(m_mapRouteItem->boundingRect().toRect());
index 07db7b9..0177ea0 100644 (file)
@@ -267,6 +267,11 @@ private:
 
 private slots:
     /**
+    * @brief Slot for clearing the current route
+    */
+    void clearRoute();
+
+    /**
      * @brief This slot is called after friend items position have been updated
      *
      * Does run MapScene::spanItems()
@@ -471,7 +476,6 @@ private:
     MapScene *m_mapScene;                       ///< Scene for map tiles
     MapScroller *m_scroller;                    ///< Kinetic scroller
     OwnLocationItem *m_ownLocation;             ///< Item to show own location
-    Route m_route;                              ///< Current route data
 };
 
 #endif // MAPENGINE_H
index 1168d3a..6701a52 100644 (file)
@@ -376,6 +376,9 @@ void MainWindow::buildRoutingPanel()
 
     connect(m_routingPanel, SIGNAL(requestSearchLocation()),
             this, SLOT(startLocationSearch()));
+
+    connect(m_routingPanel, SIGNAL(clearRoute()),
+            this, SIGNAL(clearRoute()));
 }
 
 void MainWindow::buildUserInfoPanel()
index 5c2776f..044a1c4 100644 (file)
@@ -442,6 +442,11 @@ signals:
     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
 
     /**
+    * @brief Emitted when route is cleared
+    */
+    void clearRoute();
+
+    /**
     * @brief Signal when direction and distance from current map center point to current GPS
     *        location is changed
     *
index 7b7f132..49851e9 100644 (file)
@@ -32,11 +32,12 @@ RoutingPanel::RoutingPanel(QWidget *parent)
     ImageButton *searchLocationButton = new ImageButton(":/res/images/search.png",
                                                         ":/res/images/search_s.png",
                                                         "", this);
-
+    searchLocationButton->setCheckable(true);
     m_contextButtonLayout->addWidget(searchLocationButton);
 
     m_routeButton = new ImageButton(":res/images/route_to_location.png",
                                     ":res/images/route_to_location_s.png", "", this);
+    m_routeButton->setCheckable(true);
     m_routeButton->setDisabled(true);
 
     m_locationListHeaderWidget = new QWidget();
@@ -76,11 +77,11 @@ RoutingPanel::RoutingPanel(QWidget *parent)
     connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
             this, SIGNAL(routeWaypointItemClicked(GeoCoordinate)));
 
-    connect(m_routeButton, SIGNAL(clicked()),
-            this, SLOT(routeToSelectedLocation()));
+    connect(m_routeButton, SIGNAL(toggled(bool)),
+            this, SLOT(routeButtonToggled(bool)));
 
-    connect(searchLocationButton, SIGNAL(clicked()),
-            this, SIGNAL(requestSearchLocation()));
+    connect(searchLocationButton, SIGNAL(toggled(bool)),
+            this, SLOT(searchLocationButtonToggled(bool)));
 
     // CONTEXT BUTTONS
     m_contextButtonLayout->addWidget(m_routeButton);
@@ -135,6 +136,16 @@ void RoutingPanel::populateLocationListView(const QList<Location> &locations)
     m_locationListView->scrollToTop();
 }
 
+void RoutingPanel::routeButtonToggled(bool checked)
+{
+    if (checked) {
+        routeToSelectedLocation();
+    } else {
+        emit clearRoute();
+        /// @todo clear route panel
+    }
+}
+
 void RoutingPanel::routeToSelectedLocation()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -146,6 +157,16 @@ void RoutingPanel::routeToSelectedLocation()
         emit routeToLocation(item->coordinates());
 }
 
+void RoutingPanel::searchLocationButtonToggled(bool checked)
+{
+    if (checked) {
+        emit requestSearchLocation();
+    } else {
+        m_locationListHeaderWidget->hide();
+        m_locationListView->hide();
+    }
+}
+
 void RoutingPanel::setRoute(Route &route)
 {
     qDebug() << __PRETTY_FUNCTION__;
index bb433f5..24ae2c5 100644 (file)
@@ -82,6 +82,8 @@ private slots:
     */
     void populateLocationListView(const QList<Location> &locations);
 
+    void routeButtonToggled(bool checked);
+
     /**
     * @brief Routes to selected location.
     *
@@ -89,6 +91,8 @@ private slots:
     */
     void routeToSelectedLocation();
 
+    void searchLocationButtonToggled(bool checked);
+
     /**
     * @brief Sets route to the panel.
     *
@@ -109,6 +113,11 @@ private slots:
  ******************************************************************************/
 signals:
     /**
+    * @brief Emitted when route is cleared
+    */
+    void clearRoute();
+
+    /**
     * @brief Signal for location item clicked.
     *
     * @param swBound south-west bound GeoCoordinate