applicationdatabasemodel.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 
25 
27 
28 #include <QColor>
29 #include <QDataStream>
30 #include <QMimeData>
31 #include <QtGlobal>
32 
35 
36 using namespace ScenarioManager;
37 using namespace Data_Structure;
38 
40 {
41  rootItem = new ApplicationDatabaseItem(QString("Application"));
42 }
43 
44 QVariant
45 ApplicationDatabaseModel::data(const QModelIndex& index, int role) const
46 {
47  if (!index.isValid())
48  {
49  return QVariant();
50  }
51 
52  if (role == APPLICATIONITEMSOURCE)
53  {
54  return QVariant::fromValue(
55  reinterpret_cast<ApplicationDatabaseItem*>(index.internalPointer()));
56  }
57 
58  if (role != Qt::DisplayRole)
59  {
60  return QVariant();
61  }
62 
63  ApplicationDatabaseItem* item = static_cast<ApplicationDatabaseItem*>(index.internalPointer());
64 
65  return item->data(index.column());
66 }
67 
68 void
70 {
71  delete rootItem;
72  rootItem = new ApplicationDatabaseItem("Application");
73  reset();
74 }
75 
76 Qt::ItemFlags
77 ApplicationDatabaseModel::flags(const QModelIndex& index) const
78 {
79  if (!index.isValid())
80  {
81  return 0;
82  }
83 
84  Qt::ItemFlags defaultFlags = TreeModel::flags(index);
85 
86  if (index.parent().isValid())
87  {
88  return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
89  }
90  else
91  {
92  return defaultFlags;
93  }
94 }
95 
96 Qt::DropActions
98 {
99  return Qt::CopyAction;
100 }
101 
102 QStringList
104 {
105  QStringList types;
106  types << "application/pointer";
107  return types;
108 }
109 
110 QMimeData*
111 ApplicationDatabaseModel::mimeData(const QModelIndexList& indexes) const
112 {
113  QMimeData* mimeData = new QMimeData();
114  QByteArray encodedData;
115 
116  QDataStream stream(&encodedData, QIODevice::WriteOnly);
117 
118  foreach (const QModelIndex& index, indexes)
119  {
120  if (index.isValid())
121  {
122 
124  static_cast<ApplicationDatabaseItem*>(index.internalPointer())->getApplication();
125 
126  stream << reinterpret_cast<quint64>(item.get());
127  stream << QString(""); // instance name
128  }
129  }
130 
131  //mimeData->setData("application/pointer", QByteArray( (char*)item, sizeof(item) ));
132  mimeData->setData("application/pointer", encodedData);
133  return mimeData;
134 }
135 
136 void
138 {
139  QModelIndex topLeft = index(0, 0);
140  QModelIndex bottomRight = index(rowCount() - 1, columnCount() - 1);
141 
142  emit dataChanged(topLeft, bottomRight);
143 }
144 
147 {
148  return static_cast<ApplicationDatabaseItem*>(rootItem);
149 }
ApplicationDatabaseModel::ApplicationDatabaseModel
ApplicationDatabaseModel()
Constructor that sets up the first item contained by this model.
Definition: applicationdatabasemodel.cpp:39
index
uint8_t index
Definition: EtherCATFrame.h:59
ScenarioManager::Data_Structure::ApplicationPtr
std::shared_ptr< Application > ApplicationPtr
Definition: Application.h:121
TreeItem::data
virtual QVariant data(int column) const
Definition: treeitem.cpp:69
ApplicationDatabaseModel::mimeTypes
QStringList mimeTypes() const override
Returns supported MIME-types.
Definition: applicationdatabasemodel.cpp:103
TreeModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: treemodel.cpp:69
ApplicationDatabaseItem
This class represents an item in the ApplicationDatabaseView.
Definition: applicationdatabaseitem.h:36
APPLICATIONITEMSOURCE
@ APPLICATIONITEMSOURCE
Definition: treeitem.h:42
ApplicationDatabaseModel::getRootItem
ApplicationDatabaseItem * getRootItem()
Definition: applicationdatabasemodel.cpp:146
ApplicationDatabaseModel::update
void update()
Updates the model.
Definition: applicationdatabasemodel.cpp:137
ApplicationDatabaseModel::clear
void clear() override
Clears and resets this model as if it was newly constructed.
Definition: applicationdatabasemodel.cpp:69
ApplicationDatabaseModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the behavioural flags of the object at the specified index.
Definition: applicationdatabasemodel.cpp:77
ApplicationInstance.h
ApplicationDatabaseModel::mimeData
QMimeData * mimeData(const QModelIndexList &indexes) const override
Returns the mimedata of the objects at the specified indexes.
Definition: applicationdatabasemodel.cpp:111
ScenarioManager
Definition: Application.cpp:180
ApplicationDatabaseModel::data
QVariant data(const QModelIndex &index, int role) const override
Returns the data at the specified index, depending on the specified role.
Definition: applicationdatabasemodel.cpp:45
Logging.h
ApplicationDatabaseModel::supportedDragActions
Qt::DropActions supportedDragActions() const override
Returns the supported drag action.
Definition: applicationdatabasemodel.cpp:97
applicationdatabasemodel.h