Line data Source code
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/SchemaMethodImplementationEditor.cpp to apps/SchemaEditor/SchemaMethodImplementationEditor.cpp).
5 :
6 : #include <QMessageBox>
7 : /// Including Schema
8 : #include "dbe/SchemaMethodImplementationEditor.hpp"
9 : #include "dbe/SchemaKernelWrapper.hpp"
10 : #include "ui_SchemaMethodImplementationEditor.h"
11 :
12 : using namespace dunedaq::oks;
13 :
14 0 : dbse::SchemaMethodImplementationEditor::~SchemaMethodImplementationEditor() = default;
15 :
16 0 : dbse::SchemaMethodImplementationEditor::SchemaMethodImplementationEditor (
17 0 : OksClass * Class, OksMethod * Method, OksMethodImplementation * Implementation, QWidget * parent )
18 : : QWidget ( parent ),
19 0 : ui ( new Ui::SchemaMethodImplementationEditor ),
20 0 : m_class ( Class ),
21 0 : m_method ( Method ),
22 0 : m_implementation ( Implementation ),
23 0 : UsedNew ( false )
24 : {
25 0 : QWidget::setAttribute(Qt::WA_DeleteOnClose);
26 0 : ui->setupUi ( this );
27 0 : InitialSettings();
28 0 : SetController();
29 0 : }
30 :
31 0 : dbse::SchemaMethodImplementationEditor::SchemaMethodImplementationEditor (
32 : OksClass * Class,
33 : OksMethod * Method,
34 0 : QWidget * parent )
35 : : QWidget ( parent ),
36 0 : ui ( new Ui::SchemaMethodImplementationEditor ),
37 0 : m_class ( Class ),
38 0 : m_method ( Method ),
39 0 : m_implementation ( nullptr ),
40 0 : UsedNew ( true )
41 : {
42 0 : QWidget::setAttribute(Qt::WA_DeleteOnClose);
43 0 : ui->setupUi ( this );
44 0 : InitialSettings();
45 0 : SetController();
46 0 : }
47 :
48 0 : void dbse::SchemaMethodImplementationEditor::SetController()
49 : {
50 0 : connect ( ui->SaveButton, SIGNAL ( clicked() ), this, SLOT ( ProxySlot() ) );
51 0 : connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassUpdated ( QString ) ), this,
52 : SLOT ( ClassUpdated ( QString ) ) );
53 0 : }
54 :
55 0 : void dbse::SchemaMethodImplementationEditor::ClassUpdated( QString class_name )
56 : {
57 0 : if(!UsedNew && class_name.toStdString() == m_class->get_name()) {
58 0 : if(m_method->find_implementation(m_implementation->get_language()) != nullptr) {
59 0 : FillInfo();
60 : } else {
61 0 : QWidget::close();
62 : }
63 : }
64 0 : }
65 :
66 0 : void dbse::SchemaMethodImplementationEditor::FillInfo()
67 : {
68 0 : ui->MethodImplementationLanguage->setText (
69 0 : QString::fromStdString ( m_implementation->get_language() ) );
70 0 : ui->MethodImplementationPrototype->setText (
71 0 : QString::fromStdString ( m_implementation->get_prototype() ) );
72 0 : ui->MethodImplementationDescription->setPlainText (
73 0 : QString::fromStdString ( m_implementation->get_body() ) );
74 :
75 0 : std::string name = m_class->get_name() + m_method->get_name()
76 0 : + m_implementation->get_language();
77 0 : setObjectName ( QString::fromStdString(name) );
78 0 : }
79 :
80 0 : void dbse::SchemaMethodImplementationEditor::InitialSettings()
81 : {
82 0 : std::string title = "Method Implementation for " + m_class->get_name() + "::" + m_method->get_name();
83 0 : setWindowTitle (QString::fromStdString(title));
84 :
85 0 : if ( UsedNew ) {
86 0 : std::string name = m_class->get_name() + m_method->get_name();
87 0 : setObjectName ( QString::fromStdString(name) );
88 0 : }
89 : else {
90 0 : FillInfo();
91 : }
92 0 : }
93 :
94 0 : void dbse::SchemaMethodImplementationEditor::ParseToSave()
95 : {
96 0 : bool changed = false;
97 0 : std::string MethodLanguage = ui->MethodImplementationLanguage->text().toStdString();
98 0 : std::string MethodPrototype = ui->MethodImplementationPrototype->text().toStdString();
99 :
100 0 : std::string MethodDescription = ui->MethodImplementationDescription->toPlainText()
101 0 : .toStdString();
102 :
103 0 : if ( MethodLanguage != m_implementation->get_language() )
104 : {
105 0 : KernelWrapper::GetInstance().PushSetMethodImplementationLanguage ( m_class,
106 : m_method,
107 : m_implementation,
108 : MethodLanguage );
109 0 : changed = true;
110 : }
111 :
112 0 : if ( MethodPrototype != m_implementation->get_prototype() )
113 : {
114 0 : KernelWrapper::GetInstance().PushSetMethodImplementationPrototype ( m_class,
115 : m_method,
116 : m_implementation,
117 : MethodPrototype );
118 0 : changed = true;
119 : }
120 :
121 0 : if ( MethodDescription != m_implementation->get_body() )
122 : {
123 0 : KernelWrapper::GetInstance().PushSetMethodImplementationBody ( m_class,
124 : m_method,
125 : m_implementation,
126 : MethodDescription );
127 0 : changed = true;
128 : }
129 :
130 0 : if ( changed )
131 : {
132 0 : emit RebuildModel();
133 : }
134 :
135 0 : close();
136 0 : }
137 :
138 0 : void dbse::SchemaMethodImplementationEditor::ParseToCreate()
139 : {
140 0 : if ( ui->MethodImplementationLanguage->text().isEmpty()
141 0 : && ui->MethodImplementationLanguage->text().isEmpty()
142 0 : && ui->MethodImplementationDescription->toPlainText().isEmpty() ) {
143 : // Close empty dialogue box
144 0 : close();
145 0 : return;
146 : }
147 :
148 0 : if ( ui->MethodImplementationLanguage->text().isEmpty() )
149 : {
150 0 : QMessageBox::warning (
151 : 0, "Schema editor",
152 0 : QString ( "Please Provide a Language for the method implementation !" ) );
153 0 : return;
154 : }
155 :
156 0 : if ( ui->MethodImplementationPrototype->text().isEmpty() )
157 : {
158 0 : QMessageBox::warning (
159 : 0, "Schema editor",
160 0 : QString ( "Please Provide a prototype for the method implementation !" ) );
161 0 : return;
162 : }
163 :
164 0 : std::string MethodLanguage = ui->MethodImplementationLanguage->text().toStdString();
165 0 : std::string MethodPrototype = ui->MethodImplementationPrototype->text().toStdString();
166 0 : std::string MethodDescription = ui->MethodImplementationDescription->toPlainText()
167 0 : .toStdString();
168 :
169 0 : KernelWrapper::GetInstance().PushAddMethodImplementationComand ( m_class,
170 : m_method,
171 : MethodLanguage,
172 : MethodPrototype,
173 : MethodDescription );
174 0 : emit RebuildModel();
175 0 : close();
176 0 : }
177 :
178 0 : void dbse::SchemaMethodImplementationEditor::ProxySlot()
179 : {
180 0 : if ( UsedNew )
181 : {
182 0 : ParseToCreate();
183 : }
184 : else
185 : {
186 0 : ParseToSave();
187 : }
188 0 : }
|