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