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
36using namespace ScenarioManager;
37using namespace Data_Structure;
38
43
44QVariant
45ApplicationDatabaseModel::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
68void
70{
71 delete rootItem;
72 rootItem = new ApplicationDatabaseItem("Application");
73 reset();
74}
75
76Qt::ItemFlags
77ApplicationDatabaseModel::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
96Qt::DropActions
98{
99 return Qt::CopyAction;
100}
101
102QStringList
104{
105 QStringList types;
106 types << "application/pointer";
107 return types;
108}
109
110QMimeData*
111ApplicationDatabaseModel::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
136void
138{
139 QModelIndex topLeft = index(0, 0);
140 QModelIndex bottomRight = index(rowCount() - 1, columnCount() - 1);
141
142 emit dataChanged(topLeft, bottomRight);
143}
144
uint8_t index
This class represents an item in the ApplicationDatabaseView.
ScenarioManager::Data_Structure::ApplicationPtr getApplication()
Returns the Application displayed in this item.
QStringList mimeTypes() const override
Returns supported MIME-types.
ApplicationDatabaseItem * getRootItem()
ApplicationDatabaseModel()
Constructor that sets up the first item contained by this model.
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the behavioural flags of the object at the specified index.
Qt::DropActions supportedDragActions() const override
Returns the supported drag action.
QVariant data(const QModelIndex &index, int role) const override
Returns the data at the specified index, depending on the specified role.
void clear() override
Clears and resets this model as if it was newly constructed.
QMimeData * mimeData(const QModelIndexList &indexes) const override
Returns the mimedata of the objects at the specified indexes.
virtual QVariant data(int column) const
Definition treeitem.cpp:69
TreeItem * rootItem
Definition treemodel.h:69
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition treemodel.cpp:69
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition treemodel.cpp:99
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition treemodel.cpp:45
std::shared_ptr< Application > ApplicationPtr
@ APPLICATIONITEMSOURCE
Definition treeitem.h:42