DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
apps
SchemaEditor
SchemaCustomTableModel.cpp
Go to the documentation of this file.
1
// DUNE DAQ modification notice:
2
// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3
// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4
// Renamed since fork: yes (from src/SchemaEditor/SchemaCustomTableModel.cpp to apps/SchemaEditor/SchemaCustomTableModel.cpp).
5
6
#include "
dbe/SchemaCustomTableModel.hpp
"
7
#include "
dbe/SchemaKernelWrapper.hpp
"
8
#include "
dbe/SchemaStyle.hpp
"
9
#include <QIODevice>
10
#include <QDataStream>
11
12
using namespace
dunedaq::oks
;
13
14
dbse::CustomTableModel::CustomTableModel
( QStringList Headers, QObject * parent )
15
: QAbstractTableModel ( parent ),
16
HeaderList
( Headers )
17
{
18
setupModel
();
19
}
20
21
dbse::CustomTableModel::~CustomTableModel
()
22
{
23
}
24
25
int
dbse::CustomTableModel::rowCount
(
const
QModelIndex & parent )
const
26
{
27
Q_UNUSED ( parent );
28
return
m_data
.size();
29
}
30
31
int
dbse::CustomTableModel::columnCount
(
const
QModelIndex & parent )
const
32
{
33
Q_UNUSED ( parent );
34
return
HeaderList
.size();
35
}
36
37
Qt::ItemFlags
dbse::CustomTableModel::flags
(
const
QModelIndex & index )
const
38
{
39
Q_UNUSED ( index );
40
return
Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
41
}
42
43
QVariant
dbse::CustomTableModel::headerData
(
int
section
, Qt::Orientation orientation,
44
int
role )
const
45
{
46
if
( role != Qt::DisplayRole )
47
{
48
return
QVariant();
49
}
50
51
if
( orientation == Qt::Horizontal )
52
{
53
return
HeaderList
.at (
section
);
54
}
55
56
return
QVariant();
57
}
58
59
QVariant
dbse::CustomTableModel::data
(
const
QModelIndex & index,
int
role )
const
60
{
61
if
( role == Qt::DisplayRole )
62
{
63
return
m_data
.value ( index.row() ).value ( index.column() );
64
}
65
if
( role == Qt::ToolTipRole )
66
{
67
return
m_tooltips
.value ( index.row() ).value ( index.column() );
68
}
69
if
(role == Qt::ForegroundRole) {
70
return
m_brushes
.at(index.row());
71
}
72
if
(role == Qt::BackgroundRole) {
73
return
m_backgrounds
.at(index.row());
74
}
75
76
return
QVariant();
77
}
78
79
QStringList
dbse::CustomTableModel::getRowFromIndex
( QModelIndex & index )
80
{
81
if
( !index.isValid() )
82
{
83
return
QStringList();
84
}
85
86
return
m_data
.at ( index.row() );
87
}
88
89
void
dbse::CustomTableModel::setupModel
()
90
{
91
std::vector<OksClass *> ClassList;
92
KernelWrapper::GetInstance
().
GetClassList
( ClassList );
93
94
for
(
unsigned
int
i = 0; i < ClassList.size(); ++i )
95
{
96
QList<QString> Row;
97
OksClass
* Class = ClassList.at ( i );
98
Row.append ( QString ( Class->
get_name
().c_str() ) );
99
m_data
.append ( Row );
100
m_tooltips
.append (QStringList {QString ( Class->
get_description
().c_str() )});
101
102
auto
fn = Class->
get_file
()->
get_full_file_name
();
103
if
(!
KernelWrapper::GetInstance
().IsFileWritable (fn)) {
104
m_brushes
.emplace_back(QBrush(
SchemaStyle::get_color
(
"foreground"
,
"readonly"
)));
105
m_backgrounds
.emplace_back(
SchemaStyle::get_color
(
"background"
,
"readonly"
));
106
}
107
else
if
(fn ==
KernelWrapper::GetInstance
().GetActiveSchema()) {
108
m_brushes
.emplace_back(QBrush(
SchemaStyle::get_color
(
"foreground"
,
"active_file"
)));
109
m_backgrounds
.emplace_back(
SchemaStyle::get_color
(
"background"
,
"active_file"
));
110
}
111
else
{
112
m_brushes
.emplace_back(QBrush(
SchemaStyle::get_color
(
"foreground"
,
"default"
)));
113
m_backgrounds
.emplace_back(
SchemaStyle::get_color
(
"background"
,
"default"
));
114
}
115
}
116
}
117
118
QStringList
dbse::CustomTableModel::mimeTypes
()
const
119
{
120
QStringList types;
121
types <<
"application/vnd.text.list"
;
122
return
types;
123
}
124
125
QMimeData *
dbse::CustomTableModel::mimeData
(
const
QModelIndexList & indexes )
const
126
{
127
QMimeData *
mimeData
=
new
QMimeData();
128
QByteArray encodedData;
129
130
QDataStream stream ( &encodedData, QIODevice::WriteOnly );
131
132
foreach
( QModelIndex index, indexes )
133
{
134
if
( index.isValid() && index.column() == 0 )
135
{
136
QString ClassName =
data
( index, Qt::DisplayRole ).toString();
137
stream << ClassName;
138
}
139
}
140
141
mimeData
->setData (
"application/vnd.text.list"
, encodedData );
142
return
mimeData
;
143
}
SchemaCustomTableModel.hpp
SchemaKernelWrapper.hpp
SchemaStyle.hpp
dbse::CustomTableModel::rowCount
int rowCount(const QModelIndex &parent) const
Definition
SchemaCustomTableModel.cpp:25
dbse::CustomTableModel::mimeData
QMimeData * mimeData(const QModelIndexList &indexes) const
Definition
SchemaCustomTableModel.cpp:125
dbse::CustomTableModel::data
QVariant data(const QModelIndex &index, int role) const
Definition
SchemaCustomTableModel.cpp:59
dbse::CustomTableModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition
SchemaCustomTableModel.cpp:43
dbse::CustomTableModel::CustomTableModel
CustomTableModel(QStringList Headers, QObject *parent=nullptr)
Definition
SchemaCustomTableModel.cpp:14
dbse::CustomTableModel::m_tooltips
QList< QList< QString > > m_tooltips
Definition
SchemaCustomTableModel.hpp:40
dbse::CustomTableModel::HeaderList
QStringList HeaderList
Definition
SchemaCustomTableModel.hpp:38
dbse::CustomTableModel::columnCount
int columnCount(const QModelIndex &parent) const
Definition
SchemaCustomTableModel.cpp:31
dbse::CustomTableModel::mimeTypes
QStringList mimeTypes() const
Drag/Drop Handlers.
Definition
SchemaCustomTableModel.cpp:118
dbse::CustomTableModel::setupModel
void setupModel()
Definition
SchemaCustomTableModel.cpp:89
dbse::CustomTableModel::m_data
QList< QList< QString > > m_data
Definition
SchemaCustomTableModel.hpp:39
dbse::CustomTableModel::~CustomTableModel
~CustomTableModel()
Definition
SchemaCustomTableModel.cpp:21
dbse::CustomTableModel::m_backgrounds
std::vector< QColor > m_backgrounds
Definition
SchemaCustomTableModel.hpp:42
dbse::CustomTableModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const
Definition
SchemaCustomTableModel.cpp:37
dbse::CustomTableModel::m_brushes
std::vector< QBrush > m_brushes
Definition
SchemaCustomTableModel.hpp:41
dbse::CustomTableModel::getRowFromIndex
QStringList getRowFromIndex(QModelIndex &index)
Definition
SchemaCustomTableModel.cpp:79
dbse::KernelWrapper::GetInstance
static KernelWrapper & GetInstance()
Definition
SchemaKernelWrapper.cpp:18
dbse::KernelWrapper::GetClassList
void GetClassList(std::vector< dunedaq::oks::OksClass * > &ClassList) const
Definition
SchemaKernelWrapper.cpp:40
dunedaq::oks::OksClass
The OKS class.
Definition
class.hpp:205
dunedaq::oks::OksClass::get_name
const std::string & get_name() const noexcept
Definition
class.hpp:368
dunedaq::oks::OksClass::get_description
const std::string & get_description() const noexcept
Definition
class.hpp:373
dunedaq::oks::OksClass::get_file
OksFile * get_file() const noexcept
Definition
class.hpp:343
dunedaq::oks::OksFile::get_full_file_name
const std::string & get_full_file_name() const
Definition
file.hpp:528
dunedaq::oks
Definition
OksConfiguration.hpp:24
dunedaq::section
Missing configuration section
Message.
Definition
SI534xNode.hpp:38
dbse::SchemaStyle::get_color
static QColor get_color(const QString &item, const QString &group)
Definition
SchemaStyle.cpp:103
Generated on
for DUNE-DAQ by
1.17.0