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)
22 , m_class(ClassInfo)
23 , m_method(Method)
24 , ImplementationModel(nullptr)
25 , UsedNew(false)
26{
27 QWidget::setAttribute(Qt::WA_DeleteOnClose);
29 ui->setupUi(this);
33}
34
36 : QWidget(parent)
38 , m_class(ClassInfo)
39 , m_method(nullptr)
40 , ImplementationModel(nullptr)
41 , UsedNew(true)
42{
43 QWidget::setAttribute(Qt::WA_DeleteOnClose);
45 ui->setupUi(this);
48}
49
50void
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, SLOT(AddNewMethodImplementation()));
56 connect(ui->ImplementationsView,
57 SIGNAL(doubleClicked(QModelIndex)),
58 this,
59 SLOT(OpenMethodImplementationEditor(QModelIndex)));
60 connect(&KernelWrapper::GetInstance(), SIGNAL(ClassUpdated(QString)), this, SLOT(ClassUpdated(QString)));
61}
62
63void
65{
66 if (!UsedNew && ClassName.toStdString() == m_class->get_name()) {
67 if (m_class->find_direct_method(m_method->get_name()) != nullptr) {
68 FillInfo();
70 } else {
71 QWidget::close();
72 }
73 }
74}
75
76void
78{
79 auto name = QString::fromStdString(m_class->get_name() + "::" + m_method->get_name());
80 setObjectName(name);
81 setWindowTitle(QString("Method Editor : %1").arg(name));
82 ui->MethodName->setText(QString::fromStdString(m_method->get_name()));
83 ui->DescriptionTextBox->setPlainText(QString::fromStdString(m_method->get_description()));
84}
85
86void
88{
89 if (UsedNew) {
90 setWindowTitle("New Method");
91 setObjectName("NEW");
92 ui->AddButton->setEnabled(true);
93 } else {
94 if (!m_writable) {
95 ui->MethodName->setEnabled(false);
96 ui->DescriptionTextBox->setEnabled(false);
97 ui->AddButton->setEnabled(false);
98 ui->ImplementationsView->setEnabled(false);
99 }
100 FillInfo();
101 }
102}
103
104void
106{
107 bool changed = false;
108 std::string method_name = ui->MethodName->text().toStdString();
109 std::string method_description = ui->DescriptionTextBox->toPlainText().toStdString();
110
111 if (method_name != m_method->get_name()) {
113 changed = true;
114 }
115
116 if (method_description != m_method->get_description()) {
118 changed = true;
119 }
120
121 if (changed) {
122 emit RebuildModel();
123 }
124
125 close();
126}
127
128bool
130{
131 std::string method_name = ui->MethodName->text().toStdString();
132 if (method_name.empty()) {
133 return false;
134 }
135 std::string method_description = ui->DescriptionTextBox->toPlainText().toStdString();
136 KernelWrapper::GetInstance().PushAddMethodCommand(m_class, method_name, method_description);
137 emit RebuildModel();
138 UsedNew = false;
139 return true;
140}
141void
143{
144 create();
145 close();
146}
147
148void
150{
151 QStringList MethodHeaders{ "Language", "Prototype" };
152
153 if (ImplementationModel != nullptr) {
154 delete ImplementationModel;
155 }
157
158 ui->ImplementationsView->setModel(ImplementationModel);
159 ui->ImplementationsView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
160}
161
162bool
164{
165 bool WidgetFound = false;
166
167 for (QWidget* Editor : QApplication::allWidgets()) {
169
170 if (Widget != nullptr) {
171 if ((Widget->objectName()).compare(Name) == 0) {
172 Widget->raise();
173 Widget->setVisible(true);
174 Widget->activateWindow();
175 WidgetFound = true;
176 }
177 }
178 }
179
180 return !WidgetFound;
181}
182
183void
185{
186 if (UsedNew) {
188 } else {
189 ParseToSave();
190 }
191}
192
193void
195{
196 if (UsedNew) {
197 if (create()) {
198 m_method = m_class->find_method(ui->MethodName->text().toStdString());
199 } else {
200 QMessageBox::question(0,
201 tr("SchemaEditor"),
202 tr("You must set the method name before you can set an implementation"),
203 QMessageBox::Ok);
204 return;
205 }
206 }
208 connect(Editor, SIGNAL(RebuildModel()), this, SLOT(BuildModelImplementationSlot()));
209 Editor->show();
210}
211
212void
214{
215 QStringList Row = ImplementationModel->getRowFromIndex(Index);
216 if (!Row.isEmpty()) {
217 QString name = QString::fromStdString(m_class->get_name() + m_method->get_name()).append(Row.at(0));
220 new SchemaMethodImplementationEditor(m_class, m_method, m_method->find_implementation(Row.at(0).toStdString()));
221 Editor->show();
222 }
223 }
224}
225
226void
CustomMethodImplementationModel(dunedaq::oks::OksMethod *Method, QStringList Headers)
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
SchemaMethodImplementationEditor(dunedaq::oks::OksClass *Class, dunedaq::oks::OksMethod *Method, dunedaq::oks::OksMethodImplementation *Implementation, QWidget *parent=nullptr)
The OKS class.
Definition class.hpp:223
OksFile * get_file() const noexcept
Definition class.hpp:352
const std::string & get_full_file_name() const
Definition file.hpp:528
OKS method class.
Definition method.hpp:147