List classes reviewed and fixed review observations.
[situare] / src / ui / routingpanel.cpp
1 #include "coordinates/geocoordinate.h"
2 #include "locationlistitem.h"
3 #include "locationlistview.h"
4 #include "extendedlistitemdelegate.h"
5 #include "routing/location.h"
6 #include "panelcommon.h"
7
8 #include "routingpanel.h"
9
10 RoutingPanel::RoutingPanel(QWidget *parent)
11     : QWidget(parent)
12 {
13     qDebug() << __PRETTY_FUNCTION__;
14
15     QVBoxLayout *routingLayout = new QVBoxLayout;
16     routingLayout->setMargin(0);
17     routingLayout->setSpacing(0);
18     setLayout(routingLayout);
19
20     QHBoxLayout *headerLayout = new QHBoxLayout();
21     headerLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
22                                      FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
23
24     QVBoxLayout *listViewLayout = new QVBoxLayout;
25     listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, 0, PANEL_MARGIN_RIGHT, 0);
26
27     m_locationListHeaderWidget = new QWidget();
28     m_locationListHeaderWidget->setLayout(headerLayout);
29     m_locationListHeaderWidget->setAutoFillBackground(true);
30     QPalette labelPalette = m_locationListHeaderWidget->palette();
31     labelPalette.setColor(QPalette::Background, Qt::black);
32     m_locationListHeaderWidget->setPalette(labelPalette);
33     m_locationListHeaderWidget->hide();
34
35     m_locationListLabel = new QLabel(this);
36
37     m_locationListView = new LocationListView(this);
38     m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
39
40     headerLayout->addWidget(m_locationListLabel, 0, Qt::AlignCenter);
41
42     listViewLayout->addWidget(m_locationListView);
43
44     routingLayout->addWidget(m_locationListHeaderWidget);
45     routingLayout->addLayout(listViewLayout);
46
47     connect(m_locationListView,
48             SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
49             this,
50             SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
51 }
52
53 void RoutingPanel::populateLocationListView(const QList<Location> &locations)
54 {
55     qDebug() << __PRETTY_FUNCTION__;
56
57     m_locationListHeaderWidget->show();
58     m_locationListLabel->setText(tr("Search results: %1").arg(locations.count()));
59
60     m_locationListView->clearList();
61
62     for (int i = 0; i < locations.size(); ++i) {
63         LocationListItem *item = new LocationListItem();
64         item->setLocationData(locations.at(i));
65         m_locationListView->addListItem(QString::number(i), item);
66     }
67
68     //openPanel();
69
70     const int FIRST_LOCATION_ITEM_INDEX = 0;
71     const int ONE_LOCATION_ITEM = 1;
72
73     if (locations.size() == ONE_LOCATION_ITEM) {
74         ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
75
76         if (item)
77             m_locationListView->listItemClicked(item);
78     }
79 }