MCPcopy Create free account
hub / github.com/KDE/labplot / newLiveDataSource

Method newLiveDataSource

src/frontend/MainWin.cpp:2872–2905  ·  view source on GitHub ↗

! adds a new file data source to the current project. */

Source from the content-addressed store, hash-verified

2870 adds a new file data source to the current project.
2871*/
2872void MainWin::newLiveDataSource() {
2873 auto* dlg = new ImportFileDialog(this, true);
2874 if (dlg->exec() == QDialog::Accepted) {
2875 if (dlg->sourceType() == LiveDataSource::SourceType::MQTT) {
2876#ifdef HAVE_MQTT
2877 auto* mqttClient = new MQTTClient(i18n("MQTT Client%1", 1));
2878 dlg->importToMQTT(mqttClient);
2879
2880 // doesn't make sense to have more MQTTClients connected to the same broker
2881 auto clients = m_project->children<const MQTTClient>(AbstractAspect::ChildIndexFlag::Recursive);
2882 bool found = false;
2883 for (const auto* client : clients) {
2884 if (client->clientHostName() == mqttClient->clientHostName() && client->clientPort() == mqttClient->clientPort()) {
2885 found = true;
2886 break;
2887 }
2888 }
2889
2890 if (!found) {
2891 mqttClient->setName(mqttClient->clientHostName());
2892 addAspectToProject(mqttClient);
2893 } else {
2894 delete mqttClient;
2895 QMessageBox::warning(this, i18n("Warning"), i18n("There already is a MQTTClient with this host!"));
2896 }
2897#endif
2898 } else {
2899 auto* dataSource = new LiveDataSource(i18n("Live data source%1", 1), false);
2900 dlg->importToLiveDataSource(dataSource, statusBar());
2901 addAspectToProject(dataSource);
2902 }
2903 }
2904 delete dlg;
2905}
2906
2907void MainWin::addAspectToProject(AbstractAspect* aspect) {
2908 const QModelIndex& index = m_projectExplorer->currentIndex();

Callers

nothing calls this directly

Calls 7

execMethod · 0.80
importToMQTTMethod · 0.80
clientHostNameMethod · 0.80
clientPortMethod · 0.80
sourceTypeMethod · 0.45
setNameMethod · 0.45

Tested by

no test coverage detected