10#include <QListWidgetItem>
22#include "ui_SchemaClassEditor.h"
44 QWidget::setAttribute(Qt::WA_DeleteOnClose);
48 setWindowTitle(QString(
"Class Editor : %1").arg(QString::fromStdString(
SchemaClass->
get_name())));
62 if (event->key() == Qt::Key_Escape) {
65 QWidget::keyPressEvent(event);
70 connect(
ui->buttonBox, SIGNAL(accepted()),
this, SLOT(
ParseToSave()));
71 connect(
ui->buttonBox, SIGNAL(rejected()),
this, SLOT(
close_slot()));
72 connect(
ui->moveButton, SIGNAL(clicked()),
this, SLOT(
move_class()));
73 connect(
ui->AddButtonAttribute, SIGNAL(clicked()),
this, SLOT(
AddNewAttribute()));
76 connect(
ui->AddButtonMethod, SIGNAL(clicked()),
this, SLOT(
AddNewMethod()));
78 connect(
ui->MethodsView, SIGNAL(activated(QModelIndex)),
this, SLOT(
OpenMethodEditor(QModelIndex)));
79 connect(
ui->AttributeView, SIGNAL(activated(QModelIndex)),
this, SLOT(
OpenAttributeEditor(QModelIndex)));
80 connect(
ui->SuperClassView, SIGNAL(activated(QModelIndex)),
this, SLOT(
OpenSuperClass(QModelIndex)));
81 connect(
ui->SubClassView, SIGNAL(activated(QModelIndex)),
this, SLOT(
OpenSubClass(QModelIndex)));
85 connect(
ui->MethodsView, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(
CustomMenuMethodView(QPoint)));
86 connect(
ui->SuperClassView, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(
CustomMenuClassView(QPoint)));
98 if (className == objectName()) {
106 if (className == objectName()) {
125 ui->AttributeView->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
126 ui->RelationshipView->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
127 ui->MethodsView->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
128 ui->SuperClassView->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
129 ui->SubClassView->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
132 ui->ClassNameLineEdit->setText(QString::fromStdString(
SchemaClass->get_name()));
135 ui->SchemaFileLineEdit->setText(QString::fromStdString(
SchemaClass->get_file()->get_short_file_name()));
139 ui->AddButtonAttribute->setEnabled(
true);
140 ui->AddButtonSuperClass->setEnabled(
true);
141 ui->AddButtonRelationship->setEnabled(
true);
142 ui->AddButtonMethod->setEnabled(
true);
143 ui->moveButton->setEnabled(
true);
145 ui->SchemaFileLineEdit->setStyleSheet(
"color:rgb(128,0,0);");
147 ui->DescriptionTextEdit->setReadOnly(
true);
149 ui->AddButtonAttribute->setEnabled(
false);
150 ui->AddButtonSuperClass->setEnabled(
false);
151 ui->AddButtonRelationship->setEnabled(
false);
152 ui->AddButtonMethod->setEnabled(
false);
153 ui->moveButton->setEnabled(
false);
154 ui->AbstractComboBox->setEnabled(
false);
158 ui->DescriptionTextEdit->setPlainText(QString::fromStdString(
SchemaClass->get_description()));
159 ui->DescriptionTextEdit->setTabChangesFocus(
true);
162 ui->AbstractComboBox->setCurrentIndex(0);
164 ui->AbstractComboBox->setCurrentIndex(1);
178 std::vector<OksFile*> files;
180 QStringList writable_files;
181 std::map<QString, OksFile*> file_map;
182 int current_row = -1;
183 for (
auto file : files) {
184 auto fn = file->get_full_file_name();
186 if (fn == current_file) {
187 current_row = writable_files.size();
189 writable_files.append(QString::fromStdString(fn));
190 file_map[QString::fromStdString(fn)] = file;
193 if (writable_files.empty()) {
194 QMessageBox::warning(0,
"Schema editor", QString(
"No writable schema files to move class to."));
198 QWidget* widget =
new QWidget();
199 QString text =
"Select file to hold class " + QString::fromStdString(schema_class->
get_name());
200 QLabel* label =
new QLabel(text);
201 QListWidget* qlw =
new QListWidget();
202 qlw->addItems(writable_files);
203 if (current_row != -1) {
204 qlw->setCurrentRow(current_row);
207 connect(qlw, &QListWidget::itemActivated, pwidget, [=]() {
208 QListWidgetItem* it = qlw->currentItem();
209 auto fn = it->text();
210 if (fn.toStdString() != current_file) {
211 schema_class->
set_file(file_map.at(fn));
217 auto bb =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
218 connect(bb, &QDialogButtonBox::accepted, pwidget, [=]() {
219 auto it = qlw->currentItem();
221 auto fn = it->text();
222 if (fn.toStdString() != current_file) {
223 schema_class->
set_file(file_map.at(fn));
228 QMessageBox::warning(0,
"Schema editor", QString(
"No schema file selected to move class to."));
232 connect(bb, &QDialogButtonBox::rejected, pwidget, [=]() {
delete widget; });
234 QVBoxLayout* layout =
new QVBoxLayout();
235 layout->addWidget(label);
236 layout->addWidget(qlw);
237 layout->addWidget(bb);
238 widget->setWindowTitle(
"Select new file for class");
239 widget->setLayout(layout);
240 widget->setParent(pwidget, Qt::Dialog);
247 QString name = QString::fromStdString(
SchemaClass->get_name() +
"::") + attrName;
248 for (QWidget* widget : QApplication::allWidgets()) {
250 if ((widget->objectName()).compare(name) == 0) {
252 widget->setVisible(
true);
253 widget->activateWindow();
265 QString name = QString::fromStdString(
SchemaClass->get_name() +
"::") + relName;
267 for (QWidget* widget : QApplication::allWidgets()) {
269 if ((widget->objectName()).compare(name) == 0) {
271 widget->setVisible(
true);
272 widget->activateWindow();
284 bool WidgetFound =
false;
286 for (QWidget* Editor : QApplication::allWidgets()) {
289 if (Widget !=
nullptr) {
290 if ((Widget->objectName()).compare(Name) == 0) {
292 Widget->setVisible(
true);
293 Widget->activateWindow();
305 const std::string& attributeName =
CurrentRow.at(0).toStdString();
307 if (SchemaAttribute !=
nullptr) {
319 QMessageBox::warning(0,
321 QString::fromStdString(
"Cannot remove attribute \"" + attributeName +
322 "\" because it is not a direct attribute of \"" +
330 const std::string& relationshipName =
CurrentRow.at(0).toStdString();
332 if (SchemaRelationship !=
nullptr) {
344 QMessageBox::warning(0,
346 QString::fromStdString(
"Cannot remove relationship \"" + relationshipName +
347 "\" because it is not a direct relationship of \"" +
355 const std::string& methodName =
CurrentRow.at(0).toStdString();
357 if (SchemaMethod !=
nullptr) {
361 QMessageBox::warning(0,
363 QString::fromStdString(
"Cannot remove method \"" + methodName +
364 "\" because it is not a direct method of \"" +
SchemaClass->get_name() +
372 const std::string& superClassName =
CurrentRow.at(0).toStdString();
373 if (
SchemaClass->has_direct_super_class(superClassName)) {
376 QMessageBox::warning(0,
378 QString::fromStdString(
"Cannot remove super-class \"" + superClassName +
379 "\" because it is not a direct super-class of \"" +
387 std::string NewDescription =
ui->DescriptionTextEdit->toPlainText().toStdString();
389 bool Abstract =
false;
391 if (
ui->AbstractComboBox->currentIndex() == 0) {
401 if (NewDescription !=
SchemaClass->get_description()) {
411 bool widgetFound =
false;
412 QString class_name = QString::fromStdString(
SchemaClass->get_name());
414 QString wname =
"add_sc_" + class_name;
415 for (QWidget* widget : QApplication::allWidgets()) {
416 if (widget->objectName().compare(wname) == 0) {
418 widget->setVisible(
true);
419 widget->activateWindow();
426 QWidget* widget =
new QWidget();
427 widget->setObjectName(wname);
428 QLabel* label =
new QLabel(
"Select a super-class to add to " + class_name);
429 label->setWordWrap(
true);
434 auto search =
new QLineEdit(widget);
435 search->setPlaceholderText(
"Search classes");
436 search->setClearButtonEnabled(
true);
438 QListWidget* qlwidget =
new QListWidget();
439 QStringList allClasses;
441 qlwidget->addItems(allClasses);
443 connect(qlwidget, &QListWidget::itemActivated,
this, [=]() {
444 const std::string& className = qlwidget->currentItem()->text().toStdString();
450 connect(search, &QLineEdit::textChanged,
this, [search, qlwidget]() {
451 auto items = qlwidget->findItems(search->text(), Qt::MatchRegularExpression);
452 if (!items.empty()) {
453 qlwidget->setCurrentItem(items[0]);
457 auto close_button =
new QPushButton(
"Close");
458 connect(close_button, SIGNAL(clicked()), widget, SLOT(close()));
459 QVBoxLayout* lout =
new QVBoxLayout();
460 lout->addWidget(label);
461 lout->addWidget(qlwidget);
462 lout->addWidget(search);
463 lout->addWidget(close_button);
466 widget->setWindowTitle(
"Select super-class(es) for " + class_name);
467 widget->setLayout(lout);
468 widget->setParent(
this, Qt::Dialog);
507 if (!Row.isEmpty() && ShouldOpen) {
521 if (!Row.isEmpty() && ShouldOpen) {
532 QStringList Row =
MethodModel->getRowFromIndex(Index);
533 auto method = Row.at(0).toStdString();
534 if (
SchemaClass->find_direct_method(method) ==
nullptr) {
536 "Method '" + method +
"' is not a direct method of " +
SchemaClass->get_name() +
537 ". Please open the method editor from the base class or add a local implementation to overrride it."
539 QMessageBox::warning(0,
"Schema editor", QString::fromStdString(message));
545 if (!Row.isEmpty() && ShouldOpen) {
557 if (!Row.isEmpty()) {
558 QString ClassName = Row.at(0);
568 if (!Row.isEmpty()) {
569 QString ClassName = Row.at(0);
577 bool WidgetFound =
false;
580 for (QWidget* Editor : QApplication::allWidgets()) {
583 if (Widget !=
nullptr) {
584 if ((Widget->objectName()).compare(ClassName) == 0) {
586 Widget->setVisible(
true);
587 Widget->activateWindow();
602 QStringList AttributeHeaders{
"Name",
"Type" };
610 ui->AttributeView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
611 ui->AttributeView->setSelectionBehavior(QAbstractItemView::SelectRows);
617 QStringList RelationshipHeaders{
"Name",
"Type",
"Low cc",
"High cc" };
629 ui->RelationshipView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
630 ui->RelationshipView->setSelectionBehavior(QAbstractItemView::SelectRows);
636 QStringList MethodHeaders{
"Method Name" };
646 ui->MethodsView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
647 ui->MethodsView->setSelectionBehavior(QAbstractItemView::SelectRows);
653 QStringList SuperClassHeaders{
"Class Name" };
661 ui->SuperClassView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
662 ui->SuperClassView->setSelectionBehavior(QAbstractItemView::SelectRows);
668 QStringList SubClassHeaders{
"Class Name" };
676 ui->SubClassView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
677 ui->SubClassView->setSelectionBehavior(QAbstractItemView::SelectRows);
686 QAction* Add =
new QAction(tr(
"&Add"),
this);
687 Add->setShortcut(tr(
"Ctrl+A"));
688 Add->setShortcutContext(Qt::WidgetShortcut);
691 QAction* Remove =
new QAction(tr(
"&Remove"),
this);
692 Remove->setShortcut(tr(
"Ctrl+R"));
693 Remove->setShortcutContext(Qt::WidgetShortcut);
700 QModelIndex Index =
ui->SuperClassView->currentIndex();
702 if (Index.isValid()) {
714 QAction* Add =
new QAction(tr(
"&Add"),
this);
715 Add->setShortcut(tr(
"Ctrl+A"));
716 Add->setShortcutContext(Qt::WidgetShortcut);
719 QAction* Remove =
new QAction(tr(
"&Remove"),
this);
720 Remove->setShortcut(tr(
"Ctrl+R"));
721 Remove->setShortcutContext(Qt::WidgetShortcut);
728 QModelIndex Index =
ui->AttributeView->currentIndex();
730 if (Index.isValid()) {
742 QAction* Add =
new QAction(tr(
"&Add"),
this);
743 Add->setShortcut(tr(
"Ctrl+A"));
744 Add->setShortcutContext(Qt::WidgetShortcut);
747 QAction* Remove =
new QAction(tr(
"&Remove"),
this);
748 Remove->setShortcut(tr(
"Ctrl+R"));
749 Remove->setShortcutContext(Qt::WidgetShortcut);
756 QModelIndex Index =
ui->RelationshipView->currentIndex();
758 if (Index.isValid()) {
770 QAction* Add =
new QAction(tr(
"&Add"),
this);
771 Add->setShortcut(tr(
"Ctrl+A"));
772 Add->setShortcutContext(Qt::WidgetShortcut);
773 connect(Add, SIGNAL(triggered()),
this, SLOT(
AddNewMethod()));
775 QAction* Remove =
new QAction(tr(
"&Remove"),
this);
776 Remove->setShortcut(tr(
"Ctrl+R"));
777 Remove->setShortcutContext(Qt::WidgetShortcut);
778 connect(Remove, SIGNAL(triggered()),
this, SLOT(
RemoveMethod()));
784 QModelIndex Index =
ui->MethodsView->currentIndex();
786 if (Index.isValid()) {
788 const std::string& methodName =
CurrentRow.at(0).toStdString();
790 if (SchemaMethod ==
nullptr) {
805 QMessageBox::warning(
808 QString(
"There is no active schema set!\n\nPlease set a schema file as active and continue!"));
817 QMessageBox::warning(0,
"Schema editor", QString(
"Can not create class because class already exist !"));
824 QString text = QInputDialog::getText(
825 nullptr,
"Schema editor: create new class",
"New class name:", QLineEdit::Normal,
"NewOksClass", &ok);
827 if (ok && !text.isEmpty()) {
839 bool widgetFound =
false;
841 for (QWidget* widget : QApplication::allWidgets()) {
843 if (editor !=
nullptr) {
844 if ((editor->objectName()).compare(class_name) == 0) {
846 widget->setVisible(
true);
847 widget->activateWindow();
CustomAttributeModel(dunedaq::oks::OksClass *ClassInfo, QStringList Headers, bool Derived=false)
CustomMethodModel(dunedaq::oks::OksClass *ClassInfo, QStringList Headers, bool Derived=false)
CustomRelationshipModel(dunedaq::oks::OksClass *ClassInfo, QStringList Headers, bool Derived=false)
CustomSubClassModel(dunedaq::oks::OksClass *ClassInfo, QStringList Headers)
CustomSuperClassModel(dunedaq::oks::OksClass *ClassInfo, QStringList Headers, bool Derived=false)
void PushRemoveSuperClassCommand(dunedaq::oks::OksClass *Class, std::string SuperClass)
void GetClassListString(QStringList &ClassListString) const
static KernelWrapper & GetInstance()
void PushSetAbstractClassCommand(dunedaq::oks::OksClass *Class, bool Value)
dunedaq::oks::OksClass * FindClass(std::string ClassName) const
void PushAddSuperClassCommand(dunedaq::oks::OksClass *Class, std::string SuperClass)
void ClassUpdated(QString ClassName)
void PushRemoveAttributeCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string name, std::string type, bool is_mv, std::string range, std::string init_values, std::string description, bool is_null, dunedaq::oks::OksAttribute::Format format=dunedaq::oks::OksAttribute::Format::Dec)
void PushSetDescriptionClassCommand(dunedaq::oks::OksClass *Class, std::string Description)
void PushRemoveRelationship(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, std::string Name, std::string Description, std::string Type, bool Composite, bool Exclusive, bool Dependent, dunedaq::oks::OksRelationship::CardinalityConstraint LowCc, dunedaq::oks::OksRelationship::CardinalityConstraint HighCc)
void PushRemoveMethodCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksMethod *Method, std::string name, std::string description)
void PushCreateClassCommand(std::string ClassName, std::string ClassDescription, bool Abstract)
void GetSchemaFiles(std::vector< std::string > &SchemaFiles)
RemoveRelationship(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, std::string Name, std::string Description, std::string Type, bool Composite, bool Exclusive, bool Dependent, dunedaq::oks::OksRelationship::CardinalityConstraint LowCc, dunedaq::oks::OksRelationship::CardinalityConstraint HighCc)
SchemaAttributeEditor(dunedaq::oks::OksClass *ClassInfo, dunedaq::oks::OksAttribute *AttributeData, QWidget *parent=nullptr)
void CustomMenuMethodView(QPoint pos)
void keyPressEvent(QKeyEvent *event)
void OpenRelationshipEditor(QModelIndex Index)
void ClassUpdated(QString className)
bool ShouldOpenAttributeEditor(QString Name)
Helper functions.
void RemoveRelationship()
CustomRelationshipModel * RelationshipModel
bool ShouldOpenRelationshipEditor(QString Name)
CustomSuperClassModel * SuperClassModel
bool ShouldOpenMethodEditor(QString Name)
QMenu * ContextMenuMethod
QMenu * ContextMenuRelationship
void BuildSubClassModelSlot()
CustomMethodModel * MethodModel
static void move_class(dunedaq::oks::OksClass *schema_class, QWidget *widget)
void BuildAttributeModelSlot()
void RemoveAttribute()
Remove Functions.
void BuildSuperClassModelSlot()
void BuildMethodModelSlot()
void CustomMenuRelationshipView(QPoint pos)
void ClassRemoved(QString className)
void OpenSuperClass(QModelIndex Index)
SchemaClassEditor(dunedaq::oks::OksClass *ClassInfo, QWidget *parent=nullptr)
static void launch(QString class_name)
QMenu * ContextMenuAttribute
dunedaq::oks::OksClass * SchemaClass
void CustomMenuClassView(QPoint pos)
void OpenMethodEditor(QModelIndex Index)
static QString createNewClass()
CustomAttributeModel * AttributeModel
void OpenSubClass(QModelIndex Index)
void AddNewRelationship()
std::unique_ptr< dbse::Ui::SchemaClassEditor > ui
void OpenAttributeEditor(QModelIndex Index)
void OpenNewClassEditor(const QString &ClassName)
void CustomMenuAttributeView(QPoint pos)
Context Menu Functions.
void BuildRelationshipModelSlot()
CustomSubClassModel * SubClassModel
SchemaMethodEditor(dunedaq::oks::OksClass *ClassInfo, dunedaq::oks::OksMethod *Method, QWidget *parent=nullptr)
SchemaRelationshipEditor(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, QWidget *parent=nullptr)
bool get_is_multi_values() const noexcept
const std::string & get_type() const noexcept
Get attribute string type.
const std::string & get_range() const noexcept
Get attribute range.
const std::string & get_name() const noexcept
out stream operator
const std::string & get_init_value() const noexcept
const std::string & get_description() const noexcept
bool get_is_no_null() const noexcept
Format get_format() const noexcept
Get attribute format.
void set_file(OksFile *f, bool update_owner=true)
Move class to different file.
const std::string & get_name() const noexcept
OksFile * get_file() const noexcept
const std::string & get_full_file_name() const
const std::string & get_description() const noexcept
const std::string & get_name() const noexcept
bool get_is_exclusive() const noexcept
bool get_is_composite() const noexcept
bool get_is_dependent() const noexcept
const std::string & get_name() const noexcept
CardinalityConstraint get_high_cardinality_constraint() const noexcept
Get relationship high cardinality constraint.
const std::string & get_description() const noexcept
CardinalityConstraint get_low_cardinality_constraint() const noexcept
Get relationship low cardinality constraint.
const std::string & get_type() const noexcept