UrlCompleter.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
19 #include <QStringList>
20 
22 
23 namespace rqt_multiplot {
24 
25 /*****************************************************************************/
26 /* Constructors and Destructor */
27 /*****************************************************************************/
28 
29 UrlCompleter::UrlCompleter(QObject* parent) :
30  QCompleter(parent),
31  model_(new UrlItemModel(this)) {
32  setModel(model_);
33 
34  connect(model_, SIGNAL(urlLoaded(const QString&)), this,
35  SLOT(modelUrlLoaded(const QString&)));
36 }
37 
39 }
40 
41 /*****************************************************************************/
42 /* Accessors */
43 /*****************************************************************************/
44 
46  return model_;
47 }
48 
49 /*****************************************************************************/
50 /* Methods */
51 /*****************************************************************************/
52 
53 QStringList UrlCompleter::splitPath(const QString& url) const {
54  QString scheme, path;
55 
56  QStringList urlParts = url.split("://");
57 
58  if (urlParts.count() > 1) {
59  scheme = urlParts[0];
60  path = urlParts[1];
61  }
62  else
63  path = url;
64 
65  QStringList pathParts = path.split("/");
66 
67  if (path[0] == '/')
68  pathParts[0] = "/";
69 
70  QStringList parts;
71  if (!scheme.isEmpty())
72  parts.append(scheme+"://");
73  parts.append(pathParts);
74 
75  return parts;
76 }
77 
78 QString UrlCompleter::pathFromIndex(const QModelIndex& index) const {
79  return model_->getUrl(index);
80 }
81 
82 /*****************************************************************************/
83 /* Slots */
84 /*****************************************************************************/
85 
86 void UrlCompleter::modelUrlLoaded(const QString& url) {
87  QString prefix = completionPrefix();
88 
89  if (prefix.startsWith(url) && (prefix != (url+"/")))
90  complete();
91 }
92 
93 }
UrlCompleter(QObject *parent=0)
void modelUrlLoaded(const QString &url)
QStringList splitPath(const QString &url) const
QString getUrl(const QModelIndex &index) const
UrlItemModel * getModel() const
QString pathFromIndex(const QModelIndex &index) const


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44