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 30 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 30 of file SchemaClassEditor.cpp.

31 : QWidget ( parent ),
32 ui ( new Ui::SchemaClassEditor ),
33 SchemaClass ( ClassInfo ),
34 MethodModel ( nullptr ),
35 AttributeModel ( nullptr ),
36 RelationshipModel ( nullptr ),
37 SuperClassModel ( nullptr ),
38 SubClassModel ( nullptr ),
39 ContextMenuAttribute ( nullptr ),
40 ContextMenuRelationship ( nullptr ),
41 ContextMenuMethod ( nullptr ),
42 ContextMenuClass ( nullptr )
43{
44 QWidget::setAttribute(Qt::WA_DeleteOnClose);
45
47 ui->setupUi ( this );
48 setWindowTitle (
49 QString ( "Class Editor : %1" ).arg ( QString::fromStdString (
50 SchemaClass->get_name() ) ) );
51 setObjectName ( QString::fromStdString ( SchemaClass->get_name() ) );
57}
CustomRelationshipModel * RelationshipModel
CustomSuperClassModel * SuperClassModel
CustomMethodModel * MethodModel
dunedaq::oks::OksClass * SchemaClass
CustomAttributeModel * AttributeModel
std::unique_ptr< dbse::Ui::SchemaClassEditor > ui
CustomSubClassModel * SubClassModel

Member Function Documentation

◆ AddNewAttribute

void dbse::SchemaClassEditor::AddNewAttribute ( )
privateslot

Definition at line 485 of file SchemaClassEditor.cpp.

486{
488 SchemaAttributeEditor * Editor = new SchemaAttributeEditor ( SchemaClass );
489 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildAttributeModelSlot() ) );
490 Editor->show();
491 }
492}
bool ShouldOpenAttributeEditor(QString Name)
Helper functions.

◆ AddNewMethod

void dbse::SchemaClassEditor::AddNewMethod ( )
privateslot

Definition at line 503 of file SchemaClassEditor.cpp.

504{
505 SchemaMethodEditor * Editor = new SchemaMethodEditor ( SchemaClass );
506 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildMethodModelSlot() ) );
507 Editor->show();
508}

◆ AddNewRelationship

void dbse::SchemaClassEditor::AddNewRelationship ( )
privateslot

Definition at line 494 of file SchemaClassEditor.cpp.

495{
497 SchemaRelationshipEditor * Editor = new SchemaRelationshipEditor ( SchemaClass );
498 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildRelationshipModelSlot() ) );
499 Editor->show();
500 }
501}
bool ShouldOpenRelationshipEditor(QString Name)

◆ AddNewSuperClass

void dbse::SchemaClassEditor::AddNewSuperClass ( )
privateslot

Definition at line 420 of file SchemaClassEditor.cpp.

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

614{
615 QStringList AttributeHeaders
616 { "Name", "Type" };
617
618 if ( AttributeModel != nullptr ) {
619 delete AttributeModel;
620 }
621 AttributeModel = new CustomAttributeModel (
623 AttributeHeaders,
624 ui->ShowDerivedAttributes->isChecked());
625
626 ui->AttributeView->setModel ( AttributeModel );
627 ui->AttributeView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
628 ui->AttributeView->setSelectionBehavior ( QAbstractItemView::SelectRows );
629}

◆ BuildMethodModelSlot

void dbse::SchemaClassEditor::BuildMethodModelSlot ( )
privateslot

Definition at line 649 of file SchemaClassEditor.cpp.

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

◆ BuildModels()

void dbse::SchemaClassEditor::BuildModels ( )
private

◆ BuildRelationshipModelSlot

void dbse::SchemaClassEditor::BuildRelationshipModelSlot ( )
privateslot

Definition at line 631 of file SchemaClassEditor.cpp.

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

◆ BuildSubClassModelSlot

void dbse::SchemaClassEditor::BuildSubClassModelSlot ( )
privateslot

Definition at line 685 of file SchemaClassEditor.cpp.

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

◆ BuildSuperClassModelSlot

void dbse::SchemaClassEditor::BuildSuperClassModelSlot ( )
privateslot

Definition at line 669 of file SchemaClassEditor.cpp.

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

◆ ClassRemoved

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

Definition at line 105 of file SchemaClassEditor.cpp.

106{
107 if(className == objectName()) {
108 QWidget::close();
109 }
110}

◆ ClassUpdated

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

Definition at line 112 of file SchemaClassEditor.cpp.

113{
114 if(className == objectName()) {
115 BuildModels();
117 }
118}

◆ close_slot

void dbse::SchemaClassEditor::close_slot ( )
inlineprivateslot

Definition at line 69 of file SchemaClassEditor.hpp.

69{close();}

◆ createNewClass()

QString dbse::SchemaClassEditor::createNewClass ( )
static

Definition at line 826 of file SchemaClassEditor.cpp.

827{
828 auto createNewClass = [] (const std::string& className) -> bool {
829 if ( !KernelWrapper::GetInstance().IsActive() )
830 {
831 QMessageBox::warning (
832 0,
833 "Schema editor",
834 QString (
835 "There is no active schema set!\n\nPlease set a schema file as active and continue!" ) );
836
837 return false;
838 }
839
840 if ( !KernelWrapper::GetInstance().FindClass ( className ) )
841 {
843 "", false );
844 return true;
845 }
846 else
847 {
848 QMessageBox::warning ( 0, "Schema editor",
849 QString ( "Can not create class because class already exist !" ) );
850
851 return false;
852 }
853 };
854
855 bool ok;
856 QString text = QInputDialog::getText(nullptr, "Schema editor: create new class",
857 "New class name:", QLineEdit::Normal,
858 "NewOksClass", &ok);
859
860 if(ok && !text.isEmpty()) {
861 if(createNewClass(text.toStdString())) {
862 SchemaClassEditor * Editor = new SchemaClassEditor(KernelWrapper::GetInstance().FindClass(text.toStdString()));
863 Editor->show();
864 }
865 }
866 return text;
867}
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 730 of file SchemaClassEditor.cpp.

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

◆ CustomMenuClassView

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

Definition at line 701 of file SchemaClassEditor.cpp.

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

◆ CustomMenuMethodView

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

Definition at line 788 of file SchemaClassEditor.cpp.

789{
790 if ( ContextMenuMethod == nullptr )
791 {
792 ContextMenuMethod = new QMenu ( this );
793
794 QAction * Add = new QAction ( tr ( "&Add" ), this );
795 Add->setShortcut ( tr ( "Ctrl+A" ) );
796 Add->setShortcutContext ( Qt::WidgetShortcut );
797 connect ( Add, SIGNAL ( triggered() ), this, SLOT ( AddNewMethod() ) );
798
799 QAction * Remove = new QAction ( tr ( "&Remove" ), this );
800 Remove->setShortcut ( tr ( "Ctrl+R" ) );
801 Remove->setShortcutContext ( Qt::WidgetShortcut );
802 connect ( Remove, SIGNAL ( triggered() ), this, SLOT ( RemoveMethod() ) );
803
804 ContextMenuMethod->addAction ( Add );
805 ContextMenuMethod->addAction ( Remove );
806 }
807
808 QModelIndex Index = ui->MethodsView->currentIndex();
809
810 if ( Index.isValid() )
811 {
812 CurrentRow = MethodModel->getRowFromIndex ( Index );
813 const std::string& methodName = CurrentRow.at ( 0 ).toStdString();
814 OksMethod * SchemaMethod = SchemaClass->find_direct_method ( methodName );
815 if(SchemaMethod == nullptr) {
816 // Can't remove inherited method
817 ContextMenuMethod->actions().at ( 1 )->setVisible ( false );
818 }
819 else {
820 ContextMenuMethod->actions().at ( 1 )->setVisible ( true );
821 }
822 ContextMenuMethod->exec ( ui->MethodsView->mapToGlobal ( pos ) );
823 }
824}

◆ CustomMenuRelationshipView

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

Definition at line 759 of file SchemaClassEditor.cpp.

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

◆ InitialSettings()

void dbse::SchemaClassEditor::InitialSettings ( )
private

Class Name

Schema File

Description

Abstract

Definition at line 129 of file SchemaClassEditor.cpp.

130{
131 ui->AttributeView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
132 ui->RelationshipView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
133 ui->MethodsView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
134 ui->SuperClassView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
135 ui->SubClassView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
136
138 ui->ClassNameLineEdit->setText ( QString::fromStdString ( SchemaClass->get_name() ) );
139 //ui->ClassNameLineEdit->setEnabled ( false );
141 ui->SchemaFileLineEdit->setText ( QString::fromStdString ( SchemaClass->get_file()->get_short_file_name() ) );
142 //ui->SchemaFileLineEdit->setEnabled ( false );
143
144 if (KernelWrapper::GetInstance().IsFileWritable(
145 SchemaClass->get_file()->get_full_file_name())) {
146 ui->AddButtonAttribute->setEnabled (true);
147 ui->AddButtonSuperClass->setEnabled (true);
148 ui->AddButtonRelationship->setEnabled (true);
149 ui->AddButtonMethod->setEnabled (true);
150 ui->moveButton->setEnabled (true);
151 }
152 else {
153 ui->SchemaFileLineEdit->setStyleSheet("color:rgb(128,0,0);");
154 // ui->DescriptionTextEdit->setEnabled(false);
155 ui->DescriptionTextEdit->setReadOnly(true);
156
157 ui->AddButtonAttribute->setEnabled (false);
158 ui->AddButtonSuperClass->setEnabled (false);
159 ui->AddButtonRelationship->setEnabled (false);
160 ui->AddButtonMethod->setEnabled (false);
161 ui->moveButton->setEnabled (false);
162 ui->AbstractComboBox->setEnabled(false);
163 }
164
166 ui->DescriptionTextEdit->setPlainText ( QString::fromStdString ( SchemaClass->get_description() ) );
167 ui->DescriptionTextEdit->setTabChangesFocus (true);
169 if ( SchemaClass->get_is_abstract() )
170 {
171 ui->AbstractComboBox->setCurrentIndex ( 0 );
172 }
173 else
174 {
175 ui->AbstractComboBox->setCurrentIndex ( 1 );
176 }
177}

◆ keyPressEvent()

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

Definition at line 61 of file SchemaClassEditor.cpp.

61 {
62 if (event->key() == Qt::Key_Escape) {
63 close();
64 }
65 QWidget::keyPressEvent(event);
66}

◆ launch()

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

Definition at line 869 of file SchemaClassEditor.cpp.

869 {
870 bool widgetFound=false;
871 dunedaq::oks::OksClass* class_info =
872 KernelWrapper::GetInstance().FindClass (class_name.toStdString());
873 for ( QWidget* widget : QApplication::allWidgets() ) {
874 SchemaClassEditor* editor = dynamic_cast<SchemaClassEditor *> (widget);
875 if (editor != nullptr) {
876 if ((editor->objectName()).compare(class_name) == 0 ) {
877 widget->raise();
878 widget->setVisible ( true );
879 widget->activateWindow();
880 widgetFound = true;
881 break;
882 }
883 }
884 }
885
886 if ( !widgetFound ) {
887 SchemaClassEditor* editor = new SchemaClassEditor (class_info);
888 editor->show();
889 }
890}
dunedaq::oks::OksClass * FindClass(std::string ClassName) const

◆ move_class [1/2]

void dbse::SchemaClassEditor::move_class ( )
privateslot

Definition at line 179 of file SchemaClassEditor.cpp.

179 {
180 move_class(SchemaClass, this);
181}

◆ move_class() [2/2]

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

Definition at line 184 of file SchemaClassEditor.cpp.

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

◆ OpenAttributeEditor

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

Definition at line 510 of file SchemaClassEditor.cpp.

511{
512 QStringList Row = AttributeModel->getRowFromIndex ( Index );
513 bool ShouldOpen = ShouldOpenAttributeEditor ( Row.at ( 0 ) );
514
515 if ( !Row.isEmpty() && ShouldOpen )
516 {
517 SchemaAttributeEditor * Editor = new SchemaAttributeEditor (
518 SchemaClass, SchemaClass->find_attribute ( Row.at ( 0 ).toStdString() ) );
519 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildAttributeModelSlot() ) );
520 Editor->show();
521 }
522}

◆ OpenMethodEditor

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

Definition at line 538 of file SchemaClassEditor.cpp.

539{
540 QStringList Row = MethodModel->getRowFromIndex ( Index );
541 auto method = Row.at(0).toStdString();
542 if (SchemaClass->find_direct_method(method) == nullptr) {
543 std::string message{"Method '" + method + "' is not a direct method of " +
544 SchemaClass->get_name() +
545". Please open the method editor from the base class or add a local implementation to overrride it."};
546 QMessageBox::warning (0,
547 "Schema editor",
548 QString::fromStdString(message));
549 return;
550 }
551
552 bool ShouldOpen = ShouldOpenMethodEditor ( Row.at ( 0 ) );
553
554 if ( !Row.isEmpty() && ShouldOpen )
555 {
556 SchemaMethodEditor * Editor = new SchemaMethodEditor (
557 SchemaClass, SchemaClass->find_method ( method ) );
558 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildMethodModelSlot() ) );
559 Editor->show();
560 }
561}
bool ShouldOpenMethodEditor(QString Name)
Only Configuration DB opened by rdbconfig or oksconflibs plug in can be message

◆ OpenNewClassEditor()

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

Definition at line 585 of file SchemaClassEditor.cpp.

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

◆ OpenRelationshipEditor

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

Definition at line 524 of file SchemaClassEditor.cpp.

525{
526 QStringList Row = RelationshipModel->getRowFromIndex ( Index );
527 bool ShouldOpen = ShouldOpenRelationshipEditor ( Row.at ( 0 ) );
528
529 if ( !Row.isEmpty() && ShouldOpen )
530 {
531 SchemaRelationshipEditor * Editor = new SchemaRelationshipEditor (
532 SchemaClass, SchemaClass->find_relationship ( Row.at ( 0 ).toStdString() ) );
533 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildRelationshipModelSlot() ) );
534 Editor->show();
535 }
536}

◆ OpenSubClass

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

Definition at line 574 of file SchemaClassEditor.cpp.

575{
576 QStringList Row = SubClassModel->getRowFromIndex ( Index );
577
578 if ( !Row.isEmpty() )
579 {
580 QString ClassName = Row.at ( 0 );
581 OpenNewClassEditor(ClassName);
582 }
583}
void OpenNewClassEditor(const QString &ClassName)

◆ OpenSuperClass

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

Definition at line 563 of file SchemaClassEditor.cpp.

564{
565 QStringList Row = SuperClassModel->getRowFromIndex ( Index );
566
567 if ( !Row.isEmpty() )
568 {
569 QString ClassName = Row.at ( 0 );
570 OpenNewClassEditor(ClassName);
571 }
572}

◆ ParseToSave

void dbse::SchemaClassEditor::ParseToSave ( )
privateslot

Definition at line 392 of file SchemaClassEditor.cpp.

393{
394 std::string NewDescription = ui->DescriptionTextEdit->toPlainText().toStdString();
395
396 bool Abstract = false;
397
398 if ( ui->AbstractComboBox->currentIndex() == 0 )
399 {
400 Abstract = true;
401 }
402 else
403 {
404 Abstract = false;
405 }
406
407 if ( Abstract != SchemaClass->get_is_abstract() )
408 {
410 }
411
412 if ( NewDescription != SchemaClass->get_description() )
413 {
415 }
416
417 close();
418}
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 325 of file SchemaClassEditor.cpp.

326{
327 const std::string& attributeName = CurrentRow.at ( 0 ).toStdString();
328 OksAttribute * SchemaAttribute = SchemaClass->find_direct_attribute( attributeName );
329 if(SchemaAttribute != nullptr) {
331 SchemaClass, SchemaAttribute, SchemaAttribute->get_name(), SchemaAttribute->get_type(),
332 SchemaAttribute->get_is_multi_values(), SchemaAttribute->get_range(),
333 SchemaAttribute->get_init_value(), SchemaAttribute->get_description(),
334 SchemaAttribute->get_is_no_null(), SchemaAttribute->get_format() );
335 } else {
336 QMessageBox::warning ( 0, "Schema editor",
337 QString::fromStdString( "Cannot remove attribute \"" + attributeName +
338 "\" because it is not a direct attribute of \"" + SchemaClass->get_name() + "\"") );
339 }
340}
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)
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.

◆ RemoveMethod

void dbse::SchemaClassEditor::RemoveMethod ( )
privateslot

Definition at line 361 of file SchemaClassEditor.cpp.

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

◆ RemoveRelationship

void dbse::SchemaClassEditor::RemoveRelationship ( )
privateslot

Definition at line 342 of file SchemaClassEditor.cpp.

343{
344 const std::string& relationshipName = CurrentRow.at ( 0 ).toStdString();
345 OksRelationship * SchemaRelationship = SchemaClass->find_direct_relationship( relationshipName );
346 if(SchemaRelationship != nullptr) {
348 SchemaClass, SchemaRelationship, SchemaRelationship->get_name(),
349 SchemaRelationship->get_description(), SchemaRelationship->get_type(),
350 SchemaRelationship->get_is_composite(), SchemaRelationship->get_is_exclusive(),
351 SchemaRelationship->get_is_dependent(),
352 SchemaRelationship->get_low_cardinality_constraint(),
353 SchemaRelationship->get_high_cardinality_constraint() );
354 } else {
355 QMessageBox::warning ( 0, "Schema editor",
356 QString::fromStdString( "Cannot remove relationship \"" + relationshipName +
357 "\" because it is not a direct relationship of \"" + SchemaClass->get_name() + "\"") );
358 }
359}
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)
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 376 of file SchemaClassEditor.cpp.

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

◆ SetController()

void dbse::SchemaClassEditor::SetController ( )
private

Definition at line 67 of file SchemaClassEditor.cpp.

68{
69 connect ( ui->buttonBox, SIGNAL ( accepted() ), this, SLOT ( ParseToSave() ) );
70 connect ( ui->buttonBox, SIGNAL ( rejected() ), this, SLOT ( close_slot() ) );
71 connect ( ui->moveButton, SIGNAL(clicked()), this, SLOT (move_class()));
72 connect ( ui->AddButtonAttribute, SIGNAL ( clicked() ), this, SLOT ( AddNewAttribute() ) );
73 connect ( ui->AddButtonSuperClass, SIGNAL ( clicked() ), this, SLOT ( AddNewSuperClass() ) );
74 connect ( ui->AddButtonRelationship, SIGNAL ( clicked() ), this,
75 SLOT ( AddNewRelationship() ) );
76 connect ( ui->AddButtonMethod, SIGNAL ( clicked() ), this, SLOT ( AddNewMethod() ) );
77 connect ( ui->RelationshipView, SIGNAL ( activated ( QModelIndex ) ), this,
78 SLOT ( OpenRelationshipEditor ( QModelIndex ) ) );
79 connect ( ui->MethodsView, SIGNAL ( activated ( QModelIndex ) ), this,
80 SLOT ( OpenMethodEditor ( QModelIndex ) ) );
81 connect ( ui->AttributeView, SIGNAL ( activated ( QModelIndex ) ), this,
82 SLOT ( OpenAttributeEditor ( QModelIndex ) ) );
83 connect ( ui->SuperClassView, SIGNAL ( activated ( QModelIndex ) ), this,
84 SLOT ( OpenSuperClass ( QModelIndex ) ) );
85 connect ( ui->SubClassView, SIGNAL ( activated ( QModelIndex ) ), this,
86 SLOT ( OpenSubClass ( QModelIndex ) ) );
87 connect ( ui->AttributeView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
88 SLOT ( CustomMenuAttributeView ( QPoint ) ) );
89 connect ( ui->RelationshipView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
90 SLOT ( CustomMenuRelationshipView ( QPoint ) ) );
91 connect ( ui->MethodsView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
92 SLOT ( CustomMenuMethodView ( QPoint ) ) );
93 connect ( ui->SuperClassView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
94 SLOT ( CustomMenuClassView ( QPoint ) ) );
95 connect ( ui->ShowDerivedAttributes, &QCheckBox::toggled, this, &SchemaClassEditor::BuildAttributeModelSlot );
96 connect ( ui->ShowDerivedRelationships, &QCheckBox::toggled, this, &SchemaClassEditor::BuildRelationshipModelSlot );
97 connect ( ui->ShowDerivedMethods, &QCheckBox::toggled, this, &SchemaClassEditor::BuildMethodModelSlot );
98 connect ( ui->ShowAllSuperClasses, &QCheckBox::toggled, this, &SchemaClassEditor::BuildSuperClassModelSlot );
99 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassRemoved ( QString ) ), this,
100 SLOT ( ClassRemoved ( QString ) ) );
101 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassUpdated ( QString ) ), this,
102 SLOT ( ClassUpdated ( QString ) ) );
103}
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 259 of file SchemaClassEditor.cpp.

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

◆ ShouldOpenMethodEditor()

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

Definition at line 302 of file SchemaClassEditor.cpp.

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

◆ ShouldOpenRelationshipEditor()

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

Definition at line 280 of file SchemaClassEditor.cpp.

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

Member Data Documentation

◆ AttributeModel

CustomAttributeModel* dbse::SchemaClassEditor::AttributeModel
private

Definition at line 56 of file SchemaClassEditor.hpp.

◆ ContextMenuAttribute

QMenu* dbse::SchemaClassEditor::ContextMenuAttribute
private

Definition at line 60 of file SchemaClassEditor.hpp.

◆ ContextMenuClass

QMenu* dbse::SchemaClassEditor::ContextMenuClass
private

Definition at line 63 of file SchemaClassEditor.hpp.

◆ ContextMenuMethod

QMenu* dbse::SchemaClassEditor::ContextMenuMethod
private

Definition at line 62 of file SchemaClassEditor.hpp.

◆ ContextMenuRelationship

QMenu* dbse::SchemaClassEditor::ContextMenuRelationship
private

Definition at line 61 of file SchemaClassEditor.hpp.

◆ CurrentRow

QStringList dbse::SchemaClassEditor::CurrentRow
private

Definition at line 64 of file SchemaClassEditor.hpp.

◆ MethodModel

CustomMethodModel* dbse::SchemaClassEditor::MethodModel
private

Definition at line 55 of file SchemaClassEditor.hpp.

◆ RelationshipModel

CustomRelationshipModel* dbse::SchemaClassEditor::RelationshipModel
private

Definition at line 57 of file SchemaClassEditor.hpp.

◆ SchemaClass

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

Definition at line 54 of file SchemaClassEditor.hpp.

◆ SubClassModel

CustomSubClassModel* dbse::SchemaClassEditor::SubClassModel
private

Definition at line 59 of file SchemaClassEditor.hpp.

◆ SuperClassModel

CustomSuperClassModel* dbse::SchemaClassEditor::SuperClassModel
private

Definition at line 58 of file SchemaClassEditor.hpp.

◆ ui

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

Definition at line 52 of file SchemaClassEditor.hpp.


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