[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [labplot/gsoc2018_mqtt] src/kdefrontend: Cleanup and minor fixes in ImportFileWidget and LiveDataDoc
From: Ferencz Kovacs <null () kde ! org>
Date: 2018-07-31 20:54:15
Message-ID: E1fkbep-0002cp-MR () code ! kde ! org
[Download RAW message or body]
Git commit e6f0301bce30da0e70619f30c6b898412d65a7de by Ferencz Kovacs.
Committed on 31/07/2018 at 20:53.
Pushed by ferenczkovacs into branch 'gsoc2018_mqtt'.
Cleanup and minor fixes in ImportFileWidget and LiveDataDock
M +16 -53 src/kdefrontend/datasources/ImportFileWidget.cpp
M +101 -131 src/kdefrontend/dockwidgets/LiveDataDock.cpp
https://commits.kde.org/labplot/e6f0301bce30da0e70619f30c6b898412d65a7de
diff --git a/src/kdefrontend/datasources/ImportFileWidget.cpp \
b/src/kdefrontend/datasources/ImportFileWidget.cpp index a91a1fff..788c9814 100644
--- a/src/kdefrontend/datasources/ImportFileWidget.cpp
+++ b/src/kdefrontend/datasources/ImportFileWidget.cpp
@@ -864,11 +864,9 @@ bool ImportFileWidget::checkTopicContains(const QString& \
superior, const QString
!(superiorList.at(i) == "#" && i == superiorList.size() - 1)) {
//if the two topics differ, and the superior's current level isn't + or \
#(which can be only in the last position) //then superior can't contain inferior
- qDebug() <<superiorList.at(i)<<" "<<inferiorList.at(i);
ok = false;
break;
} else if(i == superiorList.size() - 1 && (superiorList.at(i) == "+" && \
inferiorList.at(i) == "#") ) {
- qDebug() <<superiorList.at(i)<<" "<<inferiorList.at(i);
//if the two topics differ at the last level
//and the superior's current level is + while the inferior's is #(which can be \
only in the last position) //then superior can't contain inferior
@@ -890,8 +888,7 @@ bool ImportFileWidget::checkTopicContains(const QString& \
superior, const QString
* \param second the name of a topic
* \return The name of the common topic, if it exists, otherwise ""
*/
-QString ImportFileWidget::checkCommonLevel(const QString& first, const QString& \
second) {
- qDebug()<<first<<" "<<second;
+QString ImportFileWidget::checkCommonLevel(const QString& first, const QString& \
second) { QStringList firstList = first.split('/', QString::SkipEmptyParts);
QStringList secondtList = second.split('/', QString::SkipEmptyParts);
QString commonTopic = "";
@@ -937,7 +934,7 @@ QString ImportFileWidget::checkCommonLevel(const QString& first, \
const QString& }
}
- qDebug() << "Common topic: "<<commonTopic;
+ qDebug() << "Common topic for " << first << " and " << second << " is: " << \
commonTopic; return commonTopic;
}
@@ -949,7 +946,6 @@ QString ImportFileWidget::checkCommonLevel(const QString& first, \
const QString&
* \return The index of the unequal level, if there is a common topic, otherwise -1
*/
int ImportFileWidget::commonLevelIndex(const QString& first, const QString& second) \
{
- qDebug()<<first<<" "<<second;
QStringList firstList = first.split('/', QString::SkipEmptyParts);
QStringList secondtList = second.split('/', QString::SkipEmptyParts);
QString commonTopic = "";
@@ -995,8 +991,6 @@ int ImportFileWidget::commonLevelIndex(const QString& first, \
const QString& seco }
}
- qDebug() << "Common topic: "<<commonTopic;
- qDebug() << "differ Index: "<<differIndex;
//if there is a common topic we return the differIndex
if(!commonTopic.isEmpty())
return differIndex;
@@ -1014,8 +1008,6 @@ void ImportFileWidget::unsubscribeFromTopic(const QString& \
topicName) { QMqttTopicFilter filter{topicName};
m_client->unsubscribe(filter);
- qDebug()<<"unsubscribe occured";
-
for(int i = 0; i< m_mqttSubscriptions.count(); ++i)
if(m_mqttSubscriptions[i]->topic().filter() == topicName) {
m_mqttSubscriptions.remove(i);
@@ -1087,8 +1079,8 @@ void ImportFileWidget::addSubscriptionChildren(QTreeWidgetItem \
* topic, QTreeWid temp = temp->parent();
name.prepend(temp->text(0) + "/");
}
-
}
+
//if not then we simply add the topic itself
else {
name.append(temp->text(0));
@@ -1215,7 +1207,6 @@ void ImportFileWidget::manageCommonLevelSubscriptions() {
//compare the subscriptions present in the TreeWidget
for(int i = 0; i < ui.twSubscriptions->topLevelItemCount() - 1; ++i) {
for(int j = i + 1; j < ui.twSubscriptions->topLevelItemCount(); ++j) {
- qDebug()<<ui.twSubscriptions->topLevelItem(i)->text(0)<<" \
"<<ui.twSubscriptions->topLevelItem(j)->text(0);
QString commonTopic = \
checkCommonLevel(ui.twSubscriptions->topLevelItem(i)->text(0), \
ui.twSubscriptions->topLevelItem(j)->text(0));
//if there is a common topic for the 2 compared topics, we add them to the map \
(using the common topic as key) @@ -1225,7 +1216,6 @@ void \
ImportFileWidget::manageCommonLevelSubscriptions() { }
if(!equalTopicsMap[commonTopic].contains(ui.twSubscriptions->topLevelItem(j)->text(0))) \
{
- qDebug()<<commonTopic<<": "<<ui.twSubscriptions->topLevelItem(i)->text(0);
equalTopicsMap[commonTopic].push_back(ui.twSubscriptions->topLevelItem(j)->text(0));
}
}
@@ -1233,7 +1223,7 @@ void ImportFileWidget::manageCommonLevelSubscriptions() {
}
if(!equalTopicsMap.isEmpty()) {
- qDebug()<<"Equal topics not empty";
+ qDebug()<<"Manage common topics";
QVector<QString> commonTopics;
QMapIterator<QString, QVector<QString>> topics(equalTopicsMap);
@@ -1258,6 +1248,7 @@ void ImportFileWidget::manageCommonLevelSubscriptions() {
if(childCount > 0) {
//if the number of topics found and the calculated number of topics is equal, \
the topics can be merged if(topics.value().size() == childCount) {
+ qDebug() << "Found common topic to manage: " << topics.key();
foundEqual = true;
commonTopics.push_back(topics.key());
}
@@ -1275,10 +1266,9 @@ void ImportFileWidget::manageCommonLevelSubscriptions() {
lowestLevel = level;
}
}
-
+ qDebug() << "Manage: " << commonTopics[topicIdx];
equalTopics.append(equalTopicsMap[commonTopics[topicIdx]]);
- qDebug()<<"Adding common topic";
//Add the common topic ("merging")
QString commonTopic;
commonTopic = checkCommonLevel(equalTopics.first(), equalTopics.last());
@@ -1296,7 +1286,6 @@ void ImportFileWidget::manageCommonLevelSubscriptions() {
}
//remove the "merged" topics
- qDebug()<<"unsubscribe from equal topics";
for(int i = 0; i < equalTopics.size(); ++i) {
for(int j = 0; j < ui.twSubscriptions->topLevelItemCount(); ++j){
if(ui.twSubscriptions->topLevelItem(j)->text(0) == equalTopics[i]) {
@@ -1339,7 +1328,6 @@ void ImportFileWidget::updateSubscriptionTree() {
}
if(!found) {
- qDebug()<<"add:" << m_mqttSubscriptions[i]->topic().filter();
//Add the subscription to the tree widget
QTreeWidgetItem* newItem = new QTreeWidgetItem(name);
ui.twSubscriptions->addTopLevelItem(newItem);
@@ -1350,7 +1338,6 @@ void ImportFileWidget::updateSubscriptionTree() {
QTreeWidgetItem* topic = nullptr;
for(int j = 0; j < ui.twTopics->topLevelItemCount(); ++j) {
if(ui.twTopics->topLevelItem(j)->text(0) == name[0]) {
- qDebug()<<"found top level topic: "<<name[0]<<" "<<j;
topic = ui.twTopics->topLevelItem(j);
break;
}
@@ -1358,8 +1345,6 @@ void ImportFileWidget::updateSubscriptionTree() {
//restore the children of the subscription
if(topic != nullptr && topic->childCount() > 0) {
- qDebug()<<"restoring Children";
-
restoreSubscriptionChildren(topic, newItem, name, 1);
}
}
@@ -1801,15 +1786,13 @@ void ImportFileWidget::refreshPreview() {
}
case LiveDataSource::SourceType::MQTT: {
#ifdef HAVE_MQTT
- qDebug()<<"preview mqtt, is it ready:"<<m_mqttReadyForPreview;
+ qDebug()<<"Start MQTT preview, is it ready:"<<m_mqttReadyForPreview;
if(m_mqttReadyForPreview)
{
filter->vectorNames().clear();
QMapIterator<QMqttTopicName, QMqttMessage> i(m_lastMessage);
while(i.hasNext()) {
i.next();
- qDebug()<<"calling ascii mqtt preview"<< importedStrings << " \
"<<QString(i.value().payload().data())
- << " "<< i.key().name();
filter->MQTTPreview(importedStrings, QString(i.value().payload().data()), \
i.key().name() ); if(importedStrings.isEmpty())
break;
@@ -1818,7 +1801,6 @@ void ImportFileWidget::refreshPreview() {
QMapIterator<QMqttTopicName, bool> j(m_messageArrived);
while(j.hasNext()) {
j.next();
- qDebug()<<"Set false after preview: "<<j.key().name();
m_messageArrived[j.key()] = false;
}
m_mqttReadyForPreview = false;
@@ -2132,7 +2114,6 @@ void ImportFileWidget::sourceTypeChanged(int idx) {
case LiveDataSource::SourceType::MQTT:
#ifdef HAVE_MQTT
-
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui.lBaudRate->hide();
@@ -2211,7 +2192,6 @@ void ImportFileWidget::sourceTypeChanged(int idx) {
ui.lWillOwnMessage->show();
}
else if(ui.cbWillMessageType->currentIndex() == \
static_cast<int>(MQTTClient::WillMessageType::Statistics) ){
- qDebug()<<"source type changed show statistics";
ui.lWillStatistics->show();
ui.lwWillStatistics->show();
}
@@ -2329,7 +2309,7 @@ void ImportFileWidget::mqttConnection() {
const bool valid =hostSet && portSet && idValid && authenticationValid;
if (valid) {
m_client->setHostname(ui.leHost->text().simplified());
- m_client->setPort(ui.lePort->text().toUInt());
+ m_client->setPort(ui.lePort->text().simplified().toUInt());
if(ui.chbID->isChecked())
m_client->setClientId(ui.leID->text().simplified());
@@ -2446,35 +2426,29 @@ void ImportFileWidget::mqttSubscribe() {
//check if the subscription already exists
if(topLevelList.isEmpty() || topLevelList.first()->parent() != nullptr) {
- qDebug() << name;
+ qDebug() << "Subscribe to: " << name;
bool foundSuperior = false;
for(int i = 0; i < ui.twSubscriptions->topLevelItemCount(); ++i) {
- qDebug()<<i<<" "<<ui.twSubscriptions->topLevelItemCount();
-
//if the new subscirptions contains an already existing one, we remove the \
inferior one
if(checkTopicContains(name, ui.twSubscriptions->topLevelItem(i)->text(0))
&& name != ui.twSubscriptions->topLevelItem(i)->text(0)) {
- qDebug()<<"1"<<name<<" "<< ui.twSubscriptions->topLevelItem(i)->text(0);
unsubscribeFromTopic(ui.twSubscriptions->topLevelItem(i)->text(0));
i--;
continue;
}
- qDebug()<<"checked inferior";
//if there is a subscription containing the new one we set foundSuperior true
if(checkTopicContains(ui.twSubscriptions->topLevelItem(i)->text(0), name)
&& name != ui.twSubscriptions->topLevelItem(i)->text(0)) {
foundSuperior = true;
- qDebug()<<"2"<<name<<" "<< ui.twSubscriptions->topLevelItem(i)->text(0);
+ qDebug()<<"Can't continue subscribe. Found superior for " << name <<" : "<< \
ui.twSubscriptions->topLevelItem(i)->text(0); break;
}
- qDebug()<<"checked superior";
}
//if there wasn't a superior subscription we can subscribe to the new topic
if(!foundSuperior) {
- qDebug()<<"Adding new topic";
QStringList toplevelName;
toplevelName.push_back(name);
QTreeWidgetItem* newTopLevelItem = new QTreeWidgetItem(toplevelName);
@@ -2519,14 +2493,11 @@ void ImportFileWidget::mqttSubscribe() {
manageCommonLevelSubscriptions();
updateWillTopics();
updateSubscriptionCompleter();
- } else {
+ } else
QMessageBox::warning(this, "Warning", "You already subscribed to a topic \
containing this one");
- }
- }
- else
+ } else
QMessageBox::warning(this, "Warning", "You already subscribed to this topic");
- }
- else
+ } else
QMessageBox::warning(this, "Warning", "You didn't select any item from the Tree \
Widget"); }
@@ -2538,6 +2509,7 @@ void ImportFileWidget::mqttUnsubscribe() {
QTreeWidgetItem* unsubscribeItem = ui.twSubscriptions->currentItem();
if(unsubscribeItem != nullptr) {
+ qDebug() << "Unsubscribe from: " << unsubscribeItem->text(0);
//if it is a top level item, meaning a topic that we really subscribed to(not one \
that belongs to a subscription) //we can simply unsubscribe from it
if(unsubscribeItem->parent() == nullptr)
@@ -2659,7 +2631,6 @@ void ImportFileWidget::mqttMessageReceived(const QByteArray \
&message , const QMq }
//signals that a newTopic was added, in order to fill the completer of leTopics
- qDebug()<<"emit signal";
emit newTopic(rootName);
}
}
@@ -2686,7 +2657,6 @@ void ImportFileWidget::setTopicCompleter(const QString& topic) \
{
* enables updating the completer for le
*/
void ImportFileWidget::topicTimeout() {
- qDebug()<<"lejart ido";
m_searching = false;
m_searchTimer->stop();
}
@@ -2698,12 +2668,10 @@ void ImportFileWidget::mqttSubscriptionMessageReceived(const \
QMqttMessage &msg) qDebug()<<"message received from: "<<msg.topic().name();
if(!m_subscribedTopicNames.contains(msg.topic().name())) {
m_messageArrived[msg.topic()] = true;
- qDebug()<<msg.topic().name()<<"set true";
m_subscribedTopicNames.push_back(msg.topic().name());
}
if(m_messageArrived[msg.topic()] == false) {
- qDebug()<<msg.topic().name()<<"set true";
m_messageArrived[msg.topic()] = true;
}
@@ -2716,7 +2684,6 @@ void ImportFileWidget::mqttSubscriptionMessageReceived(const \
QMqttMessage &msg) while(i.hasNext()) {
i.next();
if(i.value() == false ) {
- qDebug()<<"Found false: "<<i.key().name();
check = false;
break;
}
@@ -2760,7 +2727,6 @@ void ImportFileWidget::useWillMessage(int state) {
ui.lWillUpdateInterval->show();
}
} else if (state == Qt::Unchecked) {
- qDebug()<<"will use unchecked";
ui.chbWillRetain->hide();
ui.cbWillQoS->hide();
ui.cbWillMessageType->hide();
@@ -2798,7 +2764,6 @@ void ImportFileWidget::willMessageTypeChanged(int type) {
ui.lWillStatistics->hide();
ui.lwWillStatistics->hide();
} else if(static_cast<MQTTClient::WillMessageType> (type) == \
MQTTClient::WillMessageType::Statistics) {
- qDebug()<<"will message type changed show statistics";
ui.lWillStatistics->show();
ui.lwWillStatistics->show();
ui.leWillOwnMessage->hide();
@@ -2839,8 +2804,7 @@ void ImportFileWidget::willUpdateTypeChanged(int updateType) {
if(static_cast<MQTTClient::WillUpdateType>(updateType) == \
MQTTClient::WillUpdateType::TimePeriod) { ui.leWillUpdateInterval->show();
ui.lWillUpdateInterval->show();
- }
- else if (static_cast<MQTTClient::WillUpdateType>(updateType) == \
MQTTClient::WillUpdateType::OnClick) { + } else if \
(static_cast<MQTTClient::WillUpdateType>(updateType) == \
MQTTClient::WillUpdateType::OnClick) { ui.leWillUpdateInterval->hide();
ui.lWillUpdateInterval->hide();
}
@@ -2942,7 +2906,6 @@ void ImportFileWidget::checkConnectEnable() {
void ImportFileWidget::mqttConnectTimeout() {
m_client->disconnectFromHost();
m_connectTimeoutTimer->stop();
- QMessageBox::warning(this, "Warning", "Couldn't connect to the given broker");
+ QMessageBox::warning(this, "Warning", "Connecting to the given broker timed out!");
}
#endif
-
diff --git a/src/kdefrontend/dockwidgets/LiveDataDock.cpp \
b/src/kdefrontend/dockwidgets/LiveDataDock.cpp index 7f6a9df4..218d7423 100644
--- a/src/kdefrontend/dockwidgets/LiveDataDock.cpp
+++ b/src/kdefrontend/dockwidgets/LiveDataDock.cpp
@@ -103,18 +103,18 @@ void LiveDataDock::setMQTTClients(const QList<MQTTClient *> \
&clients) { m_liveDataSources.clear();
m_mqttClients.clear();
m_mqttClients = clients;
- const MQTTClient* const fds = clients.at(0);
+ const MQTTClient* const fmc = clients.at(0);
- ui.sbUpdateInterval->setValue(fds->updateInterval());
- ui.cbUpdateType->setCurrentIndex(static_cast<int>(fds->updateType()));
- ui.cbReadingType->setCurrentIndex(static_cast<int>(fds->readingType()));
+ ui.sbUpdateInterval->setValue(fmc->updateInterval());
+ ui.cbUpdateType->setCurrentIndex(static_cast<int>(fmc->updateType()));
+ ui.cbReadingType->setCurrentIndex(static_cast<int>(fmc->readingType()));
- if (fds->updateType() == MQTTClient::UpdateType::NewData) {
+ if (fmc->updateType() == MQTTClient::UpdateType::NewData) {
ui.lUpdateInterval->hide();
ui.sbUpdateInterval->hide();
}
- if (fds->isPaused()) {
+ if (fmc->isPaused()) {
ui.bPausePlayReading->setText(i18n("Continue reading"));
ui.bPausePlayReading->setIcon(QIcon::fromTheme(QLatin1String("media-record")));
} else {
@@ -122,16 +122,16 @@ void LiveDataDock::setMQTTClients(const QList<MQTTClient *> \
&clients) { ui.bPausePlayReading->setIcon(QIcon::fromTheme(QLatin1String("media-playback-pause")));
}
- ui.sbKeepNValues->setValue(fds->keepNValues());
+ ui.sbKeepNValues->setValue(fmc->keepNValues());
ui.sbKeepNValues->setEnabled(true);
- if (fds->readingType() == MQTTClient::ReadingType::TillEnd) {
+ if (fmc->readingType() == MQTTClient::ReadingType::TillEnd) {
ui.lSampleSize->hide();
ui.sbSampleSize->hide();
} else
- ui.sbSampleSize->setValue(fds->sampleSize());
+ ui.sbSampleSize->setValue(fmc->sampleSize());
- // disable "whole file" when having no file (i.e. socket or port)
+ // disable "whole file" option
const QStandardItemModel* model = qobject_cast<const \
QStandardItemModel*>(ui.cbReadingType->model()); QStandardItem* item = \
model->item(LiveDataSource::ReadingType::WholeFile); item->setFlags(item->flags() & \
~(Qt::ItemIsSelectable | Qt::ItemIsEnabled)); @@ -168,71 +168,71 @@ void \
LiveDataDock::setMQTTClients(const QList<MQTTClient *> &clients) { \
ui.chbWill->show();
//if there isn't a client with this hostname we instantiate a new one
- if(m_clients[fds->clientHostName()] == nullptr) {
- m_clients[fds->clientHostName()] = new QMqttClient();
+ if(m_clients[fmc->clientHostName()] == nullptr) {
+ m_clients[fmc->clientHostName()] = new QMqttClient();
- connect(fds, &MQTTClient::clientAboutToBeDeleted, this, \
&LiveDataDock::removeClient); + connect(fmc, &MQTTClient::clientAboutToBeDeleted, \
this, &LiveDataDock::removeClient);
- connect(m_clients[fds->clientHostName()], &QMqttClient::connected, this, \
&LiveDataDock::onMQTTConnect);
- connect(m_clients[fds->clientHostName()], &QMqttClient::messageReceived, this, \
&LiveDataDock::mqttMessageReceived); + connect(m_clients[fmc->clientHostName()], \
&QMqttClient::connected, this, &LiveDataDock::onMQTTConnect); \
+ connect(m_clients[fmc->clientHostName()], &QMqttClient::messageReceived, this, \
&LiveDataDock::mqttMessageReceived);
- m_clients[fds->clientHostName()]->setHostname(fds->clientHostName());
- m_clients[fds->clientHostName()]->setPort(fds->clientPort());
+ m_clients[fmc->clientHostName()]->setHostname(fmc->clientHostName());
+ m_clients[fmc->clientHostName()]->setPort(fmc->clientPort());
- if(fds->MQTTUseAuthentication()) {
- m_clients[fds->clientHostName()]->setUsername(fds->clientUserName());
- m_clients[fds->clientHostName()]->setPassword(fds->clientPassword());
+ if(fmc->MQTTUseAuthentication()) {
+ m_clients[fmc->clientHostName()]->setUsername(fmc->clientUserName());
+ m_clients[fmc->clientHostName()]->setPassword(fmc->clientPassword());
}
- if(fds->MQTTUseID()) {
- m_clients[fds->clientHostName()]->setClientId(fds->clientID());
+ if(fmc->MQTTUseID()) {
+ m_clients[fmc->clientHostName()]->setClientId(fmc->clientID());
}
- m_clients[fds->clientHostName()]->connectToHost();
+ m_clients[fmc->clientHostName()]->connectToHost();
}
if(m_previousMQTTClient == nullptr) {
- connect(fds, &MQTTClient::MQTTSubscribed, this, &LiveDataDock::fillSubscriptions);
- connect(fds, &MQTTClient::MQTTTopicsChanged, this, \
&LiveDataDock::updateWillTopics); + connect(fmc, &MQTTClient::MQTTSubscribed, this, \
&LiveDataDock::fillSubscriptions); + connect(fmc, &MQTTClient::MQTTTopicsChanged, \
this, &LiveDataDock::updateWillTopics); }
+
//if the previous MQTTClient's host name was different from the current one we have \
to disconnect some slots //and clear the tree widgets
- else if(m_previousMQTTClient->clientHostName() != fds->clientHostName()) {
- qDebug()<<"At load host name not equal: \
"<<m_previousMQTTClient->clientHostName()<<" "<<fds->clientHostName(); + else \
if(m_previousMQTTClient->clientHostName() != fmc->clientHostName()) { \
disconnect(m_previousMQTTClient, &MQTTClient::MQTTSubscribed, this, \
&LiveDataDock::fillSubscriptions); disconnect(m_previousMQTTClient, \
&MQTTClient::MQTTTopicsChanged, this, &LiveDataDock::updateWillTopics); \
disconnect(m_clients[m_previousMQTTClient->clientHostName()], \
&QMqttClient::messageReceived, this, &LiveDataDock::mqttMessageReceived); \
connect(m_clients[m_previousMQTTClient->clientHostName()], \
&QMqttClient::messageReceived, this, &LiveDataDock::mqttMessageReceivedInBackground); \
- disconnect(m_clients[fds->clientHostName()], &QMqttClient::messageReceived, this, \
&LiveDataDock::mqttMessageReceivedInBackground); \
+ disconnect(m_clients[fmc->clientHostName()], &QMqttClient::messageReceived, this, \
&LiveDataDock::mqttMessageReceivedInBackground);
ui.twTopics->clear();
//repopulating the tree widget with the already known topics of the client
- for(int i = 0; i < m_addedTopics[fds->clientHostName()].size(); ++i) {
- addTopicToTree(m_addedTopics[fds->clientHostName()].at(i));
+ for(int i = 0; i < m_addedTopics[fmc->clientHostName()].size(); ++i) {
+ addTopicToTree(m_addedTopics[fmc->clientHostName()].at(i));
}
//fill subscriptions tree widget
ui.twSubscriptions->clear();
fillSubscriptions();
- connect(fds, &MQTTClient::MQTTSubscribed, this, &LiveDataDock::fillSubscriptions);
- connect(fds, &MQTTClient::MQTTTopicsChanged, this, \
&LiveDataDock::updateWillTopics);
- connect(m_clients[fds->clientHostName()], &QMqttClient::messageReceived, this, \
&LiveDataDock::mqttMessageReceived); + connect(fmc, &MQTTClient::MQTTSubscribed, \
this, &LiveDataDock::fillSubscriptions); + connect(fmc, \
&MQTTClient::MQTTTopicsChanged, this, &LiveDataDock::updateWillTopics); \
+ connect(m_clients[fmc->clientHostName()], &QMqttClient::messageReceived, this, \
&LiveDataDock::mqttMessageReceived); }
//set will message connected options
updateWillTopics();
- ui.leWillOwnMessage->setText(fds->willOwnMessage());
- ui.leWillUpdateInterval->setText(QString::number(fds->willTimeInterval()));
- ui.cbWillUpdate->setCurrentIndex(static_cast<int>(fds->willUpdateType()) );
- fds->startWillTimer();
- ui.cbWillMessageType->setCurrentIndex(static_cast<int>(fds->willMessageType()) );
- ui.cbWillQoS->setCurrentIndex(fds->willQoS());
- ui.cbWillTopic->setCurrentText(fds->willTopic());
- ui.chbWillRetain->setChecked(fds->willRetain());
-
- QVector<bool> statitics = fds->willStatistics();
+ ui.leWillOwnMessage->setText(fmc->willOwnMessage());
+ ui.leWillUpdateInterval->setText(QString::number(fmc->willTimeInterval()));
+ ui.cbWillUpdate->setCurrentIndex(static_cast<int>(fmc->willUpdateType()) );
+ fmc->startWillTimer();
+ ui.cbWillMessageType->setCurrentIndex(static_cast<int>(fmc->willMessageType()) );
+ ui.cbWillQoS->setCurrentIndex(fmc->willQoS());
+ ui.cbWillTopic->setCurrentText(fmc->willTopic());
+ ui.chbWillRetain->setChecked(fmc->willRetain());
+
+ QVector<bool> statitics = fmc->willStatistics();
for(int i = 0; i < statitics.count(); ++i) {
QListWidgetItem* item = ui.lwWillStatistics->item(static_cast<int>(i));
if(statitics[i]) {
@@ -244,10 +244,10 @@ void LiveDataDock::setMQTTClients(const QList<MQTTClient *> \
&clients) { }
//when chbWill's isChecked corresponds with source's m_mqttWillUse it doesn't emit \
state changed signal, we have to force it
- bool checked = fds->MQTTWillUse();
+ bool checked = fmc->MQTTWillUse();
ui.chbWill->setChecked(!checked);
ui.chbWill->setChecked(checked);
- m_previousMQTTClient = fds;
+ m_previousMQTTClient = fmc;
}
#endif
@@ -408,7 +408,8 @@ void LiveDataDock::updateTypeChanged(int idx) {
}
#ifdef HAVE_MQTT
else if (!m_mqttClients.isEmpty()) {
- MQTTClient::UpdateType type = static_cast<MQTTClient::UpdateType>(idx);
+ DEBUG("LiveDataDock::updateTypeChanged()");
+ const MQTTClient::UpdateType type = static_cast<MQTTClient::UpdateType>(idx);
if (type == MQTTClient::UpdateType::TimeInterval) {
ui.lUpdateInterval->show();
@@ -565,7 +566,8 @@ void LiveDataDock::pauseContinueReading() {
* \param state the state of the checbox
*/
void LiveDataDock::useWillMessage(int state) {
- qDebug()<<"will checkstate changed" <<state;
+ qDebug()<<"Use will message: " <<state;
+
if(state == Qt::Checked) {
for (auto* source: m_mqttClients)
source->setMQTTWillUse(true);
@@ -589,15 +591,13 @@ void LiveDataDock::useWillMessage(int state) {
ui.lwWillStatistics->show();
}
-
if(ui.cbWillUpdate->currentIndex() == \
static_cast<int>(MQTTClient::WillUpdateType::TimePeriod)) { \
ui.leWillUpdateInterval->show(); ui.lWillUpdateInterval->show();
}
else if (ui.cbWillUpdate->currentIndex() == \
static_cast<int>(MQTTClient::WillUpdateType::OnClick)) ui.bWillUpdateNow->show();
- }
- else if (state == Qt::Unchecked) {
+ } else if (state == Qt::Unchecked) {
for (auto* source: m_mqttClients)
source->setMQTTWillUse(false);
@@ -654,10 +654,10 @@ void LiveDataDock::willRetainChanged(int state) {
* \param topic the current text of cbWillTopic
*/
void LiveDataDock::willTopicChanged(const QString& topic) {
- qDebug()<<"topic changed" << topic;
for (auto* source: m_mqttClients) {
if(source->willTopic() != topic)
source->clearLastMessage();
+
source->setWillTopic(topic);
}
}
@@ -710,19 +710,16 @@ void LiveDataDock::willOwnMessageChanged(const QString& \
message) {
*/
void LiveDataDock::updateWillTopics() {
ui.cbWillTopic->clear();
- const MQTTClient* const fds = m_mqttClients.at(0);
- QVector<QString> topics = fds->topicNames();
+ const MQTTClient* const fmc = m_mqttClients.at(0);
+ QVector<QString> topics = fmc->topicNames();
if(!topics.isEmpty()) {
for(int i = 0; i < topics.count(); i++) {
- qDebug()<<"Live Data Dock: updating will topics: "<<topics[i];
ui.cbWillTopic->addItem(topics[i]);
}
- if(!fds->willTopic().isEmpty())
- ui.cbWillTopic->setCurrentText(fds->willTopic());
+ if(!fmc->willTopic().isEmpty())
+ ui.cbWillTopic->setCurrentText(fmc->willTopic());
}
- else
- qDebug()<<"Topic Vector Empty";
}
/*!
@@ -733,8 +730,6 @@ void LiveDataDock::updateWillTopics() {
* \param type the selected will update type
*/
void LiveDataDock::willUpdateTypeChanged(int updateType) {
- qDebug()<<"Update type changed" << updateType;
-
for (auto* source: m_mqttClients)
source->setWillUpdateType(static_cast<MQTTClient::WillUpdateType>(updateType));
@@ -747,8 +742,7 @@ void LiveDataDock::willUpdateTypeChanged(int updateType) {
source->setWillTimeInterval(ui.leWillUpdateInterval->text().toInt());
source->startWillTimer();
}
- }
- else if (static_cast<MQTTClient::WillUpdateType>(updateType) == \
MQTTClient::WillUpdateType::OnClick) { + } else if \
(static_cast<MQTTClient::WillUpdateType>(updateType) == \
MQTTClient::WillUpdateType::OnClick) { ui.bWillUpdateNow->show();
ui.leWillUpdateInterval->hide();
ui.lWillUpdateInterval->hide();
@@ -757,7 +751,6 @@ void LiveDataDock::willUpdateTypeChanged(int updateType) {
for (auto* source: m_mqttClients)
source->stopWillTimer();
}
-
}
/*!
@@ -776,7 +769,6 @@ void LiveDataDock::willUpdateNow() {
* \param interval the new will update interval
*/
void LiveDataDock::willUpdateIntervalChanged(const QString& interval) {
- qDebug()<<"Update interval changed " <<interval;
for (auto* source: m_mqttClients) {
source->setWillTimeInterval(interval.toInt());
source->startWillTimer();
@@ -858,37 +850,30 @@ void LiveDataDock::addSubscription() {
//check if the subscription already exists
QList<QTreeWidgetItem *> topLevelList = ui.twSubscriptions->findItems(name, \
Qt::MatchExactly); if(topLevelList.isEmpty() || topLevelList.first()->parent() != \
nullptr) {
-
- qDebug() << name;
+ qDebug() << "LiveDataDock: start to add new subscription: " << name;
bool foundSuperior = false;
for(int i = 0; i < ui.twSubscriptions->topLevelItemCount(); ++i) {
- qDebug()<<i<<" "<<ui.twSubscriptions->topLevelItemCount();
-
//if the new subscriptions contains an already existing one, we remove the \
inferior one
if(checkTopicContains(name, ui.twSubscriptions->topLevelItem(i)->text(0))
&& name != ui.twSubscriptions->topLevelItem(i)->text(0)) {
- qDebug()<<"1"<<name<<" "<< ui.twSubscriptions->topLevelItem(i)->text(0);
ui.twSubscriptions->topLevelItem(i)->takeChildren();
ui.twSubscriptions->takeTopLevelItem(i);
i--;
continue;
}
- qDebug()<<"checked inferior";
//if there is a subscription containing the new one we set foundSuperior true
if(checkTopicContains(ui.twSubscriptions->topLevelItem(i)->text(0), name)
&& name != ui.twSubscriptions->topLevelItem(i)->text(0)) {
foundSuperior = true;
- qDebug()<<"2"<<name<<" "<< ui.twSubscriptions->topLevelItem(i)->text(0);
+ qDebug()<<"Can't add "<<name<<" because found usperior: "<< \
ui.twSubscriptions->topLevelItem(i)->text(0); break;
}
- qDebug()<<"checked superior";
}
//if there wasn't a superior subscription we can subscribe to the new topic
if(!foundSuperior) {
- qDebug()<<"Adding new topic";
QStringList toplevelName;
toplevelName.push_back(name);
QTreeWidgetItem* newTopLevelItem = new QTreeWidgetItem(toplevelName);
@@ -949,6 +934,7 @@ void LiveDataDock::addSubscription() {
for (auto* source: m_mqttClients) {
source->removeMQTTSubscription(unsubscribeItem->text(0));
}
+
ui.twSubscriptions->takeTopLevelItem(ui.twSubscriptions->indexOfTopLevelItem(unsubscribeItem));
}
}
@@ -977,6 +963,8 @@ void LiveDataDock::removeSubscription() {
QTreeWidgetItem* unsubscribeItem = ui.twSubscriptions->currentItem();
if(unsubscribeItem != nullptr) {
+ qDebug() << "LiveDataDock: unsubscribe from " << unsubscribeItem->text(0);
+
//if it is a top level item, meaning a topic that we really subscribed to(not one \
that belongs to a subscription) //we can simply unsubscribe from it
if(unsubscribeItem->parent() == nullptr) {
@@ -1067,7 +1055,6 @@ void LiveDataDock::updateSubscriptionCompleter() {
* enables updating the completer for le
*/
void LiveDataDock::topicTimeout() {
- qDebug()<<"lejart ido";
m_searching = false;
m_searchTimer->stop();
}
@@ -1078,11 +1065,11 @@ void LiveDataDock::topicTimeout() {
* Fills twSubscriptions with the subscriptions of the MQTTClient
*/
void LiveDataDock::fillSubscriptions() {
- const MQTTClient* const fds = m_mqttClients.at(0);
+ const MQTTClient* const fmc = m_mqttClients.at(0);
ui.twSubscriptions->clear();
- QVector<QString> subscriptions = fds->MQTTSubscriptions();
+ QVector<QString> subscriptions = fmc->MQTTSubscriptions();
for (int i = 0; i < subscriptions.count(); ++i) {
QStringList name;
name.append(subscriptions[i]);
@@ -1096,7 +1083,6 @@ void LiveDataDock::fillSubscriptions() {
}
if(!found) {
- qDebug()<<"add:" << subscriptions[i];
//Add the subscription to the tree widget
QTreeWidgetItem* newItem = new QTreeWidgetItem(name);
ui.twSubscriptions->addTopLevelItem(newItem);
@@ -1107,7 +1093,6 @@ void LiveDataDock::fillSubscriptions() {
QTreeWidgetItem* topic = nullptr;
for(int j = 0; j < ui.twTopics->topLevelItemCount(); ++j) {
if(ui.twTopics->topLevelItem(j)->text(0) == name[0]) {
- qDebug()<<"found top level topic: "<<name[0]<<" "<<j;
topic = ui.twTopics->topLevelItem(j);
break;
}
@@ -1115,12 +1100,9 @@ void LiveDataDock::fillSubscriptions() {
//restore the children of the subscription
if(topic != nullptr && topic->childCount() > 0) {
- qDebug()<<"restoring Children";
-
restoreSubscriptionChildren(topic, newItem, name, 1);
}
}
-
}
m_searching = false;
}
@@ -1150,13 +1132,11 @@ bool LiveDataDock::checkTopicContains(const QString \
&superior, const QString &in if(superiorList.at(i) != inferiorList.at(i)) {
if((superiorList.at(i) != "+") &&
!(superiorList.at(i) == "#" && i == superiorList.size() - 1)) {
- qDebug() <<superiorList.at(i)<<" "<<inferiorList.at(i);
//if the two topics differ, and the superior's current level isn't + or \
#(which can be only in the last position) //then superior can't contain inferior
ok = false;
break;
} else if(i == superiorList.size() - 1 && (superiorList.at(i) == "+" && \
inferiorList.at(i) == "#") ) {
- qDebug() <<superiorList.at(i)<<" "<<inferiorList.at(i);
//if the two topics differ at the last level
//and the superior's current level is + while the inferior's is #(which can be \
only in the last position) //then superior can't contain inferior
@@ -1181,7 +1161,6 @@ void LiveDataDock::scrollToTopicTreeItem(const QString& \
rootName) { m_searching = true;
m_searchTimer->start();
- qDebug()<<rootName;
int topItemIdx = -1;
for(int i = 0; i< ui.twTopics->topLevelItemCount(); ++i)
if(ui.twTopics->topLevelItem(i)->text(0) == rootName) {
@@ -1201,9 +1180,6 @@ void LiveDataDock::scrollToTopicTreeItem(const QString& \
rootName) {
* \param rootName the current text of leSubscriptions
*/
void LiveDataDock::scrollToSubsriptionTreeItem(const QString& rootName) {
- m_searching = true;
- m_searchTimer->start();
-
int topItemIdx = -1;
for(int i = 0; i < ui.twSubscriptions->topLevelItemCount(); ++i)
if(ui.twSubscriptions->topLevelItem(i)->text(0) == rootName) {
@@ -1223,8 +1199,7 @@ void LiveDataDock::scrollToSubsriptionTreeItem(const QString& \
rootName) {
* \param second the name of a topic
* \return The name of the common topic, if it exists, otherwise ""
*/
-QString LiveDataDock::checkCommonLevel(const QString& first, const QString& second) \
{
- qDebug()<<first<<" "<<second;
+QString LiveDataDock::checkCommonLevel(const QString& first, const QString& second) \
{ QStringList firstList = first.split('/', QString::SkipEmptyParts);
QStringList secondtList = second.split('/', QString::SkipEmptyParts);
QString commonTopic = "";
@@ -1271,7 +1246,7 @@ QString LiveDataDock::checkCommonLevel(const QString& first, \
const QString& seco }
}
}
- qDebug() << "Common topic: "<<commonTopic;
+ qDebug() << "Common topic for " << first << " and "<<second << " is: " << \
commonTopic; return commonTopic;
}
@@ -1325,39 +1300,41 @@ void LiveDataDock::addSubscriptionChildren(QTreeWidgetItem * \
topic, QTreeWidgetI
* \param level the level's number which is being investigated
*/
void LiveDataDock::restoreSubscriptionChildren(QTreeWidgetItem * topic, \
QTreeWidgetItem * subscription, const QStringList& list, int level) {
- if(list[level] != "+" && list[level] != "#" && level < list.size() - 1) {
- for(int i = 0; i < topic->childCount(); ++i) {
- //if the current level isn't + or # wildcard we recursively continue with the \
next level
- if(topic->child(i)->text(0) == list[level]) {
- restoreSubscriptionChildren(topic->child(i), subscription, list, level + 1);
- break;
- }
- }
- } else if (list[level] == "+") {
- for(int i = 0; i < topic->childCount(); ++i) {
- //determine the name of the topic, contained by the subscription
- QString name;
- name.append(topic->child(i)->text(0));
- for(int j = level + 1; j < list.size(); ++j) {
- name.append("/" + list[j]);
- }
- QTreeWidgetItem* temp = topic->child(i);
- while(temp->parent() != nullptr) {
- temp = temp->parent();
- name.prepend(temp->text(0) + "/");
+ if(level < list.size()) {
+ if((level < list.size() - 1) && (list[level] != "+") && (list[level] != "#")) {
+ for(int i = 0; i < topic->childCount(); ++i) {
+ //if the current level isn't + or # wildcard we recursively continue with the \
next level + if(topic->child(i)->text(0) == list[level]) {
+ restoreSubscriptionChildren(topic->child(i), subscription, list, level + 1);
+ break;
+ }
}
+ } else if (list[level] == "+") {
+ for(int i = 0; i < topic->childCount(); ++i) {
+ //determine the name of the topic, contained by the subscription
+ QString name;
+ name.append(topic->child(i)->text(0));
+ for(int j = level + 1; j < list.size(); ++j) {
+ name.append("/" + list[j]);
+ }
+ QTreeWidgetItem* temp = topic->child(i);
+ while(temp->parent() != nullptr) {
+ temp = temp->parent();
+ name.prepend(temp->text(0) + "/");
+ }
- //Add the topic as child of the subscription
- QStringList nameList;
- nameList.append(name);
- QTreeWidgetItem* newItem = new QTreeWidgetItem(nameList);
- subscription->addChild(newItem);
- //Continue adding children recursively to the new item
- restoreSubscriptionChildren(topic->child(i), newItem, list, level + 1);
+ //Add the topic as child of the subscription
+ QStringList nameList;
+ nameList.append(name);
+ QTreeWidgetItem* newItem = new QTreeWidgetItem(nameList);
+ subscription->addChild(newItem);
+ //Continue adding children recursively to the new item
+ restoreSubscriptionChildren(topic->child(i), newItem, list, level + 1);
+ }
+ } else if (list[level] == "#") {
+ //add the children of the # wildcard containing subscription
+ addSubscriptionChildren(topic, subscription);
}
- } else if (list[level] == "#") {
- //add the children of the # wildcard containing subscription
- addSubscriptionChildren(topic, subscription);
}
}
@@ -1369,7 +1346,6 @@ void LiveDataDock::restoreSubscriptionChildren(QTreeWidgetItem \
* topic, QTreeWid
* \return The index of the unequal level, if there is a common topic, otherwise -1
*/
int LiveDataDock::commonLevelIndex(const QString& first, const QString& second) {
- qDebug()<<first<<" "<<second;
QStringList firstList = first.split('/', QString::SkipEmptyParts);
QStringList secondtList = second.split('/', QString::SkipEmptyParts);
QString commonTopic = "";
@@ -1527,18 +1503,15 @@ void LiveDataDock::manageCommonLevelSubscriptions() {
//compare the subscriptions present in the TreeWidget
for(int i = 0; i < ui.twSubscriptions->topLevelItemCount() - 1; ++i) {
for(int j = i + 1; j < ui.twSubscriptions->topLevelItemCount(); ++j) {
- qDebug()<<ui.twSubscriptions->topLevelItem(i)->text(0)<<" \
"<<ui.twSubscriptions->topLevelItem(j)->text(0);
QString commonTopic = \
checkCommonLevel(ui.twSubscriptions->topLevelItem(i)->text(0), \
ui.twSubscriptions->topLevelItem(j)->text(0));
//if there is a common topic for the 2 compared topics, we add them to the map \
(using the common topic as key) if(!commonTopic.isEmpty()) {
if(!equalTopicsMap[commonTopic].contains(ui.twSubscriptions->topLevelItem(i)->text(0))) \
{
- qDebug()<<commonTopic<<": "<<ui.twSubscriptions->topLevelItem(i)->text(0);
equalTopicsMap[commonTopic].push_back(ui.twSubscriptions->topLevelItem(i)->text(0));
}
if(!equalTopicsMap[commonTopic].contains(ui.twSubscriptions->topLevelItem(j)->text(0))) \
{
- qDebug()<<commonTopic<<": "<<ui.twSubscriptions->topLevelItem(i)->text(0);
equalTopicsMap[commonTopic].push_back(ui.twSubscriptions->topLevelItem(j)->text(0));
}
}
@@ -1546,7 +1519,7 @@ void LiveDataDock::manageCommonLevelSubscriptions() {
}
if(!equalTopicsMap.isEmpty()) {
- qDebug()<<"Equal topics not empty";
+ qDebug()<<"Manage equal topics";
QVector<QString> commonTopics;
QMapIterator<QString, QVector<QString>> topics(equalTopicsMap);
@@ -1554,7 +1527,6 @@ void LiveDataDock::manageCommonLevelSubscriptions() {
//check for every map entry, if the found topics can be merged or not
while(topics.hasNext()) {
topics.next();
- qDebug()<<"Checking: " << topics.key();
int level = commonLevelIndex(topics.value().last(), topics.value().first());
QStringList commonList = topics.value().first().split('/', \
QString::SkipEmptyParts); @@ -1573,9 +1545,7 @@ void \
LiveDataDock::manageCommonLevelSubscriptions() { if(childCount > 0) {
//if the number of topics found and the calculated number of topics is equal, \
the topics can be merged if(topics.value().size() == childCount) {
- for(int k = 0; k < topics.value().size(); ++k)
- qDebug()<<topics.value().at(k);
-
+ qDebug() << "Found common topic to manage: " << topics.key();
foundEqual = true;
commonTopics.push_back(topics.key());
}
@@ -1593,9 +1563,9 @@ void LiveDataDock::manageCommonLevelSubscriptions() {
highestLevel = level;
}
}
+ qDebug() << "Start to manage: " << commonTopics[topicIdx];
equalTopics.append(equalTopicsMap[commonTopics[topicIdx]]);
- qDebug()<<"Adding common topic";
//Add the common topic ("merging")
QString commonTopic;
commonTopic = checkCommonLevel(equalTopics.first(), equalTopics.last());
@@ -1710,13 +1680,13 @@ void LiveDataDock::addTopicToTree(const QString &topicName) {
for(int i = 0; i < ui.twSubscriptions->topLevelItemCount(); ++i) {
QStringList subscriptionName = \
ui.twSubscriptions->topLevelItem(i)->text(0).split('/', QString::SkipEmptyParts); if \
(rootName == subscriptionName[0]) {
- qDebug()<<topicName;
fillSubscriptions();
break;
}
}
//signals that a newTopic was added, in order to fill the completer of leTopics
+ //we have to pass the whole topic name, not just the root name, for testing \
purposes emit newTopic(topicName);
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic