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 <QLineEdit>
00020
00021 #include "rqt_multiplot/UrlComboBox.h"
00022
00023 namespace rqt_multiplot {
00024
00025
00026
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
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
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 }