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
22
23int dbse::CustomFileModel::rowCount ( const QModelIndex & parent ) const
24{
25 Q_UNUSED ( parent );
26 return Data.size();
27}
28
29int 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
45QVariant dbse::CustomFileModel::headerData ( int section, Qt::Orientation orientation,
46 int role ) const
47{
48 if ( role != Qt::DisplayRole )
49 {
50 return QVariant();
51 }
52
53 if ( orientation == Qt::Horizontal )
54 {
55 return HeaderList.at ( section );
56 }
57
58 return QVariant();
59}
60
61QVariant dbse::CustomFileModel::data ( const QModelIndex & index, int role ) const
62{
63 if ( role == Qt::DisplayRole ) {
64 return Data.value(index.row()).value(index.column());
65 }
66 if (role == Qt::ForegroundRole) {
67 if (Data.value(index.row()).value(2).contains("Active")) {
68 return QBrush(QColor (SchemaStyle::get_color("foreground", "active_file")));
69 }
70 if (Data.value(index.row()).value(1) == "RW" ) {
71 return QBrush(QColor (SchemaStyle::get_color("foreground", "default")));
72 }
73 return QBrush(SchemaStyle::get_color("foreground", "readonly"));
74 }
75 if (role == Qt::BackgroundRole) {
76 if (Data.value(index.row()).value(2).contains("Active")) {
77 return QBrush(QColor (SchemaStyle::get_color("background", "active_file")));
78 }
79 if (Data.value(index.row()).value(1) == "RW" ) {
80 return QBrush(QColor (SchemaStyle::get_color("background", "default")));
81 }
82 return QBrush(SchemaStyle::get_color("background", "readonly"));
83 }
84 if (role == Qt::ToolTipRole) {
85 return Data.value(index.row()).value(0);
86 }
87
88 return QVariant();
89}
90
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 {
99 QStringList Row;
100 Row.append ( QString::fromStdString ( FileName ) );
101
102 if ( KernelWrapper::GetInstance().IsFileWritable ( FileName ) )
103 {
104 Row.append ( "RW" );
105 }
106 else
107 {
108 Row.append ( "RO" );
109 }
110
111 std::string Status = "";
112 if ( Modified.find( FileName ) != std::string::npos) {
113 Status = "Modified";
114 }
115 if ( FileName == ActiveSchema) {
116 if ( !Status.empty() ) {
117 Status += " ";
118 }
119 Status += "Active";
120 }
121
122 Row.append ( QString::fromStdString ( Status ) );
123 Data.append ( Row );
124 }
125}
126
127QStringList dbse::CustomFileModel::getRowFromIndex ( QModelIndex & index )
128{
129 if ( !index.isValid() )
130 {
131 return QStringList();
132 }
133
134 return Data.at ( index.row() );
135}
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)