MessageFieldCompleter.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/MessageFieldCompleter.h"
00022 
00023 namespace rqt_multiplot {
00024 
00025 /*****************************************************************************/
00026 /* Constructors and Destructor                                               */
00027 /*****************************************************************************/
00028 
00029 MessageFieldCompleter::MessageFieldCompleter(QObject* parent) :
00030   QCompleter(parent) {
00031 }
00032   
00033 MessageFieldCompleter::MessageFieldCompleter(MessageFieldItemModel* model,
00034     QObject* parent) :
00035   QCompleter(model, parent) {
00036 }
00037 
00038 MessageFieldCompleter::~MessageFieldCompleter() {
00039 }
00040 
00041 /*****************************************************************************/
00042 /* Methods                                                                   */
00043 /*****************************************************************************/
00044 
00045 QStringList MessageFieldCompleter::splitPath(const QString& path) const {
00046   MessageFieldItemModel* messageFieldItemModel = qobject_cast<
00047     MessageFieldItemModel*>(model());
00048     
00049   if (messageFieldItemModel)
00050     messageFieldItemModel->update(path);
00051   
00052   return path.split("/");
00053 }
00054 
00055 QString MessageFieldCompleter::pathFromIndex(const QModelIndex& index) const {
00056   QStringList fieldNames;
00057   QModelIndex fieldIndex = index;
00058   
00059   if (model()) {
00060     while (fieldIndex.isValid()) {
00061       fieldNames.prepend(model()->data(fieldIndex, Qt::DisplayRole).
00062         toString());
00063       fieldIndex = fieldIndex.parent();
00064     }
00065   }
00066       
00067   return fieldNames.join("/");
00068 }
00069 
00070 }


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