DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
tableselection.cpp
Go to the documentation of this file.
2
3#include "dbe/messenger.hpp"
4
6 : QSortFilterProxyModel ( parent ),
7 Type ( ExactFilter )
8{
10}
11
17
18dbe::TableNode * dbe::models::tableselection::getnode ( const QModelIndex & index ) const
19{
20 if ( index.isValid() )
21 {
22 QModelIndex sourceParent = mapToSource ( index );
23 dbe::models::table * my = dynamic_cast<dbe::models::table *> ( sourceModel() );
24
25 if ( my != 0 )
26 {
27 return my->getnode ( sourceParent );
28 }
29 else
30 {
31 return nullptr;
32 }
33 }
34 else
35 {
36 return nullptr;
37 }
38}
39
40bool dbe::models::tableselection::setData ( const QModelIndex & index,
41 const QVariant & value,
42 int role )
43{
44 if ( index.isValid() )
45 {
46 QModelIndex sourceParent;
47
48 int idx_row = index.row();
49 int idx_col = index.column();
50
51 try
52 {
53 QModelIndex idx_index = this->index ( idx_row, idx_col );
54 sourceParent = mapToSource ( idx_index );
55 }
56 catch ( std::exception const & stderr )
57 {
58 WARN ( "Error setting data", stderr.what() );
59 return true;
60 }
61
62 bool success = sourceModel()->setData ( sourceParent, value, role );
63 QModelIndex idx_index = this->index ( idx_row, idx_col );
64 emit dataChanged ( idx_index, idx_index );
65
66 return success;
67 }
68 else
69 {
70 return true;
71 }
72}
73
75{
76 beginResetModel();
77 endResetModel();
78}
79
81 const QModelIndex & sourceParent ) const
82{
83 QModelIndex index0 = sourceModel()->index ( sourceRow, 0, sourceParent );
84
85 if ( filterRegExp().isEmpty() )
86 {
87 return true;
88 }
89
90 switch ( Type )
91 {
93 if ( filterRegExp().indexIn ( sourceModel()->data ( index0 ).toString() ) != -1 )
94 {
95 return true;
96 }
97 else
98 {
99 return false;
100 }
101
103 return ( filterRegExp().exactMatch ( sourceModel()->data ( index0 ).toString() ) );
104
105 default:
106 return true;
107 }
108}
109
110bool dbe::models::tableselection::lessThan ( const QModelIndex & left,
111 const QModelIndex & right ) const
112{
113 QVariant LeftData = sourceModel()->data ( left );
114 QVariant RightData = sourceModel()->data ( right );
115
116 switch ( LeftData.type() )
117 {
118 case QVariant::Bool:
119 case QVariant::UInt:
120 return ( LeftData.toUInt() < RightData.toUInt() );
121
122 case QVariant::Int:
123 return ( LeftData.toInt() < RightData.toInt() );
124
125 case QVariant::String:
126 {
127 const QString& l = LeftData.toString();
128 const QString& r = RightData.toString();
129
130 bool ok;
131 const double ld = l.toDouble(&ok);
132 if(ok == true) {
133 return ( ld < r.toDouble());
134 }
135
136 const qint64 lll = l.toLongLong(&ok);
137 if(ok == true) {
138 return (lll < r.toLongLong());
139 }
140
141 const quint64 lull = l.toULongLong(&ok);
142 if(ok == true) {
143 return (lull < r.toULongLong());
144 }
145
146 return ((l).compare(r) > 0);
147 }
148
149 default:
150 return false;
151 }
152
153 return true;
154}
155
156dbe::tref dbe::models::tableselection::getobject ( QModelIndex const & index ) const
157{
158 if ( index.isValid() )
159 {
160 if ( models::table * src_model = dynamic_cast<dbe::models::table *>
161 ( this->sourceModel() ) )
162 {
163 QModelIndex const src_index = this->mapToSource ( index );
164
165 if ( src_index.isValid() )
166 {
167 return src_model->GetTableObject ( src_index.row() );
168 }
169 }
170 }
171
172 throw daq::dbe::cannot_handle_invalid_qmodelindex ( ERS_HERE );
173}
174
176const
177{
178 if ( index.isValid() )
179 {
180 if ( dbe::models::table * src_model =
181 dynamic_cast<dbe::models::table *> ( this->sourceModel() ) )
182 {
183 QModelIndex const src_index = this->mapToSource ( index );
184
185 if ( src_index.isValid() )
186 {
187 return src_model->getclass ( src_index );
188 }
189 }
190 }
191
193}
194
195QAbstractItemModel * dbe::models::tableselection::ReturnSourceModel() const
196{
197 return nullptr;
198}
199
200//-----------------------------------------------------------------------------------------------------
204
208
212
216
217//-----------------------------------------------------------------------------------------------------
218
219//-----------------------------------------------------------------------------------------------------
224//-----------------------------------------------------------------------------------------------------
225
226//-----------------------------------------------------------------------------------------------------
231
233//------------------------------------------------------------------------------------------
#define ERS_HERE
TableNode * getnode(const QModelIndex &Index) const
Definition table.cpp:455
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:80
#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)
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