Re-factoring, adding missing functionality
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 26 Aug 2010 10:06:25 +0000 (13:06 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 26 Aug 2010 10:06:25 +0000 (13:06 +0300)
 - Re-factored RoutingPanel constructor

 - Routing instructions list is cleared when route is cleared

 - Route instruction / search result selection is cleared when view
   is changed

 - Route button is disabled if it is not checked and there is no
   search result currently selected

src/ui/routingpanel.cpp
src/ui/routingpanel.h

index 49851e9..229875a 100644 (file)
@@ -16,55 +16,44 @@ RoutingPanel::RoutingPanel(QWidget *parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QVBoxLayout *routingLayout = new QVBoxLayout;
-    routingLayout->setMargin(0);
-    routingLayout->setSpacing(0);
-    setLayout(routingLayout);
+    // --- ROUTING INSTRUCTIONS WIDGET ---
+    m_routeWaypointListView = new RouteWaypointListView(this);
+    m_routeWaypointListView->setItemDelegate(new ExtendedListItemDelegate(this));
+//    m_routeWaypointListView->hide();
 
-    QHBoxLayout *headerLayout = new QHBoxLayout();
-    headerLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
-                                     PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
+    connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
+            this, SIGNAL(routeWaypointItemClicked(GeoCoordinate)));
 
-    QVBoxLayout *listViewLayout = new QVBoxLayout;
-    listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
-                                       PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
+    QVBoxLayout *routingViewLayout = new QVBoxLayout;
+    routingViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
+                                          PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
 
-    ImageButton *searchLocationButton = new ImageButton(":/res/images/search.png",
-                                                        ":/res/images/search_s.png",
-                                                        "", this);
-    searchLocationButton->setCheckable(true);
-    m_contextButtonLayout->addWidget(searchLocationButton);
+    // main routing layout
+    m_routingView = new QWidget();
+    m_routingView->setLayout(routingViewLayout);
+    routingViewLayout->addWidget(m_routeWaypointListView);
 
-    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();
-    m_locationListHeaderWidget->setLayout(headerLayout);
-    m_locationListHeaderWidget->setAutoFillBackground(true);
-    QPalette labelPalette = m_locationListHeaderWidget->palette();
+    // --- SEARCH RESULTS WIDGET ---
+    // header
+    QWidget *resultsHeaderWidget = new QWidget();
+    resultsHeaderWidget->setAutoFillBackground(true);
+    QPalette labelPalette = resultsHeaderWidget->palette();
     labelPalette.setColor(QPalette::Background, Qt::black);
-    m_locationListHeaderWidget->setPalette(labelPalette);
-    m_locationListHeaderWidget->hide();
+    resultsHeaderWidget->setPalette(labelPalette);
+//    m_resultsHeaderWidget->hide();
+
+    QHBoxLayout *headerLayout = new QHBoxLayout();
+    resultsHeaderWidget->setLayout(headerLayout);
+    headerLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
+                                     PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
 
-    m_locationListLabel = new QLabel(this);
+    m_resultsLabel = new QLabel(this);
+    headerLayout->addWidget(m_resultsLabel, 0, Qt::AlignCenter);
 
+    // list view
     m_locationListView = new LocationListView(this);
     m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
-    m_locationListView->hide();
-
-    m_routeWaypointListView = new RouteWaypointListView(this);
-    m_routeWaypointListView->setItemDelegate(new ExtendedListItemDelegate(this));
-    m_routeWaypointListView->hide();
-
-    headerLayout->addWidget(m_locationListLabel, 0, Qt::AlignCenter);
-
-    listViewLayout->addWidget(m_locationListView);
-    listViewLayout->addWidget(m_routeWaypointListView);
-
-    routingLayout->addWidget(m_locationListHeaderWidget);
-    routingLayout->addLayout(listViewLayout);
+//    m_locationListView->hide();
 
     connect(m_locationListView,
             SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
@@ -74,16 +63,51 @@ RoutingPanel::RoutingPanel(QWidget *parent)
     connect(m_locationListView, SIGNAL(listItemSelectionChanged()),
             this, SLOT(setRouteButtonDisabled()));
 
-    connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
-            this, SIGNAL(routeWaypointItemClicked(GeoCoordinate)));
+    QVBoxLayout *resultsListViewLayout = new QVBoxLayout;
+    resultsListViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
+                                       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 *routingPanelLayout = new QVBoxLayout;
+    routingPanelLayout->setMargin(0);
+    routingPanelLayout->setSpacing(0);
+    setLayout(routingPanelLayout);
+
+    m_views = new QStackedLayout();
+    routingPanelLayout->addLayout(m_views);
+    m_views->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
+                                PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
+
+    m_views->addWidget(m_resultsView);
+    m_views->addWidget(m_routingView);
+
+    // --- 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)));
 
+    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(searchLocationButton, SIGNAL(toggled(bool)),
-            this, SLOT(searchLocationButtonToggled(bool)));
-
-    // CONTEXT BUTTONS
+    m_contextButtonLayout->addWidget(m_searchLocationButton);
     m_contextButtonLayout->addWidget(m_routeButton);
 }
 
@@ -110,11 +134,11 @@ void RoutingPanel::populateLocationListView(const QList<Location> &locations)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_locationListHeaderWidget->show();
-    m_locationListLabel->setText(tr("Search results: %1").arg(locations.count()));
+//    m_resultsHeaderWidget->show();
+    m_resultsLabel->setText(tr("Search results: %1").arg(locations.count()));
 
-    m_routeWaypointListView->hide();
-    m_locationListView->show();
+//    m_routeWaypointListView->hide();
+//    m_locationListView->show();
     m_locationListView->clearList();
 
     for (int i = 0; i < locations.size(); ++i) {
@@ -140,9 +164,11 @@ void RoutingPanel::routeButtonToggled(bool checked)
 {
     if (checked) {
         routeToSelectedLocation();
+        m_searchLocationButton->setChecked(false);
     } else {
         emit clearRoute();
-        /// @todo clear route panel
+        m_routeWaypointListView->clearList();
+        setRouteButtonDisabled();
     }
 }
 
@@ -160,10 +186,12 @@ void RoutingPanel::routeToSelectedLocation()
 void RoutingPanel::searchLocationButtonToggled(bool checked)
 {
     if (checked) {
+        showResultsView();
         emit requestSearchLocation();
     } else {
-        m_locationListHeaderWidget->hide();
-        m_locationListView->hide();
+        showRoutingView();
+//        m_resultsHeaderWidget->hide();
+//        m_locationListView->hide();
     }
 }
 
@@ -171,10 +199,10 @@ void RoutingPanel::setRoute(Route &route)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_locationListHeaderWidget->hide();
-    m_locationListView->hide();
-    m_routeWaypointListView->show();
-    m_routeWaypointListView->clearList();
+//    m_resultsHeaderWidget->hide();
+//    m_locationListView->hide();
+//    m_routeWaypointListView->show();
+//    m_routeWaypointListView->clearList();
 
     QList<RouteSegment> segments = route.segments();
     QList<GeoCoordinate> geometryPoints = route.geometryPoints();
@@ -197,5 +225,23 @@ void RoutingPanel::setRouteButtonDisabled()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty());
+    m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty()
+                               && !m_routeButton->isChecked());
+}
+
+void RoutingPanel::showResultsView()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_views->setCurrentWidget(m_resultsView);
+    m_routeWaypointListView->clearItemSelection();
+}
+
+void RoutingPanel::showRoutingView()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_views->setCurrentWidget(m_routingView);
+    m_locationListView->clearItemSelection();
+
 }
index 24ae2c5..2f486d2 100644 (file)
@@ -67,6 +67,11 @@ protected:
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
+private:
+    void showResultsView();
+
+    void showRoutingView();
+
 private slots:
     /**
     * @brief Clears lists' selections.
@@ -155,13 +160,15 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    QLabel *m_locationListLabel;            ///< Location list label
+    QLabel *m_resultsLabel;            ///< Location list label
 
-    QPushButton *m_searchLocationButton;    ///< Search location button
+    QStackedLayout *m_views;
 
-    QWidget *m_locationListHeaderWidget;    ///< Location list header widget
+    QWidget *m_resultsView;
+    QWidget *m_routingView;
 
     ImageButton *m_routeButton;             ///< Route to location button
+    ImageButton *m_searchLocationButton;    ///< Search location button
     LocationListView *m_locationListView;   ///< Location list view
     RouteWaypointListView *m_routeWaypointListView; ///< Route waypoint list view
 };