DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
model_common_operations.hpp
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: yes (from dbe/model_common_operations.hpp to include/dbe/model_common_operations.hpp).
5
6/*
7 * model_common_operations.hpp
8 *
9 * Created on: Dec 7, 2015
10 * Author: lgeorgop
11 */
12
13#ifndef DBE_MODEL_COMMON_OPERATIONS_HPP_
14#define DBE_MODEL_COMMON_OPERATIONS_HPP_
15
17#include "dbe/treenode.hpp"
19
20#include <QUuid>
21
22#include <boost/scope_exit.hpp>
23
24//------------------------------------------------------------------------------------------
29template<typename T>
31{
32 static_cast<T *> ( this )->connect (
33 &confaccessor::ref(), SIGNAL ( object_deleted ( QString const &, dref const & ) ),
34 static_cast<T *> ( this ), SLOT ( slot_remove_object ( QString const &, dref const & ) ) );
35 static_cast<T *> ( this )->connect (
36 &confaccessor::ref(), SIGNAL ( object_renamed ( QString const &, dref const & ) ),
37 static_cast<T *> ( this ), SLOT ( slot_rename_object ( QString const &, dref const & ) ) );
38 static_cast<T *> ( this )->connect (
39 &confaccessor::ref(), SIGNAL ( object_changed ( QString const &, dref const & ) ),
40 static_cast<T *> ( this ), SLOT ( slot_update_object ( QString const &, dref const & ) ) );
41 static_cast<T *> ( this )->connect (
42 &confaccessor::ref(), SIGNAL ( object_created ( QString const &, dref const & ) ),
43 static_cast<T *> ( this ), SLOT ( slot_create_object ( QString const &, dref const & ) ) );
44}
45//------------------------------------------------------------------------------------------
46
47//------------------------------------------------------------------------------------------
48template<typename T>
50 type_object_info const & obj )
51{
52 type_index oid ( static_cast<T *> ( this )->lookup ( obj ) );
53
54 if ( oid.isValid() )
55 {
56 static_cast<T *> ( this )->remove_deleted_object ( oid );
57 }
58}
59
60template<typename T>
62 type_object_info const & obj )
63{
64 type_index oid ( static_cast<T *> ( this )->lookup ( obj ) );
65
66 if ( oid.isValid() )
67 {
68 static_cast<T *> ( this )->rename_contained_object ( oid, obj );
69 }
70}
71
72template<typename T>
74 type_object_info const & obj )
75{
76 type_index oid ( static_cast<T *> ( this )->lookup ( obj ) );
77
78 if ( oid.isValid() )
79 {
80 static_cast<T *> ( this )->update_contained_object ( oid, obj );
81 }
82}
83
84template<typename T>
86 std::vector<type_object_info> const & objects )
87{
88 BOOST_SCOPE_EXIT_TPL(this_)
89 {
90 emit static_cast<T *> ( this_ )->layoutChanged();
91 }
92 BOOST_SCOPE_EXIT_END
93
94 static_cast<T *> ( this )->layoutAboutToBeChanged();
95
96 {
97 BOOST_SCOPE_EXIT_TPL(this_)
98 {
99 static_cast<T *> ( this_ )->blockSignals(false);
100 }
101 BOOST_SCOPE_EXIT_END
102
103 static_cast<T *> ( this )->blockSignals(true);
104
105 for(const auto& obj : objects) {
106 static_cast<T *> ( this )->update_object(obj);
107 }
108 }
109}
110
111template<typename T>
113 type_object_info const & obj )
114{
115 type_index oid ( static_cast<T *> ( this )->lookup ( obj ) );
116
117 if ( not oid.isValid() )
118 {
119 static_cast<T *> ( this )->create_contained_object ( oid, obj );
120 }
121}
122
123template<typename T> inline
126{
127}
128//------------------------------------------------------------------------------------------
129
130//------------------------------------------------------------------------------------------
131// FOR FUTURE USE
132//template<typename T> inline std::vector<dbe::dref> dbe::model_common_impl<T>::filter_indices(
133// type_indices::iterator b, type_indices::iterator e)
134//{
135// typedef std::set<decltype(b->row())> t_qrows;
136// typedef std::vector<dref> t_objects;
137//
138// t_objects objects_to_act_upon;
139// t_indices indices_to_check;
140//
141// for(t_indices::iterator iter = b ; iter != e ; ++iter)
142// {
143// if(iter->isValid() and iter->column() == 0)
144// {
145// dref o = static_cast<T *>(this)->getobject(*iter);
146// if(o.is_valid())
147// {
148// indices_to_check.push_back(*iter);
149// objects_to_act_upon.push_back(o);
150// }
151// }
152// }
153//
154//}
155//------------------------------------------------------------------------------------------
156
157//------------------------------------------------------------------------------------------
158template<typename T> inline bool dbe::model_common_impl<T>::delete_objects (
159 type_indices::iterator b, type_indices::iterator e )
160{
161 typedef std::set < decltype ( b->row() ) > t_qrows;
162 typedef std::vector<type_object_info> t_objects;
163 t_objects to_remove_objects;
164
165 for ( type_indices::iterator iter = b; iter != e; ++iter )
166 {
167 if ( iter->isValid() and iter->column() == 0 )
168 {
169 dref o = static_cast<T *> ( this )->getobject ( *iter );
170
171 if ( o.is_valid() )
172 {
173 to_remove_objects.push_back ( o );
174 }
175 }
176 }
177
178 t_objects removed_objects;
179
180 for ( auto const & o : to_remove_objects )
181 {
182 if ( dbe::config::api::commands::delobj ( o.ref(), static_cast<T *> ( this )->uuid ) )
183 {
184 removed_objects.push_back ( o );
185 }
186 }
187
188 t_qrows to_remove_rows;
189
190 for ( auto const & o : removed_objects )
191 {
192 QModelIndex newloc = static_cast<T *> ( this )->lookup ( o );
193
194 if ( newloc.isValid() )
195 {
196 to_remove_rows.insert ( newloc.row() );
197 }
198 }
199
200 t_qrows::reverse_iterator uend = to_remove_rows.rbegin();
201
202 if ( uend != to_remove_rows.rend() )
203 {
204 for ( int count = 0, bottom = *uend, last = bottom; uend != to_remove_rows.rend();
205 count = 0, bottom = *uend )
206 {
207 for ( ; uend != to_remove_rows.rend() and count == bottom - *uend;
208 last = *uend, ++uend, ++count )
209 ;
210
211 static_cast<T *> ( this )->removeRows ( last, count, b->parent() );
212 }
213
214 return true;
215 }
216
217 return false;
218}
219//------------------------------------------------------------------------------------------
220
221//------------------------------------------------------------------------------------------
222template<typename T> inline bool dbe::model_common_impl<T>::update_objects (
223 type_indices::iterator b, type_indices::iterator e )
224{
225 Q_UNUSED ( b );
226 Q_UNUSED ( e );
227 return false;
228}
229//------------------------------------------------------------------------------------------
230
231//------------------------------------------------------------------------------------------
232template<typename T> inline bool dbe::model_common_impl<T>::create_objects (
233 type_indices::iterator b, type_indices::iterator e )
234{
235 Q_UNUSED ( b );
236 Q_UNUSED ( e );
237 return false;
238}
239//------------------------------------------------------------------------------------------
240
241#endif /* DBE_MODEL_COMMON_OPERATIONS_HPP_ */
static confaccessor & ref()
inner::configobject::tref ref() const
void update_multiple_objects(std::vector< type_object_info > const &)
void remove_object(type_object_info const &)
void rename_object(type_object_info const &)
void update_object(type_object_info const &)
MODEL_COMMON_TYPES_TOPLEVEL_DEFINITIONS model_common_async_operations()
void create_object(type_object_info const &)
bool create_objects(type_indices::iterator, type_indices::iterator) override
bool delete_objects(type_indices::iterator, type_indices::iterator) override
bool update_objects(type_indices::iterator, type_indices::iterator) override
#define MODEL_COMMON_INTERFACE_UUID_DECL
bool delobj(inner::configobject::tref obj, QUuid const &src)
config_object_description dref