DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
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>
13#include "ui_SchemaMethodEditor.h"
14
15using namespace dunedaq::oks;
16
18
20 QWidget * parent )
21 : QWidget ( parent ),
22 ui ( new Ui::SchemaMethodEditor ),
23 m_class ( ClassInfo ),
24 m_method ( Method ),
25 ImplementationModel ( nullptr ),
26 UsedNew ( false )
27{
28 QWidget::setAttribute(Qt::WA_DeleteOnClose);
29 m_writable = KernelWrapper::GetInstance().IsFileWritable(m_class->get_file()->get_full_file_name());
30 ui->setupUi ( this );
34}
35
37 : QWidget ( parent ),
38 ui ( new Ui::SchemaMethodEditor ),
39 m_class ( ClassInfo ),
40 m_method ( nullptr ),
41 ImplementationModel ( nullptr ),
42 UsedNew ( true )
43{
44 QWidget::setAttribute(Qt::WA_DeleteOnClose);
45 m_writable = KernelWrapper::GetInstance().IsFileWritable(m_class->get_file()->get_full_file_name());
46 ui->setupUi ( this );
49}
50
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,
56 SLOT ( AddNewMethodImplementation() ) );
57 connect ( ui->ImplementationsView, SIGNAL ( doubleClicked ( QModelIndex ) ), this,
58 SLOT ( OpenMethodImplementationEditor ( QModelIndex ) ) );
59 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassUpdated ( QString ) ), this,
60 SLOT ( ClassUpdated ( QString ) ) );
61}
62
64{
65 if(!UsedNew && ClassName.toStdString() == m_class->get_name()) {
66 if(m_class->find_direct_method(m_method->get_name()) != nullptr) {
67 FillInfo();
69 } else {
70 QWidget::close();
71 }
72 }
73}
74
76{
77 auto name = QString::fromStdString (
78 m_class->get_name() + "::" + m_method->get_name() );
79 setObjectName ( name );
80 setWindowTitle ( QString ( "Method Editor : %1" ).arg ( name ) );
81 ui->MethodName->setText ( QString::fromStdString ( m_method->get_name() ) );
82 ui->DescriptionTextBox->setPlainText (
83 QString::fromStdString ( m_method->get_description() ) );
84}
85
87{
88 if ( UsedNew )
89 {
90 setWindowTitle ( "New Method" );
91 setObjectName ( "NEW" );
92 ui->AddButton->setEnabled ( true );
93 }
94 else
95 {
96 if (!m_writable) {
97 ui->MethodName->setEnabled (false);
98 ui->DescriptionTextBox->setEnabled (false);
99 ui->AddButton->setEnabled (false);
100 ui->ImplementationsView->setEnabled (false);
101 }
102 FillInfo();
103 }
104}
105
107{
108 bool changed = false;
109 std::string method_name = ui->MethodName->text().toStdString();
110 std::string method_description = ui->DescriptionTextBox->toPlainText().toStdString();
111
112 if ( method_name != m_method->get_name() )
113 {
115 changed = true;
116 }
117
118 if ( method_description != m_method->get_description() )
119 {
121 m_method,
122 method_description );
123 changed = true;
124 }
125
126 if ( changed )
127 {
128 emit RebuildModel();
129 }
130
131 close();
132}
133
135 std::string method_name = ui->MethodName->text().toStdString();
136 if (method_name.empty()) {
137 return false;
138 }
139 std::string method_description = ui->DescriptionTextBox->toPlainText().toStdString();
141 method_description );
142 emit RebuildModel();
143 UsedNew = false;
144 return true;
145}
147{
148 create();
149 close();
150}
151
153{
154 QStringList MethodHeaders { "Language", "Prototype" };
155
156 if ( ImplementationModel != nullptr ) {
157 delete ImplementationModel;
158 }
160
161 ui->ImplementationsView->setModel ( ImplementationModel );
162 ui->ImplementationsView->horizontalHeader()->setSectionResizeMode ( QHeaderView::ResizeToContents );
163}
164
166{
167 bool WidgetFound = false;
168
169 for ( QWidget * Editor : QApplication::allWidgets() )
170 {
172 dynamic_cast<SchemaMethodImplementationEditor *> ( Editor );
173
174 if ( Widget != nullptr )
175 {
176 if ( ( Widget->objectName() ).compare ( Name ) == 0 )
177 {
178 Widget->raise();
179 Widget->setVisible ( true );
180 Widget->activateWindow();
181 WidgetFound = true;
182 }
183 }
184 }
185
186 return !WidgetFound;
187}
188
190{
191 if ( UsedNew )
192 {
194 }
195 else
196 {
197 ParseToSave();
198 }
199}
200
202{
203 if (UsedNew) {
204 if (create()) {
205 m_method = m_class->find_method(ui->MethodName->text().toStdString());
206 }
207 else {
208 QMessageBox::question (
209 0, tr ( "SchemaEditor" ),
210 tr ( "You must set the method name before you can set an implementation" ),
211 QMessageBox::Ok );
212 return;
213 }
214 }
216 m_class, m_method );
217 connect ( Editor, SIGNAL ( RebuildModel() ), this,
218 SLOT ( BuildModelImplementationSlot() ) );
219 Editor->show();
220}
221
223{
224 QStringList Row = ImplementationModel->getRowFromIndex ( Index );
225 if ( !Row.isEmpty() ) {
226 QString name = QString::fromStdString(
227 m_class->get_name()+m_method->get_name()).append(Row.at ( 0 ));
230 m_class, m_method, m_method->find_implementation ( Row.at ( 0 ).toStdString() ) );
231 Editor->show();
232 }
233 }
234}
235
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)
CustomMethodImplementationModel * ImplementationModel
dunedaq::oks::OksClass * m_class
dunedaq::oks::OksMethod * m_method
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:205
OKS method class.
Definition method.hpp:158