1
#include "PropertiesDock.h"
3
#include "MainWindow.h"
6
#include "Utils/EditCompleterDelegate.h"
7
#include "Utils/ShortcutOverrideFilter.h"
8
#include "Command/DocumentCommands.h"
9
#include "Command/FeatureCommands.h"
10
#include "Command/TrackPointCommands.h"
11
#include "Command/RelationCommands.h"
12
#include "Maps/Coord.h"
13
#include "Maps/MapDocument.h"
14
#include "Maps/MapFeature.h"
15
#include "Maps/Relation.h"
16
#include "Maps/Road.h"
17
#include "Maps/FeatureManipulations.h"
18
#include "Maps/TrackPoint.h"
19
#include "TagTemplate/TagTemplate.h"
22
#include "GeoImageDock.h"
25
#include <QtCore/QTimer>
26
#include <QtGui/QHeaderView>
27
#include <QtGui/QLineEdit>
28
#include <QtGui/QListWidget>
29
#include <QtGui/QTableView>
31
#include <QMessageBox>
35
PropertiesDock::PropertiesDock(MainWindow* aParent)
36
: MDockAncestor(aParent), Main(aParent), CurrentUi(0),
37
theTemplates(0), CurrentTagView(0), CurrentMembersView(0), NowShowing(NoUiShowing)
39
setMinimumSize(220,100);
41
setObjectName("propertiesDock");
42
theModel = new TagModel(aParent);
43
delegate = new EditCompleterDelegate(aParent);
45
// Set up the shortcut event filter for the tableviews
46
// This allows them to react to keys already bound to
47
// application wide shortcuts
48
shortcutFilter = new ShortcutOverrideFilter();
49
shortcutFilter->addOverride(Qt::Key_Up);
50
shortcutFilter->addOverride(Qt::Key_Down);
51
shortcutFilter->addOverride(Qt::Key_Left);
52
shortcutFilter->addOverride(Qt::Key_Right);
53
shortcutFilter->addOverride(Qt::Key_F2);
54
shortcutFilter->addOverride(Qt::Key_Delete);
55
shortcutFilter->addOverride(Qt::Key_Escape);
57
centerAction = new QAction(NULL, this);
58
connect(centerAction, SIGNAL(triggered()), this, SLOT(on_centerAction_triggered()));
59
centerZoomAction = new QAction(NULL, this);
60
connect(centerZoomAction, SIGNAL(triggered()), this, SLOT(on_centerZoomAction_triggered()));
61
selectAction = new QAction(NULL, this);
62
connect(selectAction, SIGNAL(triggered()), this, SLOT(on_Member_selected()));
69
PropertiesDock::~PropertiesDock(void)
73
delete shortcutFilter;
76
static bool isChildOfSingleRoadInner(MapFeature *mapFeature)
78
return Road::GetSingleParentRoadInner(mapFeature) != NULL;
81
static bool isChildOfArea(MapFeature *mapFeature)
83
Road* R = Road::GetSingleParentRoadInner(mapFeature);
85
return (R->area() > 0.0);
89
static bool isChildOfSingleRoad(MapFeature *mapFeature)
91
return Road::GetSingleParentRoad(mapFeature) != NULL;
94
static bool isChildOfSingleRelation(MapFeature *mapFeature)
96
int parents = mapFeature->sizeParents();
101
int parentRelations = 0;
104
for (i=0; i<parents; i++)
106
MapFeature * parent = mapFeature->getParent(i);
107
bool isParentRelation = dynamic_cast<Relation*>(parent) != 0;
108
if (isParentRelation)
110
if (parentRelations > 1)
114
return (parentRelations == 1);
117
static bool isChildOfRelation(MapFeature *mapFeature)
119
int parents = mapFeature->sizeParents();
125
for (i=0; i<parents; i++)
127
MapFeature * parent = mapFeature->getParent(i);
128
if (dynamic_cast<Relation*>(parent))
135
void PropertiesDock::checkMenuStatus()
137
bool IsPoint = false;
139
bool IsParentRoad = false;
140
bool IsParentRoadInner = false;
141
bool IsParentRelation = false;
142
bool IsParentArea = false;
144
int NumCommitableFeature = 0;
147
int NumRelationChild = 0;
149
if (Selection.size() == 1)
151
IsPoint = dynamic_cast<TrackPoint*>(Selection[0]) != 0;
152
IsRoad = dynamic_cast<Road*>(Selection[0]) != 0;
153
IsParentRoad = IsPoint && isChildOfSingleRoad(Selection[0]);
154
IsParentRoadInner = IsPoint && isChildOfSingleRoadInner(Selection[0]);
155
IsParentRelation = isChildOfSingleRelation(Selection[0]);
156
IsParentArea = isChildOfArea(Selection[0]);
158
for (int i=0; i<Selection.size(); ++i)
160
if (CAST_NODE(Selection[i]))
162
if (Road* R = dynamic_cast<Road*>(Selection[i]))
173
if (CAST_RELATION(Selection[i]))
175
if (isChildOfRelation(Selection[i]))
178
if (!Selection[i]->isDirty())
179
++NumCommitableFeature;
181
Main->createRelationAction->setEnabled(Selection.size());
182
Main->editRemoveAction->setEnabled(Selection.size());
183
Main->editMoveAction->setEnabled(true);
184
Main->editReverseAction->setEnabled(IsRoad);
185
Main->roadJoinAction->setEnabled(NumRoads > 1 && canJoinRoads(this));
186
Main->roadCreateJunctionAction->setEnabled(NumRoads > 1 && canCreateJunction(this));
187
Main->roadSplitAction->setEnabled((IsParentRoadInner && !IsParentArea) || (NumRoads && NumPoints) || (NumAreas && NumPoints));
188
Main->roadBreakAction->setEnabled(IsParentRoadInner || (NumRoads == 1 && NumPoints) || (NumRoads > 1 && canBreakRoads(this)));
189
Main->featureCommitAction->setEnabled(NumCommitableFeature);
190
Main->nodeMergeAction->setEnabled(NumPoints > 1);
191
Main->nodeAlignAction->setEnabled(NumPoints > 2);
192
Main->nodeDetachAction->setEnabled(NumPoints && canDetachNodes(this));
193
Main->relationAddMemberAction->setEnabled(NumRelation && Selection.size() > 1);
194
Main->relationRemoveMemberAction->setEnabled((NumRelation && Selection.size() > 1 && NumRelationChild) || IsParentRelation);
196
Main->editCopyAction->setEnabled(Selection.size());
197
Main->clipboardChanged();
200
int PropertiesDock::size() const
202
return Selection.size();
205
MapFeature* PropertiesDock::selection(int idx)
207
if (idx < Selection.size())
208
return Selection[idx];
212
QList<MapFeature*> PropertiesDock::selection()
217
void PropertiesDock::setSelection(MapFeature*aFeature)
222
Selection.push_back(aFeature);
223
FullSelection = Selection;
225
fillMultiUiSelectionBox();
228
void PropertiesDock::setMultiSelection(const QList<MapFeature*>& aFeatureList)
232
for (int i=0; i<aFeatureList.size(); ++i)
233
Selection.push_back(aFeatureList[i]);
234
FullSelection = Selection;
236
// to prevent slots to change the values also
237
QList<MapFeature*> Current = Selection;
239
MultiUi.TagView->setModel(theModel);
240
MultiUi.TagView->setItemDelegate(delegate);
241
Main->info()->setHtml("");
243
Main->geoImage()->setImage((TrackPoint *)NULL);
245
CurrentTagView = MultiUi.TagView;
246
theModel->setFeature(Current);
248
fillMultiUiSelectionBox();
251
void PropertiesDock::toggleSelection(MapFeature* S)
254
QList<MapFeature*>::iterator i = std::find(Selection.begin(),Selection.end(),S);
255
if (i == Selection.end())
256
Selection.push_back(S);
259
FullSelection = Selection;
261
fillMultiUiSelectionBox();
264
void PropertiesDock::addSelection(MapFeature* S)
267
QList<MapFeature*>::iterator i = std::find(Selection.begin(),Selection.end(),S);
268
if (i == Selection.end())
269
Selection.push_back(S);
270
FullSelection = Selection;
272
fillMultiUiSelectionBox();
275
void PropertiesDock::adjustSelection()
277
QList<MapFeature*> aSelection;
278
int cnt = Selection.size();
280
for (int i=0; i<FullSelection.size(); ++i) {
281
if (Main->document()->exists(FullSelection[i])) {
282
aSelection.push_back(FullSelection[i]);
284
QList<MapFeature*>::iterator it = std::find(Selection.begin(),Selection.end(),FullSelection[i]);
285
if (it != Selection.end())
290
FullSelection = aSelection;
291
if (Selection.size() != cnt)
295
bool PropertiesDock::isSelected(MapFeature *aFeature)
297
QList<MapFeature*>::iterator i = std::find(Selection.begin(),Selection.end(),aFeature);
298
if (i == Selection.end())
304
void PropertiesDock::fillMultiUiSelectionBox()
306
if (NowShowing == MultiShowing)
308
// to prevent on_SelectionList_itemSelectionChanged to kick in
309
NowShowing = NoUiShowing;
310
Main->setUpdatesEnabled(false);
311
MultiUi.SelectionList->clear();
312
for (int i=0; i<FullSelection.size(); ++i)
314
QListWidgetItem* it = new QListWidgetItem(FullSelection[i]->description(),MultiUi.SelectionList);
315
it->setData(Qt::UserRole,QVariant(i));
316
it->setSelected(true);
318
MultiUi.lbStatus->setText(tr("%1/%1 selected item(s)").arg(FullSelection.size()));
319
Main->setUpdatesEnabled(true);
320
NowShowing = MultiShowing;
324
void PropertiesDock::on_SelectionList_itemSelectionChanged()
326
if (NowShowing == MultiShowing)
329
for (int i=0; i<FullSelection.size(); ++i)
330
if (MultiUi.SelectionList->item(i)->isSelected())
331
Selection.push_back(FullSelection[i]);
332
if (Selection.size() == 1) {
333
Main->info()->setHtml(Selection[0]->toHtml());
337
if ((Pt = dynamic_cast<TrackPoint*>(Selection[0]))) Main->geoImage()->setImage(Pt);
340
theModel->setFeature(Selection);
341
MultiUi.lbStatus->setText(tr("%1/%2 selected item(s)").arg(Selection.size()).arg(FullSelection.size()));
342
Main->view()->update();
346
void PropertiesDock::on_SelectionList_itemDoubleClicked(QListWidgetItem* item)
348
int i=item->data(Qt::UserRole).toUInt();
349
PendingSelectionChange = i;
350
// changing directly from this method would delete the current Ui from
351
// which this slot is called
352
QTimer::singleShot(0,this,SLOT(executePendingSelectionChange()));
355
void PropertiesDock::executePendingSelectionChange()
357
if (PendingSelectionChange < FullSelection.size())
358
setSelection(FullSelection[PendingSelectionChange]);
361
void PropertiesDock::cleanUpUi()
363
if (NowShowing == RelationUiShowing)
365
RelationUi.MembersView->setModel(0);
366
Relation* R = dynamic_cast<Relation*>(FullSelection[0]);
367
R->releaseMemberModel();
371
void PropertiesDock::switchUi()
374
M_PREFS->setTagListFirstColumnWidth(CurrentTagView->columnWidth(0));
376
if (FullSelection.size() == 0)
378
else if (FullSelection.size() == 1)
380
if (CAST_NODE(FullSelection[0]))
381
switchToTrackPointUi();
382
else if (CAST_WAY(FullSelection[0]))
384
else if (CAST_RELATION(FullSelection[0]))
385
switchToRelationUi();
394
void PropertiesDock::switchToMultiUi()
396
if (NowShowing == MultiShowing) return;
397
NowShowing = MultiShowing;
398
QWidget* NewUi = new QWidget(this);
399
MultiUi.setupUi(NewUi);
400
MultiUi.TagView->verticalHeader()->hide();
401
MultiUi.SelectionList->setContextMenuPolicy(Qt::CustomContextMenu);
402
MultiUi.lbStatus->setText(tr("Selected items"));
405
CurrentUi->deleteLater();
407
connect(MultiUi.RemoveTagButton,SIGNAL(clicked()),this, SLOT(on_RemoveTagButton_clicked()));
408
connect(MultiUi.SelectionList,SIGNAL(itemSelectionChanged()),this,SLOT(on_SelectionList_itemSelectionChanged()));
409
connect(MultiUi.SelectionList,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(on_SelectionList_itemDoubleClicked(QListWidgetItem*)));
410
connect(MultiUi.SelectionList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(on_SelectionList_customContextMenuRequested(const QPoint &)));
411
setWindowTitle(tr("Properties - Multiple elements"));
414
void PropertiesDock::switchToTrackPointUi()
416
NowShowing = TrackPointUiShowing;
417
QWidget* NewUi = new QWidget(this);
418
TrackPointUi.setupUi(NewUi);
419
TrackPointUi.TagView->verticalHeader()->hide();
422
CurrentUi->deleteLater();
424
connect(TrackPointUi.Longitude,SIGNAL(editingFinished()),this, SLOT(on_TrackPointLon_editingFinished()));
425
connect(TrackPointUi.Latitude,SIGNAL(editingFinished()),this, SLOT(on_TrackPointLat_editingFinished()));
426
connect(TrackPointUi.RemoveTagButton,SIGNAL(clicked()),this, SLOT(on_RemoveTagButton_clicked()));
427
setWindowTitle(tr("Properties - Trackpoint"));
430
void PropertiesDock::switchToRoadUi()
432
NowShowing = RoadUiShowing;
433
QWidget* NewUi = new QWidget(this);
434
RoadUi.setupUi(NewUi);
435
RoadUi.TagView->verticalHeader()->hide();
438
CurrentUi->deleteLater();
440
connect(RoadUi.RemoveTagButton,SIGNAL(clicked()),this, SLOT(on_RemoveTagButton_clicked()));
441
setWindowTitle(tr("Properties - Road"));
444
void PropertiesDock::switchToRelationUi()
446
NowShowing = RelationUiShowing;
447
QWidget* NewUi = new QWidget(this);
448
RelationUi.setupUi(NewUi);
449
RelationUi.TagView->verticalHeader()->hide();
452
CurrentUi->deleteLater();
454
RelationUi.MembersView->setContextMenuPolicy(Qt::CustomContextMenu);
455
connect(RelationUi.MembersView, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(on_Member_customContextMenuRequested(const QPoint &)));
456
connect(RelationUi.MembersView, SIGNAL(clicked(QModelIndex)), this, SLOT(on_Member_clicked(QModelIndex)));
457
connect(RelationUi.RemoveMemberButton,SIGNAL(clicked()),this, SLOT(on_RemoveMemberButton_clicked()));
458
connect(RelationUi.RemoveTagButton,SIGNAL(clicked()),this, SLOT(on_RemoveTagButton_clicked()));
459
setWindowTitle(tr("Properties - Relation"));
462
void PropertiesDock::switchToNoUi()
464
if (NowShowing == NoUiShowing) return;
465
NowShowing = NoUiShowing;
466
QWidget* NewUi = new QWidget(this);
469
CurrentUi->deleteLater();
471
setWindowTitle(tr("Properties"));
474
void PropertiesDock::resetValues()
478
// Tables that might need column sizing
479
CurrentTagView = NULL;
480
CurrentMembersView = NULL;
482
// to prevent slots to change the values also
483
QList<MapFeature*> Current = Selection;
485
if (FullSelection.size() == 1)
487
Main->info()->setHtml(FullSelection[0]->toHtml());
489
TrackPoint* Pt = dynamic_cast<TrackPoint*>(FullSelection[0]);
490
Road* R = dynamic_cast<Road*>(FullSelection[0]);
491
Relation* L = dynamic_cast<Relation*>(FullSelection[0]);
493
if ((Pt) && (NowShowing == TrackPointUiShowing))
495
TrackPointUi.Id->setText(Pt->id());
496
TrackPointUi.Latitude->setText(QString::number(intToAng(Pt->position().lat()),'g',8));
497
TrackPointUi.Longitude->setText(QString::number(intToAng(Pt->position().lon()),'g',8));
498
TrackPointUi.TagView->setModel(theModel);
499
TrackPointUi.TagView->setItemDelegate(delegate);
502
for (int i=0; i<TrackPointUi.variableLayout->count(); ++i) {
503
w = TrackPointUi.variableLayout->itemAt(i)->widget();
510
w = theTemplates->getWidget(Pt);
511
w->installEventFilter(shortcutFilter);
512
TrackPointUi.variableLayout->addWidget(w);
515
CurrentTagView = TrackPointUi.TagView;
518
Main->geoImage()->setImage(Pt);
521
else if ((R) && (NowShowing == RoadUiShowing))
523
RoadUi.Id->setText(R->id());
524
//RoadUi.Name->setText(R->tagValue("name",""));
525
RoadUi.TagView->setModel(theModel);
526
RoadUi.TagView->setItemDelegate(delegate);
529
for (int i=0; i<RoadUi.variableLayout->count(); ++i) {
530
w = RoadUi.variableLayout->itemAt(i)->widget();
537
w = theTemplates->getWidget(R);
538
w->installEventFilter(shortcutFilter);
539
RoadUi.variableLayout->addWidget(w);
542
CurrentTagView = RoadUi.TagView;
544
else if ((L) && (NowShowing == RelationUiShowing))
546
RelationUi.MembersView->setModel(L->referenceMemberModel(Main));
547
RelationUi.TagView->setModel(theModel);
548
RelationUi.TagView->setItemDelegate(delegate);
551
for (int i=0; i<RelationUi.variableLayout->count(); ++i) {
552
w = RelationUi.variableLayout->itemAt(i)->widget();
559
w = theTemplates->getWidget(L);
560
w->installEventFilter(shortcutFilter);
561
RelationUi.variableLayout->addWidget(w);
564
CurrentTagView = RelationUi.TagView;
565
CurrentMembersView = RelationUi.MembersView;
569
theTemplates->apply(FullSelection[0]);
571
else if ((FullSelection.size() > 1) && (NowShowing == MultiShowing))
573
Main->info()->setHtml("");
575
Main->geoImage()->setImage((TrackPoint *)NULL);
577
MultiUi.TagView->setModel(theModel);
578
MultiUi.TagView->setItemDelegate(delegate);
579
CurrentTagView = MultiUi.TagView;
581
theModel->setFeature(Current);
584
/* If we have standard TableViews in the current UI, set it so that the */
585
/* first column is the width of the default text (Edit this to add...) */
586
/* And the rest of the space is assigned to the second column */
587
if (CurrentTagView) {
588
if (M_PREFS->getTagListFirstColumnWidth())
589
CurrentTagView->setColumnWidth(
590
0, M_PREFS->getTagListFirstColumnWidth()
593
CurrentTagView->setColumnWidth(
594
0, CurrentTagView->fontMetrics().width(theModel->newKeyText())+10
596
CurrentTagView->horizontalHeader()->setStretchLastSection(true);
597
CurrentTagView->installEventFilter(shortcutFilter);
599
if (CurrentMembersView) {
600
CurrentMembersView->setColumnWidth(
601
0, CurrentMembersView->fontMetrics().width(theModel->newKeyText())+10
603
CurrentMembersView->horizontalHeader()->setStretchLastSection(true);
604
CurrentMembersView->installEventFilter(shortcutFilter);
608
void PropertiesDock::on_TrackPointLat_editingFinished()
610
if (TrackPointUi.Latitude->text().isEmpty()) return;
611
TrackPoint* Pt = dynamic_cast<TrackPoint*>(selection(0));
614
Main->document()->addHistory(
615
new MoveTrackPointCommand(Pt,
616
Coord(angToInt(TrackPointUi.Latitude->text().toDouble()),Pt->position().lon()), Main->document()->getDirtyOrOriginLayer(Pt->layer()) ));
617
Main->invalidateView(false);
621
void PropertiesDock::on_TrackPointLon_editingFinished()
623
if (TrackPointUi.Longitude->text().isEmpty()) return;
624
TrackPoint* Pt = dynamic_cast<TrackPoint*>(selection(0));
627
Main->document()->addHistory(
628
new MoveTrackPointCommand(Pt,
629
Coord(Pt->position().lat(),angToInt(TrackPointUi.Longitude->text().toDouble())), Main->document()->getDirtyOrOriginLayer(Pt->layer()) ));
630
Main->invalidateView(false);
634
void PropertiesDock::on_tag_changed(QString k, QString v)
636
MapFeature* F = FullSelection[0];
637
if (F->tagValue(k, "__NULL__") != v) {
638
Main->document()->addHistory(new SetTagCommand(F,k,v,Main->document()->getDirtyOrOriginLayer(F->layer())));
639
Main->invalidateView();
643
void PropertiesDock::on_tag_cleared(QString k)
645
MapFeature* F = FullSelection[0];
646
Main->document()->addHistory(new ClearTagCommand(F,k,Main->document()->getDirtyOrOriginLayer(F->layer())));
647
Main->invalidateView();
650
void PropertiesDock::on_RemoveTagButton_clicked()
652
QTableView* TagTable = 0;
655
case TrackPointUiShowing:
656
TagTable = TrackPointUi.TagView; break;
658
TagTable = RoadUi.TagView; break;
660
TagTable = MultiUi.TagView; break;
661
case RelationUiShowing:
662
TagTable = RelationUi.TagView; break;
667
QModelIndexList indexes = TagTable->selectionModel()->selectedIndexes();
670
foreach(index, indexes)
672
QModelIndex idx = index.sibling(index.row(),0);
673
QVariant Content(theModel->data(idx,Qt::DisplayRole));
674
if (Content.isValid())
676
QString KeyName = Content.toString();
677
CommandList* L = new CommandList(MainWindow::tr("Clear Tag '%1' on %2").arg(KeyName).arg(Selection[0]->id()), Selection[0]);
678
for (int i=0; i<Selection.size(); ++i)
679
if (Selection[i]->findKey(KeyName) < Selection[i]->tagSize())
680
L->add(new ClearTagCommand(Selection[i],KeyName,Main->document()->getDirtyOrOriginLayer(Selection[i]->layer())));
685
Main->document()->addHistory(L);
686
Main->invalidateView();
694
void PropertiesDock::on_RemoveMemberButton_clicked()
696
if (CurrentMembersView)
698
Relation* R = dynamic_cast<Relation*>(Selection[0]);
700
QModelIndexList indexes = CurrentMembersView->selectionModel()->selectedIndexes();
703
foreach(index, indexes)
705
QModelIndex idx = index.sibling(index.row(),0);
706
QVariant Content(R->referenceMemberModel(Main)->data(idx,Qt::UserRole));
707
if (Content.isValid())
709
MapFeature* F = Content.value<MapFeature*>();
711
CommandList* L = new CommandList(MainWindow::tr("Remove member '%1' on %2").arg(F->description()).arg(R->description()), R);
712
if (R->find(F) < R->size())
713
L->add(new RelationRemoveFeatureCommand(R,F,Main->document()->getDirtyOrOriginLayer(R->layer())));
718
Main->document()->addHistory(L);
719
Main->invalidateView();
729
void PropertiesDock::on_Member_customContextMenuRequested(const QPoint & pos)
731
QModelIndex ix = CurrentMembersView->indexAt(pos);
733
QMenu menu(CurrentMembersView);
734
menu.addAction(centerAction);
735
menu.addAction(centerZoomAction);
736
menu.addAction(selectAction);
737
menu.exec(CurrentMembersView->mapToGlobal(pos));
741
void PropertiesDock::on_Member_clicked(const QModelIndex & index)
745
Relation* R = dynamic_cast<Relation*>(Selection[0]);
747
QVariant Content(R->referenceMemberModel(Main)->data(index,Qt::UserRole));
748
if (Content.isValid())
750
MapFeature* F = Content.value<MapFeature*>();
752
Highlighted.push_back(F);
755
Main->view()->update();
758
void PropertiesDock::on_Member_selected()
760
Relation* R = dynamic_cast<Relation*>(Selection[0]);
762
QModelIndexList indexes = CurrentMembersView->selectionModel()->selectedIndexes();
765
foreach(index, indexes)
767
QModelIndex idx = index.sibling(index.row(),0);
768
QVariant Content(R->referenceMemberModel(Main)->data(idx,Qt::UserRole));
769
if (Content.isValid())
771
MapFeature* F = Content.value<MapFeature*>();
778
Main->invalidateView(false);
781
void PropertiesDock::on_SelectionList_customContextMenuRequested(const QPoint & pos)
783
QListWidgetItem *it = MultiUi.SelectionList->itemAt(pos);
785
QMenu menu(MultiUi.SelectionList);
786
menu.addAction(centerAction);
787
menu.addAction(centerZoomAction);
788
menu.exec(MultiUi.SelectionList->mapToGlobal(pos));
792
void PropertiesDock::on_centerAction_triggered()
795
if (CurrentMembersView)
797
Relation* R = dynamic_cast<Relation*>(Selection[0]);
799
QModelIndexList indexes = CurrentMembersView->selectionModel()->selectedIndexes();
802
foreach(index, indexes)
804
QModelIndex idx = index.sibling(index.row(),0);
805
QVariant Content(R->referenceMemberModel(Main)->data(idx,Qt::UserRole));
806
if (Content.isValid())
808
MapFeature* F = Content.value<MapFeature*>();
811
cb = F->boundingBox();
817
if (CurrentTagView) {
818
Main->setUpdatesEnabled(false);
819
int idx = MultiUi.SelectionList->selectedItems()[0]->data(Qt::UserRole).toUInt();
820
cb = FullSelection[idx]->boundingBox();
821
for (int i=1; i < MultiUi.SelectionList->selectedItems().size(); i++) {
822
idx = MultiUi.SelectionList->selectedItems()[i]->data(Qt::UserRole).toUInt();
823
cb.merge(FullSelection[idx]->boundingBox());
826
Coord c = cb.center();
827
Main->view()->setCenter(c, Main->view()->rect());
828
Main->setUpdatesEnabled(true);
829
Main->invalidateView(false);
832
void PropertiesDock::on_centerZoomAction_triggered()
835
if (CurrentMembersView)
837
Relation* R = dynamic_cast<Relation*>(Selection[0]);
839
QModelIndexList indexes = CurrentMembersView->selectionModel()->selectedIndexes();
842
foreach(index, indexes)
844
QModelIndex idx = index.sibling(index.row(),0);
845
QVariant Content(R->referenceMemberModel(Main)->data(idx,Qt::UserRole));
846
if (Content.isValid())
848
MapFeature* F = Content.value<MapFeature*>();
851
cb = F->boundingBox();
852
CoordBox mini(cb.center()-2000, cb.center()+2000);
860
if (CurrentTagView) {
861
Main->setUpdatesEnabled(false);
862
int idx = MultiUi.SelectionList->selectedItems()[0]->data(Qt::UserRole).toUInt();
863
cb = FullSelection[idx]->boundingBox();
864
for (int i=1; i < MultiUi.SelectionList->selectedItems().size(); i++) {
865
idx = MultiUi.SelectionList->selectedItems()[i]->data(Qt::UserRole).toUInt();
866
cb.merge(FullSelection[idx]->boundingBox());
868
CoordBox mini(cb.center()-2000, cb.center()+2000);
872
Main->view()->setViewport(cb, Main->view()->rect());
873
Main->setUpdatesEnabled(true);
874
Main->invalidateView(false);
877
bool PropertiesDock::loadTemplates(const QString& filename)
879
SAFE_DELETE(theTemplates);
882
if (!filename.isEmpty())
883
File.setFileName(filename);
885
File.setFileName(M_PREFS->getDefaultTemplate());
887
if (!File.open(QIODevice::ReadOnly)) {
888
QMessageBox::warning(Main,"Template read error", "Error reading template file");
897
if (!DomDoc.setContent(&File, true, &ErrorStr, &ErrorLine,&ErrorColumn))
900
QMessageBox::warning(Main,"Parse error",
901
QString("Parse error at line %1, column %2:\n%3")
908
QDomElement root = DomDoc.documentElement();
909
theTemplates = TagTemplates::fromXml(root);
911
connect(theTemplates, SIGNAL(tagChanged(QString, QString)), this, SLOT(on_tag_changed(QString, QString)));
912
connect(theTemplates, SIGNAL(tagCleared(QString)), this, SLOT(on_tag_cleared(QString)));
913
connect(theTemplates, SIGNAL(templateChanged(TagTemplate*)), this, SLOT(on_template_changed(TagTemplate*)));
915
QMessageBox::warning(Main,"Template read error", "Error parsing template file");
922
bool PropertiesDock::mergeTemplates(const QString& filename)
925
if (!filename.isEmpty())
926
File.setFileName(filename);
930
if (!File.open(QIODevice::ReadOnly)) {
931
QMessageBox::warning(Main,"Template read error", "Error reading template file");
940
if (!DomDoc.setContent(&File, true, &ErrorStr, &ErrorLine,&ErrorColumn))
943
QMessageBox::warning(Main,"Parse error",
944
QString("Parse error at line %1, column %2:\n%3")
951
QDomElement root = DomDoc.documentElement();
952
if (!theTemplates->mergeXml(root)) {
953
QMessageBox::warning(Main,"Template read error", "Error parsing template file");
960
bool PropertiesDock::saveTemplates(const QString& filename)
965
QDomDocument theXmlDoc;
966
theXmlDoc.appendChild(theXmlDoc.createProcessingInstruction("xml", "version=\"1.0\""));
968
if (!theTemplates->toXML(theXmlDoc)) {
969
QMessageBox::warning(Main,"Tag templates write error", "Unable to generate XML document");
973
QFile File(filename);
974
if (!File.open(QIODevice::WriteOnly)) {
975
QMessageBox::warning(Main,"Tag templates write error", "Error opening template file for writing");
978
File.write(theXmlDoc.toString().toUtf8());
983
void PropertiesDock::on_template_changed(TagTemplate* /* aNewTemplate */)
988
void PropertiesDock::changeEvent(QEvent * event)
990
if (event->type() == QEvent::LanguageChange)
992
MDockAncestor::changeEvent(event);
995
void PropertiesDock::retranslateUi()
997
setWindowTitle(tr("Properties"));
998
centerAction->setText(tr("Center map"));
999
centerZoomAction->setText(tr("Center && Zoom map"));
1000
selectAction->setText(tr("Select member"));
1003
int PropertiesDock::highlightedSize() const
1007
return Highlighted.size();
1010
MapFeature* PropertiesDock::highlighted(int idx)
1012
if (idx < Highlighted.size())
1013
return Highlighted[idx];
1017
QList<MapFeature*> PropertiesDock::highlighted()