summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaszlo Papp <lpapp@kde.org>2013-11-06 08:37:47 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-06 09:55:30 +0100
commit8e0b66f1269c0516fd339a18b5644bf38a1e2412 (patch)
tree14bb8482e2ca6d7712657163f85a916b1f0671a4
parent77f5e60cd23391f5103ac9c238066611b2fc4223 (diff)
downloadqtserialport-8e0b66f1269c0516fd339a18b5644bf38a1e2412.tar.gz
Define QStringLiteral when undefined (e.g. Qt 4)
This will allow us Qt 5 style coding. QLatin1String replaced everywhere where it works for Qt 4 and 5, namely: the direct literal passing. Note that the "standard" typo has also been fixed in this commit as the line had to change anyway, so it is not much of an additional noise. Change-Id: I8b7e4fe5f337441000bd3d8f58db528fdd0e175b Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
-rw-r--r--examples/serialport/terminal/settingsdialog.cpp40
-rw-r--r--src/serialport/qserialport_unix.cpp18
-rw-r--r--src/serialport/qserialport_win.cpp2
-rw-r--r--src/serialport/qserialportglobal.h7
-rw-r--r--src/serialport/qserialportinfo_unix.cpp56
-rw-r--r--src/serialport/qserialportinfo_win.cpp10
-rw-r--r--src/serialport/qserialportinfo_wince.cpp2
-rw-r--r--src/serialport/qtudev_p.h4
8 files changed, 71 insertions, 68 deletions
diff --git a/examples/serialport/terminal/settingsdialog.cpp b/examples/serialport/terminal/settingsdialog.cpp
index 65f6b87..ad32824 100644
--- a/examples/serialport/terminal/settingsdialog.cpp
+++ b/examples/serialport/terminal/settingsdialog.cpp
@@ -115,37 +115,37 @@ void SettingsDialog::fillPortsParameters()
{
// fill baud rate (is not the entire list of available values,
// desired values??, add your independently)
- ui->baudRateBox->addItem(QLatin1String("9600"), QSerialPort::Baud9600);
- ui->baudRateBox->addItem(QLatin1String("19200"), QSerialPort::Baud19200);
- ui->baudRateBox->addItem(QLatin1String("38400"), QSerialPort::Baud38400);
- ui->baudRateBox->addItem(QLatin1String("115200"), QSerialPort::Baud115200);
- ui->baudRateBox->addItem(QLatin1String("Custom"));
+ ui->baudRateBox->addItem(QStringLiteral("9600"), QSerialPort::Baud9600);
+ ui->baudRateBox->addItem(QStringLiteral("19200"), QSerialPort::Baud19200);
+ ui->baudRateBox->addItem(QStringLiteral("38400"), QSerialPort::Baud38400);
+ ui->baudRateBox->addItem(QStringLiteral("115200"), QSerialPort::Baud115200);
+ ui->baudRateBox->addItem(QStringLiteral("Custom"));
// fill data bits
- ui->dataBitsBox->addItem(QLatin1String("5"), QSerialPort::Data5);
- ui->dataBitsBox->addItem(QLatin1String("6"), QSerialPort::Data6);
- ui->dataBitsBox->addItem(QLatin1String("7"), QSerialPort::Data7);
- ui->dataBitsBox->addItem(QLatin1String("8"), QSerialPort::Data8);
+ ui->dataBitsBox->addItem(QStringLiteral("5"), QSerialPort::Data5);
+ ui->dataBitsBox->addItem(QStringLiteral("6"), QSerialPort::Data6);
+ ui->dataBitsBox->addItem(QStringLiteral("7"), QSerialPort::Data7);
+ ui->dataBitsBox->addItem(QStringLiteral("8"), QSerialPort::Data8);
ui->dataBitsBox->setCurrentIndex(3);
// fill parity
- ui->parityBox->addItem(QLatin1String("None"), QSerialPort::NoParity);
- ui->parityBox->addItem(QLatin1String("Even"), QSerialPort::EvenParity);
- ui->parityBox->addItem(QLatin1String("Odd"), QSerialPort::OddParity);
- ui->parityBox->addItem(QLatin1String("Mark"), QSerialPort::MarkParity);
- ui->parityBox->addItem(QLatin1String("Space"), QSerialPort::SpaceParity);
+ ui->parityBox->addItem(QStringLiteral("None"), QSerialPort::NoParity);
+ ui->parityBox->addItem(QStringLiteral("Even"), QSerialPort::EvenParity);
+ ui->parityBox->addItem(QStringLiteral("Odd"), QSerialPort::OddParity);
+ ui->parityBox->addItem(QStringLiteral("Mark"), QSerialPort::MarkParity);
+ ui->parityBox->addItem(QStringLiteral("Space"), QSerialPort::SpaceParity);
// fill stop bits
- ui->stopBitsBox->addItem(QLatin1String("1"), QSerialPort::OneStop);
+ ui->stopBitsBox->addItem(QStringLiteral("1"), QSerialPort::OneStop);
#ifdef Q_OS_WIN
- ui->stopBitsBox->addItem(QLatin1String("1.5"), QSerialPort::OneAndHalfStop);
+ ui->stopBitsBox->addItem(QStringLiteral("1.5"), QSerialPort::OneAndHalfStop);
#endif
- ui->stopBitsBox->addItem(QLatin1String("2"), QSerialPort::TwoStop);
+ ui->stopBitsBox->addItem(QStringLiteral("2"), QSerialPort::TwoStop);
// fill flow control
- ui->flowControlBox->addItem(QLatin1String("None"), QSerialPort::NoFlowControl);
- ui->flowControlBox->addItem(QLatin1String("RTS/CTS"), QSerialPort::HardwareControl);
- ui->flowControlBox->addItem(QLatin1String("XON/XOFF"), QSerialPort::SoftwareControl);
+ ui->flowControlBox->addItem(QStringLiteral("None"), QSerialPort::NoFlowControl);
+ ui->flowControlBox->addItem(QStringLiteral("RTS/CTS"), QSerialPort::HardwareControl);
+ ui->flowControlBox->addItem(QStringLiteral("XON/XOFF"), QSerialPort::SoftwareControl);
}
void SettingsDialog::fillPortsInfo()
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 81aafe7..cd5ea71 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -64,11 +64,11 @@ QT_BEGIN_NAMESPACE
QString serialPortLockFilePath(const QString &portName)
{
static const QStringList lockDirectoryPaths = QStringList()
- << QLatin1String("/var/lock")
- << QLatin1String("/etc/locks")
- << QLatin1String("/var/spool/locks")
- << QLatin1String("/var/spool/uucp")
- << QLatin1String("/tmp");
+ << QStringLiteral("/var/lock")
+ << QStringLiteral("/etc/locks")
+ << QStringLiteral("/var/spool/locks")
+ << QStringLiteral("/var/spool/uucp")
+ << QStringLiteral("/tmp");
QString lockFilePath;
@@ -89,7 +89,7 @@ QString serialPortLockFilePath(const QString &portName)
QString replacedPortName = portName;
- lockFilePath.append(QLatin1String("/LCK.."));
+ lockFilePath.append(QStringLiteral("/LCK.."));
lockFilePath.append(replacedPortName.replace(QLatin1Char('/'), QLatin1Char('_')));
return lockFilePath;
@@ -1228,10 +1228,10 @@ qint64 QSerialPortPrivate::readPerChar(char *data, qint64 maxSize)
}
#ifdef Q_OS_MAC
-static const QLatin1String defaultFilePathPrefix("/dev/cu.");
-static const QLatin1String unusedFilePathPrefix("/dev/tty.");
+static const QString defaultFilePathPrefix = QStringLiteral("/dev/cu.");
+static const QString unusedFilePathPrefix = QStringLiteral("/dev/tty.");
#else
-static const QLatin1String defaultFilePathPrefix("/dev/");
+static const QString defaultFilePathPrefix = QStringLiteral("/dev/");
#endif
QString QSerialPortPrivate::portNameToSystemLocation(const QString &port)
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index 79a5190..597f63e 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -1001,7 +1001,7 @@ bool QSerialPortPrivate::waitAnyEvent(int msecs, bool *timedOut,
return true;
}
-static const QLatin1String defaultPathPrefix("\\\\.\\");
+static const QString defaultPathPrefix = QStringLiteral("\\\\.\\");
QString QSerialPortPrivate::portNameToSystemLocation(const QString &port)
{
diff --git a/src/serialport/qserialportglobal.h b/src/serialport/qserialportglobal.h
index 03cd6a6..09ba0df 100644
--- a/src/serialport/qserialportglobal.h
+++ b/src/serialport/qserialportglobal.h
@@ -43,6 +43,7 @@
#ifndef QSERIALPORTGLOBAL_H
#define QSERIALPORTGLOBAL_H
+#include <QtCore/qstring.h>
#include <QtCore/qglobal.h>
QT_BEGIN_NAMESPACE
@@ -57,11 +58,15 @@ QT_BEGIN_NAMESPACE
# define Q_SERIALPORT_EXPORT
#endif
-// The macro has been available only since Qt 5.0
+// These macros have been available only since Qt 5.0
#ifndef Q_DECL_OVERRIDE
#define Q_DECL_OVERRIDE
#endif
+#ifndef QStringLiteral
+#define QStringLiteral(str) QString::fromUtf8(str)
+#endif
+
QT_END_NAMESPACE
#endif // QSERIALPORTGLOBAL_H
diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp
index 38f9124..955b6b1 100644
--- a/src/serialport/qserialportinfo_unix.cpp
+++ b/src/serialport/qserialportinfo_unix.cpp
@@ -70,19 +70,17 @@ static inline const QStringList& filtersOfDevices()
static const QStringList deviceFileNameFilterList = QStringList()
# ifdef Q_OS_LINUX
- << QLatin1String("ttyS*") // Standart UART 8250 and etc.
- << QLatin1String("ttyUSB*") // Usb/serial converters PL2303 and etc.
- << QLatin1String("ttyACM*") // CDC_ACM converters (i.e. Mobile Phones).
- << QLatin1String("ttyGS*") // Gadget serial device (i.e. Mobile Phones with gadget serial driver).
- << QLatin1String("ttyHS*") // High speed UART (e.g. Android).
- << QLatin1String("ttyHSL*") // Low speed UART (e.g. Android).
- << QLatin1String("ttyMI*") // MOXA pci/serial converters.
- << QLatin1String("ttymxc*") // Motorola IMX serial ports (i.e. Freescale i.MX).
- << QLatin1String("ttyAMA*") // AMBA serial device for embedded platform on ARM (i.e. Raspberry Pi).
- << QLatin1String("rfcomm*") // Bluetooth serial device.
- << QLatin1String("ircomm*"); // IrDA serial device.
+ << QStringLiteral("ttyS*") // Standard UART 8250 and etc.
+ << QStringLiteral("ttyUSB*") // Usb/serial converters PL2303 and etc.
+ << QStringLiteral("ttyACM*") // CDC_ACM converters (i.e. Mobile Phones).
+ << QStringLiteral("ttyGS*") // Gadget serial device (i.e. Mobile Phones with gadget serial driver).
+ << QStringLiteral("ttyMI*") // MOXA pci/serial converters.
+ << QStringLiteral("ttymxc*") // Motorola IMX serial ports (i.e. Freescale i.MX).
+ << QStringLiteral("ttyAMA*") // AMBA serial device for embedded platform on ARM (i.e. Raspberry Pi).
+ << QStringLiteral("rfcomm*") // Bluetooth serial device.
+ << QStringLiteral("ircomm*"); // IrDA serial device.
# elif defined (Q_OS_FREEBSD)
- << QLatin1String("cu*");
+ << QStringLiteral("cu*");
# else
; // Here for other *nix OS.
# endif
@@ -94,7 +92,7 @@ static QStringList filteredDeviceFilePaths()
{
QStringList result;
- QDir deviceDir(QLatin1String("/dev"));
+ QDir deviceDir(QStringLiteral("/dev"));
if (deviceDir.exists()) {
deviceDir.setNameFilters(filtersOfDevices());
deviceDir.setFilter(QDir::Files | QDir::System | QDir::NoSymLinks);
@@ -119,7 +117,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
#ifdef Q_OS_LINUX
- QDir ttySysClassDir(QLatin1String("/sys/class/tty"));
+ QDir ttySysClassDir(QStringLiteral("/sys/class/tty"));
sysfsEnabled = ttySysClassDir.exists() && ttySysClassDir.isReadable();
if (sysfsEnabled) {
@@ -136,18 +134,18 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
bool canAppendToList = true;
QSerialPortInfo serialPortInfo;
- if (targetPath.contains(QLatin1String("pnp"))) {
+ if (targetPath.contains(QStringLiteral("pnp"))) {
// TODO: Implement me.
- } else if (targetPath.contains(QLatin1String("platform"))) {
+ } else if (targetPath.contains(QStringLiteral("platform"))) {
// Platform 'pseudo' bus for legacy device.
// Skip this devices because this type of subsystem does
// not include a real physical serial device.
canAppendToList = false;
- } else if (targetPath.contains(QLatin1String("usb"))) {
+ } else if (targetPath.contains(QStringLiteral("usb"))) {
QDir targetDir(targetPath);
targetDir.setFilter(QDir::Files | QDir::Readable);
- targetDir.setNameFilters(QStringList(QLatin1String("uevent")));
+ targetDir.setNameFilters(QStringList(QStringLiteral("uevent")));
do {
const QFileInfoList entryInfoList = targetDir.entryInfoList();
@@ -160,24 +158,24 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
const QString ueventContent = QString::fromLatin1(uevent.readAll());
- if (ueventContent.contains(QLatin1String("DEVTYPE=usb_device"))
- && ueventContent.contains(QLatin1String("DRIVER=usb"))) {
+ if (ueventContent.contains(QStringLiteral("DEVTYPE=usb_device"))
+ && ueventContent.contains(QStringLiteral("DRIVER=usb"))) {
- QFile description(QFileInfo(targetDir, QLatin1String("product")).absoluteFilePath());
+ QFile description(QFileInfo(targetDir, QStringLiteral("product")).absoluteFilePath());
if (description.open(QIODevice::ReadOnly | QIODevice::Text))
serialPortInfo.d_ptr->description = QString::fromLatin1(description.readAll()).simplified();
- QFile manufacturer(QFileInfo(targetDir, QLatin1String("manufacturer")).absoluteFilePath());
+ QFile manufacturer(QFileInfo(targetDir, QStringLiteral("manufacturer")).absoluteFilePath());
if (manufacturer.open(QIODevice::ReadOnly | QIODevice::Text))
serialPortInfo.d_ptr->manufacturer = QString::fromLatin1(manufacturer.readAll()).simplified();
- QFile vendorIdentifier(QFileInfo(targetDir, QLatin1String("idVendor")).absoluteFilePath());
+ QFile vendorIdentifier(QFileInfo(targetDir, QStringLiteral("idVendor")).absoluteFilePath());
if (vendorIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) {
serialPortInfo.d_ptr->vendorIdentifier = QString::fromLatin1(vendorIdentifier.readAll())
.toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16);
}
- QFile productIdentifier(QFileInfo(targetDir, QLatin1String("idProduct")).absoluteFilePath());
+ QFile productIdentifier(QFileInfo(targetDir, QStringLiteral("idProduct")).absoluteFilePath());
if (productIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) {
serialPortInfo.d_ptr->productIdentifier = QString::fromLatin1(productIdentifier.readAll())
.toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16);
@@ -226,7 +224,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
QList<QSerialPortInfo> serialPortInfoList;
// White list for devices without a parent
- static const QString rfcommDeviceName(QLatin1String("rfcomm"));
+ static const QString rfcommDeviceName(QStringLiteral("rfcomm"));
struct ::udev *udev = ::udev_new();
if (udev) {
@@ -266,8 +264,8 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
QLatin1String subsys(::udev_device_get_subsystem(parentdev));
- if (subsys == QLatin1String("usb-serial")
- || subsys == QLatin1String("usb")) { // USB bus type
+ if (subsys == QStringLiteral("usb-serial")
+ || subsys == QStringLiteral("usb")) { // USB bus type
// Append this devices and try get additional information about them.
serialPortInfo.d_ptr->description = QString(
QLatin1String(::udev_device_get_property_value(dev,
@@ -284,11 +282,11 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
QString::fromLatin1(::udev_device_get_property_value(dev,
"ID_MODEL_ID")).toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16);
- } else if (subsys == QLatin1String("pnp")) { // PNP bus type
+ } else if (subsys == QStringLiteral("pnp")) { // PNP bus type
// Append this device.
// FIXME: How to get additional information about serial devices
// with this subsystem?
- } else if (subsys == QLatin1String("platform")) { // Platform 'pseudo' bus for legacy device.
+ } else if (subsys == QStringLiteral("platform")) { // Platform 'pseudo' bus for legacy device.
// Skip this devices because this type of subsystem does
// not include a real physical serial device.
canAppendToList = false;
diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp
index 45236a0..7eec46a 100644
--- a/src/serialport/qserialportinfo_win.cpp
+++ b/src/serialport/qserialportinfo_win.cpp
@@ -159,10 +159,10 @@ static QString devicePortName(HDEVINFO deviceInfoSet, PSP_DEVINFO_DATA deviceInf
QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
{
- static const QString usbVendorIdentifierPrefix(QLatin1String("VID_"));
- static const QString usbProductIdentifierPrefix(QLatin1String("PID_"));
- static const QString pciVendorIdentifierPrefix(QLatin1String("VEN_"));
- static const QString pciDeviceIdentifierPrefix(QLatin1String("DEV_"));
+ static const QString usbVendorIdentifierPrefix(QStringLiteral("VID_"));
+ static const QString usbProductIdentifierPrefix(QStringLiteral("PID_"));
+ static const QString pciVendorIdentifierPrefix(QStringLiteral("VEN_"));
+ static const QString pciDeviceIdentifierPrefix(QStringLiteral("DEV_"));
static const int vendorIdentifierSize = 4;
static const int productIdentifierSize = 4;
@@ -184,7 +184,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
QSerialPortInfo serialPortInfo;
QString s = devicePortName(deviceInfoSet, &deviceInfoData);
- if (s.isEmpty() || s.contains(QLatin1String("LPT")))
+ if (s.isEmpty() || s.contains(QStringLiteral("LPT")))
continue;
serialPortInfo.d_ptr->portName = s;
diff --git a/src/serialport/qserialportinfo_wince.cpp b/src/serialport/qserialportinfo_wince.cpp
index 279acea..0d0fd0d 100644
--- a/src/serialport/qserialportinfo_wince.cpp
+++ b/src/serialport/qserialportinfo_wince.cpp
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
static QString findDescription(HKEY parentKeyHandle, const QString &subKey)
{
- const static QString valueName(QLatin1String("FriendlyName"));
+ const static QString valueName(QStringLiteral("FriendlyName"));
QString result;
HKEY hSubKey = 0;
diff --git a/src/serialport/qtudev_p.h b/src/serialport/qtudev_p.h
index 2619f8e..457c3f0 100644
--- a/src/serialport/qtudev_p.h
+++ b/src/serialport/qtudev_p.h
@@ -109,9 +109,9 @@ inline void *resolveSymbol(const char *symbolName)
inline bool resolveSymbols()
{
if (!udevLibrary.isLoaded()) {
- udevLibrary.setFileNameAndVersion(QLatin1String("udev"), 1);
+ udevLibrary.setFileNameAndVersion(QStringLiteral("udev"), 1);
if (!udevLibrary.load()) {
- udevLibrary.setFileNameAndVersion(QLatin1String("udev"), 0);
+ udevLibrary.setFileNameAndVersion(QStringLiteral("udev"), 0);
if (!udevLibrary.load()) {
qWarning("Failed to load the library: %s, supported version(s): %i and %i", qPrintable(udevLibrary.fileName()), 1, 0);
return false;