2 ******************************************************************************
4 * @file gpsdisplaygadgetoptionspage.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup GPSGadgetPlugin GPS Gadget Plugin
10 * @brief A gadget that displays GPS status and enables basic configuration
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 "gpsdisplaygadgetoptionspage.h"
29 #include "gpsdisplaygadgetconfiguration.h"
30 #include "ui_gpsdisplaygadgetoptionspage.h"
32 #include <QFileDialog>
33 #include <QtAlgorithms>
34 #include <QStringList>
36 GpsDisplayGadgetOptionsPage::GpsDisplayGadgetOptionsPage(GpsDisplayGadgetConfiguration
*config
, QObject
*parent
) :
41 bool sortPorts(QSerialPortInfo
const & s1
, QSerialPortInfo
const & s2
)
43 return s1
.portName() < s2
.portName();
46 // creates options page widget (uses the UI file)
47 QWidget
*GpsDisplayGadgetOptionsPage::createPage(QWidget
*parent
)
51 options_page
= new Ui::GpsDisplayGadgetOptionsPage();
52 QWidget
*optionsPageWidget
= new QWidget
;
53 options_page
->setupUi(optionsPageWidget
);
57 QList
<QSerialPortInfo
> ports
= QSerialPortInfo::availablePorts();
58 qSort(ports
.begin(), ports
.end(), sortPorts
);
59 foreach(QSerialPortInfo port
, ports
) {
60 qDebug() << "Adding port: " << port
.systemLocation() << " (" << port
.portName() << ")";
61 options_page
->portComboBox
->addItem(port
.portName(), port
.portName());
64 int portIndex
= options_page
->portComboBox
->findData(m_config
->port());
65 if (portIndex
!= -1) {
66 qDebug() << "createPage(): port is " << m_config
->port();
67 options_page
->portComboBox
->setCurrentIndex(portIndex
);
71 options_page
->portSpeedComboBox
->addItem("Baud1200", QSerialPort::Baud1200
);
72 options_page
->portSpeedComboBox
->addItem("Baud2400", QSerialPort::Baud2400
);
73 options_page
->portSpeedComboBox
->addItem("Baud4800", QSerialPort::Baud4800
);
74 options_page
->portSpeedComboBox
->addItem("Baud9600", QSerialPort::Baud9600
);
75 options_page
->portSpeedComboBox
->addItem("Baud19200", QSerialPort::Baud19200
);
76 options_page
->portSpeedComboBox
->addItem("Baud38400", QSerialPort::Baud38400
);
77 options_page
->portSpeedComboBox
->addItem("Baud57600", QSerialPort::Baud57600
);
78 options_page
->portSpeedComboBox
->addItem("Baud115200", QSerialPort::Baud115200
);
79 options_page
->portSpeedComboBox
->addItem("UnknownBaud", QSerialPort::UnknownBaud
);
81 int portSpeedIndex
= options_page
->portSpeedComboBox
->findData(m_config
->speed());
82 if (portSpeedIndex
!= -1) {
83 options_page
->portSpeedComboBox
->setCurrentIndex(portSpeedIndex
);
87 options_page
->flowControlComboBox
->addItem("NoFlowControl", QSerialPort::NoFlowControl
);
88 options_page
->flowControlComboBox
->addItem("HardwareControl", QSerialPort::HardwareControl
);
89 options_page
->flowControlComboBox
->addItem("SoftwareControl", QSerialPort::SoftwareControl
);
90 options_page
->flowControlComboBox
->addItem("UnknownFlowControl", QSerialPort::UnknownFlowControl
);
92 int flowControlIndex
= options_page
->flowControlComboBox
->findData(m_config
->flow());
93 if (flowControlIndex
!= -1) {
94 options_page
->flowControlComboBox
->setCurrentIndex(flowControlIndex
);
98 options_page
->dataBitsComboBox
->addItem("Data5", QSerialPort::Data5
);
99 options_page
->dataBitsComboBox
->addItem("Data6", QSerialPort::Data6
);
100 options_page
->dataBitsComboBox
->addItem("Data7", QSerialPort::Data7
);
101 options_page
->dataBitsComboBox
->addItem("Data8", QSerialPort::Data8
);
102 options_page
->dataBitsComboBox
->addItem("UnknownDataBits", QSerialPort::UnknownDataBits
);
104 int dataBitsIndex
= options_page
->dataBitsComboBox
->findData(m_config
->dataBits());
105 if (dataBitsIndex
!= -1) {
106 options_page
->dataBitsComboBox
->setCurrentIndex(dataBitsIndex
);
110 options_page
->stopBitsComboBox
->addItem("OneStop", QSerialPort::OneStop
);
111 options_page
->stopBitsComboBox
->addItem("OneAndHalfStop", QSerialPort::OneAndHalfStop
);
112 options_page
->stopBitsComboBox
->addItem("TwoStop", QSerialPort::TwoStop
);
113 options_page
->stopBitsComboBox
->addItem("UnknownStopBits", QSerialPort::UnknownStopBits
);
115 int stopBitsIndex
= options_page
->stopBitsComboBox
->findData(m_config
->stopBits());
116 if (stopBitsIndex
!= -1) {
117 options_page
->stopBitsComboBox
->setCurrentIndex(stopBitsIndex
);
121 options_page
->parityComboBox
->addItem("NoParity", QSerialPort::NoParity
);
122 options_page
->parityComboBox
->addItem("EvenParity", QSerialPort::EvenParity
);
123 options_page
->parityComboBox
->addItem("OddParity", QSerialPort::OddParity
);
124 options_page
->parityComboBox
->addItem("SpaceParity", QSerialPort::SpaceParity
);
125 options_page
->parityComboBox
->addItem("MarkParity", QSerialPort::MarkParity
);
126 options_page
->parityComboBox
->addItem("UnknownParity", QSerialPort::UnknownParity
);
128 int parityIndex
= options_page
->parityComboBox
->findData(m_config
->parity());
129 if (parityIndex
!= -1) {
130 options_page
->parityComboBox
->setCurrentIndex(parityIndex
);
134 options_page
->timeoutSpinBox
->setValue(m_config
->timeOut());
136 QStringList connectionModes
;
137 connectionModes
<< "Serial" << "Network" << "Telemetry";
138 options_page
->connectionMode
->addItems(connectionModes
);
139 int conMode
= options_page
->connectionMode
->findText(m_config
->connectionMode());
141 options_page
->connectionMode
->setCurrentIndex(conMode
);
145 return optionsPageWidget
;
149 * Called when the user presses apply or OK.
151 * Saves the current values
154 void GpsDisplayGadgetOptionsPage::apply()
156 int portIndex
= options_page
->portComboBox
->currentIndex();
158 m_config
->setPort(options_page
->portComboBox
->itemData(portIndex
).toString());
159 qDebug() << "apply(): port is " << m_config
->port();
161 m_config
->setSpeed((QSerialPort::BaudRate
)options_page
->portSpeedComboBox
->itemData(options_page
->portSpeedComboBox
->currentIndex()).toInt());
162 m_config
->setFlow((QSerialPort::FlowControl
)options_page
->flowControlComboBox
->itemData(options_page
->flowControlComboBox
->currentIndex()).toInt());
163 m_config
->setDataBits((QSerialPort::DataBits
)options_page
->dataBitsComboBox
->itemData(options_page
->dataBitsComboBox
->currentIndex()).toInt());
164 m_config
->setStopBits((QSerialPort::StopBits
)options_page
->stopBitsComboBox
->itemData(options_page
->stopBitsComboBox
->currentIndex()).toInt());
165 m_config
->setParity((QSerialPort::Parity
)options_page
->parityComboBox
->itemData(options_page
->parityComboBox
->currentIndex()).toInt());
166 m_config
->setTimeOut(options_page
->timeoutSpinBox
->value());
167 m_config
->setConnectionMode(options_page
->connectionMode
->currentText());
170 void GpsDisplayGadgetOptionsPage::finish()