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