DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
apps
SchemaEditor
SchemaCustomFileModel.cpp
Go to the documentation of this file.
1
2
#include "
dbe/SchemaCustomFileModel.hpp
"
3
#include "
dbe/SchemaKernelWrapper.hpp
"
4
#include "
dbe/SchemaStyle.hpp
"
6
#include <vector>
7
8
#include <QBrush>
9
#include <QColor>
10
#include <QSize>
11
12
dbse::CustomFileModel::CustomFileModel
(QStringList& Headers, QObject* parent)
13
: QAbstractTableModel(parent)
14
,
HeaderList
(Headers)
15
{
16
setupModel
();
17
}
18
19
dbse::CustomFileModel::~CustomFileModel
() {}
20
21
int
22
dbse::CustomFileModel::rowCount
(
const
QModelIndex& parent)
const
23
{
24
Q_UNUSED(parent);
25
return
Data
.size();
26
}
27
28
int
29
dbse::CustomFileModel::columnCount
(
const
QModelIndex& parent)
const
30
{
31
Q_UNUSED(parent);
32
return
HeaderList
.size();
33
}
34
35
// Qt::ItemFlags dbse::CustomFileModel::flags ( const QModelIndex & index ) const
36
// {
37
// // if ( Data.value (index.row() ).value ( 1) == "RW" ) {
38
// return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
39
// // }
40
// // else {
41
// // return Qt::NoItemFlags;
42
// // }
43
// }
44
45
QVariant
46
dbse::CustomFileModel::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::CustomFileModel::data
(
const
QModelIndex& index,
int
role)
const
61
{
62
if
(role == Qt::DisplayRole) {
63
return
Data
.value(index.row()).value(index.column());
64
}
65
if
(role == Qt::ForegroundRole) {
66
if
(
Data
.value(index.row()).value(2).contains(
"Active"
)) {
67
return
QBrush(QColor(
SchemaStyle::get_color
(
"foreground"
,
"active_file"
)));
68
}
69
if
(
Data
.value(index.row()).value(1) ==
"RW"
) {
70
return
QBrush(QColor(
SchemaStyle::get_color
(
"foreground"
,
"default"
)));
71
}
72
return
QBrush(
SchemaStyle::get_color
(
"foreground"
,
"readonly"
));
73
}
74
if
(role == Qt::BackgroundRole) {
75
if
(
Data
.value(index.row()).value(2).contains(
"Active"
)) {
76
return
QBrush(QColor(
SchemaStyle::get_color
(
"background"
,
"active_file"
)));
77
}
78
if
(
Data
.value(index.row()).value(1) ==
"RW"
) {
79
return
QBrush(QColor(
SchemaStyle::get_color
(
"background"
,
"default"
)));
80
}
81
return
QBrush(
SchemaStyle::get_color
(
"background"
,
"readonly"
));
82
}
83
if
(role == Qt::ToolTipRole) {
84
return
Data
.value(index.row()).value(0);
85
}
86
87
return
QVariant();
88
}
89
90
void
91
dbse::CustomFileModel::setupModel
()
92
{
93
std::vector<std::string> SchemaFiles;
94
KernelWrapper::GetInstance
().
GetSchemaFiles
(SchemaFiles);
95
std::string ActiveSchema =
KernelWrapper::GetInstance
().
GetActiveSchema
();
96
std::string Modified =
KernelWrapper::GetInstance
().
ModifiedSchemaFiles
();
97
for
(std::string& FileName : SchemaFiles) {
98
QStringList Row;
99
Row.append(QString::fromStdString(FileName));
100
101
if
(
KernelWrapper::GetInstance
().IsFileWritable(FileName)) {
102
Row.append(
"RW"
);
103
}
else
{
104
Row.append(
"RO"
);
105
}
106
107
std::string Status =
""
;
108
if
(Modified.find(FileName) != std::string::npos) {
109
Status =
"Modified"
;
110
}
111
if
(FileName == ActiveSchema) {
112
if
(!Status.empty()) {
113
Status +=
" "
;
114
}
115
Status +=
"Active"
;
116
}
117
118
Row.append(QString::fromStdString(Status));
119
Data
.append(Row);
120
}
121
}
122
123
QStringList
124
dbse::CustomFileModel::getRowFromIndex
(QModelIndex& index)
125
{
126
if
(!index.isValid()) {
127
return
QStringList();
128
}
129
130
return
Data
.at(index.row());
131
}
SchemaCustomFileModel.hpp
SchemaKernelWrapper.hpp
SchemaStyle.hpp
dbse::CustomFileModel::Data
QList< QStringList > Data
Definition
SchemaCustomFileModel.hpp:31
dbse::CustomFileModel::getRowFromIndex
QStringList getRowFromIndex(QModelIndex &index)
Definition
SchemaCustomFileModel.cpp:124
dbse::CustomFileModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition
SchemaCustomFileModel.cpp:46
dbse::CustomFileModel::HeaderList
QStringList HeaderList
Definition
SchemaCustomFileModel.hpp:30
dbse::CustomFileModel::data
QVariant data(const QModelIndex &index, int role) const
Definition
SchemaCustomFileModel.cpp:60
dbse::CustomFileModel::~CustomFileModel
~CustomFileModel()
Definition
SchemaCustomFileModel.cpp:19
dbse::CustomFileModel::setupModel
void setupModel()
Definition
SchemaCustomFileModel.cpp:91
dbse::CustomFileModel::columnCount
int columnCount(const QModelIndex &parent) const
Definition
SchemaCustomFileModel.cpp:29
dbse::CustomFileModel::rowCount
int rowCount(const QModelIndex &parent) const
Definition
SchemaCustomFileModel.cpp:22
dbse::CustomFileModel::CustomFileModel
CustomFileModel(QStringList &Headers, QObject *parent=nullptr)
Including Schema Editor.
Definition
SchemaCustomFileModel.cpp:12
dbse::KernelWrapper::GetActiveSchema
std::string GetActiveSchema() const
Definition
SchemaKernelWrapper.cpp:65
dbse::KernelWrapper::GetInstance
static KernelWrapper & GetInstance()
Definition
SchemaKernelWrapper.cpp:19
dbse::KernelWrapper::ModifiedSchemaFiles
std::string ModifiedSchemaFiles() const
Definition
SchemaKernelWrapper.cpp:201
dbse::KernelWrapper::GetSchemaFiles
void GetSchemaFiles(std::vector< std::string > &SchemaFiles)
Definition
SchemaKernelWrapper.cpp:101
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