openscenariomodel.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::core
19  * @author Cedric Seehausen (usdnr at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include <initializer_list>
25 
26 #include "openscenariomodel.h"
27 
29 {
30  rootItem = new OpenScenarioItem({"Scenarios", "Package", "Open"});
31 }
32 
33 QVariant OpenScenarioModel::data(const QModelIndex& index, int role) const
34 {
35  if (!index.isValid())
36  {
37  return QVariant();
38  }
39 
40  // if (role == Qt::BackgroundRole){
41  // if(index.column() == 1) {
42  // if(!index.data().toString().compare("Running")){
43  // return QColor(Qt::green);
44  // } else if(!index.data().toString().compare("Stopped")) {
45  // return QColor(Qt::red);
46  // } else if(!index.data().toString().compare("Waiting")) {
47  // return QColor(Qt::darkYellow);
48  // } else {
49  // return QColor(Qt::lightGray); //only for safety reasons
50  // }
51  // }
52  // } else if (role == Qt::DisplayRole) {
53  // if(index.column() == 2) {
54 
55  // }
56  // } else if (role != Qt::DisplayRole){
57  // return QVariant();
58  // }
59  if (role == OPENSCENARIOITEMSOURCE)
60  {
61  return QVariant::fromValue(reinterpret_cast<OpenScenarioItem*>(index.internalPointer()));
62  }
63  if (role != Qt::DisplayRole)
64  {
65  return QVariant();
66  }
67 
68  OpenScenarioItem* item = static_cast<OpenScenarioItem*>(index.internalPointer());
69 
70  return item->data(index.column());
71 }
72 
73 
75 {
76  delete rootItem;
77  rootItem = new OpenScenarioItem({"Scenarios", "Package", "Open"});
78  reset();
79 }
80 
82 {
83  QModelIndex topLeft = index(0, 0);
84  QModelIndex bottomRight = index(rowCount() - 1, columnCount() - 1);
85 
86  emit dataChanged(topLeft, bottomRight);
87 }
88 
89 
91 {
92  return static_cast<OpenScenarioItem*>(rootItem);
93 }
TreeModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: treemodel.cpp:96
index
uint8_t index
Definition: EtherCATFrame.h:59
TreeItem::data
virtual QVariant data(int column) const
Definition: treeitem.cpp:64
OPENSCENARIOITEMSOURCE
@ OPENSCENARIOITEMSOURCE
Definition: treeitem.h:42
openscenariomodel.h
OpenScenarioModel::update
void update()
Updates this model.
Definition: openscenariomodel.cpp:81
OpenScenarioModel::getRootItem
OpenScenarioItem * getRootItem()
Definition: openscenariomodel.cpp:90
OpenScenarioModel::OpenScenarioModel
OpenScenarioModel()
Constructor that sets up the root of this model.
Definition: openscenariomodel.cpp:28
OpenScenarioModel::clear
void clear() override
Deletes the current root and replaces it with a new one, as if this model was newly constructed.
Definition: openscenariomodel.cpp:74
TreeModel::rootItem
TreeItem * rootItem
Definition: treemodel.h:70
OpenScenarioModel::data
QVariant data(const QModelIndex &index, int role) const override
Returns the data of the item at the given index of the given role.
Definition: openscenariomodel.cpp:33
TreeModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: treemodel.cpp:45
OpenScenarioItem
Item in the TreeItemView. Every item represents a Scenario.
Definition: openscenarioitem.h:36
TreeModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: treemodel.cpp:136