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