DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbse::CustomTableModel Class Reference

#include <SchemaCustomTableModel.hpp>

Inheritance diagram for dbse::CustomTableModel:
[legend]
Collaboration diagram for dbse::CustomTableModel:
[legend]

Public Member Functions

 CustomTableModel (QStringList Headers, QObject *parent=nullptr)
 ~CustomTableModel ()
int rowCount (const QModelIndex &parent) const
int columnCount (const QModelIndex &parent) const
Qt::ItemFlags flags (const QModelIndex &index) const
QVariant headerData (int section, Qt::Orientation orientation, int role) const
QVariant data (const QModelIndex &index, int role) const
QStringList getRowFromIndex (QModelIndex &index)
void setupModel ()
QStringList mimeTypes () const
 Drag/Drop Handlers.
QMimeData * mimeData (const QModelIndexList &indexes) const

Private Attributes

QStringList HeaderList
QList< QList< QString > > m_data
QList< QList< QString > > m_tooltips
std::vector< QBrush > m_brushes
std::vector< QColor > m_backgrounds

Detailed Description

Definition at line 21 of file SchemaCustomTableModel.hpp.

Constructor & Destructor Documentation

◆ CustomTableModel()

dbse::CustomTableModel::CustomTableModel ( QStringList Headers,
QObject * parent = nullptr )
explicit

Definition at line 14 of file SchemaCustomTableModel.cpp.

15 : QAbstractTableModel ( parent ),
16 HeaderList ( Headers )
17{
18 setupModel();
19}

◆ ~CustomTableModel()

dbse::CustomTableModel::~CustomTableModel ( )

Definition at line 21 of file SchemaCustomTableModel.cpp.

22{
23}

Member Function Documentation

◆ columnCount()

int dbse::CustomTableModel::columnCount ( const QModelIndex & parent) const

Definition at line 31 of file SchemaCustomTableModel.cpp.

32{
33 Q_UNUSED ( parent );
34 return HeaderList.size();
35}

◆ data()

QVariant dbse::CustomTableModel::data ( const QModelIndex & index,
int role ) const

Definition at line 59 of file SchemaCustomTableModel.cpp.

60{
61 if ( role == Qt::DisplayRole )
62 {
63 return m_data.value ( index.row() ).value ( index.column() );
64 }
65 if ( role == Qt::ToolTipRole )
66 {
67 return m_tooltips.value ( index.row() ).value ( index.column() );
68 }
69 if (role == Qt::ForegroundRole) {
70 return m_brushes.at(index.row());
71 }
72 if (role == Qt::BackgroundRole) {
73 return m_backgrounds.at(index.row());
74 }
75
76 return QVariant();
77}
QList< QList< QString > > m_tooltips
QList< QList< QString > > m_data
std::vector< QColor > m_backgrounds
std::vector< QBrush > m_brushes

◆ flags()

Qt::ItemFlags dbse::CustomTableModel::flags ( const QModelIndex & index) const

Definition at line 37 of file SchemaCustomTableModel.cpp.

38{
39 Q_UNUSED ( index );
40 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
41}

◆ getRowFromIndex()

QStringList dbse::CustomTableModel::getRowFromIndex ( QModelIndex & index)

Definition at line 79 of file SchemaCustomTableModel.cpp.

80{
81 if ( !index.isValid() )
82 {
83 return QStringList();
84 }
85
86 return m_data.at ( index.row() );
87}

◆ headerData()

QVariant dbse::CustomTableModel::headerData ( int section,
Qt::Orientation orientation,
int role ) const

Definition at line 43 of file SchemaCustomTableModel.cpp.

45{
46 if ( role != Qt::DisplayRole )
47 {
48 return QVariant();
49 }
50
51 if ( orientation == Qt::Horizontal )
52 {
53 return HeaderList.at ( section );
54 }
55
56 return QVariant();
57}

◆ mimeData()

QMimeData * dbse::CustomTableModel::mimeData ( const QModelIndexList & indexes) const

Definition at line 125 of file SchemaCustomTableModel.cpp.

126{
127 QMimeData * mimeData = new QMimeData();
128 QByteArray encodedData;
129
130 QDataStream stream ( &encodedData, QIODevice::WriteOnly );
131
132 foreach ( QModelIndex index, indexes )
133 {
134 if ( index.isValid() && index.column() == 0 )
135 {
136 QString ClassName = data ( index, Qt::DisplayRole ).toString();
137 stream << ClassName;
138 }
139 }
140
141 mimeData->setData ( "application/vnd.text.list", encodedData );
142 return mimeData;
143}
QMimeData * mimeData(const QModelIndexList &indexes) const
QVariant data(const QModelIndex &index, int role) const

◆ mimeTypes()

QStringList dbse::CustomTableModel::mimeTypes ( ) const

Drag/Drop Handlers.

Definition at line 118 of file SchemaCustomTableModel.cpp.

119{
120 QStringList types;
121 types << "application/vnd.text.list";
122 return types;
123}

◆ rowCount()

int dbse::CustomTableModel::rowCount ( const QModelIndex & parent) const

Definition at line 25 of file SchemaCustomTableModel.cpp.

26{
27 Q_UNUSED ( parent );
28 return m_data.size();
29}

◆ setupModel()

void dbse::CustomTableModel::setupModel ( )

Definition at line 89 of file SchemaCustomTableModel.cpp.

90{
91 std::vector<OksClass *> ClassList;
93
94 for ( unsigned int i = 0; i < ClassList.size(); ++i )
95 {
96 QList<QString> Row;
97 OksClass * Class = ClassList.at ( i );
98 Row.append ( QString ( Class->get_name().c_str() ) );
99 m_data.append ( Row );
100 m_tooltips.append (QStringList {QString ( Class->get_description().c_str() )});
101
102 auto fn = Class->get_file()->get_full_file_name();
103 if (!KernelWrapper::GetInstance().IsFileWritable (fn)) {
104 m_brushes.emplace_back(QBrush(SchemaStyle::get_color("foreground", "readonly")));
105 m_backgrounds.emplace_back(SchemaStyle::get_color("background", "readonly"));
106 }
107 else if (fn == KernelWrapper::GetInstance().GetActiveSchema()) {
108 m_brushes.emplace_back(QBrush(SchemaStyle::get_color("foreground", "active_file")));
109 m_backgrounds.emplace_back(SchemaStyle::get_color("background", "active_file"));
110 }
111 else {
112 m_brushes.emplace_back(QBrush(SchemaStyle::get_color("foreground", "default")));
113 m_backgrounds.emplace_back(SchemaStyle::get_color("background", "default"));
114 }
115 }
116}
static KernelWrapper & GetInstance()
void GetClassList(std::vector< dunedaq::oks::OksClass * > &ClassList) const
const std::string & get_name() const noexcept
Definition class.hpp:368
const std::string & get_description() const noexcept
Definition class.hpp:373
OksFile * get_file() const noexcept
Definition class.hpp:343
const std::string & get_full_file_name() const
Definition file.hpp:528
static QColor get_color(const QString &item, const QString &group)

Member Data Documentation

◆ HeaderList

QStringList dbse::CustomTableModel::HeaderList
private

Definition at line 38 of file SchemaCustomTableModel.hpp.

◆ m_backgrounds

std::vector<QColor> dbse::CustomTableModel::m_backgrounds
private

Definition at line 42 of file SchemaCustomTableModel.hpp.

◆ m_brushes

std::vector<QBrush> dbse::CustomTableModel::m_brushes
private

Definition at line 41 of file SchemaCustomTableModel.hpp.

◆ m_data

QList<QList<QString> > dbse::CustomTableModel::m_data
private

Definition at line 39 of file SchemaCustomTableModel.hpp.

◆ m_tooltips

QList<QList<QString> > dbse::CustomTableModel::m_tooltips
private

Definition at line 40 of file SchemaCustomTableModel.hpp.


The documentation for this class was generated from the following files: