diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-09-05 09:02:02 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-09-05 09:02:03 +0200 |
commit | e4edadd2dcb0a7a20cdcfa7d4b4b2a2415227245 (patch) | |
tree | cd2adefedba016885a44f50ceaac4eeadab7aaef /examples/knx | |
parent | 0e4c4e4ddc707384e44e68c3a77479ba11bf61b1 (diff) | |
parent | df0ba9b97c26901f52769381df3c4cbf1fae9ca6 (diff) |
Merge remote-tracking branch 'origin/5.14' into 5.15
Change-Id: I573251c84151c29558c1edbbb8c394661f577b63
Diffstat (limited to 'examples/knx')
-rw-r--r-- | examples/knx/device/mainwindow.cpp | 12 | ||||
-rw-r--r-- | examples/knx/discoverer/main.cpp | 37 | ||||
-rw-r--r-- | examples/knx/feature/mainwindow.cpp | 12 | ||||
-rw-r--r-- | examples/knx/group/mainwindow.cpp | 12 | ||||
-rw-r--r-- | examples/knx/router/main.cpp | 13 |
5 files changed, 46 insertions, 40 deletions
diff --git a/examples/knx/device/mainwindow.cpp b/examples/knx/device/mainwindow.cpp index 54d3b6a..f1516a2 100644 --- a/examples/knx/device/mainwindow.cpp +++ b/examples/knx/device/mainwindow.cpp @@ -170,13 +170,16 @@ void MainWindow::on_actionImport_triggered() on_devices_currentIndexChanged(ui->devices->currentIndex()); } -void MainWindow::on_devices_currentIndexChanged(int /* index */) +void MainWindow::on_devices_currentIndexChanged(int index) { delete m_device; + m_device = nullptr; ui->secureConfigs->clear(); - const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model()); - m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone(); + if (index >= 0) { + const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model()); + m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone(); + } if (m_device) { const auto deviceInfo = m_device->info(); @@ -190,6 +193,8 @@ void MainWindow::on_devices_currentIndexChanged(int /* index */) .arg(config.userId()) .arg(ia.isValid() ? ia.toString() : tr("No specific address")), i); } + } else { + m_device = new DeviceItem({}); } ui->secureConfigs->setEnabled(bool(ui->secureConfigs->count()) @@ -311,6 +316,7 @@ void MainWindow::setupInterfaces() if (i < 0) return; m_discoveryAgent.stop(); + ui->devices->clear(); m_discoveryAgent.setLocalAddress(QHostAddress(ui->interfaces->currentData() .toStringList().first())); m_discoveryAgent.start(); diff --git a/examples/knx/discoverer/main.cpp b/examples/knx/discoverer/main.cpp index 3cf564b..d9944cb 100644 --- a/examples/knx/discoverer/main.cpp +++ b/examples/knx/discoverer/main.cpp @@ -56,8 +56,6 @@ #include <QtKnx/QKnxNetIpServerDiscoveryAgent> #include <QtKnx/QKnxNetIpSrpBuilder> -#include <QtNetwork/QNetworkInterface> - static QString familyToString(QKnxNetIp::ServiceFamily id) { switch (id) { @@ -83,17 +81,6 @@ static QString familyToString(QKnxNetIp::ServiceFamily id) return "Unknown"; } -QString interfaceFromAddress(const QHostAddress &address) -{ - auto interfaces = QNetworkInterface::allInterfaces(); - for (const auto &interface : qAsConst(interfaces)) { - if (interface.allAddresses().contains(address)) - return interface.humanReadableName(); - } - return QString(address == QHostAddress(QKnxNetIp::Constants::MulticastAddress) - ? "Multicast" : "Unknown"); -} - int main(int argc, char *argv[]) { QCoreApplication discoverer(argc, argv); @@ -130,10 +117,8 @@ int main(int argc, char *argv[]) agent.setLocalPort(parser.value("localPort").toUInt()); agent.setTimeout(parser.value("timeout").toInt() * 1000); - if (parser.isSet("localAddress")) { + if (parser.isSet("localAddress")) agent.setLocalAddress(QHostAddress(parser.value("localAddress"))); - agent.setResponseType(QKnxNetIpServerDiscoveryAgent::ResponseType::Unicast); - } if (parser.isSet("unicast")) agent.setResponseType(QKnxNetIpServerDiscoveryAgent::ResponseType::Unicast); @@ -189,21 +174,25 @@ int main(int argc, char *argv[]) QObject::connect(&agent, &QKnxNetIpServerDiscoveryAgent::finished, &discoverer, &QCoreApplication::quit); - agent.start(); - - if (agent.error() == QKnxNetIpServerDiscoveryAgent::Error::None) - discoverer.exec(); + if (!parser.isSet("localAddress")) { + agent.start(QKnxNetIpServerDiscoveryAgent::InterfaceType::Ethernet + | QKnxNetIpServerDiscoveryAgent::InterfaceType::Wifi); + } else { + agent.start(QVector<QHostAddress> { agent.localAddress() }); + } - qInfo().noquote() << endl << "Device used to send the search request:"; - qInfo().noquote() << QString::fromLatin1(" Network interface: %1, address: %2, port: %3") - .arg(interfaceFromAddress(agent.localAddress()), agent.localAddress().toString()) - .arg(agent.localPort()); + if (agent.error() == QKnxNetIpServerDiscoveryAgent::Error::None + && agent.state() == QKnxNetIpServerDiscoveryAgent::State::Running) { + discoverer.exec(); + } const auto servers = agent.discoveredServers(); if (servers.size() > 0) { qInfo().noquote() << endl << QString::fromLatin1("%1 server(s) found on the network.") .arg(servers.size()); for (auto server : servers) { + qInfo().noquote() << QString::fromLatin1(" Network interface: %1, address: %2") + .arg(server.networkInterface().humanReadableName(), server.hostAddress().toString()); qInfo().noquote() << QString::fromLatin1(" Server: %1").arg(server.deviceName()); qInfo().noquote() << QString::fromLatin1(" Individual address: %1").arg(server .individualAddress().toString()); diff --git a/examples/knx/feature/mainwindow.cpp b/examples/knx/feature/mainwindow.cpp index 7e44327..8f32b06 100644 --- a/examples/knx/feature/mainwindow.cpp +++ b/examples/knx/feature/mainwindow.cpp @@ -170,13 +170,16 @@ void MainWindow::on_actionImport_triggered() on_devices_currentIndexChanged(ui->devices->currentIndex()); } -void MainWindow::on_devices_currentIndexChanged(int /* index */) +void MainWindow::on_devices_currentIndexChanged(int index) { delete m_device; + m_device = nullptr; ui->secureConfigs->clear(); - const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model()); - m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone(); + if (index >= 0) { + const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model()); + m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone(); + } if (m_device) { const auto deviceInfo = m_device->info(); @@ -190,6 +193,8 @@ void MainWindow::on_devices_currentIndexChanged(int /* index */) .arg(config.userId()) .arg(ia.isValid() ? ia.toString() : tr("No specific address")), i); } + } else { + m_device = new DeviceItem({}); } ui->secureConfigs->setEnabled(bool(ui->secureConfigs->count()) @@ -280,6 +285,7 @@ void MainWindow::setupInterfaces() if (i < 0) return; m_discoveryAgent.stop(); + ui->devices->clear(); m_discoveryAgent.setLocalAddress(QHostAddress(ui->interfaces->currentData() .toStringList().first())); m_discoveryAgent.start(); diff --git a/examples/knx/group/mainwindow.cpp b/examples/knx/group/mainwindow.cpp index 4100e03..2e297af 100644 --- a/examples/knx/group/mainwindow.cpp +++ b/examples/knx/group/mainwindow.cpp @@ -169,13 +169,16 @@ void MainWindow::on_actionImport_triggered() on_devices_currentIndexChanged(ui->devices->currentIndex()); } -void MainWindow::on_devices_currentIndexChanged(int /* index */) +void MainWindow::on_devices_currentIndexChanged(int index) { delete m_device; + m_device = nullptr; ui->secureConfigs->clear(); - const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model()); - m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone(); + if (index >= 0) { + const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model()); + m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone(); + } if (m_device) { const auto deviceInfo = m_device->info(); @@ -189,6 +192,8 @@ void MainWindow::on_devices_currentIndexChanged(int /* index */) .arg(config.userId()) .arg(ia.isValid() ? ia.toString() : tr("No specific address")), i); } + } else { + m_device = new DeviceItem({}); } ui->secureConfigs->setEnabled(bool(ui->secureConfigs->count()) @@ -288,6 +293,7 @@ void MainWindow::setupInterfaces() if (i < 0) return; m_discoveryAgent.stop(); + ui->devices->clear(); m_discoveryAgent.setLocalAddress(QHostAddress(ui->interfaces->currentData() .toStringList().first())); m_discoveryAgent.start(); diff --git a/examples/knx/router/main.cpp b/examples/knx/router/main.cpp index f9ccc9a..5218661 100644 --- a/examples/knx/router/main.cpp +++ b/examples/knx/router/main.cpp @@ -238,14 +238,13 @@ int main(int argc, char *argv[]) QNetworkInterface iface { QNetworkInterface::interfaceFromName(cliParser.value("interface")) }; if (!iface.isValid()) { auto interfaces = iface.allInterfaces(); - QList<QNetworkInterface>::iterator found = ( std::find_if(interfaces.begin(), - interfaces.end(), - [](const QNetworkInterface &i){ - return i.type() == QNetworkInterface::Ethernet; - })); + QList<QNetworkInterface>::iterator found = std::find_if( + interfaces.begin(), interfaces.end(), [](const QNetworkInterface &i) { + return i.type() == QNetworkInterface::Ethernet; + } + ); if (found == iface.allInterfaces().end()) { - qInfo().noquote() << "No valid network interface given and no " - "Ethernet adapter found. "; + qInfo().noquote() << "No valid network interface given and no Ethernet adapter found."; cliParser.showHelp(); } iface = static_cast<QNetworkInterface>(*found); |