From 23f8a58652e3ac4398d508691d227b3c75811e8f Mon Sep 17 00:00:00 2001 From: Laszlo Papp Date: Sat, 23 Mar 2013 18:45:26 +0000 Subject: Change the return type of the vendor/productIdentifier() API The API was established with a bit of insanity, namely: it returns raw strings for the 16-bit vendor and product _numbers_. This brings lots of limitations into the system aside from its silly nature, like how to handle lower and upper case hex letters (a-f, A-F) and so forth. Also, it is not clear whether the API should return zero aligned strings, or whether or not to return the leading indicator of the hex format (0x). This is now all being eliminated by switching to the 16-bit unsigned integer use. There are mostly two use cases for the usage of this: a) Comparison or mapping to find the requested port and device This is getting very simple because it will mean a simple 16-bit unsigned integer comparison which is cross-platform by its nature for sure. b) Display the string to the end user This is for instance with an enumerator or terminal emulator application, but in this special case the user can format the output of the integer as wished. Then, it can easily become a cross-platform display. Even customizing is simple enough to provide the native look'n feel without the library forcing one particular type. The documentation is being changed correspondingly. As for the future, if the need even arises, the following methods could be considered for the info provider class (QSerialPortInfo): bool hasVendorIdentifier() const; bool hasProductIdentifier() const; ... both can be added without any issues (i.e. in a binary compatible way). The examples are updated now as well with presenting the usage of the new API. The GUI emulator example got the string management a bit updated to be in line with the console based emulator (cenumerator). In general, it is also a way more reasonable way of putting a string together with so many placeholders. Also, the argument and list management got a bit nicer formatting style per line break. Testing: the change has been tested on Linux with Qt4 and Qt5. Task-number: QTPLAYGROUND-21 Change-Id: I33683061787af94a797685794be9ebcfa90c499a Reviewed-by: Sergey Belyashov Reviewed-by: Denis Shienkov --- examples/cenumerator/main.cpp | 4 ++-- examples/enumerator/main.cpp | 19 +++++++------------ examples/terminal/settingsdialog.cpp | 9 ++++++--- 3 files changed, 15 insertions(+), 17 deletions(-) (limited to 'examples') diff --git a/examples/cenumerator/main.cpp b/examples/cenumerator/main.cpp index 11af6183..3ae7d65e 100644 --- a/examples/cenumerator/main.cpp +++ b/examples/cenumerator/main.cpp @@ -59,8 +59,8 @@ int main(int argc, char *argv[]) << QObject::tr("Location: ") << serialPortInfo.systemLocation() << endl << QObject::tr("Description: ") << serialPortInfo.description() << endl << QObject::tr("Manufacturer: ") << serialPortInfo.manufacturer() << endl - << QObject::tr("Vendor Identifier: ") << serialPortInfo.vendorIdentifier() << endl - << QObject::tr("Product Identifier: ") << serialPortInfo.productIdentifier() << endl + << QObject::tr("Vendor Identifier: ") << QByteArray::number(serialPortInfo.vendorIdentifier(), 16) << endl + << QObject::tr("Product Identifier: ") << QByteArray::number(serialPortInfo.productIdentifier(), 16) << endl << QObject::tr("Busy: ") << (serialPortInfo.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) << endl; } diff --git a/examples/enumerator/main.cpp b/examples/enumerator/main.cpp index 0bd3fc04..a95ee76e 100644 --- a/examples/enumerator/main.cpp +++ b/examples/enumerator/main.cpp @@ -57,18 +57,13 @@ int main(int argc, char *argv[]) QVBoxLayout *layout = new QVBoxLayout; foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { - QString s(QObject::tr("Port: %1\n" - "Location: %2\n" - "Description: %3\n" - "Manufacturer: %4\n" - "Vendor Identifier: %5\n" - "Product Identifier: %6\n" - "Busy: %7\n")); - - s = s.arg(info.portName()).arg(info.systemLocation()) - .arg(info.description()).arg(info.manufacturer()) - .arg(info.vendorIdentifier()).arg(info.productIdentifier()) - .arg(info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")); + QString s = QObject::tr("Port: ") + info.portName() + "\n" + + QObject::tr("Location: ") + info.systemLocation() + "\n" + + QObject::tr("Description: ") + info.description() + "\n" + + QObject::tr("Manufacturer: ") + info.manufacturer() + "\n" + + QObject::tr("Vendor Identifier: ") + QString::number(info.vendorIdentifier(), 16) + "\n" + + QObject::tr("Product Identifier: ") + QString::number(info.productIdentifier(), 16) + "\n" + + QObject::tr("Busy: ") + (info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) + "\n"; QLabel *label = new QLabel(s); layout->addWidget(label); diff --git a/examples/terminal/settingsdialog.cpp b/examples/terminal/settingsdialog.cpp index f0779331..c516a75c 100644 --- a/examples/terminal/settingsdialog.cpp +++ b/examples/terminal/settingsdialog.cpp @@ -153,9 +153,12 @@ void SettingsDialog::fillPortsInfo() ui->serialPortInfoListBox->clear(); foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { QStringList list; - list << info.portName() << info.description() - << info.manufacturer() << info.systemLocation() - << info.vendorIdentifier() << info.productIdentifier(); + list << info.portName() + << info.description() + << info.manufacturer() + << info.systemLocation() + << QString::number(info.vendorIdentifier(), 16) + << QString::number(info.productIdentifier(), 16); ui->serialPortInfoListBox->addItem(list.first(), list); } -- cgit v1.2.3