Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <QAbstractItemView>
00020 #include <QKeyEvent>
00021 #include <QLineEdit>
00022
00023 #include "rqt_multiplot/MessageTopicComboBox.h"
00024
00025 namespace rqt_multiplot {
00026
00027
00028
00029
00030
00031 MessageTopicComboBox::MessageTopicComboBox(QWidget* parent) :
00032 MatchFilterComboBox(parent),
00033 registry_(new MessageTopicRegistry(this)),
00034 isUpdating_(false) {
00035 connect(registry_, SIGNAL(updateStarted()), this,
00036 SLOT(registryUpdateStarted()));
00037 connect(registry_, SIGNAL(updateFinished()), this,
00038 SLOT(registryUpdateFinished()));
00039
00040 connect(this, SIGNAL(currentIndexChanged(const QString&)), this,
00041 SLOT(currentIndexChanged(const QString&)));
00042
00043 if (registry_->isUpdating())
00044 registryUpdateStarted();
00045 else if (!registry_->isEmpty())
00046 registryUpdateFinished();
00047 else
00048 registry_->update();
00049 }
00050
00051 MessageTopicComboBox::~MessageTopicComboBox() {
00052 }
00053
00054
00055
00056
00057
00058 void MessageTopicComboBox::setEditable(bool editable) {
00059 if (editable != QComboBox::isEditable()) {
00060 MatchFilterComboBox::setEditable(editable);
00061
00062 if (lineEdit()) {
00063 blockSignals(true);
00064
00065 int index = findText(currentTopic_);
00066
00067 if (index < 0)
00068 setEditText(currentTopic_);
00069 else
00070 setCurrentIndex(index);
00071
00072 blockSignals(false);
00073
00074 connect(lineEdit(), SIGNAL(editingFinished()), this,
00075 SLOT(lineEditEditingFinished()));
00076 }
00077 }
00078 }
00079
00080 void MessageTopicComboBox::setCurrentTopic(const QString& topic) {
00081 if (topic != currentTopic_) {
00082 currentTopic_ = topic;
00083
00084 int index = findText(topic);
00085
00086 if (index < 0)
00087 setEditText(topic);
00088 else
00089 setCurrentIndex(index);
00090
00091 emit currentTopicChanged(topic);
00092 }
00093 }
00094
00095 QString MessageTopicComboBox::getCurrentTopic() const {
00096 return currentTopic_;
00097 }
00098
00099 QString MessageTopicComboBox::getCurrentTopicType() const {
00100 int index = findText(currentTopic_);
00101
00102 if (index >= 0)
00103 return itemData(index).toString();
00104 else
00105 return QString();
00106 }
00107
00108 bool MessageTopicComboBox::isUpdating() const {
00109 return isUpdating_;
00110 }
00111
00112 bool MessageTopicComboBox::isCurrentTopicRegistered() const {
00113 return (findText(currentTopic_) >= 0);
00114 }
00115
00116
00117
00118
00119
00120 void MessageTopicComboBox::updateTopics() {
00121 registry_->update();
00122 }
00123
00124
00125
00126
00127
00128 void MessageTopicComboBox::registryUpdateStarted() {
00129 setEnabled(false);
00130
00131 isUpdating_ = true;
00132 emit updateStarted();
00133
00134 clear();
00135 }
00136
00137 void MessageTopicComboBox::registryUpdateFinished() {
00138 QMap<QString, QString> topics = registry_->getTopics();
00139
00140 blockSignals(true);
00141
00142 for (QMap<QString, QString>::const_iterator it = topics.begin();
00143 it != topics.end(); ++it)
00144 addItem(it.key(), it.value());
00145
00146 int index = findText(currentTopic_);
00147
00148 if (index < 0)
00149 setEditText(currentTopic_);
00150 else
00151 setCurrentIndex(index);
00152
00153 blockSignals(false);
00154
00155 isUpdating_ = false;
00156 emit updateFinished();
00157
00158 setEnabled(true);
00159 }
00160
00161 void MessageTopicComboBox::currentIndexChanged(const QString& text) {
00162 if (currentIndex() >= 0)
00163 setCurrentTopic(text);
00164 }
00165
00166 void MessageTopicComboBox::lineEditEditingFinished() {
00167 setCurrentTopic(currentText());
00168 }
00169
00170 }