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
5
// apps/SchemaEditor/SchemaCustomTableModel.cpp).
6
7
#include "
dbe/SchemaCustomTableModel.hpp
"
8
#include "
dbe/SchemaKernelWrapper.hpp
"
9
#include "
dbe/SchemaStyle.hpp
"
10
#include <QDataStream>
11
#include <QIODevice>
12
13
using namespace
dunedaq::oks
;
14
15
dbse::CustomTableModel::CustomTableModel
(QStringList Headers, QObject* parent)
16
: QAbstractTableModel(parent)
17
,
HeaderList
(Headers)
18
{
19
setupModel
();
20
}
21
22
dbse::CustomTableModel::~CustomTableModel
() {}
23
24
int
25
dbse::CustomTableModel::rowCount
(
const
QModelIndex& parent)
const
26
{
27
Q_UNUSED(parent);
28
return
m_data
.size();
29
}
30
31
int
32
dbse::CustomTableModel::columnCount
(
const
QModelIndex& parent)
const
33
{
34
Q_UNUSED(parent);
35
return
HeaderList
.size();
36
}
37
38
Qt::ItemFlags
39
dbse::CustomTableModel::flags
(
const
QModelIndex& index)
const
40
{
41
Q_UNUSED(index);
42
return
Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
43
}
44
45
QVariant
46
dbse::CustomTableModel::headerData
(
int
section
, Qt::Orientation orientation,
int
role)
const
47
{
48
if
(role != Qt::DisplayRole) {
49
return
QVariant();
50
}
51
52
if
(orientation == Qt::Horizontal) {
53
return
HeaderList
.at(
section
);
54
}
55
56
return
QVariant();
57
}
58
59
QVariant
60
dbse::CustomTableModel::data
(
const
QModelIndex& index,
int
role)
const
61
{
62
if
(role == Qt::DisplayRole) {
63
return
m_data
.value(index.row()).value(index.column());
64
}
65
if
(role == Qt::ToolTipRole) {
66
return
m_tooltips
.value(index.row()).value(index.column());
67
}
68
if
(role == Qt::ForegroundRole) {
69
return
m_brushes
.at(index.row());
70
}
71
if
(role == Qt::BackgroundRole) {
72
return
m_backgrounds
.at(index.row());
73
}
74
75
return
QVariant();
76
}
77
78
QStringList
79
dbse::CustomTableModel::getRowFromIndex
(QModelIndex& index)
80
{
81
if
(!index.isValid()) {
82
return
QStringList();
83
}
84
85
return
m_data
.at(index.row());
86
}
87
88
void
89
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
QList<QString> Row;
96
OksClass
* Class = ClassList.at(i);
97
Row.append(QString(Class->
get_name
().c_str()));
98
m_data
.append(Row);
99
m_tooltips
.append(QStringList{ QString(Class->
get_description
().c_str()) });
100
101
auto
fn = Class->
get_file
()->
get_full_file_name
();
102
if
(!
KernelWrapper::GetInstance
().IsFileWritable(fn)) {
103
m_brushes
.emplace_back(QBrush(
SchemaStyle::get_color
(
"foreground"
,
"readonly"
)));
104
m_backgrounds
.emplace_back(
SchemaStyle::get_color
(
"background"
,
"readonly"
));
105
}
else
if
(fn ==
KernelWrapper::GetInstance
().GetActiveSchema()) {
106
m_brushes
.emplace_back(QBrush(
SchemaStyle::get_color
(
"foreground"
,
"active_file"
)));
107
m_backgrounds
.emplace_back(
SchemaStyle::get_color
(
"background"
,
"active_file"
));
108
}
else
{
109
m_brushes
.emplace_back(QBrush(
SchemaStyle::get_color
(
"foreground"
,
"default"
)));
110
m_backgrounds
.emplace_back(
SchemaStyle::get_color
(
"background"
,
"default"
));
111
}
112
}
113
}
114
115
QStringList
116
dbse::CustomTableModel::mimeTypes
()
const
117
{
118
QStringList types;
119
types <<
"application/vnd.text.list"
;
120
return
types;
121
}
122
123
QMimeData*
124
dbse::CustomTableModel::mimeData
(
const
QModelIndexList& indexes)
const
125
{
126
QMimeData*
mimeData
=
new
QMimeData();
127
QByteArray encodedData;
128
129
QDataStream stream(&encodedData, QIODevice::WriteOnly);
130
131
foreach
(QModelIndex index, indexes) {
132
if
(index.isValid() && index.column() == 0) {
133
QString ClassName =
data
(index, Qt::DisplayRole).toString();
134
stream << ClassName;
135
}
136
}
137
138
mimeData
->setData(
"application/vnd.text.list"
, encodedData);
139
return
mimeData
;
140
}
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:124
dbse::CustomTableModel::data
QVariant data(const QModelIndex &index, int role) const
Definition
SchemaCustomTableModel.cpp:60
dbse::CustomTableModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition
SchemaCustomTableModel.cpp:46
dbse::CustomTableModel::CustomTableModel
CustomTableModel(QStringList Headers, QObject *parent=nullptr)
Definition
SchemaCustomTableModel.cpp:15
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:32
dbse::CustomTableModel::mimeTypes
QStringList mimeTypes() const
Drag/Drop Handlers.
Definition
SchemaCustomTableModel.cpp:116
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:22
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:39
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:19
dbse::KernelWrapper::GetClassList
void GetClassList(std::vector< dunedaq::oks::OksClass * > &ClassList) const
Definition
SchemaKernelWrapper.cpp:43
dunedaq::oks::OksClass
The OKS class.
Definition
class.hpp:223
dunedaq::oks::OksClass::get_name
const std::string & get_name() const noexcept
Definition
class.hpp:374
dunedaq::oks::OksClass::get_description
const std::string & get_description() const noexcept
Definition
class.hpp:378
dunedaq::oks::OksClass::get_file
OksFile * get_file() const noexcept
Definition
class.hpp:352
dunedaq::oks::OksFile::get_full_file_name
const std::string & get_full_file_name() const
Definition
file.hpp:528
dunedaq::oks
Definition
SchemaCommand.hpp:17
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:105
Generated on
for DUNE-DAQ by
1.18.0