UrlCompleter.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 <QStringList>
00020 
00021 #include "rqt_multiplot/UrlCompleter.h"
00022 
00023 namespace rqt_multiplot {
00024 
00025 /*****************************************************************************/
00026 /* Constructors and Destructor                                               */
00027 /*****************************************************************************/
00028 
00029 UrlCompleter::UrlCompleter(QObject* parent) :
00030   QCompleter(parent),
00031   model_(new UrlItemModel(this)) {
00032   setModel(model_);
00033   
00034   connect(model_, SIGNAL(urlLoaded(const QString&)), this,
00035     SLOT(modelUrlLoaded(const QString&)));
00036 }
00037 
00038 UrlCompleter::~UrlCompleter() {
00039 }
00040 
00041 /*****************************************************************************/
00042 /* Accessors                                                                 */
00043 /*****************************************************************************/
00044 
00045 UrlItemModel* UrlCompleter::getModel() const {
00046   return model_;
00047 }
00048 
00049 /*****************************************************************************/
00050 /* Methods                                                                   */
00051 /*****************************************************************************/
00052 
00053 QStringList UrlCompleter::splitPath(const QString& url) const {
00054   QString scheme, path;
00055   
00056   QStringList urlParts = url.split("://");
00057   
00058   if (urlParts.count() > 1) {
00059     scheme = urlParts[0];
00060     path = urlParts[1];
00061   }
00062   else
00063     path = url;
00064   
00065   QStringList pathParts = path.split("/");
00066 
00067   if (path[0] == '/')
00068     pathParts[0] = "/";
00069 
00070   QStringList parts;
00071   if (!scheme.isEmpty())
00072     parts.append(scheme+"://");
00073   parts.append(pathParts);
00074   
00075   return parts;
00076 }
00077 
00078 QString UrlCompleter::pathFromIndex(const QModelIndex& index) const {
00079   return model_->getUrl(index);
00080 }
00081 
00082 /*****************************************************************************/
00083 /* Slots                                                                     */
00084 /*****************************************************************************/
00085 
00086 void UrlCompleter::modelUrlLoaded(const QString& url) {
00087   QString prefix = completionPrefix();
00088   
00089   if (prefix.startsWith(url) && (prefix != (url+"/")))
00090     complete();
00091 }
00092 
00093 }


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