2 ******************************************************************************
4 * @file opmapgadgetoptionspage.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup OPMapPlugin OpenPilot Map Plugin
10 * @brief The OpenPilot Map plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "opmapgadgetoptionspage.h"
29 #include "opmapgadgetconfiguration.h"
33 #include <QDoubleSpinBox>
34 #include <QHBoxLayout>
35 #include <QVBoxLayout>
36 #include <QFileDialog>
38 #include "opmapcontrol/opmapcontrol.h"
39 #include "utils/pathutils.h"
40 #include "ui_opmapgadgetoptionspage.h"
42 // *********************************************
44 OPMapGadgetOptionsPage::OPMapGadgetOptionsPage(OPMapGadgetConfiguration
*config
, QObject
*parent
) :
49 QWidget
*OPMapGadgetOptionsPage::createPage(QWidget
*parent
)
53 m_page
= new Ui::OPMapGadgetOptionsPage();
54 QWidget
*w
= new QWidget(parent
);
57 // populate the map provider combobox
58 m_page
->providerComboBox
->clear();
59 m_page
->providerComboBox
->addItems(mapcontrol::Helper::MapTypes());
61 // populate the access mode combobox
62 m_page
->accessModeComboBox
->clear();
63 m_page
->accessModeComboBox
->addItems(mapcontrol::Helper::AccessModeTypes());
65 index
= m_page
->providerComboBox
->findText(m_config
->mapProvider());
66 index
= (index
>= 0) ? index
: 0;
67 m_page
->providerComboBox
->setCurrentIndex(index
);
69 // populate the map max update rate combobox
70 m_page
->maxUpdateRateComboBox
->clear();
71 m_page
->maxUpdateRateComboBox
->addItem("100ms", 100);
72 m_page
->maxUpdateRateComboBox
->addItem("200ms", 200);
73 m_page
->maxUpdateRateComboBox
->addItem("500ms", 500);
74 m_page
->maxUpdateRateComboBox
->addItem("1 sec", 1000);
75 m_page
->maxUpdateRateComboBox
->addItem("2 sec", 2000);
76 m_page
->maxUpdateRateComboBox
->addItem("5 sec", 5000);
78 index
= m_page
->maxUpdateRateComboBox
->findData(m_config
->maxUpdateRate());
79 index
= (index
>= 0) ? index
: 4;
80 m_page
->maxUpdateRateComboBox
->setCurrentIndex(index
);
82 m_page
->zoomSpinBox
->setValue(m_config
->zoom());
83 m_page
->latitudeSpinBox
->setValue(m_config
->latitude());
84 m_page
->longitudeSpinBox
->setValue(m_config
->longitude());
86 m_page
->checkBoxUseOpenGL
->setChecked(m_config
->useOpenGL());
87 m_page
->checkBoxShowTileGridLines
->setChecked(m_config
->showTileGridLines());
89 index
= m_page
->accessModeComboBox
->findText(m_config
->accessMode());
90 index
= (index
>= 0) ? index
: 0;
91 m_page
->accessModeComboBox
->setCurrentIndex(index
);
93 m_page
->checkBoxUseMemoryCache
->setChecked(m_config
->useMemoryCache());
95 m_page
->lineEditCacheLocation
->setExpectedKind(Utils::PathChooser::Directory
);
96 m_page
->lineEditCacheLocation
->setPromptDialogTitle(tr("Choose Cache Directory"));
97 m_page
->lineEditCacheLocation
->setPath(m_config
->cacheLocation());
99 QDir
dir(":/uavs/images/");
100 QStringList list
= dir
.entryList();
101 foreach(QString i
, list
) {
102 QIcon
icon(QPixmap(":/uavs/images/" + i
));
104 m_page
->uavSymbolComboBox
->addItem(icon
, QString(), i
);
106 for (int x
= 0; x
< m_page
->uavSymbolComboBox
->count(); ++x
) {
107 if (m_page
->uavSymbolComboBox
->itemData(x
).toString() == m_config
->uavSymbol()) {
108 m_page
->uavSymbolComboBox
->setCurrentIndex(x
);
112 connect(m_page
->pushButtonCacheDefaults
, SIGNAL(clicked()), this, SLOT(on_pushButtonCacheDefaults_clicked()));
117 void OPMapGadgetOptionsPage::on_pushButtonCacheDefaults_clicked()
119 int index
= m_page
->accessModeComboBox
->findText("ServerAndCache");
121 index
= (index
>= 0) ? index
: 0;
122 m_page
->accessModeComboBox
->setCurrentIndex(index
);
124 m_page
->checkBoxUseMemoryCache
->setChecked(true);
125 m_page
->lineEditCacheLocation
->setPath(Utils::PathUtils().GetStoragePath() + "mapscache" + QDir::separator());
128 void OPMapGadgetOptionsPage::apply()
130 m_config
->setMapProvider(m_page
->providerComboBox
->currentText());
131 m_config
->setZoom(m_page
->zoomSpinBox
->value());
132 m_config
->setLatitude(m_page
->latitudeSpinBox
->value());
133 m_config
->setLongitude(m_page
->longitudeSpinBox
->value());
134 m_config
->setUseOpenGL(m_page
->checkBoxUseOpenGL
->isChecked());
135 m_config
->setShowTileGridLines(m_page
->checkBoxShowTileGridLines
->isChecked());
136 m_config
->setAccessMode(m_page
->accessModeComboBox
->currentText());
137 m_config
->setUseMemoryCache(m_page
->checkBoxUseMemoryCache
->isChecked());
138 m_config
->setCacheLocation(m_page
->lineEditCacheLocation
->path());
139 m_config
->setUavSymbol(m_page
->uavSymbolComboBox
->itemData(m_page
->uavSymbolComboBox
->currentIndex()).toString());
140 m_config
->setMaxUpdateRate(m_page
->maxUpdateRateComboBox
->itemData(m_page
->maxUpdateRateComboBox
->currentIndex()).toInt());
143 void OPMapGadgetOptionsPage::finish()