MessageTypeComboBox.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 <QLineEdit>
20 
22 
23 namespace rqt_multiplot {
24 
25 /*****************************************************************************/
26 /* Constructors and Destructor */
27 /*****************************************************************************/
28 
30  MatchFilterComboBox(parent),
31  registry_(new MessageTypeRegistry(this)),
32  isUpdating_(false) {
33  getMatchFilterCompleter()->setFilterCaseSensitivity(Qt::CaseInsensitive);
34 
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 MessageTypeComboBox::setEditable(bool editable) {
59  if (editable != QComboBox::isEditable()) {
61 
62  if (lineEdit()) {
63  blockSignals(true);
64 
65  int index = findText(currentType_);
66 
67  if (index < 0)
68  setEditText(currentType_);
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 MessageTypeComboBox::setCurrentType(const QString& type) {
81  if (type != currentType_) {
82  currentType_ = type;
83 
84  int index = findText(type);
85 
86  if (index < 0)
87  setEditText(type);
88  else
89  setCurrentIndex(index);
90 
91  emit currentTypeChanged(type);
92  }
93 }
94 
96  return currentType_;
97 }
98 
100  return isUpdating_;
101 }
102 
104  return (findText(currentType_) >= 0);
105 }
106 
107 /*****************************************************************************/
108 /* Methods */
109 /*****************************************************************************/
110 
112  registry_->update();
113 }
114 
115 /*****************************************************************************/
116 /* Slots */
117 /*****************************************************************************/
118 
120  setEnabled(false);
121 
122  isUpdating_= true;
123  emit updateStarted();
124 
125  clear();
126 }
127 
129  QList<QString> types = registry_->getTypes();
130 
131  blockSignals(true);
132 
133  for (QList<QString>::const_iterator it = types.begin();
134  it != types.end(); ++it)
135  addItem(*it);
136 
137  int index = findText(currentType_);
138 
139  if (index < 0)
140  setEditText(currentType_);
141  else
142  setCurrentIndex(index);
143 
144  blockSignals(false);
145 
146  isUpdating_= false;
147  emit updateFinished();
148 
149  setEnabled(true);
150 }
151 
152 void MessageTypeComboBox::currentIndexChanged(const QString& text) {
153  if (currentIndex() >= 0)
154  setCurrentType(text);
155 }
156 
158  setCurrentType(currentText());
159 }
160 
161 }
void setFilterCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
void currentTypeChanged(const QString &type)
MatchFilterCompleter * getMatchFilterCompleter() const
void currentIndexChanged(const QString &text)
void setCurrentType(const QString &type)


rqt_multiplot_plugin
Author(s): Ralf Kaestner
autogenerated on Fri Jan 15 2021 03:47:53