FileScheme.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 
20 
21 namespace rqt_multiplot {
22 
23 /*****************************************************************************/
24 /* Constructors and Destructor */
25 /*****************************************************************************/
26 
27 FileScheme::FileScheme(QObject* parent, const QString& prefix, const QString&
28  rootPath, QDir::Filters filter) :
29  UrlScheme(prefix),
30  model_(new QFileSystemModel(this)) {
31  model_->setRootPath(rootPath);
32  model_->setFilter(filter);
33 
34  connect(model_, SIGNAL(directoryLoaded(const QString&)), this,
35  SLOT(modelDirectoryLoaded(const QString&)));
36 }
37 
39 }
40 
41 /*****************************************************************************/
42 /* Accessors */
43 /*****************************************************************************/
44 
45 void FileScheme::setRootPath(const QString& rootPath) {
46  model_->setRootPath(rootPath);
47 }
48 
49 QString FileScheme::getRootPath() const {
50  return model_->rootPath();
51 }
52 
53 void FileScheme::setFilter(QDir::Filters filter) {
54  model_->setFilter(filter);
55 }
56 
57 QDir::Filters FileScheme::getFilter() const {
58  return model_->filter();
59 }
60 
61 size_t FileScheme::getNumHosts() const {
62  return 0;
63 }
64 
65 QModelIndex FileScheme::getHostIndex(size_t row) const {
66  return QModelIndex();
67 }
68 
69 QVariant FileScheme::getHostData(const QModelIndex& index, int role) const {
70  return QVariant();
71 }
72 
73 size_t FileScheme::getNumPaths(const QModelIndex& hostIndex, const
74  QModelIndex& parent) const {
75  if (!parent.isValid())
76  return 1;
77  else if (!parent.parent().isValid())
78  return model_->rowCount(model_->index(model_->rootPath()));
79  else {
80  if (model_->canFetchMore(parent))
81  model_->fetchMore(parent);
82 
83  return model_->rowCount(parent);
84  }
85 }
86 
87 QModelIndex FileScheme::getPathIndex(const QModelIndex& hostIndex, size_t
88  row, const QModelIndex& parent) const {
89  if (!parent.isValid())
90  return model_->index(model_->rootPath());
91  else
92  return model_->index(row, 0, parent);
93 }
94 
95 QVariant FileScheme::getPathData(const QModelIndex& index, int role) const {
96  if (index == model_->index(model_->rootPath())) {
97  if ((role == Qt::DisplayRole) || (role == Qt::EditRole))
98  return "/";
99  }
100  else
101  return model_->data(index, role);
102 
103  return QVariant();
104 }
105 
106 QString FileScheme::getHost(const QModelIndex& hostIndex) const {
107  return QString();
108 }
109 
110 QString FileScheme::getPath(const QModelIndex& hostIndex, const QModelIndex&
111  pathIndex) const {
112  return model_->rootDirectory().relativeFilePath(model_->filePath(
113  pathIndex));
114 }
115 
116 QString FileScheme::getFilePath(const QModelIndex& hostIndex, const
117  QModelIndex& pathIndex) const {
118  if (pathIndex.isValid())
119  return model_->filePath(pathIndex);
120 
121  return QString();
122 }
123 
124 QString FileScheme::getFilePath(const QString& host, const QString& path)
125  const {
126  return model_->rootDirectory().absoluteFilePath(path);
127 }
128 
129 /*****************************************************************************/
130 /* Slots */
131 /*****************************************************************************/
132 
133 void FileScheme::modelDirectoryLoaded(const QString& path) {
134  emit pathLoaded(QString(), model_->rootDirectory().relativeFilePath(path));
135 }
136 
137 }
void setFilter(QDir::Filters filter)
Definition: FileScheme.cpp:53
QVariant getPathData(const QModelIndex &index, int role) const
Definition: FileScheme.cpp:95
QString getFilePath(const QModelIndex &hostIndex, const QModelIndex &pathIndex) const
Definition: FileScheme.cpp:116
void pathLoaded(const QString &host, const QString &path)
void modelDirectoryLoaded(const QString &path)
Definition: FileScheme.cpp:133
FileScheme(QObject *parent=0, const QString &prefix="file", const QString &rootPath="/", QDir::Filters filter=QDir::NoFilter)
Definition: FileScheme.cpp:27
QString getPath(const QModelIndex &hostIndex, const QModelIndex &pathIndex) const
Definition: FileScheme.cpp:110
QVariant getHostData(const QModelIndex &index, int role) const
Definition: FileScheme.cpp:69
QString getRootPath() const
Definition: FileScheme.cpp:49
void setRootPath(const QString &rootPath)
Definition: FileScheme.cpp:45
QDir::Filters getFilter() const
Definition: FileScheme.cpp:57
QModelIndex getHostIndex(size_t row) const
Definition: FileScheme.cpp:65
QFileSystemModel * model_
Definition: FileScheme.h:60
QString getHost(const QModelIndex &hostIndex) const
Definition: FileScheme.cpp:106
QModelIndex getPathIndex(const QModelIndex &hostIndex, size_t row, const QModelIndex &parent=QModelIndex()) const
Definition: FileScheme.cpp:87
size_t getNumPaths(const QModelIndex &hostIndex, const QModelIndex &parent) const
Definition: FileScheme.cpp:73
size_t getNumHosts() const
Definition: FileScheme.cpp:61


rqt_multiplot_plugin
Author(s): Ralf Kaestner
autogenerated on Fri Jan 15 2021 03:47:53