diff options
author | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-02-20 15:55:55 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-02-25 10:22:53 +0100 |
commit | a325de1910e6627e4d042114d22303cc68fae7a9 (patch) | |
tree | cabf88f9e4e42579e6695ecff5e6ab787f3922ab /examples | |
parent | d42d5838b9a4c3cbd6b0e67dabce658ba737eba8 (diff) | |
parent | b84fe7eb3d6d977a347bfbb82da724409b2eda69 (diff) |
Merge remote-tracking branch 'origin/5.4' into 5.5
Conflicts:
.qmake.conf
src/serialport/qserialport_unix.cpp
src/serialport/qserialport_unix_p.h
src/serialport/qserialport_win.cpp
src/serialport/qserialport_win_p.h
src/serialport/qserialport_wince.cpp
src/serialport/qserialport_wince_p.h
Change-Id: Ibb917652b132e66fbb90f437bf762c1094911dc0
Diffstat (limited to 'examples')
-rw-r--r-- | examples/serialport/doc/cenumerator.qdoc | 2 | ||||
-rw-r--r-- | examples/serialport/enumerator/main.cpp | 12 | ||||
-rw-r--r-- | examples/serialport/examples.qdoc | 46 | ||||
-rw-r--r-- | examples/serialport/terminal/mainwindow.cpp | 3 | ||||
-rw-r--r-- | examples/serialport/terminal/settingsdialog.cpp | 54 | ||||
-rw-r--r-- | examples/serialport/terminal/settingsdialog.h | 1 |
6 files changed, 46 insertions, 72 deletions
diff --git a/examples/serialport/doc/cenumerator.qdoc b/examples/serialport/doc/cenumerator.qdoc index 26d6a4ec..67057ac8 100644 --- a/examples/serialport/doc/cenumerator.qdoc +++ b/examples/serialport/doc/cenumerator.qdoc @@ -29,7 +29,7 @@ /*! \example cenumerator \title Command Line Enumerator Example - \ingroup qtserialport-example + \ingroup qtserialport-examples \brief Shows how to get information about serial devices in a system. \e{Command Line Enumerator} shows how to use the class QSerialPortInfo for diff --git a/examples/serialport/enumerator/main.cpp b/examples/serialport/enumerator/main.cpp index e7564ec3..41bfddd4 100644 --- a/examples/serialport/enumerator/main.cpp +++ b/examples/serialport/enumerator/main.cpp @@ -36,6 +36,7 @@ #include <QWidget> #include <QVBoxLayout> #include <QLabel> +#include <QScrollArea> #include <QtSerialPort/QSerialPortInfo> QT_USE_NAMESPACE @@ -44,8 +45,6 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - QWidget w; - w.setWindowTitle(QObject::tr("Info about all available serial ports.")); QVBoxLayout *layout = new QVBoxLayout; foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { @@ -62,8 +61,13 @@ int main(int argc, char *argv[]) layout->addWidget(label); } - w.setLayout(layout); - w.show(); + QWidget *workPage = new QWidget; + workPage->setLayout(layout); + + QScrollArea area; + area.setWindowTitle(QObject::tr("Info about all available serial ports.")); + area.setWidget(workPage); + area.show(); return a.exec(); } diff --git a/examples/serialport/examples.qdoc b/examples/serialport/examples.qdoc deleted file mode 100644 index f6f1912c..00000000 --- a/examples/serialport/examples.qdoc +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \title Qt Serial Port Examples - \page examples-serialport.html - \group qtserialport-examples - \brief List of serial port examples - - The \l{Qt Serial Port} module provides the following examples for reference - to help understand the API usage. - - \section1 Running the Examples - - To run the examples from \l{Qt Creator Manual}{Qt Creator}, open the \gui - Welcome mode and select the example from \gui Examples. - For more information, visit - \l{Qt Creator: Building and Running an Example}{Building and Running an Example}. - -*/ diff --git a/examples/serialport/terminal/mainwindow.cpp b/examples/serialport/terminal/mainwindow.cpp index fd65a744..9a984562 100644 --- a/examples/serialport/terminal/mainwindow.cpp +++ b/examples/serialport/terminal/mainwindow.cpp @@ -109,7 +109,8 @@ void MainWindow::openSerialPort() //! [5] void MainWindow::closeSerialPort() { - serial->close(); + if (serial->isOpen()) + serial->close(); console->setEnabled(false); ui->actionConnect->setEnabled(true); ui->actionDisconnect->setEnabled(false); diff --git a/examples/serialport/terminal/settingsdialog.cpp b/examples/serialport/terminal/settingsdialog.cpp index 2a164714..900d2fec 100644 --- a/examples/serialport/terminal/settingsdialog.cpp +++ b/examples/serialport/terminal/settingsdialog.cpp @@ -41,6 +41,8 @@ QT_USE_NAMESPACE +static const char blankString[] = QT_TRANSLATE_NOOP("SettingsDialog", "N/A"); + SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog) @@ -57,6 +59,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) : this, SLOT(showPortInfo(int))); connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(checkCustomBaudRatePolicy(int))); + connect(ui->serialPortInfoListBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(checkCustomDevicePathPolicy(int))); fillPortsParameters(); fillPortsInfo(); @@ -76,15 +80,16 @@ SettingsDialog::Settings SettingsDialog::settings() const void SettingsDialog::showPortInfo(int idx) { - if (idx != -1) { - QStringList list = ui->serialPortInfoListBox->itemData(idx).toStringList(); - ui->descriptionLabel->setText(tr("Description: %1").arg(list.at(1))); - ui->manufacturerLabel->setText(tr("Manufacturer: %1").arg(list.at(2))); - ui->serialNumberLabel->setText(tr("Serial number: %1").arg(list.at(3))); - ui->locationLabel->setText(tr("Location: %1").arg(list.at(4))); - ui->vidLabel->setText(tr("Vendor Identifier: %1").arg(list.at(5))); - ui->pidLabel->setText(tr("Product Identifier: %1").arg(list.at(6))); - } + if (idx == -1) + return; + + QStringList list = ui->serialPortInfoListBox->itemData(idx).toStringList(); + ui->descriptionLabel->setText(tr("Description: %1").arg(list.count() > 1 ? list.at(1) : tr(blankString))); + ui->manufacturerLabel->setText(tr("Manufacturer: %1").arg(list.count() > 2 ? list.at(2) : tr(blankString))); + ui->serialNumberLabel->setText(tr("Serial number: %1").arg(list.count() > 3 ? list.at(3) : tr(blankString))); + ui->locationLabel->setText(tr("Location: %1").arg(list.count() > 4 ? list.at(4) : tr(blankString))); + ui->vidLabel->setText(tr("Vendor Identifier: %1").arg(list.count() > 5 ? list.at(5) : tr(blankString))); + ui->pidLabel->setText(tr("Product Identifier: %1").arg(list.count() > 6 ? list.at(6) : tr(blankString))); } void SettingsDialog::apply() @@ -104,13 +109,21 @@ void SettingsDialog::checkCustomBaudRatePolicy(int idx) } } +void SettingsDialog::checkCustomDevicePathPolicy(int idx) +{ + bool isCustomPath = !ui->serialPortInfoListBox->itemData(idx).isValid(); + ui->serialPortInfoListBox->setEditable(isCustomPath); + if (isCustomPath) + ui->serialPortInfoListBox->clearEditText(); +} + void SettingsDialog::fillPortsParameters() { 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")); + ui->baudRateBox->addItem(tr("Custom")); ui->dataBitsBox->addItem(QStringLiteral("5"), QSerialPort::Data5); ui->dataBitsBox->addItem(QStringLiteral("6"), QSerialPort::Data6); @@ -118,27 +131,26 @@ void SettingsDialog::fillPortsParameters() ui->dataBitsBox->addItem(QStringLiteral("8"), QSerialPort::Data8); ui->dataBitsBox->setCurrentIndex(3); - 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); + ui->parityBox->addItem(tr("None"), QSerialPort::NoParity); + ui->parityBox->addItem(tr("Even"), QSerialPort::EvenParity); + ui->parityBox->addItem(tr("Odd"), QSerialPort::OddParity); + ui->parityBox->addItem(tr("Mark"), QSerialPort::MarkParity); + ui->parityBox->addItem(tr("Space"), QSerialPort::SpaceParity); ui->stopBitsBox->addItem(QStringLiteral("1"), QSerialPort::OneStop); #ifdef Q_OS_WIN - ui->stopBitsBox->addItem(QStringLiteral("1.5"), QSerialPort::OneAndHalfStop); + ui->stopBitsBox->addItem(tr("1.5"), QSerialPort::OneAndHalfStop); #endif ui->stopBitsBox->addItem(QStringLiteral("2"), QSerialPort::TwoStop); - ui->flowControlBox->addItem(QStringLiteral("None"), QSerialPort::NoFlowControl); - ui->flowControlBox->addItem(QStringLiteral("RTS/CTS"), QSerialPort::HardwareControl); - ui->flowControlBox->addItem(QStringLiteral("XON/XOFF"), QSerialPort::SoftwareControl); + ui->flowControlBox->addItem(tr("None"), QSerialPort::NoFlowControl); + ui->flowControlBox->addItem(tr("RTS/CTS"), QSerialPort::HardwareControl); + ui->flowControlBox->addItem(tr("XON/XOFF"), QSerialPort::SoftwareControl); } void SettingsDialog::fillPortsInfo() { ui->serialPortInfoListBox->clear(); - static const QString blankString = QObject::tr("N/A"); QString description; QString manufacturer; QString serialNumber; @@ -157,6 +169,8 @@ void SettingsDialog::fillPortsInfo() ui->serialPortInfoListBox->addItem(list.first(), list); } + + ui->serialPortInfoListBox->addItem(tr("Custom")); } void SettingsDialog::updateSettings() diff --git a/examples/serialport/terminal/settingsdialog.h b/examples/serialport/terminal/settingsdialog.h index be7b5c86..5dbe82b1 100644 --- a/examples/serialport/terminal/settingsdialog.h +++ b/examples/serialport/terminal/settingsdialog.h @@ -79,6 +79,7 @@ private slots: void showPortInfo(int idx); void apply(); void checkCustomBaudRatePolicy(int idx); + void checkCustomDevicePathPolicy(int idx); private: void fillPortsParameters(); |