10#include <QListWidgetItem>
11#include <QInputDialog>
22#include "ui_SchemaClassEditor.h"
44 QWidget::setAttribute(Qt::WA_DeleteOnClose);
49 QString (
"Class Editor : %1" ).arg ( QString::fromStdString (
51 setObjectName ( QString::fromStdString (
SchemaClass->get_name() ) );
62 if (event->key() == Qt::Key_Escape) {
65 QWidget::keyPressEvent(event);
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,
76 connect (
ui->AddButtonMethod, SIGNAL ( clicked() ),
this, SLOT (
AddNewMethod() ) );
77 connect (
ui->RelationshipView, SIGNAL ( activated ( QModelIndex ) ),
this,
79 connect (
ui->MethodsView, SIGNAL ( activated ( QModelIndex ) ),
this,
81 connect (
ui->AttributeView, SIGNAL ( activated ( QModelIndex ) ),
this,
83 connect (
ui->SuperClassView, SIGNAL ( activated ( QModelIndex ) ),
this,
85 connect (
ui->SubClassView, SIGNAL ( activated ( QModelIndex ) ),
this,
87 connect (
ui->AttributeView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
89 connect (
ui->RelationshipView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
91 connect (
ui->MethodsView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
93 connect (
ui->SuperClassView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
107 if(className == objectName()) {
114 if(className == objectName()) {
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 );
138 ui->ClassNameLineEdit->setText ( QString::fromStdString (
SchemaClass->get_name() ) );
141 ui->SchemaFileLineEdit->setText ( QString::fromStdString (
SchemaClass->get_file()->get_short_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);
153 ui->SchemaFileLineEdit->setStyleSheet(
"color:rgb(128,0,0);");
155 ui->DescriptionTextEdit->setReadOnly(
true);
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);
166 ui->DescriptionTextEdit->setPlainText ( QString::fromStdString (
SchemaClass->get_description() ) );
167 ui->DescriptionTextEdit->setTabChangesFocus (
true);
171 ui->AbstractComboBox->setCurrentIndex ( 0 );
175 ui->AbstractComboBox->setCurrentIndex ( 1 );
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();
195 if (fn == current_file) {
196 current_row = writable_files.size();
198 writable_files.append(QString::fromStdString(fn));
199 file_map[QString::fromStdString(fn)] = file;
202 if (writable_files.empty()) {
203 QMessageBox::warning ( 0,
"Schema editor",
204 QString (
"No writable schema files to move class to." ) );
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);
218 connect (qlw, &QListWidget::itemActivated,
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));
230 auto bb =
new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
231 connect (bb, &QDialogButtonBox::accepted, pwidget, [=] () {
232 auto it = qlw->currentItem();
234 auto fn = it->text();
235 if (fn.toStdString() != current_file) {
236 schema_class->
set_file(file_map.at(fn));
242 QMessageBox::warning ( 0,
"Schema editor",
243 QString (
"No schema file selected to move class to." ) );
247 connect ( bb, &QDialogButtonBox::rejected, pwidget, [=] () {
delete widget;} );
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);
261 QString name = QString::fromStdString(
SchemaClass->get_name() +
"::") +
263 for (QWidget* widget : QApplication::allWidgets())
267 if ( (widget->objectName()).compare (name) == 0 )
270 widget->setVisible (
true );
271 widget->activateWindow();
282 QString name = QString::fromStdString(
SchemaClass->get_name() +
"::") +
285 for ( QWidget* widget : QApplication::allWidgets() )
289 if ( ( widget->objectName() ).compare ( name ) == 0 )
292 widget->setVisible (
true );
293 widget->activateWindow();
304 bool WidgetFound =
false;
306 for ( QWidget * Editor : QApplication::allWidgets() )
310 if ( Widget !=
nullptr )
312 if ( ( Widget->objectName() ).compare ( Name ) == 0 )
315 Widget->setVisible (
true );
316 Widget->activateWindow();
327 const std::string& attributeName =
CurrentRow.at ( 0 ).toStdString();
329 if(SchemaAttribute !=
nullptr) {
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() +
"\"") );
344 const std::string& relationshipName =
CurrentRow.at ( 0 ).toStdString();
346 if(SchemaRelationship !=
nullptr) {
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() +
"\"") );
363 const std::string& methodName =
CurrentRow.at ( 0 ).toStdString();
365 if(SchemaMethod !=
nullptr) {
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() +
"\"") );
378 const std::string& superClassName =
CurrentRow.at ( 0 ).toStdString();
379 if(
SchemaClass->has_direct_super_class(superClassName))
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() +
"\"") );
394 std::string NewDescription =
ui->DescriptionTextEdit->toPlainText().toStdString();
396 bool Abstract =
false;
398 if (
ui->AbstractComboBox->currentIndex() == 0 )
412 if ( NewDescription !=
SchemaClass->get_description() )
422 bool widgetFound=
false;
423 QString class_name = QString::fromStdString(
SchemaClass->get_name());
425 QString wname =
"add_sc_"+class_name;
426 for ( QWidget* widget : QApplication::allWidgets() ) {
427 if (widget->objectName().compare(wname) == 0 ) {
429 widget->setVisible (
true );
430 widget->activateWindow();
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);
445 auto search =
new QLineEdit(widget);
446 search->setPlaceholderText(
"Search classes");
447 search->setClearButtonEnabled(
true);
449 QListWidget* qlwidget =
new QListWidget();
450 QStringList allClasses;
452 qlwidget->addItems(allClasses);
454 connect ( qlwidget, &QListWidget::itemActivated,
456 const std::string& className = qlwidget->currentItem()->text().toStdString();
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]);
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);
478 widget->setWindowTitle(
"Select super-class(es) for " + class_name);
479 widget->setLayout(lout);
480 widget->setParent(
this, Qt::Dialog);
515 if ( !Row.isEmpty() && ShouldOpen )
529 if ( !Row.isEmpty() && ShouldOpen )
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 " +
545". Please open the method editor from the base class or add a local implementation to overrride it."};
546 QMessageBox::warning (0,
548 QString::fromStdString(message));
554 if ( !Row.isEmpty() && ShouldOpen )
567 if ( !Row.isEmpty() )
569 QString ClassName = Row.at ( 0 );
578 if ( !Row.isEmpty() )
580 QString ClassName = Row.at ( 0 );
587 bool WidgetFound =
false;
590 for ( QWidget * Editor : QApplication::allWidgets() )
594 if ( Widget !=
nullptr )
596 if ( ( Widget->objectName() ).compare ( ClassName ) == 0 )
599 Widget->setVisible (
true );
600 Widget->activateWindow();
615 QStringList AttributeHeaders
624 ui->ShowDerivedAttributes->isChecked());
627 ui->AttributeView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
628 ui->AttributeView->setSelectionBehavior ( QAbstractItemView::SelectRows );
633 QStringList RelationshipHeaders
634 {
"Name",
"Type",
"Low cc",
"High cc" };
637 SchemaClass, RelationshipHeaders,
ui->ShowDerivedRelationships->isChecked() );
645 ui->RelationshipView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
646 ui->RelationshipView->setSelectionBehavior ( QAbstractItemView::SelectRows );
651 QStringList MethodHeaders
665 ui->MethodsView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
666 ui->MethodsView->setSelectionBehavior ( QAbstractItemView::SelectRows );
671 QStringList SuperClassHeaders
681 ui->SuperClassView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
682 ui->SuperClassView->setSelectionBehavior ( QAbstractItemView::SelectRows );
687 QStringList SubClassHeaders
697 ui->SubClassView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
698 ui->SubClassView->setSelectionBehavior ( QAbstractItemView::SelectRows );
707 QAction * Add =
new QAction ( tr (
"&Add" ),
this );
708 Add->setShortcut ( tr (
"Ctrl+A" ) );
709 Add->setShortcutContext ( Qt::WidgetShortcut );
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() ) );
721 QModelIndex Index =
ui->SuperClassView->currentIndex();
723 if ( Index.isValid() )
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() ) );
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() ) );
750 QModelIndex Index =
ui->AttributeView->currentIndex();
752 if ( Index.isValid() )
765 QAction * Add =
new QAction ( tr (
"&Add" ),
this );
766 Add->setShortcut ( tr (
"Ctrl+A" ) );
767 Add->setShortcutContext ( Qt::WidgetShortcut );
770 QAction * Remove =
new QAction ( tr (
"&Remove" ),
this );
771 Remove->setShortcut ( tr (
"Ctrl+R" ) );
772 Remove->setShortcutContext ( Qt::WidgetShortcut );
779 QModelIndex Index =
ui->RelationshipView->currentIndex();
781 if ( Index.isValid() )
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() ) );
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() ) );
808 QModelIndex Index =
ui->MethodsView->currentIndex();
810 if ( Index.isValid() )
813 const std::string& methodName =
CurrentRow.at ( 0 ).toStdString();
815 if(SchemaMethod ==
nullptr) {
831 QMessageBox::warning (
835 "There is no active schema set!\n\nPlease set a schema file as active and continue!" ) );
848 QMessageBox::warning ( 0,
"Schema editor",
849 QString (
"Can not create class because class already exist !" ) );
856 QString text = QInputDialog::getText(
nullptr,
"Schema editor: create new class",
857 "New class name:", QLineEdit::Normal,
860 if(ok && !text.isEmpty()) {
870 bool widgetFound=
false;
873 for ( QWidget* widget : QApplication::allWidgets() ) {
875 if (editor !=
nullptr) {
876 if ((editor->objectName()).compare(class_name) == 0 ) {
878 widget->setVisible (
true );
879 widget->activateWindow();
886 if ( !widgetFound ) {
void PushRemoveSuperClassCommand(dunedaq::oks::OksClass *Class, std::string SuperClass)
void GetClassListString(QStringList &ClassListString) const
static KernelWrapper & GetInstance()
void PushSetAbstractClassCommand(dunedaq::oks::OksClass *Class, bool Value)
dunedaq::oks::OksClass * FindClass(std::string ClassName) const
void PushAddSuperClassCommand(dunedaq::oks::OksClass *Class, std::string SuperClass)
void ClassUpdated(QString ClassName)
void PushRemoveAttributeCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string name, std::string type, bool is_mv, std::string range, std::string init_values, std::string description, bool is_null, dunedaq::oks::OksAttribute::Format format=dunedaq::oks::OksAttribute::Format::Dec)
void PushSetDescriptionClassCommand(dunedaq::oks::OksClass *Class, std::string Description)
void PushRemoveRelationship(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, std::string Name, std::string Description, std::string Type, bool Composite, bool Exclusive, bool Dependent, dunedaq::oks::OksRelationship::CardinalityConstraint LowCc, dunedaq::oks::OksRelationship::CardinalityConstraint HighCc)
void PushRemoveMethodCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksMethod *Method, std::string name, std::string description)
void PushCreateClassCommand(std::string ClassName, std::string ClassDescription, bool Abstract)
void GetSchemaFiles(std::vector< std::string > &SchemaFiles)
void CustomMenuMethodView(QPoint pos)
void keyPressEvent(QKeyEvent *event)
void OpenRelationshipEditor(QModelIndex Index)
void ClassUpdated(QString className)
bool ShouldOpenAttributeEditor(QString Name)
Helper functions.
void RemoveRelationship()
CustomRelationshipModel * RelationshipModel
bool ShouldOpenRelationshipEditor(QString Name)
CustomSuperClassModel * SuperClassModel
bool ShouldOpenMethodEditor(QString Name)
QMenu * ContextMenuMethod
QMenu * ContextMenuRelationship
void BuildSubClassModelSlot()
CustomMethodModel * MethodModel
static void move_class(dunedaq::oks::OksClass *schema_class, QWidget *widget)
void BuildAttributeModelSlot()
void RemoveAttribute()
Remove Functions.
void BuildSuperClassModelSlot()
void BuildMethodModelSlot()
void CustomMenuRelationshipView(QPoint pos)
void ClassRemoved(QString className)
void OpenSuperClass(QModelIndex Index)
SchemaClassEditor(dunedaq::oks::OksClass *ClassInfo, QWidget *parent=nullptr)
static void launch(QString class_name)
QMenu * ContextMenuAttribute
dunedaq::oks::OksClass * SchemaClass
void CustomMenuClassView(QPoint pos)
void OpenMethodEditor(QModelIndex Index)
static QString createNewClass()
CustomAttributeModel * AttributeModel
void OpenSubClass(QModelIndex Index)
void AddNewRelationship()
std::unique_ptr< dbse::Ui::SchemaClassEditor > ui
void OpenAttributeEditor(QModelIndex Index)
void OpenNewClassEditor(const QString &ClassName)
void CustomMenuAttributeView(QPoint pos)
Context Menu Functions.
void BuildRelationshipModelSlot()
CustomSubClassModel * SubClassModel
bool get_is_multi_values() const noexcept
const std::string & get_type() const noexcept
Get attribute string type.
const std::string & get_range() const noexcept
Get attribute range.
const std::string & get_name() const noexcept
out stream operator
const std::string & get_init_value() const noexcept
const std::string & get_description() const noexcept
bool get_is_no_null() const noexcept
Format get_format() const noexcept
Get attribute format.
void set_file(OksFile *f, bool update_owner=true)
Move class to different file.
const std::string & get_name() const noexcept
OksFile * get_file() const noexcept
const std::string & get_full_file_name() const
const std::string & get_description() const noexcept
const std::string & get_name() const noexcept
bool get_is_exclusive() const noexcept
bool get_is_composite() const noexcept
bool get_is_dependent() const noexcept
const std::string & get_name() const noexcept
CardinalityConstraint get_high_cardinality_constraint() const noexcept
Get relationship high cardinality constraint.
const std::string & get_description() const noexcept
CardinalityConstraint get_low_cardinality_constraint() const noexcept
Get relationship low cardinality constraint.
const std::string & get_type() const noexcept