Changeset - 30cf692b39ee
[Not reviewed]
settings
0 1 0
Hasan Yavuz ÖZDERYA - 9 years ago 2016-09-03 02:19:30
hy@ozderya.net
simplified parity setting code
1 file changed with 15 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/portcontrol.cpp
Show inline comments
 
@@ -14,29 +14,37 @@
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "portcontrol.h"
 
#include "ui_portcontrol.h"
 

	
 
#include <QSerialPortInfo>
 
#include <QKeySequence>
 
#include <QLabel>
 
#include <QMap>
 
#include <QtDebug>
 
#include "utils.h"
 

	
 
#define TBPORTLIST_MINWIDTH (200)
 

	
 
// setting mappings
 
const QMap<QSerialPort::Parity, QString> paritySettingMap({
 
        {QSerialPort::NoParity, "none"},
 
        {QSerialPort::OddParity, "odd"},
 
        {QSerialPort::EvenParity, "even"},
 
    });
 

	
 
PortControl::PortControl(QSerialPort* port, QWidget* parent) :
 
    QWidget(parent),
 
    ui(new Ui::PortControl),
 
    portToolBar("Port Toolbar"),
 
    openAction("Open", this),
 
    loadPortListAction("↺", this)
 
{
 
    ui->setupUi(this);
 

	
 
    serialPort = port;
 

	
 
    // setup actions
 
@@ -302,36 +310,26 @@ void PortControl::openActionTriggered(bo
 
void PortControl::onCbPortListActivated(int index)
 
{
 
    tbPortList.setCurrentIndex(index);
 
}
 

	
 
void PortControl::onTbPortListActivated(int index)
 
{
 
    ui->cbPortList->setCurrentIndex(index);
 
}
 

	
 
QString PortControl::currentParityText()
 
{
 
    if (parityButtons.checkedId() == QSerialPort::OddParity)
 
    {
 
        return "odd";
 
    }
 
    else if (parityButtons.checkedId() == QSerialPort::EvenParity)
 
    {
 
        return "even";
 
    }
 
    else // no parity
 
    {
 
        return "none";
 
    }
 
    return paritySettingMap.value(
 
        (QSerialPort::Parity) parityButtons.checkedId());
 
}
 

	
 
QString PortControl::currentFlowControlText()
 
{
 
    if (flowControlButtons.checkedId() == QSerialPort::HardwareControl)
 
    {
 
        return "hardware";
 
    }
 
    else if (flowControlButtons.checkedId() == QSerialPort::SoftwareControl)
 
    {
 
        return "software";
 
    }
 
@@ -364,40 +362,30 @@ void PortControl::loadSettings(QSettings
 
    {
 
        int index = portList.indexOfName(portName);
 
        if (index > -1) ui->cbPortList->setCurrentIndex(index);
 
    }
 

	
 
    // load baud rate setting if it exists in baud rate list
 
    QString baudSetting = settings->value(
 
        "baudRate", ui->cbBaudRate->currentText()).toString();
 
    int baudIndex = ui->cbBaudRate->findText(baudSetting);
 
    if (baudIndex > -1) ui->cbBaudRate->setCurrentIndex(baudIndex);
 

	
 
    // load parity setting
 
    QString paritySetting =
 
    QString parityText =
 
        settings->value("parity", currentParityText()).toString();
 

	
 
    if (paritySetting == "odd")
 
    {
 
        ui->rbOddParity->setChecked(true);
 
    }
 
    else if (paritySetting == "even")
 
    {
 
        ui->rbEvenParity->setChecked(true);
 
    }
 
    else
 
    {
 
        ui->rbNoParity->setChecked(true);
 
    }
 
    selectParity((QSerialPort::Parity) parityButtons.checkedId());
 
    QSerialPort::Parity paritySetting = paritySettingMap.key(
 
        parityText, (QSerialPort::Parity) parityButtons.checkedId());
 
    parityButtons.button(paritySetting)->setChecked(true);
 
    selectParity(paritySetting);
 

	
 
    // load number of bits
 
    int dataBits = settings->value("dataBits", dataBitsButtons.checkedId()).toInt();
 
    if (dataBits >=5 && dataBits <= 8)
 
    {
 
        dataBitsButtons.button((QSerialPort::DataBits) dataBits)->setChecked(true);
 
        selectDataBits(dataBits);
 
    }
 

	
 
    // load stop bits
 
    int stopBits = settings->value("stopBits", stopBitsButtons.checkedId()).toInt();
 
    if (stopBits == QSerialPort::OneStop)
0 comments (0 inline, 0 general)