Merge branch 'master' into locationlistview
[situare] / src / ui / locationlistitem.cpp
1 #include <QDebug>
2
3 #include "../common.h"
4 #include "listcommon.h"
5
6 #include "locationlistitem.h"
7
8 const int LOCATION_SUBITEM_TEXT_MAX_WIDTH = SUBITEM_TEXT_MAX_WIDTH + MARGIN + IMAGE_WIDTH;
9
10 LocationListItem::LocationListItem()
11 {
12     qDebug() << __PRETTY_FUNCTION__;
13
14     setSubitemTextWidth(LOCATION_SUBITEM_TEXT_MAX_WIDTH);
15 }
16
17 GeoCoordinate LocationListItem::coordinates()
18 {
19     qDebug() << __PRETTY_FUNCTION__;
20
21     return m_location.coordinates();
22 }
23
24 QString LocationListItem::id() const
25 {
26     qDebug() << __PRETTY_FUNCTION__;
27
28     return QString();
29 }
30
31 void LocationListItem::setLocationData(const Location &location)
32 {
33     m_location = location;
34
35     QStringList addressComponents = m_location.addressComponents();
36
37     if (addressComponents.count() > 0)
38         setName(shortenText(addressComponents.at(0), ITEM_WIDTH - 3*MARGIN,
39                             ListItem::TEXT_SIZE_NORMAL));
40
41     QString addressTail;
42
43     for (int i = 1; i < addressComponents.count(); ++i) {
44         addressTail.append(addressComponents.at(i));
45
46         if (i < (addressComponents.count() - 1))
47             addressTail.append(", ");
48     }
49
50     addSubItem(addressTail, QPixmap(":/res/images/compass.png"));
51
52 }
53
54 void LocationListItem::bounds(GeoCoordinate &swBound, GeoCoordinate &neBound)
55 {
56     m_location.bounds(swBound, neBound);
57 }