MessageTypeComboBox.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include <QLineEdit>
00020 
00021 #include "rqt_multiplot/MessageTypeComboBox.h"
00022 
00023 namespace rqt_multiplot {
00024 
00025 /*****************************************************************************/
00026 /* Constructors and Destructor                                               */
00027 /*****************************************************************************/
00028 
00029 MessageTypeComboBox::MessageTypeComboBox(QWidget* parent) :
00030   MatchFilterComboBox(parent),
00031   registry_(new MessageTypeRegistry(this)),
00032   isUpdating_(false) {    
00033   getMatchFilterCompleter()->setFilterCaseSensitivity(Qt::CaseInsensitive);
00034     
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 MessageTypeComboBox::~MessageTypeComboBox() {
00052 }
00053 
00054 /*****************************************************************************/
00055 /* Accessors                                                                 */
00056 /*****************************************************************************/
00057 
00058 void MessageTypeComboBox::setEditable(bool editable) {
00059   if (editable != QComboBox::isEditable()) {
00060     MatchFilterComboBox::setEditable(editable);
00061     
00062     if (lineEdit()) {
00063       blockSignals(true);
00064   
00065       int index = findText(currentType_);
00066       
00067       if (index < 0)
00068         setEditText(currentType_);
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 MessageTypeComboBox::setCurrentType(const QString& type) {
00081   if (type != currentType_) {
00082     currentType_ = type;
00083     
00084     int index = findText(type);
00085     
00086     if (index < 0)
00087       setEditText(type);
00088     else
00089       setCurrentIndex(index);
00090     
00091     emit currentTypeChanged(type);
00092   }
00093 }
00094 
00095 QString MessageTypeComboBox::getCurrentType() const {
00096   return currentType_;
00097 }
00098 
00099 bool MessageTypeComboBox::isUpdating() const {
00100   return isUpdating_;
00101 }
00102 
00103 bool MessageTypeComboBox::isCurrentTypeRegistered() const {
00104   return (findText(currentType_) >= 0);
00105 }
00106 
00107 /*****************************************************************************/
00108 /* Methods                                                                   */
00109 /*****************************************************************************/
00110 
00111 void MessageTypeComboBox::updateTypes() {
00112   registry_->update();
00113 }
00114 
00115 /*****************************************************************************/
00116 /* Slots                                                                     */
00117 /*****************************************************************************/
00118 
00119 void MessageTypeComboBox::registryUpdateStarted() {
00120   setEnabled(false);
00121   
00122   isUpdating_= true;
00123   emit updateStarted();
00124   
00125   clear();
00126 }
00127 
00128 void MessageTypeComboBox::registryUpdateFinished() {
00129   QList<QString> types = registry_->getTypes();
00130   
00131   blockSignals(true);
00132   
00133   for (QList<QString>::const_iterator it = types.begin();
00134       it != types.end(); ++it)
00135     addItem(*it);
00136   
00137   int index = findText(currentType_);
00138   
00139   if (index < 0)
00140     setEditText(currentType_);
00141   else
00142     setCurrentIndex(index);
00143 
00144   blockSignals(false);
00145   
00146   isUpdating_= false;
00147   emit updateFinished();
00148   
00149   setEnabled(true);
00150 }
00151 
00152 void MessageTypeComboBox::currentIndexChanged(const QString& text) {
00153   if (currentIndex() >= 0)
00154     setCurrentType(text);
00155 }
00156 
00157 void MessageTypeComboBox::lineEditEditingFinished() {
00158   setCurrentType(currentText());
00159 }
00160 
00161 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:11