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