UrlItem.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 "rqt_multiplot/UrlItem.h"
20 
21 namespace rqt_multiplot {
22 
23 /*****************************************************************************/
24 /* Constructors and Destructor */
25 /*****************************************************************************/
26 
27 UrlItem::UrlItem(UrlScheme* scheme, Type type, const QModelIndex& index,
28  UrlItem* parent) :
29  parent_(parent),
30  scheme_(scheme),
31  type_(type),
32  index_(index) {
33 }
34 
36  for (QMap<size_t, UrlItem*>::iterator it = children_.begin();
37  it != children_.end(); ++it)
38  delete it.value();
39 }
40 
41 /*****************************************************************************/
42 /* Accessors */
43 /*****************************************************************************/
44 
46  return parent_;
47 }
48 
49 size_t UrlItem::getNumChildren() const {
50  return children_.count();
51 }
52 
53 UrlItem* UrlItem::getChild(size_t row) const {
54  QMap<size_t, UrlItem*>::const_iterator it = children_.find(row);
55 
56  if (it != children_.end())
57  return it.value();
58  else
59  return 0;
60 }
61 
62 int UrlItem::getRow() const {
63  if (parent_) {
64  for (QMap<size_t, UrlItem*>::const_iterator it = parent_->children_.
65  begin(); it != parent_->children_.end(); ++it) {
66  if (it.value() == this)
67  return it.key();
68  }
69  }
70 
71  return -1;
72 }
73 
75  scheme_ = scheme;
76 }
77 
79  return scheme_;
80 }
81 
82 void UrlItem::setType(Type type) {
83  type_ = type;
84 }
85 
87  return type_;
88 }
89 
90 void UrlItem::setIndex(const QModelIndex& index) {
91  index_ = index;
92 }
93 
94 const QModelIndex& UrlItem::getIndex() const {
95  return index_;
96 }
97 
98 QModelIndex UrlItem::getIndex(Type type) const {
99  const UrlItem* item = this;
100 
101  while (item) {
102  if (item->type_ != type)
103  item = item->parent_;
104  else
105  return item->index_;
106  }
107 
108  return QModelIndex();
109 }
110 
111 /*****************************************************************************/
112 /* Accessors */
113 /*****************************************************************************/
114 
115 UrlItem* UrlItem::addChild(size_t row, Type type, const QModelIndex& index) {
116  QMap<size_t, UrlItem*>::iterator it = children_.find(row);
117 
118  if (it != children_.end()) {
119  it.value()->type_ = type;
120  it.value()->index_ = index;
121 
122  return it.value();
123  }
124  else {
125  UrlItem* item = new UrlItem(scheme_, type, index, this);
126  children_.insert(row, item);
127 
128  return item;
129  }
130 }
131 
132 }
void setIndex(const QModelIndex &index)
Definition: UrlItem.cpp:90
UrlItem * getParent() const
Definition: UrlItem.cpp:45
QModelIndex index_
Definition: UrlItem.h:61
UrlScheme * getScheme() const
Definition: UrlItem.cpp:78
UrlScheme * scheme_
Definition: UrlItem.h:59
int getRow() const
Definition: UrlItem.cpp:62
UrlItem * parent_
Definition: UrlItem.h:56
const QModelIndex & getIndex() const
Definition: UrlItem.cpp:94
UrlItem * addChild(size_t row, Type type, const QModelIndex &index)
Definition: UrlItem.cpp:115
QMap< size_t, UrlItem * > children_
Definition: UrlItem.h:57
UrlItem * getChild(size_t row) const
Definition: UrlItem.cpp:53
void setType(Type type)
Definition: UrlItem.cpp:82
size_t getNumChildren() const
Definition: UrlItem.cpp:49
void setScheme(UrlScheme *scheme)
Definition: UrlItem.cpp:74
Type getType() const
Definition: UrlItem.cpp:86
UrlItem(UrlScheme *scheme=0, Type type=Scheme, const QModelIndex &index=QModelIndex(), UrlItem *parent=0)
Definition: UrlItem.cpp:27


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