1 /**********************************************************************************************
2     Copyright (C) 2014 Oliver Eichler <oliver.eichler@gmx.de>
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 **********************************************************************************************/
18 
19 #include "helpers/CSettings.h"
20 #include "helpers/Signals.h"
21 #include "map/CMapDraw.h"
22 #include "map/CMapPropSetup.h"
23 #include "map/IMap.h"
24 #include "units/IUnit.h"
25 
26 #include <QtWidgets>
27 QPointF CMapPropSetup::scale;
28 
CMapPropSetup(IMap * mapfile,CMapDraw * map)29 CMapPropSetup::CMapPropSetup(IMap* mapfile, CMapDraw* map)
30     : IMapProp(mapfile, map)
31 {
32     setupUi(this);
33 
34     CMapPropSetup::slotPropertiesChanged();
35 
36     connect(sliderOpacity, &QSlider::valueChanged, mapfile, &IMap::slotSetOpacity);
37     connect(sliderOpacity, &QSlider::valueChanged, map, &CMapDraw::emitSigCanvasUpdate);
38     connect(map, &CMapDraw::sigScaleChanged, this, &CMapPropSetup::slotScaleChanged);
39     connect(toolSetMinScale, &QToolButton::toggled, this, &CMapPropSetup::slotSetMinScale);
40     connect(toolSetMaxScale, &QToolButton::toggled, this, &CMapPropSetup::slotSetMaxScale);
41 
42     connect(checkPolygons, &QCheckBox::toggled, mapfile, &IMap::slotSetShowPolygons);
43     connect(checkPolylines, &QCheckBox::toggled, mapfile, &IMap::slotSetShowPolylines);
44     connect(checkPoints, &QCheckBox::toggled, mapfile, &IMap::slotSetShowPOIs);
45     connect(spinAdjustDetails, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), mapfile, &IMap::slotSetAdjustDetailLevel);
46     connect(checkPolygons, &QCheckBox::clicked, map, &CMapDraw::emitSigCanvasUpdate);
47     connect(checkPolylines, &QCheckBox::clicked, map, &CMapDraw::emitSigCanvasUpdate);
48     connect(checkPoints, &QCheckBox::clicked, map, &CMapDraw::emitSigCanvasUpdate);
49     connect(spinAdjustDetails, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), map, &CMapDraw::emitSigCanvasUpdate);
50 
51     connect(spinCacheSize, static_cast<void (QSpinBox::*)(int) >(&QSpinBox::valueChanged), mapfile, &IMap::slotSetCacheSize);
52     connect(spinCacheExpiration, static_cast<void (QSpinBox::*)(int) >(&QSpinBox::valueChanged), mapfile, &IMap::slotSetCacheExpiration);
53 
54     connect(toolOpenTypFile, &QToolButton::pressed, this, &CMapPropSetup::slotLoadTypeFile);
55     connect(toolClearTypFile, &QToolButton::pressed, this, &CMapPropSetup::slotClearTypeFile);
56 
57     frameVectorItems->setVisible( mapfile->hasFeatureVectorItems() );
58     frameTileCache->setVisible( mapfile->hasFeatureTileCache() );
59 
60     if(mapfile->hasFeatureLayers())
61     {
62         frameLayers->show();
63         mapfile->getLayers(*listLayers);
64     }
65     else
66     {
67         frameLayers->hide();
68     }
69 
70     frameTypFile->setVisible(mapfile->hasFeatureTypFile());
71 }
72 
~CMapPropSetup()73 CMapPropSetup::~CMapPropSetup()
74 {
75 }
76 
77 
slotPropertiesChanged()78 void CMapPropSetup::slotPropertiesChanged() /* override */
79 {
80     X______________BlockAllSignals______________X(this);
81     // block all signals to avoid retrigger
82 
83     // opacity and visibility settings
84     sliderOpacity->setValue(mapfile->getOpacity());
85     qreal minScale = mapfile->getMinScale();
86     toolSetMinScale->setChecked(minScale != NOFLOAT);
87     qreal maxScale = mapfile->getMaxScale();
88     toolSetMaxScale->setChecked(maxScale != NOFLOAT);
89 
90     labelScale->setValue(mapfile->getMinScale(), scale.x(), mapfile->getMaxScale());
91 
92     // vector maps properties
93     checkPolygons->setChecked(mapfile->getShowPolygons());
94     checkPolylines->setChecked(mapfile->getShowPolylines());
95     checkPoints->setChecked(mapfile->getShowPOIs());
96     spinAdjustDetails->setValue(mapfile->getAdjustDetailLevel());
97 
98     // streaming map properties
99     QString lbl = mapfile->getCachePath();
100     labelCachePath->setText(lbl.size() < 20 ? lbl : "..." + lbl.right(17));
101     labelCachePath->setToolTip(lbl);
102     spinCacheSize->setValue(mapfile->getCacheSize());
103     spinCacheExpiration->setValue(mapfile->getCacheExpiration());
104 
105     // type file
106     QFileInfo fi(mapfile->getTypeFile());
107     labelTypeFile->setText(fi.completeBaseName());
108     labelTypeFile->setToolTip(fi.absoluteFilePath());
109     toolClearTypFile->setEnabled(!labelTypeFile->text().isEmpty());
110 
111     // unblock all signals
112     X_____________UnBlockAllSignals_____________X(this);
113 }
114 
slotScaleChanged(const QPointF & s)115 void CMapPropSetup::slotScaleChanged(const QPointF& s)
116 {
117     scale = s;
118     slotPropertiesChanged();
119 }
120 
slotSetMinScale(bool checked)121 void CMapPropSetup::slotSetMinScale(bool checked)
122 {
123     mapfile->setMinScale(checked ? scale.x() : NOFLOAT);
124     slotPropertiesChanged();
125 }
126 
slotSetMaxScale(bool checked)127 void CMapPropSetup::slotSetMaxScale(bool checked)
128 {
129     mapfile->setMaxScale(checked ? scale.x() : NOFLOAT);
130     slotPropertiesChanged();
131 }
132 
133 
134 
135 
slotLoadTypeFile()136 void CMapPropSetup::slotLoadTypeFile()
137 {
138     SETTINGS;
139     QString path = cfg.value("Paths/lastTypePath", QDir::homePath()).toString();
140     QString filename = QFileDialog::getOpenFileName(this, tr("Select type file..."), path, "Garmin type file (*.typ)");
141     if(filename.isEmpty())
142     {
143         return;
144     }
145 
146     QFileInfo fi(filename);
147     cfg.setValue("Paths/lastTypePath", fi.absolutePath());
148 
149     mapfile->slotSetTypeFile(filename);
150     slotPropertiesChanged();
151 }
152 
slotClearTypeFile()153 void CMapPropSetup::slotClearTypeFile()
154 {
155     mapfile->slotSetTypeFile("");
156     slotPropertiesChanged();
157 }
158