-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinfo.cpp
More file actions
105 lines (75 loc) · 1.57 KB
/
info.cpp
File metadata and controls
105 lines (75 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// this file is part of osmbrowser
// copyright Martijn Versteegh
// osmbrowser is licenced under the gpl v3
#include "info.h"
#include "osmcanvas.h"
BEGIN_EVENT_TABLE(InfoTreeCtrl, wxTreeCtrl)
EVT_TREE_SEL_CHANGED(-1, InfoTreeCtrl::OnSelection)
END_EVENT_TABLE()
class InfoData
: public wxTreeItemData
{
public:
InfoData(OsmWay *way)
{
m_way = way;
}
OsmWay *m_way;
};
InfoTreeCtrl::InfoTreeCtrl(wxWindow *parent)
: wxTreeCtrl(parent, -1)
{
m_canvas = NULL;
}
void InfoTreeCtrl::SetInfo(TileWay *ways)
{
if (m_canvas)
{
m_canvas->SelectWay(NULL);
}
DeleteAllItems();
wxTreeItemId root = AddRoot(wxT("this node is a member of:"));
for (TileWay *w = ways; w ; w = static_cast<TileWay *>(w->m_next))
{
AddWay(root, w->m_way);
}
ExpandAll();
}
void InfoTreeCtrl::AddWay(wxTreeItemId const &root, OsmWay *way)
{
InfoData *data = new InfoData(way);
wxTreeItemId w = AppendItem(root, wxString::Format(wxT("%ud"), way->m_id), -1, -1, data);
for (OsmTag *t = way->m_tags; t; t = static_cast<OsmTag *>(t->m_next))
{
char const *k = t->GetKey();
char const *v = t->GetValue();
wxString tag(k, wxConvUTF8);
if (v)
{
tag += wxT("=");
tag += wxString(v, wxConvUTF8);
}
AppendItem(w, tag);
}
}
void InfoTreeCtrl::SetCanvas(OsmCanvas *canvas)
{
m_canvas = canvas;
}
void InfoTreeCtrl::OnSelection(wxTreeEvent &evt)
{
wxTreeItemId id = evt.GetItem();
InfoData *data = static_cast<InfoData *>(GetItemData(id));
if (!m_canvas)
{
return;
}
if (data)
{
m_canvas->SelectWay(data->m_way);
}
else
{
m_canvas->SelectWay(NULL);
}
}