UrlItem.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/UrlItem.h"
00020 
00021 namespace rqt_multiplot {
00022 
00023 /*****************************************************************************/
00024 /* Constructors and Destructor                                               */
00025 /*****************************************************************************/
00026 
00027 UrlItem::UrlItem(UrlScheme* scheme, Type type, const QModelIndex& index,
00028     UrlItem* parent) :
00029   parent_(parent),
00030   scheme_(scheme),
00031   type_(type),
00032   index_(index) {
00033 }
00034 
00035 UrlItem::~UrlItem() {
00036   for (QMap<size_t, UrlItem*>::iterator it = children_.begin();
00037       it != children_.end(); ++it)
00038     delete it.value();
00039 }
00040 
00041 /*****************************************************************************/
00042 /* Accessors                                                                 */
00043 /*****************************************************************************/
00044 
00045 UrlItem* UrlItem::getParent() const {
00046   return parent_;
00047 }
00048 
00049 size_t UrlItem::getNumChildren() const {
00050   return children_.count();
00051 }
00052 
00053 UrlItem* UrlItem::getChild(size_t row) const {
00054   QMap<size_t, UrlItem*>::const_iterator it = children_.find(row);
00055   
00056   if (it != children_.end())
00057     return it.value();
00058   else
00059     return 0;
00060 }
00061 
00062 int UrlItem::getRow() const {
00063   if (parent_) {
00064     for (QMap<size_t, UrlItem*>::const_iterator it = parent_->children_.
00065         begin(); it != parent_->children_.end(); ++it) {
00066       if (it.value() == this)
00067         return it.key();
00068     }
00069   }
00070 
00071   return -1;
00072 }
00073 
00074 void UrlItem::setScheme(UrlScheme* scheme) {
00075   scheme_ = scheme;
00076 }
00077 
00078 UrlScheme* UrlItem::getScheme() const {
00079   return scheme_;
00080 }
00081 
00082 void UrlItem::setType(Type type) {
00083   type_ = type;
00084 }
00085 
00086 UrlItem::Type UrlItem::getType() const {
00087   return type_;
00088 }
00089 
00090 void UrlItem::setIndex(const QModelIndex& index) {
00091   index_ = index;
00092 }
00093 
00094 const QModelIndex& UrlItem::getIndex() const {
00095   return index_;
00096 }
00097 
00098 QModelIndex UrlItem::getIndex(Type type) const {
00099   const UrlItem* item = this;
00100   
00101   while (item) {
00102     if (item->type_ != type)
00103       item = item->parent_;
00104     else
00105       return item->index_;
00106   }
00107   
00108   return QModelIndex();
00109 }
00110 
00111 /*****************************************************************************/
00112 /* Accessors                                                                 */
00113 /*****************************************************************************/
00114 
00115 UrlItem* UrlItem::addChild(size_t row, Type type, const QModelIndex& index) {
00116   QMap<size_t, UrlItem*>::iterator it = children_.find(row);
00117   
00118   if (it != children_.end()) {
00119     it.value()->type_ = type;
00120     it.value()->index_ = index;
00121 
00122     return it.value();
00123   }
00124   else {
00125     UrlItem* item = new UrlItem(scheme_, type, index, this);
00126     children_.insert(row, item);
00127     
00128     return item;
00129   }
00130 }
00131 
00132 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:11