12#include "ui_SchemaClassEditor.h"
19 SchemaClass ( ClassInfo ),
20 MethodModel ( nullptr ),
21 AttributeModel ( nullptr ),
22 RelationshipModel ( nullptr ),
23 SuperClassModel ( nullptr ),
24 SubClassModel ( nullptr ),
25 ContextMenuAttribute ( nullptr ),
26 ContextMenuRelationship ( nullptr ),
27 ContextMenuMethod ( nullptr ),
28 ContextMenuClass ( nullptr )
30 QWidget::setAttribute(Qt::WA_DeleteOnClose);
35 QString (
"Class Editor : %1" ).arg ( QString::fromStdString (
49 connect ( ui->SaveButton, SIGNAL ( clicked() ),
this, SLOT ( ProxySlot() ) );
50 connect ( ui->AddButtonAttribute, SIGNAL ( clicked() ),
this, SLOT ( AddNewAttribute() ) );
51 connect ( ui->AddButtonSuperClass, SIGNAL ( clicked() ),
this, SLOT ( AddNewSuperClass() ) );
52 connect ( ui->AddButtonRelationship, SIGNAL ( clicked() ),
this,
53 SLOT ( AddNewRelationship() ) );
54 connect ( ui->AddButtonMethod, SIGNAL ( clicked() ),
this, SLOT ( AddNewMethod() ) );
55 connect ( ui->RelationshipView, SIGNAL ( doubleClicked ( QModelIndex ) ),
this,
56 SLOT ( OpenRelationshipEditor ( QModelIndex ) ) );
57 connect ( ui->MethodsView, SIGNAL ( doubleClicked ( QModelIndex ) ),
this,
58 SLOT ( OpenMethodEditor ( QModelIndex ) ) );
59 connect ( ui->AttributeView, SIGNAL ( doubleClicked ( QModelIndex ) ),
this,
60 SLOT ( OpenAttributeEditor ( QModelIndex ) ) );
61 connect ( ui->SuperClassView, SIGNAL ( doubleClicked ( QModelIndex ) ),
this,
62 SLOT ( OpenSuperClass ( QModelIndex ) ) );
63 connect ( ui->SubClassView, SIGNAL ( doubleClicked ( QModelIndex ) ),
this,
64 SLOT ( OpenSubClass ( QModelIndex ) ) );
65 connect ( ui->AttributeView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
66 SLOT ( CustomMenuAttributeView ( QPoint ) ) );
67 connect ( ui->RelationshipView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
68 SLOT ( CustomMenuRelationshipView ( QPoint ) ) );
69 connect ( ui->MethodsView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
70 SLOT ( CustomMenuMethodView ( QPoint ) ) );
71 connect ( ui->SuperClassView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
72 SLOT ( CustomMenuClassView ( QPoint ) ) );
78 SLOT ( ClassRemoved ( QString ) ) );
80 SLOT ( ClassUpdated ( QString ) ) );
85 if(className == objectName()) {
92 if(className == objectName()) {
100 BuildSubClassModelSlot();
101 BuildSuperClassModelSlot();
102 BuildMethodModelSlot();
103 BuildAttributeModelSlot();
104 BuildRelationshipModelSlot();
109 ui->AttributeView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
110 ui->RelationshipView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
111 ui->MethodsView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
112 ui->SuperClassView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
113 ui->SubClassView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
116 ui->ClassNameLineEdit->setText ( QString::fromStdString ( SchemaClass->get_name() ) );
117 ui->ClassNameLineEdit->setEnabled (
false );
119 ui->SchemaFileLineEdit->setText ( QString::fromStdString ( SchemaClass->get_file()->get_short_file_name() ) );
120 ui->SchemaFileLineEdit->setEnabled (
false );
122 ui->DescriptionTextEdit->setPlainText ( QString::fromStdString ( SchemaClass->get_description() ) );
125 if ( SchemaClass->get_is_abstract() )
127 ui->AbstractComboBox->setCurrentIndex ( 0 );
131 ui->AbstractComboBox->setCurrentIndex ( 1 );
137 bool WidgetFound =
false;
139 for ( QWidget * Editor : QApplication::allWidgets() )
143 if ( Widget !=
nullptr )
145 if ( ( Widget->objectName() ).compare ( Name ) == 0 )
148 Widget->setVisible (
true );
149 Widget->activateWindow();
160 bool WidgetFound =
false;
162 for ( QWidget * Editor : QApplication::allWidgets() )
166 if ( Widget !=
nullptr )
168 if ( ( Widget->objectName() ).compare ( Name ) == 0 )
171 Widget->setVisible (
true );
172 Widget->activateWindow();
183 bool WidgetFound =
false;
185 for ( QWidget * Editor : QApplication::allWidgets() )
189 if ( Widget !=
nullptr )
191 if ( ( Widget->objectName() ).compare ( Name ) == 0 )
194 Widget->setVisible (
true );
195 Widget->activateWindow();
206 const std::string& attributeName = CurrentRow.at ( 0 ).toStdString();
207 OksAttribute * SchemaAttribute = SchemaClass->find_direct_attribute( attributeName );
208 if(SchemaAttribute !=
nullptr) {
210 SchemaClass, SchemaAttribute, SchemaAttribute->
get_name(), SchemaAttribute->
get_type(),
215 QMessageBox::warning ( 0,
"Schema editor",
216 QString::fromStdString(
"Cannot remove attribute \"" + attributeName +
217 "\" because it is not a direct attribute of \"" + SchemaClass->get_name() +
"\"") );
223 const std::string& relationshipName = CurrentRow.at ( 0 ).toStdString();
224 OksRelationship * SchemaRelationship = SchemaClass->find_direct_relationship( relationshipName );
225 if(SchemaRelationship !=
nullptr) {
227 SchemaClass, SchemaRelationship, SchemaRelationship->
get_name(),
234 QMessageBox::warning ( 0,
"Schema editor",
235 QString::fromStdString(
"Cannot remove relationship \"" + relationshipName +
236 "\" because it is not a direct relationship of \"" + SchemaClass->get_name() +
"\"") );
242 const std::string& methodName = CurrentRow.at ( 0 ).toStdString();
243 OksMethod * SchemaMethod = SchemaClass->find_direct_method ( methodName );
244 if(SchemaMethod !=
nullptr) {
249 QMessageBox::warning ( 0,
"Schema editor",
250 QString::fromStdString(
"Cannot remove method \"" + methodName +
251 "\" because it is not a direct method of \"" + SchemaClass->get_name() +
"\"") );
257 const std::string& superClassName = CurrentRow.at ( 0 ).toStdString();
258 if(SchemaClass->has_direct_super_class(superClassName))
264 QMessageBox::warning ( 0,
"Schema editor",
265 QString::fromStdString(
"Cannot remove super-class \"" + superClassName +
266 "\" because it is not a direct super-class of \"" + SchemaClass->get_name() +
"\"") );
278 std::string NewDescription = ui->DescriptionTextEdit->toPlainText().toStdString();
280 bool Abstract =
false;
282 if ( ui->AbstractComboBox->currentIndex() == 0 )
291 if ( Abstract != SchemaClass->get_is_abstract() )
296 if ( NewDescription != SchemaClass->get_description() )
306 QWidget* w =
new QWidget();
308 QLabel* label =
new QLabel(
"Double click on a list item to add the corresponding super-class");
309 label->setWordWrap(
true);
311 QLabel* status =
new QLabel();
312 status->setStyleSheet(
"QLabel { color : green; }");
314 QListWidget* qlw =
new QListWidget();
315 QStringList allClasses;
317 qlw->addItems(allClasses);
319 connect ( qlw, &QListWidget::itemDoubleClicked,
321 const std::string& className = qlw->currentItem()->text().toStdString();
324 status->setText(QString::fromStdString(className +
" added as a super-class of " + SchemaClass->get_name()));
327 QVBoxLayout* l =
new QVBoxLayout();
330 l->addWidget(status);
332 w->setWindowTitle(
"Select super-classe(s)");
334 w->setParent(
this, Qt::Dialog);
341 connect ( Editor, SIGNAL ( RebuildModel() ),
this, SLOT ( BuildAttributeModelSlot() ) );
348 connect ( Editor, SIGNAL ( RebuildModel() ),
this, SLOT ( BuildRelationshipModelSlot() ) );
355 connect ( Editor, SIGNAL ( RebuildModel() ),
this, SLOT ( BuildMethodModelSlot() ) );
361 QStringList Row = AttributeModel->getRowFromIndex ( Index );
362 bool ShouldOpen = ShouldOpenAttributeEditor ( Row.at ( 0 ) );
364 if ( !Row.isEmpty() && ShouldOpen )
367 SchemaClass, SchemaClass->find_attribute ( Row.at ( 0 ).toStdString() ) );
368 connect ( Editor, SIGNAL ( RebuildModel() ),
this, SLOT ( BuildAttributeModelSlot() ) );
375 QStringList Row = RelationshipModel->getRowFromIndex ( Index );
376 bool ShouldOpen = ShouldOpenRelationshipEditor ( Row.at ( 0 ) );
378 if ( !Row.isEmpty() && ShouldOpen )
381 SchemaClass, SchemaClass->find_relationship ( Row.at ( 0 ).toStdString() ) );
382 connect ( Editor, SIGNAL ( RebuildModel() ),
this, SLOT ( BuildRelationshipModelSlot() ) );
389 QStringList Row = MethodModel->getRowFromIndex ( Index );
390 bool ShouldOpen = ShouldOpenMethodEditor ( Row.at ( 0 ) );
392 if ( !Row.isEmpty() && ShouldOpen )
395 SchemaClass, SchemaClass->find_method ( Row.at ( 0 ).toStdString() ) );
396 connect ( Editor, SIGNAL ( RebuildModel() ),
this, SLOT ( BuildMethodModelSlot() ) );
403 QStringList Row = SuperClassModel->getRowFromIndex ( Index );
405 if ( !Row.isEmpty() )
407 QString ClassName = Row.at ( 0 );
408 OpenNewClassEditor(ClassName);
414 QStringList Row = SubClassModel->getRowFromIndex ( Index );
416 if ( !Row.isEmpty() )
418 QString ClassName = Row.at ( 0 );
419 OpenNewClassEditor(ClassName);
425 bool WidgetFound =
false;
428 for ( QWidget * Editor : QApplication::allWidgets() )
432 if ( Widget !=
nullptr )
434 if ( ( Widget->objectName() ).compare ( ClassName ) == 0 )
437 Widget->setVisible (
true );
438 Widget->activateWindow();
453 QStringList AttributeHeaders
458 ui->ShowDerivedAttributes->isChecked());
461 delete AttributeModel;
462 AttributeModel =
new CustomAttributeModel ( SchemaClass, AttributeHeaders, ui->ShowDerivedAttributes->isChecked() );
465 ui->AttributeView->setModel ( AttributeModel );
466 ui->AttributeView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
467 ui->AttributeView->setSelectionBehavior ( QAbstractItemView::SelectRows );
472 QStringList RelationshipHeaders
473 {
"Name",
"Type",
"Low cc",
"High cc" };
476 SchemaClass, RelationshipHeaders, ui->ShowDerivedRelationships->isChecked() );
479 delete RelationshipModel;
480 RelationshipModel =
new CustomRelationshipModel ( SchemaClass, RelationshipHeaders, ui->ShowDerivedRelationships->isChecked() );
483 ui->RelationshipView->setModel ( RelationshipModel );
484 ui->RelationshipView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
485 ui->RelationshipView->setSelectionBehavior ( QAbstractItemView::SelectRows );
490 QStringList MethodHeaders
493 if ( MethodModel ==
nullptr )
495 MethodModel =
new CustomMethodModel ( SchemaClass, MethodHeaders, ui->ShowDerivedMethods->isChecked() );
500 MethodModel =
new CustomMethodModel ( SchemaClass, MethodHeaders, ui->ShowDerivedMethods->isChecked() );
503 ui->MethodsView->setModel ( MethodModel );
504 ui->MethodsView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
505 ui->MethodsView->setSelectionBehavior ( QAbstractItemView::SelectRows );
510 QStringList SuperClassHeaders
513 if ( SuperClassModel ==
nullptr )
515 SuperClassModel =
new CustomSuperClassModel ( SchemaClass, SuperClassHeaders, ui->ShowAllSuperClasses->isChecked() );
519 delete SuperClassModel;
520 SuperClassModel =
new CustomSuperClassModel ( SchemaClass, SuperClassHeaders, ui->ShowAllSuperClasses->isChecked() );
523 ui->SuperClassView->setModel ( SuperClassModel );
524 ui->SuperClassView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
525 ui->SuperClassView->setSelectionBehavior ( QAbstractItemView::SelectRows );
530 QStringList SubClassHeaders
533 if ( SubClassModel ==
nullptr )
539 delete SubClassModel;
543 ui->SubClassView->setModel ( SubClassModel );
544 ui->SubClassView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
545 ui->SubClassView->setSelectionBehavior ( QAbstractItemView::SelectRows );
550 if ( ContextMenuClass ==
nullptr )
552 ContextMenuClass =
new QMenu (
this );
554 QAction * Add =
new QAction ( tr (
"&Add" ),
this );
555 Add->setShortcut ( tr (
"Ctrl+A" ) );
556 Add->setShortcutContext ( Qt::WidgetShortcut );
557 connect ( Add, SIGNAL ( triggered() ),
this, SLOT ( AddNewSuperClass() ) );
559 QAction * Remove =
new QAction ( tr (
"&Remove" ),
this );
560 Remove->setShortcut ( tr (
"Ctrl+R" ) );
561 Remove->setShortcutContext ( Qt::WidgetShortcut );
562 connect ( Remove, SIGNAL ( triggered() ),
this, SLOT ( RemoveSuperClass() ) );
564 ContextMenuClass->addAction ( Add );
565 ContextMenuClass->addAction ( Remove );
568 QModelIndex Index = ui->SuperClassView->currentIndex();
570 if ( Index.isValid() )
572 CurrentRow = SuperClassModel->getRowFromIndex ( Index );
573 ContextMenuClass->exec ( ui->SuperClassView->mapToGlobal ( pos ) );
579 if ( ContextMenuAttribute ==
nullptr )
581 ContextMenuAttribute =
new QMenu (
this );
583 QAction * Add =
new QAction ( tr (
"&Add" ),
this );
584 Add->setShortcut ( tr (
"Ctrl+A" ) );
585 Add->setShortcutContext ( Qt::WidgetShortcut );
586 connect ( Add, SIGNAL ( triggered() ),
this, SLOT ( AddNewAttribute() ) );
588 QAction * Remove =
new QAction ( tr (
"&Remove" ),
this );
589 Remove->setShortcut ( tr (
"Ctrl+R" ) );
590 Remove->setShortcutContext ( Qt::WidgetShortcut );
591 connect ( Remove, SIGNAL ( triggered() ),
this, SLOT ( RemoveAttribute() ) );
593 ContextMenuAttribute->addAction ( Add );
594 ContextMenuAttribute->addAction ( Remove );
597 QModelIndex Index = ui->AttributeView->currentIndex();
599 if ( Index.isValid() )
601 CurrentRow = AttributeModel->getRowFromIndex ( Index );
602 ContextMenuAttribute->exec ( ui->AttributeView->mapToGlobal ( pos ) );
608 if ( ContextMenuRelationship ==
nullptr )
610 ContextMenuRelationship =
new QMenu (
this );
612 QAction * Add =
new QAction ( tr (
"&Add" ),
this );
613 Add->setShortcut ( tr (
"Ctrl+A" ) );
614 Add->setShortcutContext ( Qt::WidgetShortcut );
615 connect ( Add, SIGNAL ( triggered() ),
this, SLOT ( AddNewRelationship() ) );
617 QAction * Remove =
new QAction ( tr (
"&Remove" ),
this );
618 Remove->setShortcut ( tr (
"Ctrl+R" ) );
619 Remove->setShortcutContext ( Qt::WidgetShortcut );
622 ContextMenuRelationship->addAction ( Add );
623 ContextMenuRelationship->addAction ( Remove );
626 QModelIndex Index = ui->RelationshipView->currentIndex();
628 if ( Index.isValid() )
630 CurrentRow = RelationshipModel->getRowFromIndex ( Index );
631 ContextMenuRelationship->exec ( ui->RelationshipView->mapToGlobal ( pos ) );
637 if ( ContextMenuMethod ==
nullptr )
639 ContextMenuMethod =
new QMenu (
this );
641 QAction * Add =
new QAction ( tr (
"&Add" ),
this );
642 Add->setShortcut ( tr (
"Ctrl+A" ) );
643 Add->setShortcutContext ( Qt::WidgetShortcut );
644 connect ( Add, SIGNAL ( triggered() ),
this, SLOT ( AddNewMethod() ) );
646 QAction * Remove =
new QAction ( tr (
"&Remove" ),
this );
647 Remove->setShortcut ( tr (
"Ctrl+R" ) );
648 Remove->setShortcutContext ( Qt::WidgetShortcut );
649 connect ( Remove, SIGNAL ( triggered() ),
this, SLOT ( RemoveMethod() ) );
651 ContextMenuMethod->addAction ( Add );
652 ContextMenuMethod->addAction ( Remove );
655 QModelIndex Index = ui->MethodsView->currentIndex();
657 if ( Index.isValid() )
659 CurrentRow = MethodModel->getRowFromIndex ( Index );
660 ContextMenuMethod->exec ( ui->MethodsView->mapToGlobal ( pos ) );
666 auto createNewClass = [] (
const std::string& className) ->
bool {
669 QMessageBox::warning (
673 "There is no active schema set!\n\nPlease set a schema file as active and continue!" ) );
686 QMessageBox::warning ( 0,
"Schema editor",
687 QString (
"Can not create class because class already exist !" ) );
694 QString text = QInputDialog::getText(
nullptr,
"Schema editor: create new class",
695 "New class name:", QLineEdit::Normal,
698 if(ok && !text.isEmpty()) {
699 if(createNewClass(text.toStdString())) {
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 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 CustomMenuMethodView(QPoint pos)
void OpenRelationshipEditor(QModelIndex Index)
void ClassUpdated(QString className)
bool ShouldOpenAttributeEditor(QString Name)
Helper functions.
void RemoveRelationship()
bool ShouldOpenRelationshipEditor(QString Name)
bool ShouldOpenMethodEditor(QString Name)
void BuildSubClassModelSlot()
void BuildAttributeModelSlot()
void RemoveAttribute()
Remove Functions.
void BuildSuperClassModelSlot()
static void createNewClass()
void BuildMethodModelSlot()
void CustomMenuRelationshipView(QPoint pos)
void ClassRemoved(QString className)
void OpenSuperClass(QModelIndex Index)
SchemaClassEditor(dunedaq::oks::OksClass *ClassInfo, QWidget *parent=nullptr)
dunedaq::oks::OksClass * SchemaClass
void CustomMenuClassView(QPoint pos)
void OpenMethodEditor(QModelIndex Index)
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()
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.
const std::string & get_name() const noexcept
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