Line data Source code
1 : // DUNE DAQ modification notice:
2 : // This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3 : // Fork baseline commit: dbe-02-12-17 (2022-05-12).
4 : // Renamed since fork: yes (from src/SchemaEditor/SchemaCustomTableModel.cpp to apps/SchemaEditor/SchemaCustomTableModel.cpp).
5 :
6 : #include "dbe/SchemaCustomTableModel.hpp"
7 : #include "dbe/SchemaKernelWrapper.hpp"
8 : #include "dbe/SchemaStyle.hpp"
9 : #include <QIODevice>
10 : #include <QDataStream>
11 :
12 : using namespace dunedaq::oks;
13 :
14 0 : dbse::CustomTableModel::CustomTableModel ( QStringList Headers, QObject * parent )
15 : : QAbstractTableModel ( parent ),
16 0 : HeaderList ( Headers )
17 : {
18 0 : setupModel();
19 0 : }
20 :
21 0 : dbse::CustomTableModel::~CustomTableModel()
22 : {
23 0 : }
24 :
25 0 : int dbse::CustomTableModel::rowCount ( const QModelIndex & parent ) const
26 : {
27 0 : Q_UNUSED ( parent );
28 0 : return m_data.size();
29 : }
30 :
31 0 : int dbse::CustomTableModel::columnCount ( const QModelIndex & parent ) const
32 : {
33 0 : Q_UNUSED ( parent );
34 0 : return HeaderList.size();
35 : }
36 :
37 0 : Qt::ItemFlags dbse::CustomTableModel::flags ( const QModelIndex & index ) const
38 : {
39 0 : Q_UNUSED ( index );
40 0 : return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
41 : }
42 :
43 0 : QVariant dbse::CustomTableModel::headerData ( int section, Qt::Orientation orientation,
44 : int role ) const
45 : {
46 0 : if ( role != Qt::DisplayRole )
47 : {
48 0 : return QVariant();
49 : }
50 :
51 0 : if ( orientation == Qt::Horizontal )
52 : {
53 0 : return HeaderList.at ( section );
54 : }
55 :
56 0 : return QVariant();
57 : }
58 :
59 0 : QVariant dbse::CustomTableModel::data ( const QModelIndex & index, int role ) const
60 : {
61 0 : if ( role == Qt::DisplayRole )
62 : {
63 0 : return m_data.value ( index.row() ).value ( index.column() );
64 : }
65 0 : if ( role == Qt::ToolTipRole )
66 : {
67 0 : return m_tooltips.value ( index.row() ).value ( index.column() );
68 : }
69 0 : if (role == Qt::ForegroundRole) {
70 0 : return m_brushes.at(index.row());
71 : }
72 0 : if (role == Qt::BackgroundRole) {
73 0 : return m_backgrounds.at(index.row());
74 : }
75 :
76 0 : return QVariant();
77 : }
78 :
79 0 : QStringList dbse::CustomTableModel::getRowFromIndex ( QModelIndex & index )
80 : {
81 0 : if ( !index.isValid() )
82 : {
83 0 : return QStringList();
84 : }
85 :
86 0 : return m_data.at ( index.row() );
87 : }
88 :
89 0 : void dbse::CustomTableModel::setupModel()
90 : {
91 0 : std::vector<OksClass *> ClassList;
92 0 : KernelWrapper::GetInstance().GetClassList ( ClassList );
93 :
94 0 : for ( unsigned int i = 0; i < ClassList.size(); ++i )
95 : {
96 0 : QList<QString> Row;
97 0 : OksClass * Class = ClassList.at ( i );
98 0 : Row.append ( QString ( Class->get_name().c_str() ) );
99 0 : m_data.append ( Row );
100 0 : m_tooltips.append (QStringList {QString ( Class->get_description().c_str() )});
101 :
102 0 : auto fn = Class->get_file()->get_full_file_name();
103 0 : if (!KernelWrapper::GetInstance().IsFileWritable (fn)) {
104 0 : m_brushes.emplace_back(QBrush(SchemaStyle::get_color("foreground", "readonly")));
105 0 : m_backgrounds.emplace_back(SchemaStyle::get_color("background", "readonly"));
106 : }
107 0 : else if (fn == KernelWrapper::GetInstance().GetActiveSchema()) {
108 0 : m_brushes.emplace_back(QBrush(SchemaStyle::get_color("foreground", "active_file")));
109 0 : m_backgrounds.emplace_back(SchemaStyle::get_color("background", "active_file"));
110 : }
111 : else {
112 0 : m_brushes.emplace_back(QBrush(SchemaStyle::get_color("foreground", "default")));
113 0 : m_backgrounds.emplace_back(SchemaStyle::get_color("background", "default"));
114 : }
115 0 : }
116 0 : }
117 :
118 0 : QStringList dbse::CustomTableModel::mimeTypes() const
119 : {
120 0 : QStringList types;
121 0 : types << "application/vnd.text.list";
122 0 : return types;
123 0 : }
124 :
125 0 : QMimeData * dbse::CustomTableModel::mimeData ( const QModelIndexList & indexes ) const
126 : {
127 0 : QMimeData * mimeData = new QMimeData();
128 0 : QByteArray encodedData;
129 :
130 0 : QDataStream stream ( &encodedData, QIODevice::WriteOnly );
131 :
132 0 : foreach ( QModelIndex index, indexes )
133 : {
134 0 : if ( index.isValid() && index.column() == 0 )
135 : {
136 0 : QString ClassName = data ( index, Qt::DisplayRole ).toString();
137 0 : stream << ClassName;
138 0 : }
139 0 : }
140 :
141 0 : mimeData->setData ( "application/vnd.text.list", encodedData );
142 0 : return mimeData;
143 0 : }
|