diff options
Diffstat (limited to 'src/serialport/qserialport.cpp')
-rw-r--r-- | src/serialport/qserialport.cpp | 109 |
1 files changed, 37 insertions, 72 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index bc9504c2..fadd98eb 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -1,44 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Copyright (C) 2012 Andre Hartmann <aha_1980@gmx.de> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// Copyright (C) 2012 Andre Hartmann <aha_1980@gmx.de> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qserialport.h" #include "qserialportinfo.h" @@ -101,6 +65,7 @@ void QSerialPortPrivate::setError(const QSerialPortErrorInfo &errorInfo) q->setErrorString(errorInfo.errorString); error.setValue(errorInfo.errorCode); + error.notify(); emit q->errorOccurred(error); } @@ -606,16 +571,16 @@ qint32 QSerialPort::baudRate(Directions directions) const bool QSerialPort::setDataBits(DataBits dataBits) { Q_D(QSerialPort); - - const auto currentDataBits = d->dataBits.value(); + d->dataBits.removeBindingUnlessInWrapper(); + const auto currentDataBits = d->dataBits.valueBypassingBindings(); if (!isOpen() || d->setDataBits(dataBits)) { - d->dataBits.setValue(dataBits); - if (currentDataBits != dataBits) + d->dataBits.setValueBypassingBindings(dataBits); + if (currentDataBits != dataBits) { + d->dataBits.notify(); emit dataBitsChanged(dataBits); + } return true; } - d->dataBits.setValue(currentDataBits); // removes the binding if necessary, keep - return false; } @@ -657,16 +622,16 @@ QBindable<QSerialPort::DataBits> QSerialPort::bindableDataBits() bool QSerialPort::setParity(Parity parity) { Q_D(QSerialPort); - - const auto currentParity = d->parity.value(); + d->parity.removeBindingUnlessInWrapper(); + const auto currentParity = d->parity.valueBypassingBindings(); if (!isOpen() || d->setParity(parity)) { - d->parity.setValue(parity); - if (currentParity != parity) + d->parity.setValueBypassingBindings(parity); + if (currentParity != parity) { + d->parity.notify(); emit parityChanged(parity); + } return true; } - d->parity.setValue(currentParity); // removes the binding if necessary, keep - return false; } @@ -707,16 +672,16 @@ QBindable<QSerialPort::Parity> QSerialPort::bindableParity() bool QSerialPort::setStopBits(StopBits stopBits) { Q_D(QSerialPort); - - const auto currentStopBits = d->stopBits.value(); + d->stopBits.removeBindingUnlessInWrapper(); + const auto currentStopBits = d->stopBits.valueBypassingBindings(); if (!isOpen() || d->setStopBits(stopBits)) { - d->stopBits.setValue(stopBits); - if (currentStopBits != stopBits) + d->stopBits.setValueBypassingBindings(stopBits); + if (currentStopBits != stopBits) { + d->stopBits.notify(); emit stopBitsChanged(stopBits); + } return true; } - d->stopBits.setValue(currentStopBits); // removes the binding if necessary, keep - return false; } @@ -726,7 +691,7 @@ QSerialPort::StopBits QSerialPort::stopBits() const return d->stopBits; } -QBindable<bool> QSerialPort::bindableStopBits() +QBindable<QSerialPort::StopBits> QSerialPort::bindableStopBits(QT6_IMPL_NEW_OVERLOAD) { return &d_func()->stopBits; } @@ -757,16 +722,16 @@ QBindable<bool> QSerialPort::bindableStopBits() bool QSerialPort::setFlowControl(FlowControl flowControl) { Q_D(QSerialPort); - - const auto currentFlowControl = d->flowControl.value(); + d->flowControl.removeBindingUnlessInWrapper(); + const auto currentFlowControl = d->flowControl.valueBypassingBindings(); if (!isOpen() || d->setFlowControl(flowControl)) { - d->flowControl.setValue(flowControl); - if (currentFlowControl != flowControl) + d->flowControl.setValueBypassingBindings(flowControl); + if (currentFlowControl != flowControl) { + d->flowControl.notify(); emit flowControlChanged(flowControl); + } return true; } - d->flowControl.setValue(currentFlowControl); // removes the binding if necessary, keep - return false; } @@ -1177,21 +1142,21 @@ bool QSerialPort::waitForBytesWritten(int msecs) bool QSerialPort::setBreakEnabled(bool set) { Q_D(QSerialPort); - - const auto currentSet = d->isBreakEnabled.value(); + d->isBreakEnabled.removeBindingUnlessInWrapper(); + const auto currentSet = d->isBreakEnabled.valueBypassingBindings(); if (isOpen()) { if (d->setBreakEnabled(set)) { - d->isBreakEnabled.setValue(set); - if (currentSet != set) + d->isBreakEnabled.setValueBypassingBindings(set); + if (currentSet != set) { + d->isBreakEnabled.notify(); emit breakEnabledChanged(set); + } return true; } } else { d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); qWarning("%s: device not open", Q_FUNC_INFO); } - d->isBreakEnabled.setValue(currentSet); // removes the binding if necessary, keep - return false; } |