DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SchemaCustomFileModel.cpp
Go to the documentation of this file.
1
4#include "dbe/SchemaStyle.hpp"
6#include <vector>
7
8#include <QBrush>
9#include <QColor>
10#include <QSize>
11
12dbse::CustomFileModel::CustomFileModel(QStringList& Headers, QObject* parent)
13 : QAbstractTableModel(parent)
14 , HeaderList(Headers)
15{
16 setupModel();
17}
18
20
21int
22dbse::CustomFileModel::rowCount(const QModelIndex& parent) const
23{
24 Q_UNUSED(parent);
25 return Data.size();
26}
27
28int
29dbse::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
45QVariant
46dbse::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
59QVariant
60dbse::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
90void
92{
93 std::vector<std::string> 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
123QStringList
125{
126 if (!index.isValid()) {
127 return QStringList();
128 }
129
130 return Data.at(index.row());
131}
QStringList getRowFromIndex(QModelIndex &index)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
QVariant data(const QModelIndex &index, int role) const
int columnCount(const QModelIndex &parent) const
int rowCount(const QModelIndex &parent) const
CustomFileModel(QStringList &Headers, QObject *parent=nullptr)
Including Schema Editor.
std::string GetActiveSchema() const
static KernelWrapper & GetInstance()
std::string ModifiedSchemaFiles() const
void GetSchemaFiles(std::vector< std::string > &SchemaFiles)
static QColor get_color(const QString &item, const QString &group)