MessageFieldItem.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 <QRegExp>
20 #include <QStringList>
21 
25 
27 
28 namespace rqt_multiplot {
29 
30 /*****************************************************************************/
31 /* Constructors and Destructor */
32 /*****************************************************************************/
33 
35  dataType, MessageFieldItem* parent, const QString& name) :
36  parent_(parent),
37  name_(name),
38  dataType_(dataType) {
39  if (dataType_.isMessage()) {
41 
42  for (size_t i = 0; i < messageType.getNumVariableMembers(); ++i)
44  getType(), this, QString::fromStdString(messageType.
45  getVariableMember(i).getName())));
46  }
47  else if (dataType_.isArray()) {
49 
50  if (!arrayType.isDynamic()) {
51  for (size_t i = 0; i < arrayType.getNumMembers(); ++i)
52  appendChild(new MessageFieldItem(arrayType.getMemberType(), this,
53  QString::number(i)));
54  }
55  else {
56  for (size_t i = 0; i <= 9; ++i)
57  appendChild(new MessageFieldItem(arrayType.getMemberType(), this,
58  QString::number(i)));
59  }
60  }
61 }
62 
64  for (QList<MessageFieldItem*>::iterator it = children_.begin();
65  it != children_.end(); ++it)
66  delete *it;
67 }
68 
69 /*****************************************************************************/
70 /* Accessors */
71 /*****************************************************************************/
72 
74  return parent_;
75 }
76 
78  return children_.count();
79 }
80 
82  return children_.value(row);
83 }
84 
85 MessageFieldItem* MessageFieldItem::getChild(const QString& name) const {
86  for (QList<MessageFieldItem*>::const_iterator it = children_.begin();
87  it != children_.end(); ++it) {
88  if ((*it)->name_ == name)
89  return *it;
90  }
91 
92  return 0;
93 }
94 
96  QStringList names = path.split("/");
97 
98  if (!names.isEmpty()) {
99  MessageFieldItem* child = getChild(names.first());
100 
101  if (child) {
102  names.removeFirst();
103  return child->getDescendant(names.join("/"));
104  }
105  }
106 
107  return 0;
108 }
109 
111  if (parent_)
112  return parent_->children_.indexOf(const_cast<MessageFieldItem*>(this));
113 
114  return -1;
115 }
116 
118  return 1;
119 }
120 
121 const QString& MessageFieldItem::getName() const {
122  return name_;
123 }
124 
126  return dataType_;
127 }
128 
129 /*****************************************************************************/
130 /* Methods */
131 /*****************************************************************************/
132 
134  children_.append(child);
135 }
136 
137 void MessageFieldItem::update(const QString& path) {
138  QStringList names = path.split("/");
139 
140  if (dataType_.isArray() && QRegExp("[1-9][0-9]*").exactMatch(
141  names.first())) {
143 
144  if (arrayType.isDynamic()) {
145  if (children_.count() < 11)
146  appendChild(new MessageFieldItem(arrayType.getMemberType(), this));
147 
148  children_[0]->name_ = names.first();
149 
150  for (size_t i = 0; i <= 9; ++i)
151  children_[i+1]->name_ = names.first()+QString::number(i);
152  }
153  }
154 
155  for (size_t row = 0; row < children_.count(); ++row) {
156  MessageFieldItem* child = children_[row];
157 
158  if (child->dataType_.isArray()) {
160 
161  if (arrayType.isDynamic()) {
162  if (child->children_.count() > 10) {
163  for (size_t i = 0; i <= 9; ++i)
164  child->children_[i]->name_ = QString::number(i);
165 
166  delete child->children_.last();
167  child->children_.removeLast();
168  }
169 
170  }
171  }
172  }
173 
174  if (!names.isEmpty()) {
175  MessageFieldItem* child = getChild(names.first());
176 
177  if (child) {
178  names.removeFirst();
179  child->update(names.join("/"));
180  }
181  }
182 }
183 
184 }
const QString & getName() const
MessageFieldItem(const variant_topic_tools::DataType &dataType, MessageFieldItem *parent=0, const QString &name=QString())
MessageFieldItem * getChild(size_t row) const
const variant_topic_tools::DataType & getDataType() const
MessageFieldItem * getParent() const
MessageFieldItem * getDescendant(const QString &path) const
const MessageVariable & getVariableMember(const std::string &name) const
void update(const QString &path)
variant_topic_tools::DataType dataType_
void appendChild(MessageFieldItem *child)
variant_topic_tools::MessageType messageType
const DataType & getMemberType() const
QList< MessageFieldItem * > children_


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