FileScheme.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 "rqt_multiplot/FileScheme.h"
00020 
00021 namespace rqt_multiplot {
00022 
00023 /*****************************************************************************/
00024 /* Constructors and Destructor                                               */
00025 /*****************************************************************************/
00026 
00027 FileScheme::FileScheme(QObject* parent, const QString& prefix, const QString&
00028     rootPath, QDir::Filters filter) :
00029   UrlScheme(prefix),
00030   model_(new QFileSystemModel(this)) {
00031   model_->setRootPath(rootPath);
00032   model_->setFilter(filter);
00033   
00034   connect(model_, SIGNAL(directoryLoaded(const QString&)), this,
00035     SLOT(modelDirectoryLoaded(const QString&)));
00036 }
00037 
00038 FileScheme::~FileScheme() {
00039 }
00040 
00041 /*****************************************************************************/
00042 /* Accessors                                                                 */
00043 /*****************************************************************************/
00044 
00045 void FileScheme::setRootPath(const QString& rootPath) {
00046   model_->setRootPath(rootPath);
00047 }
00048 
00049 QString FileScheme::getRootPath() const {
00050   return model_->rootPath();
00051 }
00052 
00053 void FileScheme::setFilter(QDir::Filters filter) {
00054   model_->setFilter(filter);
00055 }
00056 
00057 QDir::Filters FileScheme::getFilter() const {
00058   return model_->filter();
00059 }
00060 
00061 size_t FileScheme::getNumHosts() const {
00062   return 0;
00063 }
00064 
00065 QModelIndex FileScheme::getHostIndex(size_t row) const {
00066   return QModelIndex();
00067 }
00068 
00069 QVariant FileScheme::getHostData(const QModelIndex& index, int role) const {
00070   return QVariant();
00071 }
00072 
00073 size_t FileScheme::getNumPaths(const QModelIndex& hostIndex, const
00074     QModelIndex& parent) const {
00075   if (!parent.isValid())
00076     return 1;
00077   else if (!parent.parent().isValid())
00078     return model_->rowCount(model_->index(model_->rootPath()));
00079   else {
00080     if (model_->canFetchMore(parent))
00081       model_->fetchMore(parent);
00082     
00083     return model_->rowCount(parent);
00084   }
00085 }
00086 
00087 QModelIndex FileScheme::getPathIndex(const QModelIndex& hostIndex, size_t
00088     row, const QModelIndex& parent) const {
00089   if (!parent.isValid())
00090     return model_->index(model_->rootPath());
00091   else
00092     return model_->index(row, 0, parent);
00093 }
00094 
00095 QVariant FileScheme::getPathData(const QModelIndex& index, int role) const {
00096   if (index == model_->index(model_->rootPath())) {
00097     if ((role == Qt::DisplayRole) || (role == Qt::EditRole))
00098       return "/";
00099   }
00100   else
00101     return model_->data(index, role);
00102   
00103   return QVariant();
00104 }
00105 
00106 QString FileScheme::getHost(const QModelIndex& hostIndex) const {
00107   return QString();
00108 }
00109 
00110 QString FileScheme::getPath(const QModelIndex& hostIndex, const QModelIndex&
00111     pathIndex) const {
00112   return model_->rootDirectory().relativeFilePath(model_->filePath(
00113     pathIndex));
00114 }
00115 
00116 QString FileScheme::getFilePath(const QModelIndex& hostIndex, const
00117     QModelIndex& pathIndex) const {
00118   if (pathIndex.isValid())
00119     return model_->filePath(pathIndex);
00120   
00121   return QString();
00122 }
00123 
00124 QString FileScheme::getFilePath(const QString& host, const QString& path)
00125     const {
00126   return model_->rootDirectory().absoluteFilePath(path);
00127 }
00128 
00129 /*****************************************************************************/
00130 /* Slots                                                                     */
00131 /*****************************************************************************/
00132 
00133 void FileScheme::modelDirectoryLoaded(const QString& path) {
00134   emit pathLoaded(QString(), model_->rootDirectory().relativeFilePath(path));
00135 }
00136 
00137 }


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