DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
tableselection.cpp
Go to the documentation of this file.
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: no.
5
7
8#include "dbe/messenger.hpp"
9
11 : QSortFilterProxyModel(parent)
13{
15}
16
17void
22
24dbe::models::tableselection::getnode(const QModelIndex& index) const
25{
26 if (index.isValid()) {
27 QModelIndex sourceParent = mapToSource(index);
28 dbe::models::table* my = dynamic_cast<dbe::models::table*>(sourceModel());
29
30 if (my != 0) {
31 return my->getnode(sourceParent);
32 } else {
33 return nullptr;
34 }
35 } else {
36 return nullptr;
37 }
38}
39
40bool
41dbe::models::tableselection::setData(const QModelIndex& index, const QVariant& value, int role)
42{
43 if (index.isValid()) {
44 QModelIndex sourceParent;
45
46 int idx_row = index.row();
47 int idx_col = index.column();
48
49 try {
50 QModelIndex idx_index = this->index(idx_row, idx_col);
51 sourceParent = mapToSource(idx_index);
52 } catch (std::exception const& stderr) {
53 WARN("Error setting data", stderr.what());
54 return true;
55 }
56
57 bool success = sourceModel()->setData(sourceParent, value, role);
58 QModelIndex idx_index = this->index(idx_row, idx_col);
59 emit dataChanged(idx_index, idx_index);
60
61 return success;
62 } else {
63 return true;
64 }
65}
66
67void
69{
70 beginResetModel();
71 endResetModel();
72}
73
74bool
75dbe::models::tableselection::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
76{
77 QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
78
79 if (filterRegExp().isEmpty()) {
80 return true;
81 }
82
83 switch (Type) {
85 if (filterRegExp().indexIn(sourceModel()->data(index0).toString()) != -1) {
86 return true;
87 } else {
88 return false;
89 }
90
92 return (filterRegExp().exactMatch(sourceModel()->data(index0).toString()));
93
94 default:
95 return true;
96 }
97}
98
99bool
100dbe::models::tableselection::lessThan(const QModelIndex& left, const QModelIndex& right) const
101{
102 QVariant LeftData = sourceModel()->data(left);
103 QVariant RightData = sourceModel()->data(right);
104
105 switch (LeftData.type()) {
106 case QVariant::Bool:
107 case QVariant::UInt:
108 return (LeftData.toUInt() < RightData.toUInt());
109
110 case QVariant::Int:
111 return (LeftData.toInt() < RightData.toInt());
112
113 case QVariant::String: {
114 const QString& l = LeftData.toString();
115 const QString& r = RightData.toString();
116
117 bool ok;
118 const double ld = l.toDouble(&ok);
119 if (ok == true) {
120 return (ld < r.toDouble());
121 }
122
123 const qint64 lll = l.toLongLong(&ok);
124 if (ok == true) {
125 return (lll < r.toLongLong());
126 }
127
128 const quint64 lull = l.toULongLong(&ok);
129 if (ok == true) {
130 return (lull < r.toULongLong());
131 }
132
133 return ((l).compare(r) > 0);
134 }
135
136 default:
137 return false;
138 }
139
140 return true;
141}
142
144dbe::models::tableselection::getobject(QModelIndex const& index) const
145{
146 if (index.isValid()) {
147 if (models::table* src_model = dynamic_cast<dbe::models::table*>(this->sourceModel())) {
148 QModelIndex const src_index = this->mapToSource(index);
149
150 if (src_index.isValid()) {
151 return src_model->GetTableObject(src_index.row());
152 }
153 }
154 }
155
156 throw daq::dbe::cannot_handle_invalid_qmodelindex(ERS_HERE);
157}
158
159dunedaq::conffwk::class_t
160dbe::models::tableselection::getclass(QModelIndex const& index) const
161{
162 if (index.isValid()) {
163 if (dbe::models::table* src_model = dynamic_cast<dbe::models::table*>(this->sourceModel())) {
164 QModelIndex const src_index = this->mapToSource(index);
165
166 if (src_index.isValid()) {
167 return src_model->getclass(src_index);
168 }
169 }
170 }
171
172 return dunedaq::conffwk::class_t();
173}
174
175QAbstractItemModel*
177{
178 return nullptr;
179}
180
181//-----------------------------------------------------------------------------------------------------
183{
184 Q_UNUSED(index);
185 Q_UNUSED(obj);
186}
187
192
194{
195 Q_UNUSED(index);
196 Q_UNUSED(obj);
197}
198
200{
201 Q_UNUSED(index);
202 Q_UNUSED(obj);
203}
204
205//-----------------------------------------------------------------------------------------------------
206
207//-----------------------------------------------------------------------------------------------------
209{
210 Q_UNUSED(obj);
211 return QModelIndex();
212}
213//-----------------------------------------------------------------------------------------------------
214
215//-----------------------------------------------------------------------------------------------------
217{
218 Q_UNUSED(row);
219 Q_UNUSED(count);
220 Q_UNUSED(parent);
221 return true;
222}
223
224MODEL_COMMON_INTERFACE_SLOTS_DEF(dbe::models::tableselection)
225//------------------------------------------------------------------------------------------
#define ERS_HERE
TableNode * getnode(const QModelIndex &Index) const
Definition table.cpp:442
TableNode * getnode(const QModelIndex &index) const
void SetFilterType(FilterType Filter)
bool setData(const QModelIndex &index, const QVariant &value, int role)
bool lessThan(const QModelIndex &left, const QModelIndex &right) const
tableselection(QObject *parent=0)
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
#define WARN(...)
Definition messenger.hpp:82
#define MODEL_COMMON_INTERFACE_LOOKUP_IMPL(classname)
#define MODEL_REMOVE_ROWS_DEF(classname)
#define MODEL_COMMON_INTERFACE_RENAME_THAT_OBJ_IMPL(classname)
#define MODEL_COMMON_INTERFACE_UPDATE_THAT_OBJ_IMPL(classname)
#define MODEL_COMMON_INTERFACE_DELETE_THAT_OBJ_IMPL(classname)
#define MODEL_COMMON_INTERFACE_SLOTS_DEF(classname)
#define MODEL_COMMON_INTERFACE_CREATE_THAT_OBJ_IMPL(classname)
inner::configobject::tref tref
Definition tref.hpp:36
virtual type_class_info getclass(type_index const &index) const =0
virtual type_object_ref getobject(type_index const &index) const =0
virtual QAbstractItemModel * ReturnSourceModel() const =0