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
22
23dbe::TableNode * dbe::models::tableselection::getnode ( const QModelIndex & index ) const
24{
25 if ( index.isValid() )
26 {
27 QModelIndex sourceParent = mapToSource ( index );
28 dbe::models::table * my = dynamic_cast<dbe::models::table *> ( sourceModel() );
29
30 if ( my != 0 )
31 {
32 return my->getnode ( sourceParent );
33 }
34 else
35 {
36 return nullptr;
37 }
38 }
39 else
40 {
41 return nullptr;
42 }
43}
44
45bool dbe::models::tableselection::setData ( const QModelIndex & index,
46 const QVariant & value,
47 int role )
48{
49 if ( index.isValid() )
50 {
51 QModelIndex sourceParent;
52
53 int idx_row = index.row();
54 int idx_col = index.column();
55
56 try
57 {
58 QModelIndex idx_index = this->index ( idx_row, idx_col );
59 sourceParent = mapToSource ( idx_index );
60 }
61 catch ( std::exception const & stderr )
62 {
63 WARN ( "Error setting data", stderr.what() );
64 return true;
65 }
66
67 bool success = sourceModel()->setData ( sourceParent, value, role );
68 QModelIndex idx_index = this->index ( idx_row, idx_col );
69 emit dataChanged ( idx_index, idx_index );
70
71 return success;
72 }
73 else
74 {
75 return true;
76 }
77}
78
80{
81 beginResetModel();
82 endResetModel();
83}
84
86 const QModelIndex & sourceParent ) const
87{
88 QModelIndex index0 = sourceModel()->index ( sourceRow, 0, sourceParent );
89
90 if ( filterRegExp().isEmpty() )
91 {
92 return true;
93 }
94
95 switch ( Type )
96 {
98 if ( filterRegExp().indexIn ( sourceModel()->data ( index0 ).toString() ) != -1 )
99 {
100 return true;
101 }
102 else
103 {
104 return false;
105 }
106
108 return ( filterRegExp().exactMatch ( sourceModel()->data ( index0 ).toString() ) );
109
110 default:
111 return true;
112 }
113}
114
115bool dbe::models::tableselection::lessThan ( const QModelIndex & left,
116 const QModelIndex & right ) const
117{
118 QVariant LeftData = sourceModel()->data ( left );
119 QVariant RightData = sourceModel()->data ( right );
120
121 switch ( LeftData.type() )
122 {
123 case QVariant::Bool:
124 case QVariant::UInt:
125 return ( LeftData.toUInt() < RightData.toUInt() );
126
127 case QVariant::Int:
128 return ( LeftData.toInt() < RightData.toInt() );
129
130 case QVariant::String:
131 {
132 const QString& l = LeftData.toString();
133 const QString& r = RightData.toString();
134
135 bool ok;
136 const double ld = l.toDouble(&ok);
137 if(ok == true) {
138 return ( ld < r.toDouble());
139 }
140
141 const qint64 lll = l.toLongLong(&ok);
142 if(ok == true) {
143 return (lll < r.toLongLong());
144 }
145
146 const quint64 lull = l.toULongLong(&ok);
147 if(ok == true) {
148 return (lull < r.toULongLong());
149 }
150
151 return ((l).compare(r) > 0);
152 }
153
154 default:
155 return false;
156 }
157
158 return true;
159}
160
161dbe::tref dbe::models::tableselection::getobject ( QModelIndex const & index ) const
162{
163 if ( index.isValid() )
164 {
165 if ( models::table * src_model = dynamic_cast<dbe::models::table *>
166 ( this->sourceModel() ) )
167 {
168 QModelIndex const src_index = this->mapToSource ( index );
169
170 if ( src_index.isValid() )
171 {
172 return src_model->GetTableObject ( src_index.row() );
173 }
174 }
175 }
176
177 throw daq::dbe::cannot_handle_invalid_qmodelindex ( ERS_HERE );
178}
179
180dunedaq::conffwk::class_t dbe::models::tableselection::getclass ( QModelIndex const & index )
181const
182{
183 if ( index.isValid() )
184 {
185 if ( dbe::models::table * src_model =
186 dynamic_cast<dbe::models::table *> ( this->sourceModel() ) )
187 {
188 QModelIndex const src_index = this->mapToSource ( index );
189
190 if ( src_index.isValid() )
191 {
192 return src_model->getclass ( src_index );
193 }
194 }
195 }
196
197 return dunedaq::conffwk::class_t();
198}
199
200QAbstractItemModel * dbe::models::tableselection::ReturnSourceModel() const
201{
202 return nullptr;
203}
204
205//-----------------------------------------------------------------------------------------------------
207{
208 Q_UNUSED(index);
209 Q_UNUSED(obj);
210}
211
216
218{
219 Q_UNUSED(index);
220 Q_UNUSED(obj);
221}
222
224{
225 Q_UNUSED(index);
226 Q_UNUSED(obj);
227}
228
229//-----------------------------------------------------------------------------------------------------
230
231//-----------------------------------------------------------------------------------------------------
233{
234 Q_UNUSED(obj);
235 return QModelIndex();
236}
237//-----------------------------------------------------------------------------------------------------
238
239//-----------------------------------------------------------------------------------------------------
241{
242 Q_UNUSED(row);
243 Q_UNUSED(count);
244 Q_UNUSED(parent);
245 return true;
246}
247
248MODEL_COMMON_INTERFACE_SLOTS_DEF ( dbe::models::tableselection )
249//------------------------------------------------------------------------------------------
#define ERS_HERE
TableNode * getnode(const QModelIndex &Index) const
Definition table.cpp:481
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:85
#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:35
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