~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to Map/MapFeature.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2009-09-13 00:52:12 UTC
  • mto: (1.2.7 upstream) (0.1.3 upstream) (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090913005212-pjecal8zxm07x0fj
ImportĀ upstreamĀ versionĀ 0.14+svnfixes~20090912

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "Map/MapFeature.h"
2
 
#include "Map/Relation.h"
3
 
#include "Map/Road.h"
4
 
#include "Map/TrackPoint.h"
5
 
#include "Command/Command.h"
6
 
#include "Command/DocumentCommands.h"
7
 
#include "Command/FeatureCommands.h"
8
 
#include "Command/RelationCommands.h"
9
 
#include "Command/RoadCommands.h"
10
 
#include "Command/TrackPointCommands.h"
11
 
#include "Map/MapDocument.h"
12
 
#include "Map/MapLayer.h"
13
 
#include "PaintStyle/EditPaintStyle.h"
14
 
#include "PaintStyle/TagSelector.h"
15
 
 
16
 
#include <QtCore/QUuid>
17
 
#include <QProgressDialog>
18
 
 
19
 
#include <algorithm>
20
 
 
21
 
const QString encodeAttributes(const QString & text);
22
 
 
23
 
static QString randomId()
24
 
{
25
 
        return QUuid::createUuid().toString();
26
 
}
27
 
 
28
 
void copyTags(MapFeature* Dest, MapFeature* Src)
29
 
{
30
 
        for (unsigned int i=0; i<Src->tagSize(); ++i)
31
 
                Dest->setTag(Src->tagKey(i),Src->tagValue(i));
32
 
}
33
 
 
34
 
class MapFeaturePrivate
35
 
{
36
 
        public:
37
 
                MapFeaturePrivate()
38
 
                        :  TagsSize(0), LastActor(MapFeature::User), theLayer(0),
39
 
                                PossiblePaintersUpToDate(false),
40
 
                                PixelPerMForPainter(-1), CurrentPainter(0), HasPainter(false),
41
 
                                theFeature(0), LastPartNotification(0),
42
 
                                Time(QDateTime::currentDateTime()), Deleted(false), Uploaded(false)
43
 
                {
44
 
                        initVersionNumber();
45
 
                        parentDashes << 1 << 5;
46
 
                }
47
 
                MapFeaturePrivate(const MapFeaturePrivate& other)
48
 
                        : Tags(other.Tags), TagsSize(other.TagsSize), LastActor(other.LastActor), theLayer(0),
49
 
                                PossiblePaintersUpToDate(false),
50
 
                                PixelPerMForPainter(-1), CurrentPainter(0), HasPainter(false),
51
 
                                theFeature(0), LastPartNotification(0),
52
 
                                Time(other.Time), Deleted(false), Uploaded(false)
53
 
                {
54
 
                        initVersionNumber();
55
 
                        parentDashes << 1 << 5;
56
 
                }
57
 
 
58
 
                void updatePainters(double PixelPerM);
59
 
                void blankPainters(double PixelPerM);
60
 
                void initVersionNumber();
61
 
 
62
 
                mutable QString Id;
63
 
                std::vector<std::pair<QString, QString> > Tags;
64
 
                unsigned int TagsSize;
65
 
                MapFeature::ActorType LastActor;
66
 
                MapLayer* theLayer;
67
 
                QVector<const FeaturePainter*> PossiblePainters;
68
 
                bool PossiblePaintersUpToDate;
69
 
                double PixelPerMForPainter;
70
 
                const FeaturePainter* CurrentPainter;
71
 
                bool HasPainter;
72
 
                MapFeature* theFeature;
73
 
                std::vector<MapFeature*> Parents;
74
 
                unsigned int LastPartNotification;
75
 
                QDateTime Time;
76
 
                QString User;
77
 
                int VersionNumber;
78
 
                QVector<qreal> parentDashes;
79
 
                bool Deleted;
80
 
                bool Uploaded;
81
 
 
82
 
};
83
 
 
84
 
void MapFeaturePrivate::initVersionNumber()
85
 
{
86
 
        static int VN = -1;
87
 
        VersionNumber = VN--;
88
 
}
89
 
 
90
 
MapFeature::MapFeature()
91
 
: p(0)
92
 
{
93
 
         p = new MapFeaturePrivate;
94
 
         p->theFeature = this;
95
 
}
96
 
 
97
 
MapFeature::MapFeature(const MapFeature& other) : QObject()
98
 
{
99
 
        p = new MapFeaturePrivate(*other.p);
100
 
        p->theFeature = this;
101
 
}
102
 
 
103
 
MapFeature::~MapFeature(void)
104
 
{
105
 
        while (sizeParents())
106
 
                getParent(0)->remove(this);
107
 
        if (p->theLayer)
108
 
                p->theLayer->notifyIdUpdate(p->Id,0);
109
 
        delete p;
110
 
}
111
 
 
112
 
void MapFeature::setVersionNumber(int vn)
113
 
{
114
 
        p->VersionNumber = vn;
115
 
}
116
 
 
117
 
int MapFeature::versionNumber() const
118
 
{
119
 
        return p->VersionNumber;
120
 
}
121
 
 
122
 
void MapFeature::setLayer(MapLayer* aLayer)
123
 
{
124
 
        p->theLayer = aLayer;
125
 
        notifyChanges();
126
 
}
127
 
 
128
 
MapLayer* MapFeature::layer()
129
 
{
130
 
        return p->theLayer;
131
 
}
132
 
 
133
 
void MapFeature::setLastUpdated(MapFeature::ActorType A)
134
 
{
135
 
        p->LastActor = A;
136
 
}
137
 
 
138
 
MapFeature::ActorType MapFeature::lastUpdated() const
139
 
{
140
 
        if (p->theLayer->className() == "DirtyMapLayer")
141
 
                return MapFeature::User;
142
 
        else
143
 
                return p->LastActor;
144
 
}
145
 
 
146
 
void MapFeature::setId(const QString& id)
147
 
{
148
 
        if (p->theLayer)
149
 
        {
150
 
                p->theLayer->notifyIdUpdate(p->Id,0);
151
 
                p->theLayer->notifyIdUpdate(id,this);
152
 
        }
153
 
        p->Id = id;
154
 
}
155
 
 
156
 
const QString& MapFeature::id() const
157
 
{
158
 
        if (p->Id == "")
159
 
        {
160
 
                p->Id = randomId();
161
 
                if (p->theLayer)
162
 
                        p->theLayer->notifyIdUpdate(p->Id,const_cast<MapFeature*>(this));
163
 
        }
164
 
        return p->Id;
165
 
}
166
 
 
167
 
qint64 MapFeature::idToLong() const
168
 
{
169
 
        bool ok;
170
 
 
171
 
        if (hasOSMId()) {
172
 
                QString s = stripToOSMId(id());
173
 
                qint64 l = s.toLongLong(&ok);
174
 
                Q_ASSERT(ok);
175
 
                return l;
176
 
        } else {
177
 
        return (((qint64)this) * -1);
178
 
    }
179
 
}
180
 
 
181
 
QString MapFeature::xmlId() const
182
 
{
183
 
        return stripToOSMId(id());
184
 
}
185
 
 
186
 
bool MapFeature::hasOSMId() const
187
 
{
188
 
        if (p->Id.left(5) == "node_")
189
 
                return true;
190
 
        if (p->Id.left(4) == "way_")
191
 
                return true;
192
 
        if (p->Id.left(4) == "rel_")
193
 
                return true;
194
 
        return false;
195
 
}
196
 
 
197
 
const QDateTime& MapFeature::time() const
198
 
{
199
 
        return p->Time;
200
 
}
201
 
 
202
 
void MapFeature::setTime(const QDateTime& time)
203
 
{
204
 
        p->Time = time;
205
 
        notifyChanges();
206
 
}
207
 
 
208
 
const QString& MapFeature::user() const
209
 
{
210
 
        return p->User;
211
 
}
212
 
 
213
 
void MapFeature::setUser(const QString& user)
214
 
{
215
 
        p->User = user;
216
 
        notifyChanges();
217
 
}
218
 
 
219
 
bool MapFeature::isDirty() const
220
 
{
221
 
        return (p->theLayer->className() == "DirtyMapLayer");
222
 
}
223
 
 
224
 
void MapFeature::setUploaded(bool state)
225
 
{
226
 
        p->Uploaded = state;
227
 
}
228
 
 
229
 
bool MapFeature::isUploaded() const
230
 
{
231
 
        return p->Uploaded;
232
 
}
233
 
 
234
 
bool MapFeature::isUploadable() const
235
 
{
236
 
        return (p->theLayer->isUploadable());
237
 
}
238
 
 
239
 
void MapFeature::setDeleted(bool delState)
240
 
{
241
 
        p->Deleted = delState;
242
 
}
243
 
 
244
 
bool MapFeature::isDeleted() const
245
 
{
246
 
        return p->Deleted;
247
 
}
248
 
 
249
 
void MapFeature::setTag(unsigned int index, const QString& key, const QString& value, bool addToTagList)
250
 
{
251
 
        unsigned int i;
252
 
 
253
 
        p->PixelPerMForPainter = -1;
254
 
        for (i=0; i<p->Tags.size(); ++i)
255
 
                if (p->Tags[i].first == key)
256
 
                {
257
 
                        p->Tags[i].second = value;
258
 
                        break;
259
 
                }
260
 
        if (i == p->Tags.size()) {
261
 
                p->Tags.insert(p->Tags.begin() + index, std::make_pair(key,value));
262
 
                p->TagsSize++;
263
 
        }
264
 
        if (p->theLayer && addToTagList)
265
 
                if (p->theLayer->getDocument())
266
 
                        p->theLayer->getDocument()->addToTagList(key, value);
267
 
        notifyChanges();
268
 
}
269
 
 
270
 
void MapFeature::setTag(const QString& key, const QString& value, bool addToTagList)
271
 
{
272
 
        p->PixelPerMForPainter = -1;
273
 
        for (unsigned int i=0; i<p->Tags.size(); ++i)
274
 
                if (p->Tags[i].first == key)
275
 
                {
276
 
                        p->Tags[i].second = value;
277
 
                        notifyChanges();
278
 
                        return;
279
 
                }
280
 
        p->Tags.push_back(std::make_pair(key,value));
281
 
        p->TagsSize++;
282
 
        if (p->theLayer && addToTagList)
283
 
                if (p->theLayer->getDocument())
284
 
                        p->theLayer->getDocument()->addToTagList(key, value);
285
 
        notifyChanges();
286
 
}
287
 
 
288
 
void MapFeature::clearTags()
289
 
{
290
 
        p->PixelPerMForPainter = -1;
291
 
        p->Tags.clear();
292
 
        p->TagsSize = 0;
293
 
        notifyChanges();
294
 
}
295
 
 
296
 
void MapFeature::invalidatePainter()
297
 
{
298
 
        p->PossiblePaintersUpToDate = false;
299
 
        p->PixelPerMForPainter = -1;
300
 
}
301
 
 
302
 
void MapFeature::clearTag(const QString& k)
303
 
{
304
 
        for (unsigned int i=0; i<p->Tags.size(); ++i)
305
 
                if (p->Tags[i].first == k)
306
 
                {
307
 
                        p->PixelPerMForPainter = -1;
308
 
                        p->Tags.erase(p->Tags.begin()+i);
309
 
                        p->TagsSize--;
310
 
                        notifyChanges();
311
 
                        return;
312
 
                }
313
 
}
314
 
 
315
 
void MapFeature::removeTag(unsigned int idx)
316
 
{
317
 
        p->PixelPerMForPainter = -1;
318
 
        p->Tags.erase(p->Tags.begin()+idx);
319
 
        p->TagsSize--;
320
 
        notifyChanges();
321
 
}
322
 
 
323
 
unsigned int MapFeature::tagSize() const
324
 
{
325
 
        return p->TagsSize;
326
 
}
327
 
 
328
 
QString MapFeature::tagValue(unsigned int i) const
329
 
{
330
 
        return p->Tags[i].second;
331
 
}
332
 
 
333
 
QString MapFeature::tagKey(unsigned int i) const
334
 
{
335
 
        return p->Tags[i].first;
336
 
}
337
 
 
338
 
unsigned int MapFeature::findKey(const QString &k) const
339
 
{
340
 
        for (unsigned int i=0; i<p->TagsSize; ++i)
341
 
                if (p->Tags[i].first == k)
342
 
                        return i;
343
 
        return p->Tags.size();
344
 
}
345
 
 
346
 
QString MapFeature::tagValue(const QString& k, const QString& Default) const
347
 
{
348
 
        for (unsigned int i=0; i<p->TagsSize; ++i)
349
 
                if (p->Tags[i].first == k)
350
 
                        return p->Tags[i].second;
351
 
        return Default;
352
 
}
353
 
 
354
 
void MapFeaturePrivate::updatePainters(double PixelPerM)
355
 
{
356
 
        //if the object has no tags or only the created_by tag, we don't check for style
357
 
        //search is about 15 times faster like that !!!
358
 
        //However, still match features with no tags and no parent, i.e. "lost" trackpoints
359
 
        if ( (theFeature->layer()->isTrack()) && MerkaartorPreferences::instance()->getDisableStyleForTracks() ) return blankPainters(PixelPerM);
360
 
 
361
 
        if ( (theFeature->layer()->isTrack()) || theFeature->sizeParents() ) {
362
 
                unsigned int i;
363
 
                for (i=0; i<theFeature->tagSize(); ++i)
364
 
                        if ((theFeature->tagKey(i) != "created_by") && (theFeature->tagKey(i) != "ele"))
365
 
                                break;
366
 
 
367
 
                if (i == theFeature->tagSize()) return blankPainters(PixelPerM);
368
 
        }
369
 
 
370
 
        if (PixelPerMForPainter < 0)
371
 
        {
372
 
                PossiblePainters.clear();
373
 
                QVector<const FeaturePainter*> DefaultPainters;
374
 
                for (int i=0; i<M_STYLE->painterSize(); ++i)
375
 
                {
376
 
                        const FeaturePainter* Current = M_STYLE->getPainter(i);
377
 
                        switch (Current->matchesTag(theFeature)) {
378
 
                                case TagSelect_Match:
379
 
                                        PossiblePainters.push_back(Current);
380
 
                                        break;
381
 
                                case TagSelect_DefaultMatch:
382
 
                                        DefaultPainters.push_back(Current);
383
 
                                        break;
384
 
                                default:
385
 
                                        break;
386
 
                        }
387
 
                }
388
 
                if (!PossiblePainters.size())
389
 
                        PossiblePainters = DefaultPainters;
390
 
                PossiblePaintersUpToDate = true;
391
 
                HasPainter = PossiblePainters.size();
392
 
        }
393
 
        CurrentPainter = 0;
394
 
        PixelPerMForPainter = PixelPerM;
395
 
        for (int i=0; i<PossiblePainters.size(); ++i)
396
 
                if (PossiblePainters[i]->matchesZoom(PixelPerM))
397
 
                {
398
 
                        CurrentPainter = PossiblePainters[i];
399
 
                        return;
400
 
                }
401
 
}
402
 
 
403
 
void MapFeaturePrivate::blankPainters(double PixelPerM)
404
 
{
405
 
        CurrentPainter = 0;
406
 
        PixelPerMForPainter = PixelPerM;
407
 
        PossiblePainters.clear();
408
 
        HasPainter = false;
409
 
}
410
 
 
411
 
const FeaturePainter* MapFeature::getEditPainter(double PixelPerM) const
412
 
{
413
 
        if (p->PixelPerMForPainter != PixelPerM)
414
 
                p->updatePainters(PixelPerM);
415
 
        return p->CurrentPainter;
416
 
}
417
 
 
418
 
const FeaturePainter* MapFeature::getCurrentEditPainter() const
419
 
{
420
 
        return p->CurrentPainter;
421
 
}
422
 
 
423
 
bool MapFeature::hasEditPainter() const
424
 
{
425
 
        return p->HasPainter;
426
 
}
427
 
 
428
 
void MapFeature::setParent(MapFeature* F)
429
 
{
430
 
        if (std::find(p->Parents.begin(),p->Parents.end(),F) == p->Parents.end())
431
 
                p->Parents.push_back(F);
432
 
}
433
 
 
434
 
void MapFeature::unsetParent(MapFeature* F)
435
 
{
436
 
        for (unsigned int i=0; i<p->Parents.size(); ++i)
437
 
                if (p->Parents[i] == F)
438
 
                {
439
 
                        p->Parents.erase(p->Parents.begin()+i);
440
 
                        return;
441
 
                }
442
 
}
443
 
 
444
 
unsigned int MapFeature::sizeParents() const
445
 
{
446
 
        return p->Parents.size();
447
 
}
448
 
 
449
 
MapFeature* MapFeature::getParent(unsigned int i)
450
 
{
451
 
        return p->Parents[i];
452
 
}
453
 
 
454
 
const MapFeature* MapFeature::getParent(unsigned int i) const
455
 
{
456
 
        return p->Parents[i];
457
 
}
458
 
 
459
 
 
460
 
void MapFeature::notifyChanges()
461
 
{
462
 
        static unsigned int Id = 0;
463
 
        notifyParents(++Id);
464
 
        if (p->theLayer)
465
 
                p->theLayer->invalidateRenderPriority();
466
 
}
467
 
 
468
 
void MapFeature::notifyParents(unsigned int Id)
469
 
{
470
 
        if (Id != p->LastPartNotification)
471
 
        {
472
 
                p->LastPartNotification = Id;
473
 
                for (unsigned int i=0; i<p->Parents.size(); ++i)
474
 
                        p->Parents[i]->partChanged(this, Id);
475
 
        }
476
 
}
477
 
 
478
 
QString MapFeature::tagsToXML(unsigned int lvl)
479
 
{
480
 
        QString S;
481
 
        for (unsigned int i=0; i<tagSize(); ++i)
482
 
        {
483
 
                S += QString(lvl*2, ' ') + QString("<tag k=\"%1\" v=\"%2\"/>\n").arg(encodeAttributes(tagKey(i))).arg(encodeAttributes(tagValue(i)));
484
 
        }
485
 
        return S;
486
 
}
487
 
 
488
 
bool MapFeature::tagsToXML(QDomElement xParent)
489
 
{
490
 
        bool OK = true;
491
 
 
492
 
        for (unsigned int i=0; i<tagSize(); ++i)
493
 
        {
494
 
                QDomElement e = xParent.ownerDocument().createElement("tag");
495
 
                xParent.appendChild(e);
496
 
 
497
 
                e.setAttribute("k", tagKey(i));
498
 
                e.setAttribute("v", tagValue(i));
499
 
        }
500
 
 
501
 
        return OK;
502
 
}
503
 
 
504
 
void MapFeature::tagsFromXML(MapDocument* d, MapFeature * f, QDomElement e)
505
 
{
506
 
        Q_UNUSED(d)
507
 
        QDomElement c = e.firstChildElement();
508
 
        while(!c.isNull()) {
509
 
                if (c.tagName() == "tag") {
510
 
                        f->setTag(c.attribute("k"),c.attribute("v"));
511
 
                }
512
 
                c = c.nextSiblingElement();
513
 
        }
514
 
}
515
 
 
516
 
QString MapFeature::stripToOSMId(const QString& id)
517
 
{
518
 
        int f = id.lastIndexOf("_");
519
 
        if (f>0)
520
 
                return id.right(id.length()-(f+1));
521
 
        return id;
522
 
}
523
 
 
524
 
QVector<qreal> MapFeature::getParentDashes() const
525
 
{
526
 
        return p->parentDashes;
527
 
}
528
 
 
529
 
Relation * MapFeature::GetSingleParentRelation(MapFeature * mapFeature)
530
 
{
531
 
        unsigned int parents = mapFeature->sizeParents();
532
 
 
533
 
        if (parents == 0)
534
 
                return NULL;
535
 
 
536
 
        Relation * parentRelation = NULL;
537
 
 
538
 
        unsigned int i;
539
 
        for (i=0; i<parents; i++)
540
 
        {
541
 
                MapFeature * parent = mapFeature->getParent(i);
542
 
                Relation * rel = dynamic_cast<Relation*>(parent);
543
 
 
544
 
                if (rel == NULL)
545
 
                        continue;
546
 
 
547
 
                if (parentRelation)
548
 
                        return NULL;
549
 
 
550
 
                if (rel->layer()->isEnabled())
551
 
                        parentRelation = rel;
552
 
        }
553
 
 
554
 
        return parentRelation;
555
 
}
556
 
 
557
 
//Static
558
 
TrackPoint* MapFeature::getTrackPointOrCreatePlaceHolder(MapDocument *theDocument, MapLayer *theLayer, const QString& Id)
559
 
{
560
 
        TrackPoint* Part = dynamic_cast<TrackPoint*>(theDocument->getFeature("node_"+Id));
561
 
        if (!Part)
562
 
        {
563
 
                Part = dynamic_cast<TrackPoint*>(theDocument->getFeature(Id));
564
 
                if (!Part)
565
 
                {
566
 
                        Part = new TrackPoint(Coord(0,0));
567
 
                        if (Id.startsWith('{'))
568
 
                                Part->setId(Id);
569
 
                        else
570
 
                                Part->setId("node_"+Id);
571
 
                        Part->setLastUpdated(MapFeature::NotYetDownloaded);
572
 
                        theLayer->add(Part);
573
 
                }
574
 
        }
575
 
        return Part;
576
 
}
577
 
 
578
 
Road* MapFeature::getWayOrCreatePlaceHolder(MapDocument *theDocument, MapLayer *theLayer, const QString& Id)
579
 
{
580
 
        Road* Part = dynamic_cast<Road*>(theDocument->getFeature("way_"+Id));
581
 
        if (!Part)
582
 
        {
583
 
                Part = dynamic_cast<Road*>(theDocument->getFeature(Id));
584
 
                if (!Part)
585
 
                {
586
 
                        Part = new Road;
587
 
                        if (Id.startsWith('{'))
588
 
                                Part->setId(Id);
589
 
                        else
590
 
                                Part->setId("way_"+Id);
591
 
                        Part->setLastUpdated(MapFeature::NotYetDownloaded);
592
 
                        theLayer->add(Part);
593
 
                }
594
 
        }
595
 
        return Part;
596
 
}
597
 
 
598
 
Relation* MapFeature::getRelationOrCreatePlaceHolder(MapDocument *theDocument, MapLayer *theLayer, const QString& Id)
599
 
{
600
 
        Relation* Part = dynamic_cast<Relation*>(theDocument->getFeature("rel_"+Id));
601
 
        if (!Part)
602
 
        {
603
 
                Part = dynamic_cast<Relation*>(theDocument->getFeature(Id));
604
 
                if (!Part)
605
 
                {
606
 
                        Part = new Relation;
607
 
                        if (Id.startsWith('{'))
608
 
                                Part->setId(Id);
609
 
                        else
610
 
                                Part->setId("rel_"+Id);
611
 
                        Part->setLastUpdated(MapFeature::NotYetDownloaded);
612
 
                        theLayer->add(Part);
613
 
                }
614
 
        }
615
 
        return Part;
616
 
}
617
 
 
618
 
void MapFeature::mergeTags(MapDocument* theDocument, CommandList* L, MapFeature* Dest, MapFeature* Src)
619
 
{
620
 
        for (unsigned int i=0; i<Src->tagSize(); ++i)
621
 
        {
622
 
                QString k = Src->tagKey(i);
623
 
                QString v1 = Src->tagValue(i);
624
 
                unsigned int j = Dest->findKey(k);
625
 
                if (j == Dest->tagSize())
626
 
                        L->add(new SetTagCommand(Dest,k,v1, theDocument->getDirtyOrOriginLayer(Dest->layer())));
627
 
                else
628
 
                {
629
 
                        QString v2 = Dest->tagValue(j);
630
 
                        if (v1 != v2 && k !="created_by")
631
 
                        {
632
 
                                L->add(new SetTagCommand(Dest,k,QString("%1;%2").arg(v2).arg(v1), theDocument->getDirtyOrOriginLayer(Dest->layer())));
633
 
                        }
634
 
                }
635
 
        }
636
 
}
637
 
 
638
 
 
639
 
QString MapFeature::toMainHtml(QString type, QString systemtype)
640
 
{
641
 
        QString desc;
642
 
        QString name(tagValue("name",""));
643
 
        if (!name.isEmpty())
644
 
                desc = QString("<big><b>%1</b></big><br/><small>(%2)</small>").arg(name).arg(id());
645
 
        else
646
 
                desc = QString("<big><b>%1</b></big>").arg(id());
647
 
 
648
 
        QString S =
649
 
        "<html><head/><body>"
650
 
        "<small><i>" + type + "</i></small><br/>"
651
 
        + desc + 
652
 
        "<br/>"
653
 
        "<small>";
654
 
        if (!user().isEmpty())
655
 
                S += QApplication::translate("MapFeature", "<i>last: </i><b>%1</b> by <b>%2</b>").arg(time().toString(Qt::SystemLocaleDate)).arg(user());
656
 
        else
657
 
                S += QApplication::translate("MapFeature", "<i>last: </i><b>%1</b>").arg(time().toString(Qt::SystemLocaleDate));
658
 
        S += "</small>"
659
 
        "<hr/>"
660
 
        "%1";
661
 
        int f = id().lastIndexOf("_");
662
 
        if (f>0) {
663
 
                S += "<hr/>"
664
 
                "<a href='/api/" + M_PREFS->apiVersion() + "/" + systemtype + "/" + xmlId() + "/history'>"+QApplication::translate("MapFeature", "History")+"</a>";
665
 
                if (systemtype == "node") {
666
 
                        S += "<br/>"
667
 
                        "<a href='/api/" + M_PREFS->apiVersion() + "/" + systemtype + "/" + xmlId() + "/ways'>"+QApplication::translate("MapFeature", "Referenced by ways")+"</a>";
668
 
                }
669
 
                S += "<br/>"
670
 
                "<a href='/api/" + M_PREFS->apiVersion() + "/" + systemtype + "/" + xmlId() + "/relations'>"+QApplication::translate("MapFeature", "Referenced by relation")+"</a>";
671
 
        }
672
 
        S += "</body></html>";
673
 
 
674
 
        return S;
675
 
}
676
 
 
677
 
bool MapFeature::QRectInterstects(const QRect& r, const QLine& l, QPoint& a, QPoint& b)
678
 
{
679
 
        QLineF lF = QLineF(l);
680
 
        QPointF pF;
681
 
        bool hasP1 = false;
682
 
        bool hasP2 = false;
683
 
 
684
 
        if (QLineF(r.topLeft(), r.bottomLeft()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
685
 
                a = pF.toPoint();
686
 
                hasP1 = true;
687
 
        }
688
 
        if (QLineF(r.bottomLeft(), r.bottomRight()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
689
 
                if (hasP1) {
690
 
                        b = pF.toPoint();
691
 
                        hasP2 = true;
692
 
                } else {
693
 
                        a = pF.toPoint();
694
 
                        hasP1 = true;
695
 
                }
696
 
        }
697
 
        if (QLineF(r.bottomRight(), r.topRight()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
698
 
                if (hasP1) {
699
 
                        b = pF.toPoint();
700
 
                        hasP2 = true;
701
 
                } else {
702
 
                        a = pF.toPoint();
703
 
                        hasP1 = true;
704
 
                }
705
 
        }
706
 
        if (QLineF(r.topRight(), r.topLeft()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
707
 
                if (hasP1) {
708
 
                        b = pF.toPoint();
709
 
                        hasP2 = true;
710
 
                } else {
711
 
                        a = pF.toPoint();
712
 
                        hasP1 = true;
713
 
                }
714
 
        }
715
 
 
716
 
        if (hasP1 && hasP2) {
717
 
#if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
718
 
                double la1 = QLineF(a,b).angleTo(lF);
719
 
#else
720
 
                double la1 = QLineF(a,b).angle(lF);
721
 
#endif
722
 
                if (la1 > 15.0 && la1 < 345.0) {
723
 
                        QPoint t = b;
724
 
                        b = a;
725
 
                        a = t;
726
 
                }
727
 
        }
728
 
        if (hasP1)
729
 
                return true;
730
 
        else
731
 
                return false;
732
 
}
733