MessageFieldWidget.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
19 #include <ui_MessageFieldWidget.h>
20 
22 
23 namespace rqt_multiplot {
24 
25 /*****************************************************************************/
26 /* Constructors and Destructor */
27 /*****************************************************************************/
28 
30  QWidget(parent),
31  ui_(new Ui::MessageFieldWidget()),
32  loader_(new MessageDefinitionLoader(this)),
33  isLoading_(false),
34  registry_(new MessageSubscriberRegistry(this)),
35  isConnecting_(false),
36  connectionTimer_(new QTimer(this)) {
37  ui_->setupUi(this);
38 
39  connectionTimer_->setSingleShot(true);
40 
41  connect(loader_, SIGNAL(loadingStarted()), this,
42  SLOT(loaderLoadingStarted()));
43  connect(loader_, SIGNAL(loadingFinished()), this,
44  SLOT(loaderLoadingFinished()));
45  connect(loader_, SIGNAL(loadingFailed(const QString&)), this,
46  SLOT(loaderLoadingFailed(const QString&)));
47 
48  connect(connectionTimer_, SIGNAL(timeout()), this,
49  SLOT(connectionTimerTimeout()));
50 
51  connect(ui_->lineEdit, SIGNAL(currentFieldChanged(const QString&)),
52  this, SLOT(lineEditCurrentFieldChanged(const QString&)));
53  connect(ui_->treeWidget, SIGNAL(currentFieldChanged(const QString&)),
54  this, SLOT(treeWidgetCurrentFieldChanged(const QString&)));
55 }
56 
58 }
59 
60 /*****************************************************************************/
61 /* Accessors */
62 /*****************************************************************************/
63 
65  return loader_->getType();
66 }
67 
68 variant_topic_tools::MessageDataType MessageFieldWidget::
70  return loader_->getDefinition().getMessageDataType();
71 }
72 
73 void MessageFieldWidget::setCurrentField(const QString& field) {
74  if (field != currentField_) {
75  currentField_ = field;
76 
77  ui_->lineEdit->setCurrentField(field);
78  ui_->treeWidget->setCurrentField(field);
79 
80  emit currentFieldChanged(field);
81  }
82 }
83 
85  return currentField_;
86 }
87 
88 variant_topic_tools::DataType MessageFieldWidget::
90  return ui_->treeWidget->getCurrentFieldDataType();
91 }
92 
94  return isLoading_;
95 }
96 
98  return isConnecting_;
99 }
100 
102  return getCurrentFieldDataType().isValid();
103 }
104 
105 /*****************************************************************************/
106 /* Methods */
107 /*****************************************************************************/
108 
109 void MessageFieldWidget::loadFields(const QString& type) {
110  if (isConnecting_) {
111  disconnect();
112 
113  ui_->treeWidget->clear();
114  setEnabled(true);
115  }
116 
117  loader_->load(type);
118 }
119 
120 void MessageFieldWidget::connectTopic(const QString& topic, double
121  timeout) {
122  loader_->wait();
123 
124  if (topic != subscribedTopic_) {
125  if (isConnecting_) {
126  disconnect();
127 
128  ui_->treeWidget->clear();
129  setEnabled(true);
130  }
131 
132  if (registry_->subscribe(topic, this, SLOT(subscriberMessageReceived(
133  const QString&, const Message&)))) {
134  setEnabled(false);
135 
136  isConnecting_ = true;
137  subscribedTopic_ = topic;
138  if (timeout > 0.0)
139  connectionTimer_->start(timeout*1e3);
140  emit connecting(topic);
141 
142  ui_->treeWidget->clear();
143  }
144  }
145 }
146 
149 
150  isConnecting_ = false;
151  subscribedTopic_.clear();
152  connectionTimer_->stop();
153 }
154 
155 /*****************************************************************************/
156 /* Slots */
157 /*****************************************************************************/
158 
160  setEnabled(false);
161  ui_->treeWidget->clear();
162 
163  isLoading_ = true;
164 
165  emit loadingStarted();
166 }
167 
169  ui_->lineEdit->setMessageDataType(loader_->getDefinition().
170  getMessageDataType());
171  ui_->treeWidget->setMessageDataType(loader_->getDefinition().
172  getMessageDataType());
173 
174  ui_->lineEdit->setCurrentField(currentField_);
175  ui_->treeWidget->setCurrentField(currentField_);
176 
177  setEnabled(true);
178 
179  isLoading_ = false;
180 
181  emit loadingFinished();
182 }
183 
184 void MessageFieldWidget::loaderLoadingFailed(const QString& error) {
185  ui_->treeWidget->clear();
186 
187  isLoading_ = false;
188  emit loadingFailed(error);
189 }
190 
192  const Message& message) {
193  if (!isConnecting_)
194  return;
195 
196  disconnect();
197 
198  ui_->lineEdit->setMessageDataType(message.getVariant().getType());
199  ui_->treeWidget->setMessageDataType(message.getVariant().getType());
200 
201  ui_->lineEdit->setCurrentField(currentField_);
202  ui_->treeWidget->setCurrentField(currentField_);
203 
204  setEnabled(true);
205 
206  emit connected(topic);
207 }
208 
210  if (!isConnecting_)
211  return;
212 
213  QString topic = subscribedTopic_;
214  double timeout = connectionTimer_->interval()*1e-3;
215 
216  disconnect();
217 
218  ui_->treeWidget->clear();
219 
220  emit connectionTimeout(topic, timeout);
221 }
222 
224  setCurrentField(field);
225 }
226 
228  setCurrentField(field);
229 }
230 
231 }
bool subscribe(const QString &topic, QObject *receiver, const char *method, const PropertyMap &properties=PropertyMap(), Qt::ConnectionType type=Qt::AutoConnection)
const variant_topic_tools::MessageVariant & getVariant() const
Definition: Message.cpp:54
void connectTopic(const QString &topic, double timeout=0.0)
variant_topic_tools::MessageDefinition getDefinition() const
void lineEditCurrentFieldChanged(const QString &field)
void subscriberMessageReceived(const QString &topic, const Message &message)
variant_topic_tools::MessageDataType getCurrentMessageDataType() const
variant_topic_tools::DataType getCurrentFieldDataType() const
void loaderLoadingFailed(const QString &error)
void connected(const QString &topic)
void setCurrentField(const QString &field)
void treeWidgetCurrentFieldChanged(const QString &field)
MessageDefinitionLoader * loader_
void loadFields(const QString &type)
MessageSubscriberRegistry * registry_
void loadingFailed(const QString &error)
void currentFieldChanged(const QString &field)
bool unsubscribe(const QString &topic, QObject *receiver, const char *method=0)
void connecting(const QString &topic)
void connectionTimeout(const QString &topic, double timeout)


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44