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