DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
apps
SchemaEditor
SchemaMethodEditor.cpp
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 src/SchemaEditor/SchemaMethodEditor.cpp to apps/SchemaEditor/SchemaMethodEditor.cpp).
5
7
#include <QMessageBox>
9
#include "
dbe/SchemaMethodEditor.hpp
"
10
#include "
dbe/SchemaMethodImplementationEditor.hpp
"
11
#include "
dbe/SchemaKernelWrapper.hpp
"
13
#include "ui_SchemaMethodEditor.h"
14
15
using namespace
dunedaq::oks
;
16
17
dbse::SchemaMethodEditor::~SchemaMethodEditor
() =
default
;
18
19
dbse::SchemaMethodEditor::SchemaMethodEditor
(
OksClass
* ClassInfo,
OksMethod
* Method,
20
QWidget * parent )
21
: QWidget ( parent ),
22
ui
( new
Ui
::
SchemaMethodEditor
),
23
m_class
( ClassInfo ),
24
m_method
( Method ),
25
ImplementationModel
( nullptr ),
26
UsedNew
( false )
27
{
28
QWidget::setAttribute(Qt::WA_DeleteOnClose);
29
m_writable
=
KernelWrapper::GetInstance
().
IsFileWritable
(
m_class
->get_file()->get_full_file_name());
30
ui
->setupUi (
this
);
31
InitialSettings
();
32
BuildModels
();
33
SetController
();
34
}
35
36
dbse::SchemaMethodEditor::SchemaMethodEditor
(
OksClass
* ClassInfo, QWidget * parent )
37
: QWidget ( parent ),
38
ui
( new
Ui
::
SchemaMethodEditor
),
39
m_class
( ClassInfo ),
40
m_method
( nullptr ),
41
ImplementationModel
( nullptr ),
42
UsedNew
( true )
43
{
44
QWidget::setAttribute(Qt::WA_DeleteOnClose);
45
m_writable
=
KernelWrapper::GetInstance
().
IsFileWritable
(
m_class
->get_file()->get_full_file_name());
46
ui
->setupUi (
this
);
47
InitialSettings
();
48
SetController
();
49
}
50
51
void
dbse::SchemaMethodEditor::SetController
()
52
{
53
connect (
ui
->buttonBox, SIGNAL ( accepted() ),
this
, SLOT (
ProxySlot
() ) );
54
connect (
ui
->buttonBox, SIGNAL ( rejected() ),
this
, SLOT ( close() ) );
55
connect (
ui
->AddButton, SIGNAL ( clicked() ),
this
,
56
SLOT (
AddNewMethodImplementation
() ) );
57
connect (
ui
->ImplementationsView, SIGNAL ( doubleClicked ( QModelIndex ) ),
this
,
58
SLOT (
OpenMethodImplementationEditor
( QModelIndex ) ) );
59
connect ( &
KernelWrapper::GetInstance
(), SIGNAL (
ClassUpdated
( QString ) ),
this
,
60
SLOT (
ClassUpdated
( QString ) ) );
61
}
62
63
void
dbse::SchemaMethodEditor::ClassUpdated
( QString ClassName)
64
{
65
if
(!
UsedNew
&& ClassName.toStdString() ==
m_class
->get_name()) {
66
if
(
m_class
->find_direct_method(
m_method
->get_name()) !=
nullptr
) {
67
FillInfo
();
68
BuildModels
();
69
}
else
{
70
QWidget::close();
71
}
72
}
73
}
74
75
void
dbse::SchemaMethodEditor::FillInfo
()
76
{
77
auto
name = QString::fromStdString (
78
m_class
->get_name() +
"::"
+
m_method
->get_name() );
79
setObjectName ( name );
80
setWindowTitle ( QString (
"Method Editor : %1"
).arg ( name ) );
81
ui
->MethodName->setText ( QString::fromStdString (
m_method
->get_name() ) );
82
ui
->DescriptionTextBox->setPlainText (
83
QString::fromStdString (
m_method
->get_description() ) );
84
}
85
86
void
dbse::SchemaMethodEditor::InitialSettings
()
87
{
88
if
(
UsedNew
)
89
{
90
setWindowTitle (
"New Method"
);
91
setObjectName (
"NEW"
);
92
ui
->AddButton->setEnabled (
true
);
93
}
94
else
95
{
96
if
(!
m_writable
) {
97
ui
->MethodName->setEnabled (
false
);
98
ui
->DescriptionTextBox->setEnabled (
false
);
99
ui
->AddButton->setEnabled (
false
);
100
ui
->ImplementationsView->setEnabled (
false
);
101
}
102
FillInfo
();
103
}
104
}
105
106
void
dbse::SchemaMethodEditor::ParseToSave
()
107
{
108
bool
changed =
false
;
109
std::string method_name =
ui
->MethodName->text().toStdString();
110
std::string method_description =
ui
->DescriptionTextBox->toPlainText().toStdString();
111
112
if
( method_name !=
m_method
->get_name() )
113
{
114
KernelWrapper::GetInstance
().
PushSetNameMethodCommand
(
m_class
,
m_method
, method_name );
115
changed =
true
;
116
}
117
118
if
( method_description !=
m_method
->get_description() )
119
{
120
KernelWrapper::GetInstance
().
PushSetDescriptionMethodCommand
(
m_class
,
121
m_method
,
122
method_description );
123
changed =
true
;
124
}
125
126
if
( changed )
127
{
128
emit
RebuildModel
();
129
}
130
131
close();
132
}
133
134
bool
dbse::SchemaMethodEditor::create
() {
135
std::string method_name =
ui
->MethodName->text().toStdString();
136
if
(method_name.empty()) {
137
return
false
;
138
}
139
std::string method_description =
ui
->DescriptionTextBox->toPlainText().toStdString();
140
KernelWrapper::GetInstance
().
PushAddMethodCommand
(
m_class
, method_name,
141
method_description );
142
emit
RebuildModel
();
143
UsedNew
=
false
;
144
return
true
;
145
}
146
void
dbse::SchemaMethodEditor::ParseToCreate
()
147
{
148
create
();
149
close();
150
}
151
152
void
dbse::SchemaMethodEditor::BuildModels
()
153
{
154
QStringList MethodHeaders {
"Language"
,
"Prototype"
};
155
156
if
(
ImplementationModel
!=
nullptr
) {
157
delete
ImplementationModel
;
158
}
159
ImplementationModel
=
new
CustomMethodImplementationModel
(
m_method
, MethodHeaders );
160
161
ui
->ImplementationsView->setModel (
ImplementationModel
);
162
ui
->ImplementationsView->horizontalHeader()->setSectionResizeMode ( QHeaderView::ResizeToContents );
163
}
164
165
bool
dbse::SchemaMethodEditor::ShouldOpenMethodImplementationEditor
( QString Name )
166
{
167
bool
WidgetFound =
false
;
168
169
for
( QWidget * Editor : QApplication::allWidgets() )
170
{
171
SchemaMethodImplementationEditor
* Widget =
172
dynamic_cast<
SchemaMethodImplementationEditor
*
>
( Editor );
173
174
if
( Widget !=
nullptr
)
175
{
176
if
( ( Widget->objectName() ).compare ( Name ) == 0 )
177
{
178
Widget->raise();
179
Widget->setVisible (
true
);
180
Widget->activateWindow();
181
WidgetFound =
true
;
182
}
183
}
184
}
185
186
return
!WidgetFound;
187
}
188
189
void
dbse::SchemaMethodEditor::ProxySlot
()
190
{
191
if
(
UsedNew
)
192
{
193
ParseToCreate
();
194
}
195
else
196
{
197
ParseToSave
();
198
}
199
}
200
201
void
dbse::SchemaMethodEditor::AddNewMethodImplementation
()
202
{
203
if
(
UsedNew
) {
204
if
(
create
()) {
205
m_method
=
m_class
->find_method(
ui
->MethodName->text().toStdString());
206
}
207
else
{
208
QMessageBox::question (
209
0, tr (
"SchemaEditor"
),
210
tr (
"You must set the method name before you can set an implementation"
),
211
QMessageBox::Ok );
212
return
;
213
}
214
}
215
SchemaMethodImplementationEditor
* Editor =
new
SchemaMethodImplementationEditor
(
216
m_class
,
m_method
);
217
connect ( Editor, SIGNAL (
RebuildModel
() ),
this
,
218
SLOT (
BuildModelImplementationSlot
() ) );
219
Editor->show();
220
}
221
222
void
dbse::SchemaMethodEditor::OpenMethodImplementationEditor
( QModelIndex Index )
223
{
224
QStringList Row =
ImplementationModel
->getRowFromIndex ( Index );
225
if
( !Row.isEmpty() ) {
226
QString name = QString::fromStdString(
227
m_class
->get_name()+
m_method
->get_name()).append(Row.at ( 0 ));
228
if
(
ShouldOpenMethodImplementationEditor
( name )) {
229
SchemaMethodImplementationEditor
* Editor =
new
SchemaMethodImplementationEditor
(
230
m_class
,
m_method
,
m_method
->find_implementation ( Row.at ( 0 ).toStdString() ) );
231
Editor->show();
232
}
233
}
234
}
235
236
void
dbse::SchemaMethodEditor::BuildModelImplementationSlot
()
237
{
238
BuildModels
();
239
}
SchemaKernelWrapper.hpp
SchemaMethodEditor.hpp
SchemaMethodImplementationEditor.hpp
dbse::CustomMethodImplementationModel
Definition
SchemaCustomMethodImplementationModel.hpp:18
dbse::KernelWrapper::GetInstance
static KernelWrapper & GetInstance()
Definition
SchemaKernelWrapper.cpp:18
dbse::KernelWrapper::PushSetDescriptionMethodCommand
void PushSetDescriptionMethodCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksMethod *Method, std::string description)
Definition
SchemaKernelWrapper.cpp:668
dbse::KernelWrapper::PushSetNameMethodCommand
void PushSetNameMethodCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksMethod *Method, std::string name)
Method commands.
Definition
SchemaKernelWrapper.cpp:655
dbse::KernelWrapper::IsFileWritable
bool IsFileWritable(const std::string &FileName) const
Definition
SchemaKernelWrapper.cpp:160
dbse::KernelWrapper::PushAddMethodCommand
void PushAddMethodCommand(dunedaq::oks::OksClass *Class, std::string name, std::string description)
Definition
SchemaKernelWrapper.cpp:682
dbse::SchemaMethodEditor::AddNewMethodImplementation
void AddNewMethodImplementation()
Definition
SchemaMethodEditor.cpp:201
dbse::SchemaMethodEditor::BuildModelImplementationSlot
void BuildModelImplementationSlot()
Definition
SchemaMethodEditor.cpp:236
dbse::SchemaMethodEditor::ParseToSave
void ParseToSave()
Definition
SchemaMethodEditor.cpp:106
dbse::SchemaMethodEditor::SetController
void SetController()
Definition
SchemaMethodEditor.cpp:51
dbse::SchemaMethodEditor::ClassUpdated
void ClassUpdated(QString ClassName)
Definition
SchemaMethodEditor.cpp:63
dbse::SchemaMethodEditor::FillInfo
void FillInfo()
Definition
SchemaMethodEditor.cpp:75
dbse::SchemaMethodEditor::ImplementationModel
CustomMethodImplementationModel * ImplementationModel
Definition
SchemaMethodEditor.hpp:45
dbse::SchemaMethodEditor::m_class
dunedaq::oks::OksClass * m_class
Definition
SchemaMethodEditor.hpp:43
dbse::SchemaMethodEditor::ParseToCreate
void ParseToCreate()
Definition
SchemaMethodEditor.cpp:146
dbse::SchemaMethodEditor::BuildModels
void BuildModels()
Definition
SchemaMethodEditor.cpp:152
dbse::SchemaMethodEditor::m_writable
bool m_writable
Definition
SchemaMethodEditor.hpp:47
dbse::SchemaMethodEditor::m_method
dunedaq::oks::OksMethod * m_method
Definition
SchemaMethodEditor.hpp:44
dbse::SchemaMethodEditor::RebuildModel
void RebuildModel()
dbse::SchemaMethodEditor::OpenMethodImplementationEditor
void OpenMethodImplementationEditor(QModelIndex Index)
Definition
SchemaMethodEditor.cpp:222
dbse::SchemaMethodEditor::create
bool create()
Definition
SchemaMethodEditor.cpp:134
dbse::SchemaMethodEditor::ProxySlot
void ProxySlot()
Definition
SchemaMethodEditor.cpp:189
dbse::SchemaMethodEditor::ShouldOpenMethodImplementationEditor
bool ShouldOpenMethodImplementationEditor(QString Name)
Definition
SchemaMethodEditor.cpp:165
dbse::SchemaMethodEditor::SchemaMethodEditor
SchemaMethodEditor(dunedaq::oks::OksClass *ClassInfo, dunedaq::oks::OksMethod *Method, QWidget *parent=nullptr)
Definition
SchemaMethodEditor.cpp:19
dbse::SchemaMethodEditor::InitialSettings
void InitialSettings()
Definition
SchemaMethodEditor.cpp:86
dbse::SchemaMethodEditor::~SchemaMethodEditor
~SchemaMethodEditor()
dbse::SchemaMethodEditor::UsedNew
bool UsedNew
Definition
SchemaMethodEditor.hpp:46
dbse::SchemaMethodEditor::ui
std::unique_ptr< dbse::Ui::SchemaMethodEditor > ui
Definition
SchemaMethodEditor.hpp:42
dbse::SchemaMethodImplementationEditor
Definition
SchemaMethodImplementationEditor.hpp:23
dunedaq::oks::OksClass
The OKS class.
Definition
class.hpp:205
dunedaq::oks::OksMethod
OKS method class.
Definition
method.hpp:158
Ui
Definition
SchemaSettings.hpp:10
dunedaq::oks
Definition
OksConfiguration.hpp:24
Generated on
for DUNE-DAQ by
1.17.0