5#include <QListWidgetItem>
17#include "ui_SchemaClassEditor.h"
39 QWidget::setAttribute(Qt::WA_DeleteOnClose);
44 QString (
"Class Editor : %1" ).arg ( QString::fromStdString (
46 setObjectName ( QString::fromStdString (
SchemaClass->get_name() ) );
57 if (event->key() == Qt::Key_Escape) {
60 QWidget::keyPressEvent(event);
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,
71 connect (
ui->AddButtonMethod, SIGNAL ( clicked() ),
this, SLOT (
AddNewMethod() ) );
72 connect (
ui->RelationshipView, SIGNAL ( activated ( QModelIndex ) ),
this,
74 connect (
ui->MethodsView, SIGNAL ( activated ( QModelIndex ) ),
this,
76 connect (
ui->AttributeView, SIGNAL ( activated ( QModelIndex ) ),
this,
78 connect (
ui->SuperClassView, SIGNAL ( activated ( QModelIndex ) ),
this,
80 connect (
ui->SubClassView, SIGNAL ( activated ( QModelIndex ) ),
this,
82 connect (
ui->AttributeView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
84 connect (
ui->RelationshipView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
86 connect (
ui->MethodsView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
88 connect (
ui->SuperClassView, SIGNAL ( customContextMenuRequested ( QPoint ) ),
this,
102 if(className == objectName()) {
109 if(className == objectName()) {
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 );
133 ui->ClassNameLineEdit->setText ( QString::fromStdString (
SchemaClass->get_name() ) );
136 ui->SchemaFileLineEdit->setText ( QString::fromStdString (
SchemaClass->get_file()->get_short_file_name() ) );
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);
148 ui->SchemaFileLineEdit->setStyleSheet(
"color:rgb(128,0,0);");
150 ui->DescriptionTextEdit->setReadOnly(
true);
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);
161 ui->DescriptionTextEdit->setPlainText ( QString::fromStdString (
SchemaClass->get_description() ) );
162 ui->DescriptionTextEdit->setTabChangesFocus (
true);
166 ui->AbstractComboBox->setCurrentIndex ( 0 );
170 ui->AbstractComboBox->setCurrentIndex ( 1 );
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();
190 if (fn == current_file) {
191 current_row = writable_files.size();
193 writable_files.append(QString::fromStdString(fn));
194 file_map[QString::fromStdString(fn)] = file;
197 if (writable_files.empty()) {
198 QMessageBox::warning ( 0,
"Schema editor",
199 QString (
"No writable schema files to move class to." ) );
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);
213 connect (qlw, &QListWidget::itemActivated,
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));
225 auto bb =
new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
226 connect (bb, &QDialogButtonBox::accepted, pwidget, [=] () {
227 auto it = qlw->currentItem();
229 auto fn = it->text();
230 if (fn.toStdString() != current_file) {
231 schema_class->
set_file(file_map.at(fn));
237 QMessageBox::warning ( 0,
"Schema editor",
238 QString (
"No schema file selected to move class to." ) );
242 connect ( bb, &QDialogButtonBox::rejected, pwidget, [=] () {
delete widget;} );
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);
256 QString name = QString::fromStdString(
SchemaClass->get_name() +
"::") +
258 for (QWidget* widget : QApplication::allWidgets())
262 if ( (widget->objectName()).compare (name) == 0 )
265 widget->setVisible (
true );
266 widget->activateWindow();
277 QString name = QString::fromStdString(
SchemaClass->get_name() +
"::") +
280 for ( QWidget* widget : QApplication::allWidgets() )
284 if ( ( widget->objectName() ).compare ( name ) == 0 )
287 widget->setVisible (
true );
288 widget->activateWindow();
299 bool WidgetFound =
false;
301 for ( QWidget * Editor : QApplication::allWidgets() )
305 if ( Widget !=
nullptr )
307 if ( ( Widget->objectName() ).compare ( Name ) == 0 )
310 Widget->setVisible (
true );
311 Widget->activateWindow();
322 const std::string& attributeName =
CurrentRow.at ( 0 ).toStdString();
324 if(SchemaAttribute !=
nullptr) {
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() +
"\"") );
339 const std::string& relationshipName =
CurrentRow.at ( 0 ).toStdString();
341 if(SchemaRelationship !=
nullptr) {
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() +
"\"") );
358 const std::string& methodName =
CurrentRow.at ( 0 ).toStdString();
360 if(SchemaMethod !=
nullptr) {
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() +
"\"") );
373 const std::string& superClassName =
CurrentRow.at ( 0 ).toStdString();
374 if(
SchemaClass->has_direct_super_class(superClassName))
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() +
"\"") );
389 std::string NewDescription =
ui->DescriptionTextEdit->toPlainText().toStdString();
391 bool Abstract =
false;
393 if (
ui->AbstractComboBox->currentIndex() == 0 )
407 if ( NewDescription !=
SchemaClass->get_description() )
417 bool widgetFound=
false;
418 QString class_name = QString::fromStdString(
SchemaClass->get_name());
420 QString wname =
"add_sc_"+class_name;
421 for ( QWidget* widget : QApplication::allWidgets() ) {
422 if (widget->objectName().compare(wname) == 0 ) {
424 widget->setVisible (
true );
425 widget->activateWindow();
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);
440 auto search =
new QLineEdit(widget);
441 search->setPlaceholderText(
"Search classes");
442 search->setClearButtonEnabled(
true);
444 QListWidget* qlwidget =
new QListWidget();
445 QStringList allClasses;
447 qlwidget->addItems(allClasses);
449 connect ( qlwidget, &QListWidget::itemActivated,
451 const std::string& className = qlwidget->currentItem()->text().toStdString();
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]);
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);
473 widget->setWindowTitle(
"Select super-class(es) for " + class_name);
474 widget->setLayout(lout);
475 widget->setParent(
this, Qt::Dialog);
510 if ( !Row.isEmpty() && ShouldOpen )
524 if ( !Row.isEmpty() && ShouldOpen )
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,
543 QString::fromStdString(message));
549 if ( !Row.isEmpty() && ShouldOpen )
562 if ( !Row.isEmpty() )
564 QString ClassName = Row.at ( 0 );
573 if ( !Row.isEmpty() )
575 QString ClassName = Row.at ( 0 );
582 bool WidgetFound =
false;
585 for ( QWidget * Editor : QApplication::allWidgets() )
589 if ( Widget !=
nullptr )
591 if ( ( Widget->objectName() ).compare ( ClassName ) == 0 )
594 Widget->setVisible (
true );
595 Widget->activateWindow();
610 QStringList AttributeHeaders
619 ui->ShowDerivedAttributes->isChecked());
622 ui->AttributeView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
623 ui->AttributeView->setSelectionBehavior ( QAbstractItemView::SelectRows );
628 QStringList RelationshipHeaders
629 {
"Name",
"Type",
"Low cc",
"High cc" };
632 SchemaClass, RelationshipHeaders,
ui->ShowDerivedRelationships->isChecked() );
640 ui->RelationshipView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
641 ui->RelationshipView->setSelectionBehavior ( QAbstractItemView::SelectRows );
646 QStringList MethodHeaders
660 ui->MethodsView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
661 ui->MethodsView->setSelectionBehavior ( QAbstractItemView::SelectRows );
666 QStringList SuperClassHeaders
680 ui->SuperClassView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
681 ui->SuperClassView->setSelectionBehavior ( QAbstractItemView::SelectRows );
686 QStringList SubClassHeaders
700 ui->SubClassView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
701 ui->SubClassView->setSelectionBehavior ( QAbstractItemView::SelectRows );
710 QAction * Add =
new QAction ( tr (
"&Add" ),
this );
711 Add->setShortcut ( tr (
"Ctrl+A" ) );
712 Add->setShortcutContext ( Qt::WidgetShortcut );
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() ) );
724 QModelIndex Index =
ui->SuperClassView->currentIndex();
726 if ( Index.isValid() )
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() ) );
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() ) );
753 QModelIndex Index =
ui->AttributeView->currentIndex();
755 if ( Index.isValid() )
768 QAction * Add =
new QAction ( tr (
"&Add" ),
this );
769 Add->setShortcut ( tr (
"Ctrl+A" ) );
770 Add->setShortcutContext ( Qt::WidgetShortcut );
773 QAction * Remove =
new QAction ( tr (
"&Remove" ),
this );
774 Remove->setShortcut ( tr (
"Ctrl+R" ) );
775 Remove->setShortcutContext ( Qt::WidgetShortcut );
782 QModelIndex Index =
ui->RelationshipView->currentIndex();
784 if ( Index.isValid() )
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() ) );
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() ) );
811 QModelIndex Index =
ui->MethodsView->currentIndex();
813 if ( Index.isValid() )
825 QMessageBox::warning (
829 "There is no active schema set!\n\nPlease set a schema file as active and continue!" ) );
842 QMessageBox::warning ( 0,
"Schema editor",
843 QString (
"Can not create class because class already exist !" ) );
850 QString text = QInputDialog::getText(
nullptr,
"Schema editor: create new class",
851 "New class name:", QLineEdit::Normal,
854 if(ok && !text.isEmpty()) {
864 bool widgetFound=
false;
867 for ( QWidget* widget : QApplication::allWidgets() ) {
869 if (editor !=
nullptr) {
870 if ((editor->objectName()).compare(class_name) == 0 ) {
872 widget->setVisible (
true );
873 widget->activateWindow();
880 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