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