dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
opmapgadgetoptionspage.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "opmapgadgetoptionspage.h"
30 #include <QLabel>
31 #include <QComboBox>
32 #include <QSpinBox>
33 #include <QDoubleSpinBox>
34 #include <QHBoxLayout>
35 #include <QVBoxLayout>
36 
38 #include "utils/pathutils.h"
39 #include "ui_opmapgadgetoptionspage.h"
40 
41 // *********************************************
42 
44  : IOptionsPage(parent)
45  , m_config(config)
46 {
47 }
48 
49 QWidget *OPMapGadgetOptionsPage::createPage(QWidget *parent)
50 {
51  int index;
52 
53  m_page = new Ui::OPMapGadgetOptionsPage();
54  QWidget *w = new QWidget(parent);
55  m_page->setupUi(w);
56 
57  // populate the map provider combobox
58  m_page->providerComboBox->clear();
59  m_page->providerComboBox->addItems(mapcontrol::Helper::MapTypes());
60 
61  // populate the access mode combobox
62  m_page->accessModeComboBox->clear();
63  m_page->accessModeComboBox->addItems(mapcontrol::Helper::AccessModeTypes());
64 
65  index = m_page->providerComboBox->findText(m_config->mapProvider());
66  index = (index >= 0) ? index : 0;
67  m_page->providerComboBox->setCurrentIndex(index);
68 
69  // if provider is userimage maximum zoom is 32
70  if (m_config->mapProvider() == "UserImage")
71  m_page->zoomSpinBox->setMaximum(32);
72 
73  // populate the geocode language combobox
74 
75  m_page->languageComboBox->clear();
76  m_page->languageComboBox->addItems(mapcontrol::Helper::LanguageTypes());
77  index = m_page->languageComboBox->findText(m_config->geoLanguage());
78  index = (index >= 0) ? index : 0;
79  m_page->languageComboBox->setCurrentIndex(index);
80 
81  // populate the map max update rate combobox
82  m_page->maxUpdateRateComboBox->clear();
83  m_page->maxUpdateRateComboBox->addItem("100ms", 100);
84  m_page->maxUpdateRateComboBox->addItem("200ms", 200);
85  m_page->maxUpdateRateComboBox->addItem("500ms", 500);
86  m_page->maxUpdateRateComboBox->addItem("1 sec", 1000);
87  m_page->maxUpdateRateComboBox->addItem("2 sec", 2000);
88  m_page->maxUpdateRateComboBox->addItem("5 sec", 5000);
89 
90  index = m_page->maxUpdateRateComboBox->findData(m_config->maxUpdateRate());
91  index = (index >= 0) ? index : 4;
92  m_page->maxUpdateRateComboBox->setCurrentIndex(index);
93 
94  m_page->zoomSpinBox->setValue(m_config->zoom());
95  m_page->latitudeSpinBox->setValue(m_config->latitude());
96  m_page->longitudeSpinBox->setValue(m_config->longitude());
97 
98  m_page->checkBoxShowTileGridLines->setChecked(m_config->showTileGridLines());
99 
100  index = m_page->accessModeComboBox->findText(m_config->accessMode());
101  index = (index >= 0) ? index : 0;
102  m_page->accessModeComboBox->setCurrentIndex(index);
103 
104  m_page->checkBoxUseMemoryCache->setChecked(m_config->useMemoryCache());
105 
106  m_page->lineEditCacheLocation->setExpectedKind(Utils::PathChooser::Directory);
107  m_page->lineEditCacheLocation->setPromptDialogTitle(tr("Choose Cache Directory"));
108  m_page->lineEditCacheLocation->setPath(m_config->cacheLocation());
109 
110  m_page->horizontalScaleDoubleSpinBox->setValue(m_config->getUserImageHorizontalScale());
111  m_page->verticalScaleDoubleSpinBox->setValue(m_config->getUserImageVerticalScale());
112 
113  QDir dir(":/uavs/images/");
114  QStringList list = dir.entryList();
115  foreach (QString i, list) {
116  QIcon icon(QPixmap(":/uavs/images/" + i));
117  m_page->uavSymbolComboBox->addItem(icon, QString(), i);
118  }
119  for (int x = 0; x < m_page->uavSymbolComboBox->count(); ++x) {
120  if (m_page->uavSymbolComboBox->itemData(x).toString() == m_config->uavSymbol()) {
121  m_page->uavSymbolComboBox->setCurrentIndex(x);
122  }
123  }
124 
125  connect(m_page->pushButtonCacheDefaults, &QAbstractButton::clicked, this,
126  &OPMapGadgetOptionsPage::on_pushButtonCacheDefaults_clicked);
127  connect(m_page->providerComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
128  &OPMapGadgetOptionsPage::on_providerComboBox_changed);
129 
130  // Dynamically configure page
131  on_providerComboBox_changed();
132 
133  return w;
134 }
135 
136 void OPMapGadgetOptionsPage::on_providerComboBox_changed()
137 {
138  if (m_page->providerComboBox->currentText() == "UserImage") {
139  m_page->CacheLocationLabel->setText("Map file location");
140  m_page->zoomSpinBox->setMaximum(32);
141  m_page->userImageScalingGroupBox->show();
142  m_page->lineEditCacheLocation->setExpectedKind(Utils::PathChooser::File);
143  m_page->lineEditCacheLocation->setPromptDialogTitle(tr("Choose Map File"));
144  } else {
145  m_page->CacheLocationLabel->setText("Cache location");
146  m_page->zoomSpinBox->setMaximum(21);
147  m_page->userImageScalingGroupBox->hide();
148  m_page->lineEditCacheLocation->setExpectedKind(Utils::PathChooser::Directory);
149  m_page->lineEditCacheLocation->setPromptDialogTitle(tr("Choose Cache Directory"));
150  }
151 }
152 
153 void OPMapGadgetOptionsPage::on_pushButtonCacheDefaults_clicked()
154 {
155  int index = m_page->accessModeComboBox->findText("ServerAndCache");
156  index = (index >= 0) ? index : 0;
157  m_page->accessModeComboBox->setCurrentIndex(index);
158 
159  m_page->checkBoxUseMemoryCache->setChecked(true);
160  m_page->lineEditCacheLocation->setPath(Utils::PathUtils().GetStoragePath() + "mapscache"
161  + QDir::separator());
162 }
163 
165 {
166  m_config->setMapProvider(m_page->providerComboBox->currentText());
167  m_config->setZoom(m_page->zoomSpinBox->value());
168  m_config->setLatitude(m_page->latitudeSpinBox->value());
169  m_config->setLongitude(m_page->longitudeSpinBox->value());
170  m_config->setShowTileGridLines(m_page->checkBoxShowTileGridLines->isChecked());
171  m_config->setAccessMode(m_page->accessModeComboBox->currentText());
172  m_config->setUseMemoryCache(m_page->checkBoxUseMemoryCache->isChecked());
173  m_config->setCacheLocation(m_page->lineEditCacheLocation->path());
174  m_config->setUserImageHorizontalScale(m_page->horizontalScaleDoubleSpinBox->value());
175  m_config->setUserImageVerticalScale(m_page->verticalScaleDoubleSpinBox->value());
176  m_config->setUserImageLocation(m_page->lineEditCacheLocation->path());
177  m_config->setUavSymbol(
178  m_page->uavSymbolComboBox->itemData(m_page->uavSymbolComboBox->currentIndex()).toString());
179  m_config->setMaxUpdateRate(
180  m_page->maxUpdateRateComboBox->itemData(m_page->maxUpdateRateComboBox->currentIndex())
181  .toInt());
182  m_config->setGeoLanguage(m_page->languageComboBox->currentText());
183 }
184 
186 {
187  delete m_page;
188 }
void setCacheLocation(QString cacheLocation)
void setGeoLanguage(QString language)
static QStringList LanguageTypes()
Returns QStringList with string representing all the enum values.
Definition: tlmapwidget.h:116
for i
Definition: OPPlots.m:140
OPMapGadgetOptionsPage(OPMapGadgetConfiguration *config, QObject *parent=nullptr)
void setUserImageLocation(QString userImageLocation)
void setUserImageHorizontalScale(float userImageHorizontalScale)
void setUavSymbol(QString symbol)
void setLatitude(double latitude)
void setUseMemoryCache(bool useMemoryCache)
void setUserImageVerticalScale(float userImageVerticalScale)
QWidget * createPage(QWidget *parent)
void setShowTileGridLines(bool showTileGridLines)
void setLongitude(double longitude)
void setMapProvider(QString provider)
void setAccessMode(QString accessMode)
void setMaxUpdateRate(int update_rate)
x
Definition: OPPlots.m:100
static QStringList AccessModeTypes()
Returns QStringList with string representing all the enum values.
Definition: tlmapwidget.h:128
static QStringList MapTypes()
Returns QStringList with string representing all the enum values.
Definition: tlmapwidget.h:78