UrlComboBox.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/UrlComboBox.h"
00022 
00023 namespace rqt_multiplot {
00024 
00025 /*****************************************************************************/
00026 /* Constructors and Destructor                                               */
00027 /*****************************************************************************/
00028 
00029 UrlComboBox::UrlComboBox(QWidget* parent) :
00030   QComboBox(parent),
00031   completer_(new UrlCompleter(this)) {
00032   connect(this, SIGNAL(activated(int)), this, SLOT(activated(int)));
00033   connect(this, SIGNAL(currentIndexChanged(const QString&)), this,
00034     SLOT(currentIndexChanged(const QString&)));
00035 }
00036 
00037 UrlComboBox::~UrlComboBox() {
00038 }
00039 
00040 /*****************************************************************************/
00041 /* Accessors                                                                 */
00042 /*****************************************************************************/
00043 
00044 void UrlComboBox::setEditable(bool editable) {
00045   if (editable != QComboBox::isEditable()) {
00046     QComboBox::setEditable(editable);
00047     
00048     if (lineEdit()) {
00049       lineEdit()->setCompleter(completer_);
00050 
00051       connect(lineEdit(), SIGNAL(editingFinished()), this,
00052         SLOT(lineEditEditingFinished()));
00053     }
00054   }
00055 }
00056 
00057 UrlCompleter* UrlComboBox::getCompleter() const {
00058   return completer_;
00059 }
00060 
00061 void UrlComboBox::setCurrentUrl(const QString& url) {
00062   int index = findText(url);
00063   
00064   if (index < 0) {
00065     setEditText(url);
00066     lineEditEditingFinished();
00067   }
00068   else
00069     setCurrentIndex(index);
00070 }
00071 
00072 QString UrlComboBox::getCurrentUrl() const {
00073   return currentUrl_;
00074 }
00075 
00076 bool UrlComboBox::isCurrentUrlSelectable() const {
00077   return (findText(currentUrl_) >= 0);
00078 }
00079 
00080 /*****************************************************************************/
00081 /* Slots                                                                     */
00082 /*****************************************************************************/
00083 
00084 void UrlComboBox::activated(int index) {
00085   if (currentUrl_ != itemText(index)) {
00086     currentUrl_ = itemText(index);
00087     
00088     emit currentUrlChanged(currentUrl_);
00089   }
00090 }
00091 
00092 void UrlComboBox::currentIndexChanged(const QString& text) {
00093   if (currentUrl_ != text) {
00094     currentUrl_ = text;
00095     
00096     emit currentUrlChanged(currentUrl_);
00097   }
00098 }
00099 
00100 void UrlComboBox::lineEditEditingFinished() {
00101   if (currentUrl_ != currentText()) {
00102     currentUrl_ = currentText();
00103     
00104     emit currentUrlChanged(currentUrl_);
00105   }
00106 }
00107 
00108 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Tue May 9 2017 02:16:02