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