DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
change_attribute.hpp
Go to the documentation of this file.
1/*
2 * change_attribute.hpp
3 *
4 * Created on: Nov 10, 2015
5 * Author: lgeorgop
6 */
7
8#ifndef DBE_CHANGE_ATTRIBUTE_HPP_
9#define DBE_CHANGE_ATTRIBUTE_HPP_
10
11#include "dbe/confaccessor.hpp"
14#include "dbe/Command.hpp"
15#include "dbe/Exceptions.hpp"
16
18#include "conffwk/Errors.hpp"
19#include "conffwk/Schema.hpp"
20
21#include <QtCore/qobject.h>
22#include <QtCore/qstring.h>
23#include <QtCore/qstringlist.h>
24
25#include <string>
26
27#include "dbe/messenger.hpp"
28
29namespace dbe
30{
31namespace actions
32{
33
34template<typename T>
36 public onobject
37{
38public:
39 ChangeAttribute ( tref Object, dunedaq::conffwk::attribute_t AttributeData, T NewValueData,
40 QUndoCommand * parent = nullptr );
41 void undo();
42 void redo();
43private:
47};
48
49template<typename T>
51 T NewValueData, QUndoCommand * parent )
52 : onobject ( Object, parent ),
53 NewValue ( NewValueData ),
54 Attribute ( AttributeData )
55{
56 try
57 {
58 failed();
59 QStringList Data
62 toggle();
63 }
64 catch ( dunedaq::conffwk::Exception const & )
65 {
66 }
67 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
68 {
69 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
70 ex.what() );
71 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
72 }
73
74 setText (
75 QObject::tr ( "Attribute %1 of object %2 was updated." ).arg (
76 AttributeData.p_name.c_str() ).arg ( Object.UID().c_str() ) );
77}
78
79template<typename T>
81{
82 try
83 {
84 if ( undoable() )
85 {
86 failed();
87 dbe::config::api::set::noactions::attribute ( this->checkedref(), Attribute, OldValue );
88 toggle();
89 }
90 }
91 catch ( dunedaq::conffwk::Exception const & e )
92 {
93 failed();
94 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
95 }
96 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
97 {
98 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
99 ex.what() );
100 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
101 }
102
103}
104
105template<typename T>
107{
108 try
109 {
110 if ( redoable() )
111 {
112 failed();
113
114 QStringList Data
115 { dbe::config::api::get::attribute::list<QStringList> ( this->checkedref(), Attribute ) };
116
117 OldValue = convert::to<T> ( Data, Attribute.p_int_format );
118
119 dbe::config::api::set::noactions::attribute ( this->checkedref(), Attribute, NewValue );
120 toggle();
121 }
122 }
123 catch ( dunedaq::conffwk::Exception const & e )
124 {
125 failed();
126 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
127 }
128 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
129 {
130 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
131 ex.what() );
132 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
133 }
134
135}
136
137}
138}
139#endif /* DBE_CHANGE_ATTRIBUTE_HPP_ */
#define ERS_HERE
ChangeAttribute(tref Object, dunedaq::conffwk::attribute_t AttributeData, T NewValueData, QUndoCommand *parent=nullptr)
dunedaq::conffwk::attribute_t Attribute
tref checkedref() const
Definition Command.cpp:513
void failed() const
Definition Command.cpp:536
static T list(dbe::inner::configobject::tref obj, dunedaq::conffwk::attribute_t const &attr)
#define FAIL(...)
void attribute(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
T to(QStringList const &DataList)
Include QT Headers.