DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SchemaCustomTableModel.cpp
Go to the documentation of this file.
3#include <QIODevice>
4#include <QDataStream>
5
6using namespace dunedaq::oks;
7
8dbse::CustomTableModel::CustomTableModel ( QStringList Headers, QObject * parent )
9 : QAbstractTableModel ( parent ),
10 HeaderList ( Headers )
11{
12 setupModel();
13}
14
18
19int dbse::CustomTableModel::rowCount ( const QModelIndex & parent ) const
20{
21 Q_UNUSED ( parent )
22 return Data.size();
23}
24
25int dbse::CustomTableModel::columnCount ( const QModelIndex & parent ) const
26{
27 Q_UNUSED ( parent )
28 return HeaderList.size();
29}
30
31Qt::ItemFlags dbse::CustomTableModel::flags ( const QModelIndex & index ) const
32{
33 Q_UNUSED ( index )
34 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
35}
36
37QVariant dbse::CustomTableModel::headerData ( int section, Qt::Orientation orientation,
38 int role ) const
39{
40 if ( role != Qt::DisplayRole )
41 {
42 return QVariant();
43 }
44
45 if ( orientation == Qt::Horizontal )
46 {
47 return HeaderList.at ( section );
48 }
49
50 return QVariant();
51}
52
53QVariant dbse::CustomTableModel::data ( const QModelIndex & index, int role ) const
54{
55 if ( role != Qt::DisplayRole )
56 {
57 return QVariant();
58 }
59
60 return Data.value ( index.row() ).value ( index.column() );
61}
62
63QStringList dbse::CustomTableModel::getRowFromIndex ( QModelIndex & index )
64{
65 if ( !index.isValid() )
66 {
67 return QStringList();
68 }
69
70 return Data.at ( index.row() );
71}
72
74{
75 std::vector<OksClass *> ClassList;
77
78 for ( unsigned int i = 0; i < ClassList.size(); ++i )
79 {
80 QList<QString> Row;
81 OksClass * Class = ClassList.at ( i );
82 Row.append ( QString ( Class->get_name().c_str() ) );
83 Data.append ( Row );
84 }
85}
86
88{
89 QStringList types;
90 types << "application/vnd.text.list";
91 return types;
92}
93
94QMimeData * dbse::CustomTableModel::mimeData ( const QModelIndexList & indexes ) const
95{
96 QMimeData * mimeData = new QMimeData();
97 QByteArray encodedData;
98
99 QDataStream stream ( &encodedData, QIODevice::WriteOnly );
100
101 foreach ( QModelIndex index, indexes )
102 {
103 if ( index.isValid() && index.column() == 0 )
104 {
105 QString ClassName = data ( index, Qt::DisplayRole ).toString();
106 stream << ClassName;
107 }
108 }
109
110 mimeData->setData ( "application/vnd.text.list", encodedData );
111 return mimeData;
112}
int rowCount(const QModelIndex &parent) const
QMimeData * mimeData(const QModelIndexList &indexes) const
QVariant data(const QModelIndex &index, int role) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const
CustomTableModel(QStringList Headers, QObject *parent=nullptr)
int columnCount(const QModelIndex &parent) const
QStringList mimeTypes() const
Drag/Drop Handlers.
Qt::ItemFlags flags(const QModelIndex &index) const
QStringList getRowFromIndex(QModelIndex &index)
static KernelWrapper & GetInstance()
void GetClassList(std::vector< dunedaq::oks::OksClass * > &ClassList) const
The OKS class.
Definition class.hpp:200
const std::string & get_name() const noexcept
Definition class.hpp:363