DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbse::SchemaClassEditor Class Reference

#include <SchemaClassEditor.hpp>

Inheritance diagram for dbse::SchemaClassEditor:
[legend]
Collaboration diagram for dbse::SchemaClassEditor:
[legend]

Public Member Functions

 ~SchemaClassEditor ()
 
 SchemaClassEditor (dunedaq::oks::OksClass *ClassInfo, QWidget *parent=nullptr)
 

Static Public Member Functions

static QString createNewClass ()
 
static void launch (QString class_name)
 
static void move_class (dunedaq::oks::OksClass *schema_class, QWidget *widget)
 

Private Slots

void close_slot ()
 
void OpenSuperClass (QModelIndex Index)
 
void OpenSubClass (QModelIndex Index)
 
void ParseToSave ()
 
void AddNewSuperClass ()
 
void AddNewAttribute ()
 
void AddNewRelationship ()
 
void AddNewMethod ()
 
void OpenAttributeEditor (QModelIndex Index)
 
void OpenRelationshipEditor (QModelIndex Index)
 
void OpenMethodEditor (QModelIndex Index)
 
void BuildAttributeModelSlot ()
 
void BuildRelationshipModelSlot ()
 
void BuildSuperClassModelSlot ()
 
void BuildSubClassModelSlot ()
 
void BuildMethodModelSlot ()
 
void CustomMenuAttributeView (QPoint pos)
 Context Menu Functions.
 
void CustomMenuRelationshipView (QPoint pos)
 
void CustomMenuMethodView (QPoint pos)
 
void CustomMenuClassView (QPoint pos)
 
void RemoveAttribute ()
 Remove Functions.
 
void RemoveRelationship ()
 
void RemoveMethod ()
 
void RemoveSuperClass ()
 
void ClassRemoved (QString className)
 
void ClassUpdated (QString className)
 
void move_class ()
 

Private Member Functions

void keyPressEvent (QKeyEvent *event)
 
void SetController ()
 
void BuildModels ()
 
void InitialSettings ()
 
bool ShouldOpenAttributeEditor (QString Name)
 Helper functions.
 
bool ShouldOpenRelationshipEditor (QString Name)
 
bool ShouldOpenMethodEditor (QString Name)
 
void OpenNewClassEditor (const QString &ClassName)
 

Private Attributes

std::unique_ptr< dbse::Ui::SchemaClassEditor > ui
 
dunedaq::oks::OksClassSchemaClass
 
CustomMethodModelMethodModel
 
CustomAttributeModelAttributeModel
 
CustomRelationshipModelRelationshipModel
 
CustomSuperClassModelSuperClassModel
 
CustomSubClassModelSubClassModel
 
QMenu * ContextMenuAttribute
 
QMenu * ContextMenuRelationship
 
QMenu * ContextMenuMethod
 
QMenu * ContextMenuClass
 
QStringList CurrentRow
 

Detailed Description

Definition at line 25 of file SchemaClassEditor.hpp.

Constructor & Destructor Documentation

◆ ~SchemaClassEditor()

dbse::SchemaClassEditor::~SchemaClassEditor ( )
default

◆ SchemaClassEditor()

dbse::SchemaClassEditor::SchemaClassEditor ( dunedaq::oks::OksClass * ClassInfo,
QWidget * parent = nullptr )
explicit

Settings

Settings

Editing Settings

Definition at line 25 of file SchemaClassEditor.cpp.

26 : QWidget ( parent ),
27 ui ( new Ui::SchemaClassEditor ),
28 SchemaClass ( ClassInfo ),
29 MethodModel ( nullptr ),
30 AttributeModel ( nullptr ),
31 RelationshipModel ( nullptr ),
32 SuperClassModel ( nullptr ),
33 SubClassModel ( nullptr ),
34 ContextMenuAttribute ( nullptr ),
35 ContextMenuRelationship ( nullptr ),
36 ContextMenuMethod ( nullptr ),
37 ContextMenuClass ( nullptr )
38{
39 QWidget::setAttribute(Qt::WA_DeleteOnClose);
40
42 ui->setupUi ( this );
43 setWindowTitle (
44 QString ( "Class Editor : %1" ).arg ( QString::fromStdString (
45 SchemaClass->get_name() ) ) );
46 setObjectName ( QString::fromStdString ( SchemaClass->get_name() ) );
52}
CustomRelationshipModel * RelationshipModel
CustomSuperClassModel * SuperClassModel
CustomMethodModel * MethodModel
dunedaq::oks::OksClass * SchemaClass
CustomAttributeModel * AttributeModel
std::unique_ptr< dbse::Ui::SchemaClassEditor > ui
CustomSubClassModel * SubClassModel
const std::string & get_name() const noexcept
Definition class.hpp:363

Member Function Documentation

◆ AddNewAttribute

void dbse::SchemaClassEditor::AddNewAttribute ( )
privateslot

Definition at line 480 of file SchemaClassEditor.cpp.

481{
483 SchemaAttributeEditor * Editor = new SchemaAttributeEditor ( SchemaClass );
484 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildAttributeModelSlot() ) );
485 Editor->show();
486 }
487}
bool ShouldOpenAttributeEditor(QString Name)
Helper functions.

◆ AddNewMethod

void dbse::SchemaClassEditor::AddNewMethod ( )
privateslot

Definition at line 498 of file SchemaClassEditor.cpp.

499{
500 SchemaMethodEditor * Editor = new SchemaMethodEditor ( SchemaClass );
501 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildMethodModelSlot() ) );
502 Editor->show();
503}

◆ AddNewRelationship

void dbse::SchemaClassEditor::AddNewRelationship ( )
privateslot

Definition at line 489 of file SchemaClassEditor.cpp.

490{
492 SchemaRelationshipEditor * Editor = new SchemaRelationshipEditor ( SchemaClass );
493 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildRelationshipModelSlot() ) );
494 Editor->show();
495 }
496}
bool ShouldOpenRelationshipEditor(QString Name)

◆ AddNewSuperClass

void dbse::SchemaClassEditor::AddNewSuperClass ( )
privateslot

Definition at line 415 of file SchemaClassEditor.cpp.

416{
417 bool widgetFound=false;
418 QString class_name = QString::fromStdString(SchemaClass->get_name());
419
420 QString wname = "add_sc_"+class_name;
421 for ( QWidget* widget : QApplication::allWidgets() ) {
422 if (widget->objectName().compare(wname) == 0 ) {
423 widget->raise();
424 widget->setVisible ( true );
425 widget->activateWindow();
426 widgetFound = true;
427 break;
428 }
429 }
430
431 if (!widgetFound) {
432 QWidget* widget = new QWidget();
433 widget->setObjectName(wname);
434 QLabel* label = new QLabel("Select a super-class to add to " + class_name);
435 label->setWordWrap(true);
436
437 // QLabel* status = new QLabel();
438 // status->setStyleSheet("QLabel { color : green; }");
439
440 auto search = new QLineEdit(widget);
441 search->setPlaceholderText("Search classes");
442 search->setClearButtonEnabled(true);
443
444 QListWidget* qlwidget = new QListWidget();
445 QStringList allClasses;
447 qlwidget->addItems(allClasses);
448
449 connect ( qlwidget, &QListWidget::itemActivated,
450 this, [=] () {
451 const std::string& className = qlwidget->currentItem()->text().toStdString();
453 BuildModels();
454 // status->setText(QString::fromStdString(className + " added as a super-class of " + SchemaClass->get_name()));
455 });
456
457 connect (search, &QLineEdit::textChanged, this, [search, qlwidget] () {
458 auto items = qlwidget->findItems(search->text(), Qt::MatchRegularExpression);
459 if (!items.empty()) {
460 qlwidget->setCurrentItem(items[0]);
461 }
462 });
463
464 auto close_button = new QPushButton("Close");
465 connect (close_button, SIGNAL (clicked()), widget, SLOT(close()));
466 QVBoxLayout* lout = new QVBoxLayout();
467 lout->addWidget(label);
468 lout->addWidget(qlwidget);
469 lout->addWidget(search);
470 lout->addWidget(close_button);
471 // l->addWidget(status);
472
473 widget->setWindowTitle("Select super-class(es) for " + class_name);
474 widget->setLayout(lout);
475 widget->setParent(this, Qt::Dialog);
476 widget->show();
477 }
478}
void GetClassListString(QStringList &ClassListString) const
static KernelWrapper & GetInstance()
void PushAddSuperClassCommand(dunedaq::oks::OksClass *Class, std::string SuperClass)

◆ BuildAttributeModelSlot

void dbse::SchemaClassEditor::BuildAttributeModelSlot ( )
privateslot

Definition at line 608 of file SchemaClassEditor.cpp.

609{
610 QStringList AttributeHeaders
611 { "Name", "Type" };
612
613 if ( AttributeModel != nullptr ) {
614 delete AttributeModel;
615 }
616 AttributeModel = new CustomAttributeModel (
618 AttributeHeaders,
619 ui->ShowDerivedAttributes->isChecked());
620
621 ui->AttributeView->setModel ( AttributeModel );
622 ui->AttributeView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
623 ui->AttributeView->setSelectionBehavior ( QAbstractItemView::SelectRows );
624}

◆ BuildMethodModelSlot

void dbse::SchemaClassEditor::BuildMethodModelSlot ( )
privateslot

Definition at line 644 of file SchemaClassEditor.cpp.

645{
646 QStringList MethodHeaders
647 { "Method Name" };
648
649 if ( MethodModel == nullptr )
650 {
651 MethodModel = new CustomMethodModel ( SchemaClass, MethodHeaders, ui->ShowDerivedMethods->isChecked() );
652 }
653 else
654 {
655 delete MethodModel;
656 MethodModel = new CustomMethodModel ( SchemaClass, MethodHeaders, ui->ShowDerivedMethods->isChecked() );
657 }
658
659 ui->MethodsView->setModel ( MethodModel );
660 ui->MethodsView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
661 ui->MethodsView->setSelectionBehavior ( QAbstractItemView::SelectRows );
662}

◆ BuildModels()

void dbse::SchemaClassEditor::BuildModels ( )
private

◆ BuildRelationshipModelSlot

void dbse::SchemaClassEditor::BuildRelationshipModelSlot ( )
privateslot

Definition at line 626 of file SchemaClassEditor.cpp.

627{
628 QStringList RelationshipHeaders
629 { "Name", "Type", "Low cc", "High cc" };
630
631 if ( RelationshipModel == nullptr ) RelationshipModel = new CustomRelationshipModel (
632 SchemaClass, RelationshipHeaders, ui->ShowDerivedRelationships->isChecked() );
633 else
634 {
635 delete RelationshipModel;
636 RelationshipModel = new CustomRelationshipModel ( SchemaClass, RelationshipHeaders, ui->ShowDerivedRelationships->isChecked() );
637 }
638
639 ui->RelationshipView->setModel ( RelationshipModel );
640 ui->RelationshipView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
641 ui->RelationshipView->setSelectionBehavior ( QAbstractItemView::SelectRows );
642}

◆ BuildSubClassModelSlot

void dbse::SchemaClassEditor::BuildSubClassModelSlot ( )
privateslot

Definition at line 684 of file SchemaClassEditor.cpp.

685{
686 QStringList SubClassHeaders
687 { "Class Name" };
688
689 if ( SubClassModel == nullptr )
690 {
691 SubClassModel = new CustomSubClassModel ( SchemaClass, SubClassHeaders );
692 }
693 else
694 {
695 delete SubClassModel;
696 SubClassModel = new CustomSubClassModel ( SchemaClass, SubClassHeaders );
697 }
698
699 ui->SubClassView->setModel ( SubClassModel );
700 ui->SubClassView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
701 ui->SubClassView->setSelectionBehavior ( QAbstractItemView::SelectRows );
702}

◆ BuildSuperClassModelSlot

void dbse::SchemaClassEditor::BuildSuperClassModelSlot ( )
privateslot

Definition at line 664 of file SchemaClassEditor.cpp.

665{
666 QStringList SuperClassHeaders
667 { "Class Name" };
668
669 if ( SuperClassModel == nullptr )
670 {
671 SuperClassModel = new CustomSuperClassModel ( SchemaClass, SuperClassHeaders, ui->ShowAllSuperClasses->isChecked() );
672 }
673 else
674 {
675 delete SuperClassModel;
676 SuperClassModel = new CustomSuperClassModel ( SchemaClass, SuperClassHeaders, ui->ShowAllSuperClasses->isChecked() );
677 }
678
679 ui->SuperClassView->setModel ( SuperClassModel );
680 ui->SuperClassView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
681 ui->SuperClassView->setSelectionBehavior ( QAbstractItemView::SelectRows );
682}

◆ ClassRemoved

void dbse::SchemaClassEditor::ClassRemoved ( QString className)
privateslot

Definition at line 100 of file SchemaClassEditor.cpp.

101{
102 if(className == objectName()) {
103 QWidget::close();
104 }
105}

◆ ClassUpdated

void dbse::SchemaClassEditor::ClassUpdated ( QString className)
privateslot

Definition at line 107 of file SchemaClassEditor.cpp.

108{
109 if(className == objectName()) {
110 BuildModels();
112 }
113}

◆ close_slot

void dbse::SchemaClassEditor::close_slot ( )
inlineprivateslot

Definition at line 64 of file SchemaClassEditor.hpp.

64{close();}

◆ createNewClass()

QString dbse::SchemaClassEditor::createNewClass ( )
static

Definition at line 820 of file SchemaClassEditor.cpp.

821{
822 auto createNewClass = [] (const std::string& className) -> bool {
823 if ( !KernelWrapper::GetInstance().IsActive() )
824 {
825 QMessageBox::warning (
826 0,
827 "Schema editor",
828 QString (
829 "There is no active schema set!\n\nPlease set a schema file as active and continue!" ) );
830
831 return false;
832 }
833
834 if ( !KernelWrapper::GetInstance().FindClass ( className ) )
835 {
837 "", false );
838 return true;
839 }
840 else
841 {
842 QMessageBox::warning ( 0, "Schema editor",
843 QString ( "Can not create class because class already exist !" ) );
844
845 return false;
846 }
847 };
848
849 bool ok;
850 QString text = QInputDialog::getText(nullptr, "Schema editor: create new class",
851 "New class name:", QLineEdit::Normal,
852 "NewOksClass", &ok);
853
854 if(ok && !text.isEmpty()) {
855 if(createNewClass(text.toStdString())) {
856 SchemaClassEditor * Editor = new SchemaClassEditor(KernelWrapper::GetInstance().FindClass(text.toStdString()));
857 Editor->show();
858 }
859 }
860 return text;
861}
void PushCreateClassCommand(std::string ClassName, std::string ClassDescription, bool Abstract)
SchemaClassEditor(dunedaq::oks::OksClass *ClassInfo, QWidget *parent=nullptr)

◆ CustomMenuAttributeView

void dbse::SchemaClassEditor::CustomMenuAttributeView ( QPoint pos)
privateslot

Context Menu Functions.

Definition at line 733 of file SchemaClassEditor.cpp.

734{
735 if ( ContextMenuAttribute == nullptr )
736 {
737 ContextMenuAttribute = new QMenu ( this );
738
739 QAction * Add = new QAction ( tr ( "&Add" ), this );
740 Add->setShortcut ( tr ( "Ctrl+A" ) );
741 Add->setShortcutContext ( Qt::WidgetShortcut );
742 connect ( Add, SIGNAL ( triggered() ), this, SLOT ( AddNewAttribute() ) );
743
744 QAction * Remove = new QAction ( tr ( "&Remove" ), this );
745 Remove->setShortcut ( tr ( "Ctrl+R" ) );
746 Remove->setShortcutContext ( Qt::WidgetShortcut );
747 connect ( Remove, SIGNAL ( triggered() ), this, SLOT ( RemoveAttribute() ) );
748
749 ContextMenuAttribute->addAction ( Add );
750 ContextMenuAttribute->addAction ( Remove );
751 }
752
753 QModelIndex Index = ui->AttributeView->currentIndex();
754
755 if ( Index.isValid() )
756 {
758 ContextMenuAttribute->exec ( ui->AttributeView->mapToGlobal ( pos ) );
759 }
760}
QStringList getRowFromIndex(QModelIndex &index)
void RemoveAttribute()
Remove Functions.

◆ CustomMenuClassView

void dbse::SchemaClassEditor::CustomMenuClassView ( QPoint pos)
privateslot

Definition at line 704 of file SchemaClassEditor.cpp.

705{
706 if ( ContextMenuClass == nullptr )
707 {
708 ContextMenuClass = new QMenu ( this );
709
710 QAction * Add = new QAction ( tr ( "&Add" ), this );
711 Add->setShortcut ( tr ( "Ctrl+A" ) );
712 Add->setShortcutContext ( Qt::WidgetShortcut );
713 connect ( Add, SIGNAL ( triggered() ), this, SLOT ( AddNewSuperClass() ) );
714
715 QAction * Remove = new QAction ( tr ( "&Remove" ), this );
716 Remove->setShortcut ( tr ( "Ctrl+R" ) );
717 Remove->setShortcutContext ( Qt::WidgetShortcut );
718 connect ( Remove, SIGNAL ( triggered() ), this, SLOT ( RemoveSuperClass() ) );
719
720 ContextMenuClass->addAction ( Add );
721 ContextMenuClass->addAction ( Remove );
722 }
723
724 QModelIndex Index = ui->SuperClassView->currentIndex();
725
726 if ( Index.isValid() )
727 {
729 ContextMenuClass->exec ( ui->SuperClassView->mapToGlobal ( pos ) );
730 }
731}

◆ CustomMenuMethodView

void dbse::SchemaClassEditor::CustomMenuMethodView ( QPoint pos)
privateslot

Definition at line 791 of file SchemaClassEditor.cpp.

792{
793 if ( ContextMenuMethod == nullptr )
794 {
795 ContextMenuMethod = new QMenu ( this );
796
797 QAction * Add = new QAction ( tr ( "&Add" ), this );
798 Add->setShortcut ( tr ( "Ctrl+A" ) );
799 Add->setShortcutContext ( Qt::WidgetShortcut );
800 connect ( Add, SIGNAL ( triggered() ), this, SLOT ( AddNewMethod() ) );
801
802 QAction * Remove = new QAction ( tr ( "&Remove" ), this );
803 Remove->setShortcut ( tr ( "Ctrl+R" ) );
804 Remove->setShortcutContext ( Qt::WidgetShortcut );
805 connect ( Remove, SIGNAL ( triggered() ), this, SLOT ( RemoveMethod() ) );
806
807 ContextMenuMethod->addAction ( Add );
808 ContextMenuMethod->addAction ( Remove );
809 }
810
811 QModelIndex Index = ui->MethodsView->currentIndex();
812
813 if ( Index.isValid() )
814 {
816 ContextMenuMethod->exec ( ui->MethodsView->mapToGlobal ( pos ) );
817 }
818}

◆ CustomMenuRelationshipView

void dbse::SchemaClassEditor::CustomMenuRelationshipView ( QPoint pos)
privateslot

Definition at line 762 of file SchemaClassEditor.cpp.

763{
764 if ( ContextMenuRelationship == nullptr )
765 {
766 ContextMenuRelationship = new QMenu ( this );
767
768 QAction * Add = new QAction ( tr ( "&Add" ), this );
769 Add->setShortcut ( tr ( "Ctrl+A" ) );
770 Add->setShortcutContext ( Qt::WidgetShortcut );
771 connect ( Add, SIGNAL ( triggered() ), this, SLOT ( AddNewRelationship() ) );
772
773 QAction * Remove = new QAction ( tr ( "&Remove" ), this );
774 Remove->setShortcut ( tr ( "Ctrl+R" ) );
775 Remove->setShortcutContext ( Qt::WidgetShortcut );
776 connect ( Remove, SIGNAL ( triggered() ), this, SLOT ( RemoveRelationship() ) );
777
778 ContextMenuRelationship->addAction ( Add );
779 ContextMenuRelationship->addAction ( Remove );
780 }
781
782 QModelIndex Index = ui->RelationshipView->currentIndex();
783
784 if ( Index.isValid() )
785 {
787 ContextMenuRelationship->exec ( ui->RelationshipView->mapToGlobal ( pos ) );
788 }
789}

◆ InitialSettings()

void dbse::SchemaClassEditor::InitialSettings ( )
private

Class Name

Schema File

Description

Abstract

Definition at line 124 of file SchemaClassEditor.cpp.

125{
126 ui->AttributeView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
127 ui->RelationshipView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
128 ui->MethodsView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
129 ui->SuperClassView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
130 ui->SubClassView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
131
133 ui->ClassNameLineEdit->setText ( QString::fromStdString ( SchemaClass->get_name() ) );
134 //ui->ClassNameLineEdit->setEnabled ( false );
136 ui->SchemaFileLineEdit->setText ( QString::fromStdString ( SchemaClass->get_file()->get_short_file_name() ) );
137 //ui->SchemaFileLineEdit->setEnabled ( false );
138
139 if (KernelWrapper::GetInstance().IsFileWritable(
141 ui->AddButtonAttribute->setEnabled (true);
142 ui->AddButtonSuperClass->setEnabled (true);
143 ui->AddButtonRelationship->setEnabled (true);
144 ui->AddButtonMethod->setEnabled (true);
145 ui->moveButton->setEnabled (true);
146 }
147 else {
148 ui->SchemaFileLineEdit->setStyleSheet("color:rgb(128,0,0);");
149 // ui->DescriptionTextEdit->setEnabled(false);
150 ui->DescriptionTextEdit->setReadOnly(true);
151
152 ui->AddButtonAttribute->setEnabled (false);
153 ui->AddButtonSuperClass->setEnabled (false);
154 ui->AddButtonRelationship->setEnabled (false);
155 ui->AddButtonMethod->setEnabled (false);
156 ui->moveButton->setEnabled (false);
157 ui->AbstractComboBox->setEnabled(false);
158 }
159
161 ui->DescriptionTextEdit->setPlainText ( QString::fromStdString ( SchemaClass->get_description() ) );
162 ui->DescriptionTextEdit->setTabChangesFocus (true);
165 {
166 ui->AbstractComboBox->setCurrentIndex ( 0 );
167 }
168 else
169 {
170 ui->AbstractComboBox->setCurrentIndex ( 1 );
171 }
172}
bool get_is_abstract() const noexcept
Definition class.hpp:384
const std::string & get_description() const noexcept
Definition class.hpp:368
OksFile * get_file() const noexcept
Definition class.hpp:338
const std::string & get_short_file_name() const
Definition file.hpp:518
const std::string & get_full_file_name() const
Definition file.hpp:523

◆ keyPressEvent()

void dbse::SchemaClassEditor::keyPressEvent ( QKeyEvent * event)
private

Definition at line 56 of file SchemaClassEditor.cpp.

56 {
57 if (event->key() == Qt::Key_Escape) {
58 close();
59 }
60 QWidget::keyPressEvent(event);
61}

◆ launch()

void dbse::SchemaClassEditor::launch ( QString class_name)
static

Definition at line 863 of file SchemaClassEditor.cpp.

863 {
864 bool widgetFound=false;
865 dunedaq::oks::OksClass* class_info =
866 KernelWrapper::GetInstance().FindClass (class_name.toStdString());
867 for ( QWidget* widget : QApplication::allWidgets() ) {
868 SchemaClassEditor* editor = dynamic_cast<SchemaClassEditor *> (widget);
869 if (editor != nullptr) {
870 if ((editor->objectName()).compare(class_name) == 0 ) {
871 widget->raise();
872 widget->setVisible ( true );
873 widget->activateWindow();
874 widgetFound = true;
875 break;
876 }
877 }
878 }
879
880 if ( !widgetFound ) {
881 SchemaClassEditor* editor = new SchemaClassEditor (class_info);
882 editor->show();
883 }
884}
dunedaq::oks::OksClass * FindClass(std::string ClassName) const
The OKS class.
Definition class.hpp:200

◆ move_class [1/2]

void dbse::SchemaClassEditor::move_class ( )
privateslot

Definition at line 174 of file SchemaClassEditor.cpp.

174 {
175 move_class(SchemaClass, this);
176}

◆ move_class() [2/2]

void dbse::SchemaClassEditor::move_class ( dunedaq::oks::OksClass * schema_class,
QWidget * widget )
static

Definition at line 179 of file SchemaClassEditor.cpp.

180 {
181 std::string current_file = schema_class->get_file()->get_full_file_name();
182 std::vector<OksFile*> files;
184 QStringList writable_files;
185 std::map<QString, OksFile*> file_map;
186 int current_row = -1;
187 for (auto file: files) {
188 auto fn = file->get_full_file_name();
189 if (KernelWrapper::GetInstance().IsFileWritable(fn)) {
190 if (fn == current_file) {
191 current_row = writable_files.size();
192 }
193 writable_files.append(QString::fromStdString(fn));
194 file_map[QString::fromStdString(fn)] = file;
195 }
196 }
197 if (writable_files.empty()) {
198 QMessageBox::warning ( 0, "Schema editor",
199 QString ( "No writable schema files to move class to." ) );
200 return;
201 }
202
203 QWidget* widget = new QWidget();
204 QString text = "Select file to hold class " +
205 QString::fromStdString(schema_class->get_name());
206 QLabel* label = new QLabel(text);
207 QListWidget* qlw = new QListWidget();
208 qlw->addItems(writable_files);
209 if (current_row != -1) {
210 qlw->setCurrentRow(current_row);
211 }
212
213 connect (qlw, &QListWidget::itemActivated,
214 pwidget, [=] () {
215 QListWidgetItem* it = qlw->currentItem();
216 auto fn = it->text();
217 if (fn.toStdString() != current_file) {
218 schema_class->set_file(file_map.at(fn));
219 emit KernelWrapper::GetInstance().ClassUpdated ( QString::fromStdString(schema_class->get_name()) );
220 }
221 delete widget;
222 }
223 );
224
225 auto bb = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
226 connect (bb, &QDialogButtonBox::accepted, pwidget, [=] () {
227 auto it = qlw->currentItem();
228 if (it != nullptr) {
229 auto fn = it->text();
230 if (fn.toStdString() != current_file) {
231 schema_class->set_file(file_map.at(fn));
232 emit KernelWrapper::GetInstance().ClassUpdated ( QString::fromStdString(schema_class->get_name()) );
233 }
234 delete widget;
235 }
236 else {
237 QMessageBox::warning ( 0, "Schema editor",
238 QString ( "No schema file selected to move class to." ) );
239 return;
240 }
241 });
242 connect ( bb, &QDialogButtonBox::rejected, pwidget, [=] () {delete widget;} );
243
244 QVBoxLayout* layout = new QVBoxLayout();
245 layout->addWidget(label);
246 layout->addWidget(qlw);
247 layout->addWidget(bb);
248 widget->setWindowTitle("Select new file for class");
249 widget->setLayout(layout);
250 widget->setParent(pwidget, Qt::Dialog);
251 widget->show();
252}
void ClassUpdated(QString ClassName)
void GetSchemaFiles(std::vector< std::string > &SchemaFiles)
void set_file(OksFile *f, bool update_owner=true)
Move class to different file.
Definition class.cpp:286

◆ OpenAttributeEditor

void dbse::SchemaClassEditor::OpenAttributeEditor ( QModelIndex Index)
privateslot

Definition at line 505 of file SchemaClassEditor.cpp.

506{
507 QStringList Row = AttributeModel->getRowFromIndex ( Index );
508 bool ShouldOpen = ShouldOpenAttributeEditor ( Row.at ( 0 ) );
509
510 if ( !Row.isEmpty() && ShouldOpen )
511 {
512 SchemaAttributeEditor * Editor = new SchemaAttributeEditor (
513 SchemaClass, SchemaClass->find_attribute ( Row.at ( 0 ).toStdString() ) );
514 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildAttributeModelSlot() ) );
515 Editor->show();
516 }
517}
OksAttribute * find_attribute(const std::string &name) const noexcept
Find attribute (search in this and base classes).
Definition class.cpp:1026

◆ OpenMethodEditor

void dbse::SchemaClassEditor::OpenMethodEditor ( QModelIndex Index)
privateslot

Definition at line 533 of file SchemaClassEditor.cpp.

534{
535 QStringList Row = MethodModel->getRowFromIndex ( Index );
536 auto method = Row.at(0).toStdString();
537 if (SchemaClass->find_direct_method(method) == nullptr) {
538 std::string message{"Method '" + method + "' is not a direct method of " +
540". Please open the method editor from the base class or add a local implementation to overrride it."};
541 QMessageBox::warning (0,
542 "Schema editor",
543 QString::fromStdString(message));
544 return;
545 }
546
547 bool ShouldOpen = ShouldOpenMethodEditor ( Row.at ( 0 ) );
548
549 if ( !Row.isEmpty() && ShouldOpen )
550 {
551 SchemaMethodEditor * Editor = new SchemaMethodEditor (
552 SchemaClass, SchemaClass->find_method ( method ) );
553 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildMethodModelSlot() ) );
554 Editor->show();
555 }
556}
bool ShouldOpenMethodEditor(QString Name)
OksMethod * find_method(const std::string &name) const noexcept
Find method (search in this and base classes).
Definition class.cpp:1341
OksMethod * find_direct_method(const std::string &name) const noexcept
Find direct method.
Definition class.cpp:1330

◆ OpenNewClassEditor()

void dbse::SchemaClassEditor::OpenNewClassEditor ( const QString & ClassName)
private

Definition at line 580 of file SchemaClassEditor.cpp.

581{
582 bool WidgetFound = false;
583 OksClass * ClassInfo = KernelWrapper::GetInstance().FindClass ( ClassName.toStdString() );
584
585 for ( QWidget * Editor : QApplication::allWidgets() )
586 {
587 SchemaClassEditor * Widget = dynamic_cast<SchemaClassEditor *> ( Editor );
588
589 if ( Widget != nullptr )
590 {
591 if ( ( Widget->objectName() ).compare ( ClassName ) == 0 )
592 {
593 Widget->raise();
594 Widget->setVisible ( true );
595 Widget->activateWindow();
596 WidgetFound = true;
597 }
598 }
599 }
600
601 if ( !WidgetFound )
602 {
603 SchemaClassEditor * Editor = new SchemaClassEditor ( ClassInfo );
604 Editor->show();
605 }
606}

◆ OpenRelationshipEditor

void dbse::SchemaClassEditor::OpenRelationshipEditor ( QModelIndex Index)
privateslot

Definition at line 519 of file SchemaClassEditor.cpp.

520{
521 QStringList Row = RelationshipModel->getRowFromIndex ( Index );
522 bool ShouldOpen = ShouldOpenRelationshipEditor ( Row.at ( 0 ) );
523
524 if ( !Row.isEmpty() && ShouldOpen )
525 {
526 SchemaRelationshipEditor * Editor = new SchemaRelationshipEditor (
527 SchemaClass, SchemaClass->find_relationship ( Row.at ( 0 ).toStdString() ) );
528 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildRelationshipModelSlot() ) );
529 Editor->show();
530 }
531}
OksRelationship * find_relationship(const std::string &name) const noexcept
Find relationship (search in this and base classes).
Definition class.cpp:1184

◆ OpenSubClass

void dbse::SchemaClassEditor::OpenSubClass ( QModelIndex Index)
privateslot

Definition at line 569 of file SchemaClassEditor.cpp.

570{
571 QStringList Row = SubClassModel->getRowFromIndex ( Index );
572
573 if ( !Row.isEmpty() )
574 {
575 QString ClassName = Row.at ( 0 );
576 OpenNewClassEditor(ClassName);
577 }
578}
void OpenNewClassEditor(const QString &ClassName)

◆ OpenSuperClass

void dbse::SchemaClassEditor::OpenSuperClass ( QModelIndex Index)
privateslot

Definition at line 558 of file SchemaClassEditor.cpp.

559{
560 QStringList Row = SuperClassModel->getRowFromIndex ( Index );
561
562 if ( !Row.isEmpty() )
563 {
564 QString ClassName = Row.at ( 0 );
565 OpenNewClassEditor(ClassName);
566 }
567}

◆ ParseToSave

void dbse::SchemaClassEditor::ParseToSave ( )
privateslot

Definition at line 387 of file SchemaClassEditor.cpp.

388{
389 std::string NewDescription = ui->DescriptionTextEdit->toPlainText().toStdString();
390
391 bool Abstract = false;
392
393 if ( ui->AbstractComboBox->currentIndex() == 0 )
394 {
395 Abstract = true;
396 }
397 else
398 {
399 Abstract = false;
400 }
401
402 if ( Abstract != SchemaClass->get_is_abstract() )
403 {
405 }
406
407 if ( NewDescription != SchemaClass->get_description() )
408 {
410 }
411
412 close();
413}
void PushSetAbstractClassCommand(dunedaq::oks::OksClass *Class, bool Value)
void PushSetDescriptionClassCommand(dunedaq::oks::OksClass *Class, std::string Description)

◆ RemoveAttribute

void dbse::SchemaClassEditor::RemoveAttribute ( )
privateslot

Remove Functions.

Definition at line 320 of file SchemaClassEditor.cpp.

321{
322 const std::string& attributeName = CurrentRow.at ( 0 ).toStdString();
323 OksAttribute * SchemaAttribute = SchemaClass->find_direct_attribute( attributeName );
324 if(SchemaAttribute != nullptr) {
326 SchemaClass, SchemaAttribute, SchemaAttribute->get_name(), SchemaAttribute->get_type(),
327 SchemaAttribute->get_is_multi_values(), SchemaAttribute->get_range(),
328 SchemaAttribute->get_init_value(), SchemaAttribute->get_description(),
329 SchemaAttribute->get_is_no_null(), SchemaAttribute->get_format() );
330 } else {
331 QMessageBox::warning ( 0, "Schema editor",
332 QString::fromStdString( "Cannot remove attribute \"" + attributeName +
333 "\" because it is not a direct attribute of \"" + SchemaClass->get_name() + "\"") );
334 }
335}
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)
OKS attribute class.
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.
OksAttribute * find_direct_attribute(const std::string &name) const noexcept
Find direct attribute.
Definition class.cpp:1014

◆ RemoveMethod

void dbse::SchemaClassEditor::RemoveMethod ( )
privateslot

Definition at line 356 of file SchemaClassEditor.cpp.

357{
358 const std::string& methodName = CurrentRow.at ( 0 ).toStdString();
359 OksMethod * SchemaMethod = SchemaClass->find_direct_method ( methodName );
360 if(SchemaMethod != nullptr) {
362 SchemaMethod->get_name(),
363 SchemaMethod->get_description() );
364 } else {
365 QMessageBox::warning ( 0, "Schema editor",
366 QString::fromStdString( "Cannot remove method \"" + methodName +
367 "\" because it is not a direct method of \"" + SchemaClass->get_name() + "\"") );
368 }
369}
void PushRemoveMethodCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksMethod *Method, std::string name, std::string description)
OKS method class.
Definition method.hpp:153
const std::string & get_description() const noexcept
Definition method.hpp:214
const std::string & get_name() const noexcept
Definition method.hpp:196

◆ RemoveRelationship

void dbse::SchemaClassEditor::RemoveRelationship ( )
privateslot

Definition at line 337 of file SchemaClassEditor.cpp.

338{
339 const std::string& relationshipName = CurrentRow.at ( 0 ).toStdString();
340 OksRelationship * SchemaRelationship = SchemaClass->find_direct_relationship( relationshipName );
341 if(SchemaRelationship != nullptr) {
343 SchemaClass, SchemaRelationship, SchemaRelationship->get_name(),
344 SchemaRelationship->get_description(), SchemaRelationship->get_type(),
345 SchemaRelationship->get_is_composite(), SchemaRelationship->get_is_exclusive(),
346 SchemaRelationship->get_is_dependent(),
347 SchemaRelationship->get_low_cardinality_constraint(),
348 SchemaRelationship->get_high_cardinality_constraint() );
349 } else {
350 QMessageBox::warning ( 0, "Schema editor",
351 QString::fromStdString( "Cannot remove relationship \"" + relationshipName +
352 "\" because it is not a direct relationship of \"" + SchemaClass->get_name() + "\"") );
353 }
354}
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)
OksRelationship * find_direct_relationship(const std::string &name) const noexcept
Find direct relationship.
Definition class.cpp:1173
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

◆ RemoveSuperClass

void dbse::SchemaClassEditor::RemoveSuperClass ( )
privateslot

Definition at line 371 of file SchemaClassEditor.cpp.

372{
373 const std::string& superClassName = CurrentRow.at ( 0 ).toStdString();
374 if(SchemaClass->has_direct_super_class(superClassName))
375 {
377 }
378 else
379 {
380 QMessageBox::warning ( 0, "Schema editor",
381 QString::fromStdString( "Cannot remove super-class \"" + superClassName +
382 "\" because it is not a direct super-class of \"" + SchemaClass->get_name() + "\"") );
383 }
384}
void PushRemoveSuperClassCommand(dunedaq::oks::OksClass *Class, std::string SuperClass)
bool has_direct_super_class(const std::string &) const noexcept
Definition class.cpp:754

◆ SetController()

void dbse::SchemaClassEditor::SetController ( )
private

Definition at line 62 of file SchemaClassEditor.cpp.

63{
64 connect ( ui->buttonBox, SIGNAL ( accepted() ), this, SLOT ( ParseToSave() ) );
65 connect ( ui->buttonBox, SIGNAL ( rejected() ), this, SLOT ( close_slot() ) );
66 connect ( ui->moveButton, SIGNAL(clicked()), this, SLOT (move_class()));
67 connect ( ui->AddButtonAttribute, SIGNAL ( clicked() ), this, SLOT ( AddNewAttribute() ) );
68 connect ( ui->AddButtonSuperClass, SIGNAL ( clicked() ), this, SLOT ( AddNewSuperClass() ) );
69 connect ( ui->AddButtonRelationship, SIGNAL ( clicked() ), this,
70 SLOT ( AddNewRelationship() ) );
71 connect ( ui->AddButtonMethod, SIGNAL ( clicked() ), this, SLOT ( AddNewMethod() ) );
72 connect ( ui->RelationshipView, SIGNAL ( activated ( QModelIndex ) ), this,
73 SLOT ( OpenRelationshipEditor ( QModelIndex ) ) );
74 connect ( ui->MethodsView, SIGNAL ( activated ( QModelIndex ) ), this,
75 SLOT ( OpenMethodEditor ( QModelIndex ) ) );
76 connect ( ui->AttributeView, SIGNAL ( activated ( QModelIndex ) ), this,
77 SLOT ( OpenAttributeEditor ( QModelIndex ) ) );
78 connect ( ui->SuperClassView, SIGNAL ( activated ( QModelIndex ) ), this,
79 SLOT ( OpenSuperClass ( QModelIndex ) ) );
80 connect ( ui->SubClassView, SIGNAL ( activated ( QModelIndex ) ), this,
81 SLOT ( OpenSubClass ( QModelIndex ) ) );
82 connect ( ui->AttributeView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
83 SLOT ( CustomMenuAttributeView ( QPoint ) ) );
84 connect ( ui->RelationshipView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
85 SLOT ( CustomMenuRelationshipView ( QPoint ) ) );
86 connect ( ui->MethodsView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
87 SLOT ( CustomMenuMethodView ( QPoint ) ) );
88 connect ( ui->SuperClassView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
89 SLOT ( CustomMenuClassView ( QPoint ) ) );
90 connect ( ui->ShowDerivedAttributes, &QCheckBox::toggled, this, &SchemaClassEditor::BuildAttributeModelSlot );
91 connect ( ui->ShowDerivedRelationships, &QCheckBox::toggled, this, &SchemaClassEditor::BuildRelationshipModelSlot );
92 connect ( ui->ShowDerivedMethods, &QCheckBox::toggled, this, &SchemaClassEditor::BuildMethodModelSlot );
93 connect ( ui->ShowAllSuperClasses, &QCheckBox::toggled, this, &SchemaClassEditor::BuildSuperClassModelSlot );
94 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassRemoved ( QString ) ), this,
95 SLOT ( ClassRemoved ( QString ) ) );
96 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassUpdated ( QString ) ), this,
97 SLOT ( ClassUpdated ( QString ) ) );
98}
void CustomMenuMethodView(QPoint pos)
void OpenRelationshipEditor(QModelIndex Index)
void ClassUpdated(QString className)
void CustomMenuRelationshipView(QPoint pos)
void ClassRemoved(QString className)
void OpenSuperClass(QModelIndex Index)
void CustomMenuClassView(QPoint pos)
void OpenMethodEditor(QModelIndex Index)
void OpenSubClass(QModelIndex Index)
void OpenAttributeEditor(QModelIndex Index)
void CustomMenuAttributeView(QPoint pos)
Context Menu Functions.

◆ ShouldOpenAttributeEditor()

bool dbse::SchemaClassEditor::ShouldOpenAttributeEditor ( QString Name)
private

Helper functions.

Definition at line 254 of file SchemaClassEditor.cpp.

255{
256 QString name = QString::fromStdString(SchemaClass->get_name() + "::") +
257 attrName;
258 for (QWidget* widget : QApplication::allWidgets())
259 {
260 if (dynamic_cast<SchemaAttributeEditor *> (widget) != nullptr)
261 {
262 if ( (widget->objectName()).compare (name) == 0 )
263 {
264 widget->raise();
265 widget->setVisible ( true );
266 widget->activateWindow();
267 return false;
268 }
269 }
270 }
271
272 return true;
273}

◆ ShouldOpenMethodEditor()

bool dbse::SchemaClassEditor::ShouldOpenMethodEditor ( QString Name)
private

Definition at line 297 of file SchemaClassEditor.cpp.

298{
299 bool WidgetFound = false;
300
301 for ( QWidget * Editor : QApplication::allWidgets() )
302 {
303 SchemaMethodEditor * Widget = dynamic_cast<SchemaMethodEditor *> ( Editor );
304
305 if ( Widget != nullptr )
306 {
307 if ( ( Widget->objectName() ).compare ( Name ) == 0 )
308 {
309 Widget->raise();
310 Widget->setVisible ( true );
311 Widget->activateWindow();
312 WidgetFound = true;
313 }
314 }
315 }
316
317 return !WidgetFound;
318}

◆ ShouldOpenRelationshipEditor()

bool dbse::SchemaClassEditor::ShouldOpenRelationshipEditor ( QString Name)
private

Definition at line 275 of file SchemaClassEditor.cpp.

276{
277 QString name = QString::fromStdString(SchemaClass->get_name() + "::") +
278 relName;
279
280 for ( QWidget* widget : QApplication::allWidgets() )
281 {
282 if (dynamic_cast<SchemaRelationshipEditor *> (widget) != nullptr)
283 {
284 if ( ( widget->objectName() ).compare ( name ) == 0 )
285 {
286 widget->raise();
287 widget->setVisible ( true );
288 widget->activateWindow();
289 return false;
290 }
291 }
292 }
293
294 return true;
295}

Member Data Documentation

◆ AttributeModel

CustomAttributeModel* dbse::SchemaClassEditor::AttributeModel
private

Definition at line 51 of file SchemaClassEditor.hpp.

◆ ContextMenuAttribute

QMenu* dbse::SchemaClassEditor::ContextMenuAttribute
private

Definition at line 55 of file SchemaClassEditor.hpp.

◆ ContextMenuClass

QMenu* dbse::SchemaClassEditor::ContextMenuClass
private

Definition at line 58 of file SchemaClassEditor.hpp.

◆ ContextMenuMethod

QMenu* dbse::SchemaClassEditor::ContextMenuMethod
private

Definition at line 57 of file SchemaClassEditor.hpp.

◆ ContextMenuRelationship

QMenu* dbse::SchemaClassEditor::ContextMenuRelationship
private

Definition at line 56 of file SchemaClassEditor.hpp.

◆ CurrentRow

QStringList dbse::SchemaClassEditor::CurrentRow
private

Definition at line 59 of file SchemaClassEditor.hpp.

◆ MethodModel

CustomMethodModel* dbse::SchemaClassEditor::MethodModel
private

Definition at line 50 of file SchemaClassEditor.hpp.

◆ RelationshipModel

CustomRelationshipModel* dbse::SchemaClassEditor::RelationshipModel
private

Definition at line 52 of file SchemaClassEditor.hpp.

◆ SchemaClass

dunedaq::oks::OksClass* dbse::SchemaClassEditor::SchemaClass
private

Definition at line 49 of file SchemaClassEditor.hpp.

◆ SubClassModel

CustomSubClassModel* dbse::SchemaClassEditor::SubClassModel
private

Definition at line 54 of file SchemaClassEditor.hpp.

◆ SuperClassModel

CustomSuperClassModel* dbse::SchemaClassEditor::SuperClassModel
private

Definition at line 53 of file SchemaClassEditor.hpp.

◆ ui

std::unique_ptr<dbse::Ui::SchemaClassEditor> dbse::SchemaClassEditor::ui
private

Definition at line 47 of file SchemaClassEditor.hpp.


The documentation for this class was generated from the following files: