summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2021-01-27 16:06:52 +0100
committerKarsten Heimrich <karsten.heimrich@qt.io>2021-02-01 14:03:09 +0100
commit3f33ab751950ecdd07df4d88274a4d7c759df98f (patch)
treefa83e4403f1a504acad596ae9f368e7bd85e70d8 /src
parent10a76dfebfac652e926b88db3c4b8fcec896e015 (diff)
Qt6: Migrate useful properties to new property system
Task-number: QTBUG-89885 Change-Id: I883c139e7be4ff44823170959b7daf2aa6740675 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/serialport/qserialport.cpp89
-rw-r--r--src/serialport/qserialport.h25
-rw-r--r--src/serialport/qserialport_p.h44
3 files changed, 116 insertions, 42 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp
index 75aded42..fc6b204f 100644
--- a/src/serialport/qserialport.cpp
+++ b/src/serialport/qserialport.cpp
@@ -99,8 +99,8 @@ void QSerialPortPrivate::setError(const QSerialPortErrorInfo &errorInfo)
{
Q_Q(QSerialPort);
- error = errorInfo.errorCode;
q->setErrorString(errorInfo.errorString);
+ error.setValue(errorInfo.errorCode);
emit q->errorOccurred(error);
}
@@ -518,7 +518,7 @@ void QSerialPort::close()
}
d->close();
- d->isBreakEnabled = false;
+ d->isBreakEnabled.setValue(false);
QIODevice::close();
}
@@ -607,13 +607,14 @@ bool QSerialPort::setDataBits(DataBits dataBits)
{
Q_D(QSerialPort);
+ const auto currentDataBits = d->dataBits.value();
if (!isOpen() || d->setDataBits(dataBits)) {
- if (d->dataBits != dataBits) {
- d->dataBits = dataBits;
- emit dataBitsChanged(d->dataBits);
- }
+ d->dataBits.setValue(dataBits);
+ if (currentDataBits != dataBits)
+ emit dataBitsChanged(dataBits);
return true;
}
+ d->dataBits.setValue(currentDataBits); // removes the binding if necessary, keep
return false;
}
@@ -624,6 +625,11 @@ QSerialPort::DataBits QSerialPort::dataBits() const
return d->dataBits;
}
+QBindable<QSerialPort::DataBits> QSerialPort::bindableDataBits()
+{
+ return &d_func()->dataBits;
+}
+
/*!
\fn void QSerialPort::dataBitsChanged(DataBits dataBits)
@@ -652,13 +658,14 @@ bool QSerialPort::setParity(Parity parity)
{
Q_D(QSerialPort);
+ const auto currentParity = d->parity.value();
if (!isOpen() || d->setParity(parity)) {
- if (d->parity != parity) {
- d->parity = parity;
- emit parityChanged(d->parity);
- }
+ d->parity.setValue(parity);
+ if (currentParity != parity)
+ emit parityChanged(parity);
return true;
}
+ d->parity.setValue(currentParity); // removes the binding if necessary, keep
return false;
}
@@ -669,6 +676,11 @@ QSerialPort::Parity QSerialPort::parity() const
return d->parity;
}
+QBindable<QSerialPort::Parity> QSerialPort::bindableParity()
+{
+ return &d_func()->parity;
+}
+
/*!
\fn void QSerialPort::parityChanged(Parity parity)
@@ -696,13 +708,14 @@ bool QSerialPort::setStopBits(StopBits stopBits)
{
Q_D(QSerialPort);
+ const auto currentStopBits = d->stopBits.value();
if (!isOpen() || d->setStopBits(stopBits)) {
- if (d->stopBits != stopBits) {
- d->stopBits = stopBits;
- emit stopBitsChanged(d->stopBits);
- }
+ d->stopBits.setValue(stopBits);
+ if (currentStopBits != stopBits)
+ emit stopBitsChanged(stopBits);
return true;
}
+ d->stopBits.setValue(currentStopBits); // removes the binding if necessary, keep
return false;
}
@@ -713,6 +726,11 @@ QSerialPort::StopBits QSerialPort::stopBits() const
return d->stopBits;
}
+QBindable<bool> QSerialPort::bindableStopBits()
+{
+ return &d_func()->stopBits;
+}
+
/*!
\fn void QSerialPort::stopBitsChanged(StopBits stopBits)
@@ -740,13 +758,14 @@ bool QSerialPort::setFlowControl(FlowControl flowControl)
{
Q_D(QSerialPort);
+ const auto currentFlowControl = d->flowControl.value();
if (!isOpen() || d->setFlowControl(flowControl)) {
- if (d->flowControl != flowControl) {
- d->flowControl = flowControl;
- emit flowControlChanged(d->flowControl);
- }
+ d->flowControl.setValue(flowControl);
+ if (currentFlowControl != flowControl)
+ emit flowControlChanged(flowControl);
return true;
}
+ d->flowControl.setValue(currentFlowControl); // removes the binding if necessary, keep
return false;
}
@@ -757,6 +776,11 @@ QSerialPort::FlowControl QSerialPort::flowControl() const
return d->flowControl;
}
+QBindable<QSerialPort::FlowControl> QSerialPort::bindableFlowControl()
+{
+ return &d_func()->flowControl;
+}
+
/*!
\fn void QSerialPort::flowControlChanged(FlowControl flow)
@@ -977,6 +1001,11 @@ void QSerialPort::clearError()
d->setError(QSerialPortErrorInfo(QSerialPort::NoError));
}
+QBindable<QSerialPort::SerialPortError> QSerialPort::bindableError() const
+{
+ return &d_func()->error;
+}
+
/*!
\fn void QSerialPort::errorOccurred(SerialPortError error)
\since 5.8
@@ -1149,19 +1178,20 @@ bool QSerialPort::setBreakEnabled(bool set)
{
Q_D(QSerialPort);
- if (!isOpen()) {
+ const auto currentSet = d->isBreakEnabled.value();
+ if (isOpen()) {
+ if (d->setBreakEnabled(set)) {
+ d->isBreakEnabled.setValue(set);
+ if (currentSet != set)
+ emit breakEnabledChanged(set);
+ return true;
+ }
+ } else {
d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
qWarning("%s: device not open", Q_FUNC_INFO);
- return false;
}
+ d->isBreakEnabled.setValue(currentSet); // removes the binding if necessary, keep
- if (d->setBreakEnabled(set)) {
- if (d->isBreakEnabled != set) {
- d->isBreakEnabled = set;
- emit breakEnabledChanged(d->isBreakEnabled);
- }
- return true;
- }
return false;
}
@@ -1171,6 +1201,11 @@ bool QSerialPort::isBreakEnabled() const
return d->isBreakEnabled;
}
+QBindable<bool> QSerialPort::bindableIsBreakEnabled()
+{
+ return &d_func()->isBreakEnabled;
+}
+
/*!
\reimp
diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h
index cf126ddf..8ef0f6b6 100644
--- a/src/serialport/qserialport.h
+++ b/src/serialport/qserialport.h
@@ -56,14 +56,19 @@ class Q_SERIALPORT_EXPORT QSerialPort : public QIODevice
Q_DECLARE_PRIVATE(QSerialPort)
Q_PROPERTY(qint32 baudRate READ baudRate WRITE setBaudRate NOTIFY baudRateChanged)
- Q_PROPERTY(DataBits dataBits READ dataBits WRITE setDataBits NOTIFY dataBitsChanged)
- Q_PROPERTY(Parity parity READ parity WRITE setParity NOTIFY parityChanged)
- Q_PROPERTY(StopBits stopBits READ stopBits WRITE setStopBits NOTIFY stopBitsChanged)
- Q_PROPERTY(FlowControl flowControl READ flowControl WRITE setFlowControl NOTIFY flowControlChanged)
- Q_PROPERTY(bool dataTerminalReady READ isDataTerminalReady WRITE setDataTerminalReady NOTIFY dataTerminalReadyChanged)
+ Q_PROPERTY(DataBits dataBits READ dataBits WRITE setDataBits NOTIFY dataBitsChanged
+ BINDABLE bindableDataBits)
+ Q_PROPERTY(Parity parity READ parity WRITE setParity NOTIFY parityChanged BINDABLE bindableParity)
+ Q_PROPERTY(StopBits stopBits READ stopBits WRITE setStopBits NOTIFY stopBitsChanged
+ BINDABLE bindableStopBits)
+ Q_PROPERTY(FlowControl flowControl READ flowControl WRITE setFlowControl NOTIFY flowControlChanged
+ BINDABLE bindableFlowControl)
+ Q_PROPERTY(bool dataTerminalReady READ isDataTerminalReady WRITE setDataTerminalReady
+ NOTIFY dataTerminalReadyChanged)
Q_PROPERTY(bool requestToSend READ isRequestToSend WRITE setRequestToSend NOTIFY requestToSendChanged)
- Q_PROPERTY(SerialPortError error READ error RESET clearError NOTIFY error)
- Q_PROPERTY(bool breakEnabled READ isBreakEnabled WRITE setBreakEnabled NOTIFY breakEnabledChanged)
+ Q_PROPERTY(SerialPortError error READ error RESET clearError NOTIFY errorOccurred BINDABLE bindableError)
+ Q_PROPERTY(bool breakEnabled READ isBreakEnabled WRITE setBreakEnabled NOTIFY breakEnabledChanged
+ BINDABLE bindableIsBreakEnabled)
#if defined(Q_OS_WIN32)
typedef void* Handle;
@@ -171,15 +176,19 @@ public:
bool setDataBits(DataBits dataBits);
DataBits dataBits() const;
+ QBindable<DataBits> bindableDataBits();
bool setParity(Parity parity);
Parity parity() const;
+ QBindable<Parity> bindableParity();
bool setStopBits(StopBits stopBits);
StopBits stopBits() const;
+ QBindable<bool> bindableStopBits();
bool setFlowControl(FlowControl flowControl);
FlowControl flowControl() const;
+ QBindable<FlowControl> bindableFlowControl();
bool setDataTerminalReady(bool set);
bool isDataTerminalReady();
@@ -194,6 +203,7 @@ public:
SerialPortError error() const;
void clearError();
+ QBindable<SerialPortError> bindableError() const;
qint64 readBufferSize() const;
void setReadBufferSize(qint64 size);
@@ -209,6 +219,7 @@ public:
bool setBreakEnabled(bool set = true);
bool isBreakEnabled() const;
+ QBindable<bool> bindableIsBreakEnabled();
Handle handle() const;
diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h
index 7348aed6..a9c08e95 100644
--- a/src/serialport/qserialport_p.h
+++ b/src/serialport/qserialport_p.h
@@ -55,9 +55,11 @@
#include "qserialport.h"
-#include <private/qiodevice_p.h>
#include <qdeadlinetimer.h>
+#include <private/qiodevice_p.h>
+#include <private/qproperty_p.h>
+
#if defined(Q_OS_WIN32)
# include <qt_windows.h>
#elif defined(Q_OS_UNIX)
@@ -114,7 +116,7 @@ QString serialPortLockFilePath(const QString &portName);
class QSerialPortErrorInfo
{
public:
- explicit QSerialPortErrorInfo(QSerialPort::SerialPortError newErrorCode = QSerialPort::UnknownError,
+ QSerialPortErrorInfo(QSerialPort::SerialPortError newErrorCode = QSerialPort::UnknownError,
const QString &newErrorString = QString());
QSerialPort::SerialPortError errorCode = QSerialPort::UnknownError;
QString errorString;
@@ -164,16 +166,42 @@ public:
static QList<qint32> standardBaudRates();
qint64 readBufferMaxSize = 0;
- QSerialPort::SerialPortError error = QSerialPort::NoError;
+
+ void setBindableError(QSerialPort::SerialPortError error)
+ { setError(error); }
+ Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, QSerialPort::SerialPortError, error,
+ &QSerialPortPrivate::setBindableError, QSerialPort::NoError)
+
QString systemLocation;
qint32 inputBaudRate = QSerialPort::Baud9600;
qint32 outputBaudRate = QSerialPort::Baud9600;
- QSerialPort::DataBits dataBits = QSerialPort::Data8;
- QSerialPort::Parity parity = QSerialPort::NoParity;
- QSerialPort::StopBits stopBits = QSerialPort::OneStop;
- QSerialPort::FlowControl flowControl = QSerialPort::NoFlowControl;
+
+ bool setBindableDataBits(QSerialPort::DataBits dataBits)
+ { return q_func()->setDataBits(dataBits); }
+ Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, QSerialPort::DataBits, dataBits,
+ &QSerialPortPrivate::setBindableDataBits, QSerialPort::Data8)
+
+ bool setBindableParity(QSerialPort::Parity parity)
+ { return q_func()->setParity(parity); }
+ Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, QSerialPort::Parity, parity,
+ &QSerialPortPrivate::setBindableParity, QSerialPort::NoParity)
+
+ bool setBindableStopBits(QSerialPort::StopBits stopBits)
+ { return q_func()->setStopBits(stopBits); }
+ Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, QSerialPort::StopBits, stopBits,
+ &QSerialPortPrivate::setBindableStopBits, QSerialPort::OneStop)
+
+ bool setBindableFlowControl(QSerialPort::FlowControl flowControl)
+ { return q_func()->setFlowControl(flowControl); }
+ Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, QSerialPort::FlowControl, flowControl,
+ &QSerialPortPrivate::setBindableFlowControl, QSerialPort::NoFlowControl)
+
bool settingsRestoredOnClose = true;
- bool isBreakEnabled = false;
+
+ bool setBindableBreakEnabled(bool isBreakEnabled)
+ { return q_func()->setBreakEnabled(isBreakEnabled); }
+ Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, bool, isBreakEnabled,
+ &QSerialPortPrivate::setBindableBreakEnabled, false)
bool startAsyncRead();