MessageTopicComboBox.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 <QAbstractItemView>
20 #include <QKeyEvent>
21 #include <QLineEdit>
22 
24 
25 namespace rqt_multiplot {
26 
27 /*****************************************************************************/
28 /* Constructors and Destructor */
29 /*****************************************************************************/
30 
32  MatchFilterComboBox(parent),
33  registry_(new MessageTopicRegistry(this)),
34  isUpdating_(false) {
35  connect(registry_, SIGNAL(updateStarted()), this,
36  SLOT(registryUpdateStarted()));
37  connect(registry_, SIGNAL(updateFinished()), this,
38  SLOT(registryUpdateFinished()));
39 
40  connect(this, SIGNAL(currentIndexChanged(const QString&)), this,
41  SLOT(currentIndexChanged(const QString&)));
42 
43  if (registry_->isUpdating())
45  else if (!registry_->isEmpty())
47  else
48  registry_->update();
49 }
50 
52 }
53 
54 /*****************************************************************************/
55 /* Accessors */
56 /*****************************************************************************/
57 
58 void MessageTopicComboBox::setEditable(bool editable) {
59  if (editable != QComboBox::isEditable()) {
61 
62  if (lineEdit()) {
63  blockSignals(true);
64 
65  int index = findText(currentTopic_);
66 
67  if (index < 0)
68  setEditText(currentTopic_);
69  else
70  setCurrentIndex(index);
71 
72  blockSignals(false);
73 
74  connect(lineEdit(), SIGNAL(editingFinished()), this,
75  SLOT(lineEditEditingFinished()));
76  }
77  }
78 }
79 
80 void MessageTopicComboBox::setCurrentTopic(const QString& topic) {
81  if (topic != currentTopic_) {
82  currentTopic_ = topic;
83 
84  int index = findText(topic);
85 
86  if (index < 0)
87  setEditText(topic);
88  else
89  setCurrentIndex(index);
90 
91  emit currentTopicChanged(topic);
92  }
93 }
94 
96  return currentTopic_;
97 }
98 
100  int index = findText(currentTopic_);
101 
102  if (index >= 0)
103  return itemData(index).toString();
104  else
105  return QString();
106 }
107 
109  return isUpdating_;
110 }
111 
113  return (findText(currentTopic_) >= 0);
114 }
115 
116 /*****************************************************************************/
117 /* Methods */
118 /*****************************************************************************/
119 
121  registry_->update();
122 }
123 
124 /*****************************************************************************/
125 /* Slots */
126 /*****************************************************************************/
127 
129  setEnabled(false);
130 
131  isUpdating_ = true;
132  emit updateStarted();
133 
134  clear();
135 }
136 
138  QMap<QString, QString> topics = registry_->getTopics();
139 
140  blockSignals(true);
141 
142  for (QMap<QString, QString>::const_iterator it = topics.begin();
143  it != topics.end(); ++it)
144  addItem(it.key(), it.value());
145 
146  int index = findText(currentTopic_);
147 
148  if (index < 0)
149  setEditText(currentTopic_);
150  else
151  setCurrentIndex(index);
152 
153  blockSignals(false);
154 
155  isUpdating_ = false;
156  emit updateFinished();
157 
158  setEnabled(true);
159 }
160 
161 void MessageTopicComboBox::currentIndexChanged(const QString& text) {
162  if (currentIndex() >= 0)
163  setCurrentTopic(text);
164 }
165 
167  setCurrentTopic(currentText());
168 }
169 
170 }
void currentIndexChanged(const QString &text)
void currentTopicChanged(const QString &topic)
void setCurrentTopic(const QString &topic)
QMap< QString, QString > getTopics() const


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