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