Clean-up and re-factoring for LocationSearchPanel
authorSami Rämö <sami.ramo@ixonos.com>
Wed, 1 Sep 2010 08:30:05 +0000 (11:30 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Wed, 1 Sep 2010 08:30:05 +0000 (11:30 +0300)
 - Cleaned RoutingPanel related stuff from LocationSearchPanel

 - Header is always visible in the LocationSearchPanel

src/ui/locationsearchpanel.cpp
src/ui/locationsearchpanel.h
src/ui/mainwindow.cpp

index 224b550..db8fbb1 100644 (file)
     USA.
 */
 
-#include "coordinates/geocoordinate.h"
 #include "extendedlistitemdelegate.h"
 #include "locationlistitem.h"
 #include "locationlistview.h"
 #include "imagebutton.h"
 #include "panelcommon.h"
-#include "routewaypointlistitem.h"
-#include "routewaypointlistview.h"
 #include "routing/location.h"
-#include "routing/route.h"
 
 #include "locationsearchpanel.h"
 
@@ -38,24 +34,7 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    // --- ROUTING INSTRUCTIONS WIDGET ---
-    m_routeWaypointListView = new RouteWaypointListView(this);
-    m_routeWaypointListView->setItemDelegate(new ExtendedListItemDelegate(this));
-
-    connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
-            this, SIGNAL(routeWaypointItemClicked(GeoCoordinate)));
-
-    QVBoxLayout *routingViewLayout = new QVBoxLayout;
-    routingViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
-                                          PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
-
-    // main routing layout
-    m_routingView = new QWidget();
-    m_routingView->setLayout(routingViewLayout);
-    routingViewLayout->addWidget(m_routeWaypointListView);
-
-    // --- SEARCH RESULTS WIDGET ---
-    // header
+    // --- HEADER WIDGET ---
     QWidget *resultsHeaderWidget = new QWidget();
     resultsHeaderWidget->setAutoFillBackground(true);
     QPalette labelPalette = resultsHeaderWidget->palette();
@@ -69,8 +48,9 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent)
 
     m_resultsLabel = new QLabel(this);
     headerLayout->addWidget(m_resultsLabel, 0, Qt::AlignCenter);
+    setHeaderText(0);
 
-    // list view
+    // --- SEARCH RESULTS LIST VIEW ---
     m_locationListView = new LocationListView(this);
     m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
 
@@ -87,46 +67,31 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent)
                                        PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
     resultsListViewLayout->addWidget(m_locationListView);
 
-    // main results layout
-    m_resultsView = new QWidget();
-    QVBoxLayout *resultsViewLayout = new QVBoxLayout;
-    const int CONTENTS_MARGIN_LEFT = 0;
-    resultsViewLayout->setContentsMargins(CONTENTS_MARGIN_LEFT, PANEL_MARGIN_TOP,
-                                          PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
-    m_resultsView->setLayout(resultsViewLayout);
-
-    resultsViewLayout->addWidget(resultsHeaderWidget);
-    resultsViewLayout->addLayout(resultsListViewLayout);
-
     // --- MAIN LAYOUT ---
-    QVBoxLayout *LocationSearchPanelLayout = new QVBoxLayout;
-    LocationSearchPanelLayout->setMargin(0);
-    LocationSearchPanelLayout->setSpacing(0);
-    setLayout(LocationSearchPanelLayout);
+    QVBoxLayout *panelLayout = new QVBoxLayout;
+    panelLayout->setSpacing(0);
+    setLayout(panelLayout);
 
-    m_views = new QStackedLayout();
-    LocationSearchPanelLayout->addLayout(m_views);
-    m_views->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
-                                PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
+    const int MARGIN_LEFT = 0;
+    panelLayout->setContentsMargins(MARGIN_LEFT, PANEL_MARGIN_TOP,
+                                    PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
 
-    m_views->addWidget(m_routingView);
-    m_views->addWidget(m_resultsView);
+    panelLayout->addWidget(resultsHeaderWidget);
+    panelLayout->addLayout(resultsListViewLayout);
 
     // --- CONTEXT BUTTONS ---
-    m_searchLocationButton = new ImageButton(":/res/images/search.png",
-                                             ":/res/images/search_s.png", "", this);
-    m_searchLocationButton->setCheckable(true);
-    connect(m_searchLocationButton, SIGNAL(toggled(bool)),
-            this, SLOT(searchLocationButtonToggled(bool)));
+    ImageButton *searchLocationButton = new ImageButton(":/res/images/search.png",
+                                                        ":/res/images/search_s.png", "", this);
+    connect(searchLocationButton, SIGNAL(clicked()),
+            this, SIGNAL(requestSearchLocation()));
 
     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);
-    connect(m_routeButton, SIGNAL(toggled(bool)),
-            this, SLOT(routeButtonToggled(bool)));
+    connect(m_routeButton, SIGNAL(clicked()),
+            this, SLOT(routeToSelectedLocation()));
 
-    m_contextButtonLayout->addWidget(m_searchLocationButton);
+    m_contextButtonLayout->addWidget(searchLocationButton);
     m_contextButtonLayout->addWidget(m_routeButton);
 }
 
@@ -135,7 +100,6 @@ void LocationSearchPanel::clearListsSelections()
     qDebug() << __PRETTY_FUNCTION__;
 
     m_locationListView->clearItemSelection();
-    m_routeWaypointListView->clearItemSelection();
 
     setRouteButtonDisabled();
 }
@@ -153,7 +117,7 @@ void LocationSearchPanel::populateLocationListView(const QList<Location> &locati
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_resultsLabel->setText(tr("Search results: %1").arg(locations.count()));
+    setHeaderText(locations.count());
 
     m_locationListView->clearList();
 
@@ -176,20 +140,6 @@ void LocationSearchPanel::populateLocationListView(const QList<Location> &locati
     m_locationListView->scrollToTop();
 }
 
-void LocationSearchPanel::routeButtonToggled(bool checked)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (checked) {
-        routeToSelectedLocation();
-        m_searchLocationButton->setChecked(false);
-    } else {
-        emit clearRoute();
-        m_routeWaypointListView->clearList();
-        setRouteButtonDisabled();
-    }
-}
-
 void LocationSearchPanel::routeToSelectedLocation()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -201,73 +151,16 @@ void LocationSearchPanel::routeToSelectedLocation()
         emit routeToLocation(item->coordinates());
 }
 
-void LocationSearchPanel::searchLocationButtonToggled(bool checked)
+void LocationSearchPanel::setHeaderText(int count)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (checked) {
-        showResultsView();
-        emit requestSearchLocation();
-    } else {
-        showRoutingView();
-    }
-}
-
-void LocationSearchPanel::setRoute(Route &route)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_routeWaypointListView->clearList();
-
-    QList<RouteSegment> segments = route.segments();
-    QList<GeoCoordinate> geometryPoints = route.geometryPoints();
-
-    for (int i = 0; i < segments.size(); ++i) {
-        RouteWaypointListItem *item = new RouteWaypointListItem();
-        RouteSegment routeSegment = segments.at(i);
-        item->setRouteWaypointData(routeSegment,
-                                   geometryPoints.at(routeSegment.positionIndex()));
-
-        m_routeWaypointListView->addListItem(QString::number(i), item);
-    }
-
-    m_routeWaypointListView->scrollToTop();
-
-    // route might come from FriendListPanel's route to friend button, so we have to
-    // check the routing button without emitting new routing request
-    blockSignals(true);
-    m_routeButton->setEnabled(true);
-    m_routeButton->setChecked(true);
-    blockSignals(false);
-    m_searchLocationButton->setChecked(false);
-
-    // search location button might be already false, so we have to make sure the
-    // toggle action handler is called every time
-    searchLocationButtonToggled(false);
-
-    emit openPanelRequested(this);
+    m_resultsLabel->setText(tr("Search results: %1").arg(count));
 }
 
 void LocationSearchPanel::setRouteButtonDisabled()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty()
-                               && !m_routeButton->isChecked());
-}
-
-void LocationSearchPanel::showResultsView()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_views->setCurrentWidget(m_resultsView);
-    m_routeWaypointListView->clearItemSelection();
-}
-
-void LocationSearchPanel::showRoutingView()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_views->setCurrentWidget(m_routingView);
-    m_locationListView->clearItemSelection();
+    m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty());
 }
index f0b2ebc..bb08f11 100644 (file)
@@ -32,8 +32,6 @@ class GeoCoordinate;
 class ImageButton;
 class Location;
 class LocationListView;
-class Route;
-class RouteWaypointListView;
 
 /**
  * @brief Location search panel
@@ -70,15 +68,7 @@ protected:
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 private:
-    /**
-    * @brief Switch to search results view mode
-    */
-    void showResultsView();
-
-    /**
-    * @brief Switch to routing instructions view mode
-    */
-    void showRoutingView();
+    void setHeaderText(int count);
 
 private slots:
     /**
@@ -96,11 +86,6 @@ private slots:
     void populateLocationListView(const QList<Location> &locations);
 
     /**
-    * @brief Handler for route button toggling actions
-    */
-    void routeButtonToggled(bool checked);
-
-    /**
     * @brief Routes to selected location.
     *
     * Emits routeToLocation if location is selected from list.
@@ -108,19 +93,6 @@ private slots:
     void routeToSelectedLocation();
 
     /**
-    * @brief Handler for search button toggling actions
-    */
-    void searchLocationButtonToggled(bool checked);
-
-    /**
-    * @brief Sets route to the panel.
-    *
-    * Appends route waypoint list with route segments.
-    * @param route Route item containing parsed route details
-    */
-    void setRoute(Route &route);
-
-    /**
     * @brief Sets route button disabled.
     *
     * Disabled if there isn't any list item selected.
@@ -132,11 +104,6 @@ private slots:
  ******************************************************************************/
 signals:
     /**
-    * @brief Emitted when route is cleared
-    */
-    void clearRoute();
-
-    /**
     * @brief Signal for location item clicked.
     *
     * @param swBound south-west bound GeoCoordinate
@@ -163,28 +130,14 @@ signals:
     */
     void routeWaypointItemClicked(const GeoCoordinate &coordinate);
 
-    /**
-     * @brief Signal for requesting a panel to be opened
-     *
-     * @param widget Pointer to the widget that emitted the signal
-     */
-    void showPanelRequested(QWidget *widget);
-
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
 private:
     QLabel *m_resultsLabel;                 ///< Location list label
 
-    QStackedLayout *m_views;                ///< Views
-
-    QWidget *m_resultsView;                 ///< Search results view widget
-    QWidget *m_routingView;                 ///< Routing instructions view widget
-
     ImageButton *m_routeButton;             ///< Route to location button
-    ImageButton *m_searchLocationButton;    ///< Search location button
     LocationListView *m_locationListView;   ///< Search results list view
-    RouteWaypointListView *m_routeWaypointListView;     ///< Route instructions list view
 };
 
 #endif // LOCATIONSEARCHPANEL_H
index 0358547..34819c0 100644 (file)
@@ -267,17 +267,8 @@ void MainWindow::buildLocationSearchPanel()
     connect(m_locationSearchPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
             this, SIGNAL(routeTo(const GeoCoordinate&)));
 
-    connect(this, SIGNAL(routeParsed(Route&)),
-            m_locationSearchPanel, SLOT(setRoute(Route&)));
-
-    connect(m_locationSearchPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
-            this, SIGNAL(centerToCoordinates(GeoCoordinate)));
-
     connect(m_locationSearchPanel, SIGNAL(requestSearchLocation()),
             this, SLOT(startLocationSearch()));
-
-    connect(m_locationSearchPanel, SIGNAL(clearRoute()),
-            this, SIGNAL(clearRoute()));
 }
 
 void MainWindow::buildMap()