Rev 391 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
305 | KeyOz | 1 | /* |
2 | * |
||
3 | * This file is part of QMapControl, |
||
4 | * an open-source cross-platform map widget |
||
5 | * |
||
6 | * Copyright (C) 2007 - 2008 Kai Winter |
||
7 | * |
||
8 | * This program is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU Lesser General Public License as published by |
||
10 | * the Free Software Foundation, either version 3 of the License, or |
||
11 | * (at your option) any later version. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU Lesser General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU Lesser General Public License |
||
19 | * along with QMapControl. If not, see <http://www.gnu.org/licenses/>. |
||
20 | * |
||
21 | * Contact e-mail: kaiwinter@gmx.de |
||
22 | * Program URL : http://qmapcontrol.sourceforge.net/ |
||
23 | * |
||
24 | */ |
||
25 | |||
26 | #include "linestring.h" |
||
27 | namespace qmapcontrol |
||
28 | { |
||
29 | LineString::LineString() |
||
30 | : Curve() |
||
31 | { |
||
32 | GeometryType = "LineString"; |
||
33 | } |
||
34 | |||
35 | LineString::LineString(QList<Point*> const points, QString name, QPen* pen) |
||
36 | :Curve(name) |
||
37 | { |
||
38 | mypen = pen; |
||
39 | LineString(); |
||
40 | setPoints(points); |
||
41 | } |
||
42 | |||
43 | LineString::~LineString() |
||
44 | { |
||
45 | } |
||
46 | |||
47 | // Geometry LineString::Clone(){} |
||
48 | |||
49 | // Point LineString::EndPoint(){} |
||
50 | // Point LineString::StartPoint(){} |
||
51 | // Point LineString::Value(){} |
||
52 | |||
53 | |||
54 | void LineString::addPoint(Point* point) |
||
55 | { |
||
56 | vertices.append(point); |
||
57 | } |
||
58 | |||
59 | QList<Point*> LineString::points() |
||
60 | { |
||
61 | return vertices; |
||
62 | } |
||
63 | |||
64 | void LineString::setPoints(QList<Point*> points) |
||
65 | { |
||
66 | for (int i=0; i<points.size(); i++) |
||
67 | { |
||
68 | points.at(i)->setParentGeometry(this); |
||
69 | } |
||
70 | vertices = points; |
||
71 | } |
||
72 | |||
73 | void LineString::draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &screensize, const QPoint offset) |
||
74 | { |
||
75 | if (!visible) |
||
76 | return; |
||
77 | |||
78 | QPolygon p = QPolygon(); |
||
79 | |||
80 | QPointF c; |
||
81 | for (int i=0; i<vertices.size(); i++) |
||
82 | { |
||
83 | c = vertices[i]->coordinate(); |
||
84 | p.append(mapadapter->coordinateToDisplay(c)); |
||
85 | } |
||
86 | if (mypen != 0) |
||
87 | { |
||
88 | painter->save(); |
||
89 | painter->setPen(*mypen); |
||
90 | } |
||
91 | painter->drawPolyline(p); |
||
92 | if (mypen != 0) |
||
93 | { |
||
94 | painter->restore(); |
||
95 | } |
||
96 | for (int i=0; i<vertices.size(); i++) |
||
97 | { |
||
98 | vertices[i]->draw(painter, mapadapter, screensize, offset); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | int LineString::numberOfPoints() const |
||
103 | { |
||
104 | return vertices.count(); |
||
105 | } |
||
106 | bool LineString::Touches(Point* geom, const MapAdapter* mapadapter) |
||
107 | { |
||
108 | // qDebug() << "LineString::Touches Point"; |
||
109 | touchedPoints.clear(); |
||
110 | bool touches = false; |
||
111 | for (int i=0; i<vertices.count(); i++) |
||
112 | { |
||
113 | // use implementation from Point |
||
114 | if (vertices.at(i)->Touches(geom, mapadapter)) |
||
115 | { |
||
116 | touchedPoints.append(vertices.at(i)); |
||
117 | |||
118 | touches = true; |
||
119 | } |
||
120 | } |
||
121 | if (touches) |
||
122 | { |
||
123 | emit(geometryClicked(this, QPoint(0,0))); |
||
124 | } |
||
125 | return touches; |
||
126 | } |
||
127 | bool LineString::Touches(Geometry* /*geom*/, const MapAdapter* /*mapadapter*/) |
||
128 | { |
||
129 | // qDebug() << "LineString::Touches Geom"; |
||
130 | touchedPoints.clear(); |
||
131 | |||
132 | return false; |
||
133 | } |
||
134 | |||
135 | QList<Geometry*> LineString::clickedPoints() |
||
136 | { |
||
137 | return touchedPoints; |
||
138 | } |
||
139 | bool LineString::hasPoints() const |
||
140 | { |
||
141 | return vertices.size() > 0 ? true : false; |
||
142 | } |
||
143 | bool LineString::hasClickedPoints() const |
||
144 | { |
||
145 | return touchedPoints.size() > 0 ? true : false; |
||
146 | } |
||
147 | |||
148 | QRectF LineString::boundingBox() |
||
149 | { |
||
150 | qreal minlon=180; |
||
151 | qreal maxlon=-180; |
||
152 | qreal minlat=90; |
||
153 | qreal maxlat=-90; |
||
154 | for (int i=0; i<vertices.size(); i++) |
||
155 | { |
||
156 | Point* tmp = vertices.at(i); |
||
157 | if (tmp->longitude() < minlon) minlon = tmp->longitude(); |
||
158 | if (tmp->longitude() > maxlon) maxlon = tmp->longitude(); |
||
159 | if (tmp->latitude() < minlat) minlat = tmp->latitude(); |
||
160 | if (tmp->latitude() > maxlat) maxlat = tmp->latitude(); |
||
161 | } |
||
162 | QPointF min = QPointF(minlon, minlat); |
||
163 | QPointF max = QPointF(maxlon, maxlat); |
||
164 | QPointF dist = max - min; |
||
165 | QSizeF si = QSizeF(dist.x(), dist.y()); |
||
166 | |||
167 | return QRectF(min, si); |
||
168 | |||
169 | } |
||
170 | } |