Vespucci  1.0.0
treeitem.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
20 #include "treeitem.h"
21 
22 TreeItem::TreeItem(TreeItem::ItemType type, QStringList &keys, QList<QVariant> &data, TreeItem *parent)
23 {
24  type_ = type;
25  keys_ = keys;
26  item_data_ = data;
27  parent_item_ = parent;
28 }
29 
31 {
32  qDeleteAll(child_items_);
33 }
34 
36 {
37  child_items_.append(child);
38 }
39 
41 {
42  child_items_.removeOne(child);
43 }
44 
46 {
47  return child_items_.value(row);
48 }
49 
51 {
52  return child_items_.count();
53 }
54 
56 {
57  return item_data_.count();
58 }
59 
60 QVariant TreeItem::data(int column) const
61 {
62  return item_data_.value(column);
63 }
64 
65 int TreeItem::row() const
66 {
67  if (parent_item_)
68  return parent_item_->child_items().indexOf(const_cast<TreeItem*>(this));
69  return 0;
70 }
71 
73 {
74  return parent_item_;
75 }
76 
77 QList<TreeItem *> TreeItem::child_items()
78 {
79  return child_items_;
80 }
81 
82 void TreeItem::UpdateType(QString new_type)
83 {
84  if (item_data_.size() > 1)
85  item_data_[1] = QVariant(new_type);
86 }
87 
89 {
90  child_items_.clear();
91 }
92 
94 {
95  return type_;
96 }
97 
98 QStringList TreeItem::keys() const
99 {
100  return keys_;
101 }
102 
103 const QString TreeItem::DatasetKey() const
104 {
105  return keys_[0];
106 }
107 
108 QStringList TreeItem::ChildNames() const
109 {
110  QStringList child_names;
111  for (auto item: child_items_)
112  child_names << item->data(0).toString();
113  return child_names;
114 }
115 
116 bool TreeItem::HasChild(const QString &name)
117 {
118  for (auto child_item: child_items_)
119  if (child_item->data(0) == name)
120  return true;
121 
122  return false;
123 }
124 
void ClearChildren()
Definition: treeitem.cpp:88
TreeItem * child(int row)
Definition: treeitem.cpp:45
QStringList keys() const
Definition: treeitem.cpp:98
~TreeItem()
Definition: treeitem.cpp:30
void removeChild(TreeItem *child)
Definition: treeitem.cpp:40
int row() const
Definition: treeitem.cpp:65
TreeItem::ItemType type() const
Definition: treeitem.cpp:93
void UpdateType(QString new_type)
Definition: treeitem.cpp:82
int childCount() const
Definition: treeitem.cpp:50
TreeItem * parentItem()
Definition: treeitem.cpp:72
void appendChild(TreeItem *child)
Definition: treeitem.cpp:35
QStringList ChildNames() const
Definition: treeitem.cpp:108
const QString DatasetKey() const
Definition: treeitem.cpp:103
bool HasChild(const QString &name)
Definition: treeitem.cpp:116
QVariant data(int column) const
Definition: treeitem.cpp:60
QList< TreeItem * > child_items()
Definition: treeitem.cpp:77
int columnCount() const
Definition: treeitem.cpp:55
TreeItem(TreeItem::ItemType type, QStringList &keys, QList< QVariant > &data, TreeItem *parent=0)
Definition: treeitem.cpp:22