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

#include <SchemaMainWindow.hpp>

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

Public Slots

void modifiedView (bool modified)
 
void update_models ()
 

Public Member Functions

 ~SchemaMainWindow ()
 
 SchemaMainWindow (QString SchemaFile, QWidget *parent=nullptr)
 

Protected Member Functions

void closeEvent (QCloseEvent *event)
 
void OpenSchemaFile (QString SchemaFile)
 

Private Slots

void OpenSchemaFile ()
 
void CreateNewSchema ()
 
void LaunchIncludeEditor ()
 
void LaunchIncludeEditorActiveSchema ()
 
void SaveSchema ()
 
void SaveSchemaFile ()
 
void SaveModifiedSchema ()
 
void ChangeCursorRelationship (bool State)
 
void ChangeCursorInheritance (bool State)
 
void add_tab ()
 
void SaveView ()
 
void SaveViewAs ()
 
void LoadView ()
 
void NameView ()
 
void LaunchClassEditor (QModelIndex Index)
 
void RemoveTab (int i)
 
void close_tab ()
 
void CustomContextMenuFileView (QPoint Pos)
 
void CustomContextMenuTableView (QPoint Pos)
 
void AddNewClass ()
 
void RemoveClass ()
 
void editClass ()
 
void SetSchemaFileActive ()
 
void PrintCurrentView ()
 
void export_current_view ()
 

Private Member Functions

void InitialSettings ()
 
void InitialTab ()
 
void InitialTabCorner ()
 
void SetController ()
 
void BuildFileModel ()
 
void BuildTableModel ()
 
void update_window_title (QString text)
 
void write_view_file (const QString &fn, SchemaTab *tab)
 
int ShouldSaveChanges () const
 
int ShouldSaveViewChanges () const
 

Private Attributes

std::unique_ptr< dbse::Ui::SchemaMainWindow > ui
 
CustomFileModelFileModel
 
CustomTableModelTableModel
 
QSortFilterProxyModel * proxyModel
 
QMenu * ContextMenuFileView
 
QMenu * ContextMenuTableView
 
QString m_title {"DUNE DAQ Configuration Schema editor"}
 
QString m_view_dir {"."}
 
QString m_export_path {"."}
 

Detailed Description

Definition at line 23 of file SchemaMainWindow.hpp.

Constructor & Destructor Documentation

◆ ~SchemaMainWindow()

dbse::SchemaMainWindow::~SchemaMainWindow ( )
default

◆ SchemaMainWindow()

dbse::SchemaMainWindow::SchemaMainWindow ( QString SchemaFile,
QWidget * parent = nullptr )
explicit

Definition at line 34 of file SchemaMainWindow.cpp.

35 : QMainWindow ( parent ),
36 ui ( new Ui::SchemaMainWindow ),
37 FileModel ( nullptr ),
38 TableModel ( nullptr ),
39 proxyModel ( new QSortFilterProxyModel() ),
40 ContextMenuFileView ( nullptr ),
41 ContextMenuTableView ( nullptr )
42{
44 InitialTab();
47 setFocusPolicy( Qt::StrongFocus );
48
49 OpenSchemaFile(SchemaFile);
50}
QSortFilterProxyModel * proxyModel
CustomFileModel * FileModel
CustomTableModel * TableModel
std::unique_ptr< dbse::Ui::SchemaMainWindow > ui

Member Function Documentation

◆ add_tab

void dbse::SchemaMainWindow::add_tab ( )
privateslot

Definition at line 579 of file SchemaMainWindow.cpp.

580{
581 auto index = ui->TabWidget->addTab ( new SchemaTab(), "unnamed Schema View" );
582 ui->TabWidget->setCurrentIndex ( index );
583 auto tab = dynamic_cast<SchemaTab *> ( ui->TabWidget->currentWidget() );
584 connect (tab->GetScene(), &SchemaGraphicsScene::sceneModified,
586}
void modifiedView(bool modified)

◆ AddNewClass

void dbse::SchemaMainWindow::AddNewClass ( )
privateslot

◆ BuildFileModel()

void dbse::SchemaMainWindow::BuildFileModel ( )
private

Definition at line 141 of file SchemaMainWindow.cpp.

142{
143 QStringList Headers { "File Name", "Access", "Status" };
144
145 if ( FileModel != nullptr )
146 {
147 delete FileModel;
148 }
149 FileModel = new CustomFileModel ( Headers );
150
151 ui->FileView->setModel ( FileModel );
152 ui->FileView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
153 ui->FileView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
154 ui->FileView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
155}

◆ BuildTableModel()

void dbse::SchemaMainWindow::BuildTableModel ( )
private

Definition at line 157 of file SchemaMainWindow.cpp.

158{
159 QStringList Headers
160 { "Class Name" };
161
162 if ( TableModel == nullptr )
163 {
164 TableModel = new CustomTableModel ( Headers );
165 }
166 else
167 {
168 delete TableModel;
169 TableModel = new CustomTableModel ( Headers );
170 }
171
172 proxyModel->setSourceModel(TableModel);
173 ui->ClassTableView->setModel ( proxyModel );
174}

◆ ChangeCursorInheritance

void dbse::SchemaMainWindow::ChangeCursorInheritance ( bool State)
privateslot

Definition at line 560 of file SchemaMainWindow.cpp.

561{
562 if ( ui->SetRelationship->isChecked() )
563 {
564 ui->SetRelationship->setChecked ( false );
565 }
566
567 if ( State )
568 {
569 ui->TabWidget->setCursor ( Qt::CrossCursor );
570 }
571 else
572 {
573 ui->TabWidget->setCursor ( Qt::ArrowCursor );
574 }
575
577}
static KernelWrapper & GetInstance()
void SetInheritanceMode(bool Mode)
Editor Functions.

◆ ChangeCursorRelationship

void dbse::SchemaMainWindow::ChangeCursorRelationship ( bool State)
privateslot

Definition at line 541 of file SchemaMainWindow.cpp.

542{
543 if ( ui->SetInheritance->isChecked() )
544 {
545 ui->SetInheritance->setChecked ( false );
546 }
547
548 if ( State )
549 {
550 ui->TabWidget->setCursor ( Qt::CrossCursor );
551 }
552 else
553 {
554 ui->TabWidget->setCursor ( Qt::ArrowCursor );
555 }
556
558}

◆ close_tab

void dbse::SchemaMainWindow::close_tab ( )
privateslot

Definition at line 809 of file SchemaMainWindow.cpp.

809 {
810 RemoveTab(ui->TabWidget->currentIndex());
811}

◆ closeEvent()

void dbse::SchemaMainWindow::closeEvent ( QCloseEvent * event)
protected

Definition at line 370 of file SchemaMainWindow.cpp.

371{
372 int UserChoice = ShouldSaveChanges();
373
374 if ( UserChoice == QMessageBox::Save )
375 {
377 }
378 else if ( UserChoice == QMessageBox::Cancel )
379 {
380 event->ignore();
381 return;
382 }
383
384 UserChoice = ShouldSaveViewChanges();
385 if ( UserChoice == QMessageBox::Cancel )
386 {
387 event->ignore();
388 return;
389 }
390
392
393 for ( QWidget * Widget : QApplication::allWidgets() )
394 {
395 Widget->close();
396 }
397
398 event->accept();
399}

◆ CreateNewSchema

void dbse::SchemaMainWindow::CreateNewSchema ( )
privateslot

Definition at line 502 of file SchemaMainWindow.cpp.

503{
504 QString FileName = QFileDialog::getSaveFileName ( this, tr ( "New schema File" ) );
505
506 if ( FileName.isEmpty() )
507 {
508 QMessageBox::warning ( 0, "Schema editor",
509 QString ( "Please provide a name for the schema !" ) );
510 return;
511 }
512
513 if ( !FileName.endsWith ( ".schema.xml" ) )
514 {
515 FileName.append ( ".schema.xml" );
516 }
517
518 QFile FileInfo ( FileName );
519 std::string FileNameStd = FileInfo.fileName().toStdString();
520
521 try
522 {
524 KernelWrapper::GetInstance().SaveSchema ( FileNameStd );
527 ui->CreateNewSchema->setDisabled (true );
528 ui->OpenFileSchema->setDisabled (true );
529 }
530 catch ( oks::exception & Ex )
531 {
532 QMessageBox::warning (
533 0,
534 "Schema editor",
535 QString ( "Could not create file : %1.\n\n%2" ).arg ( QString::fromStdString (
536 FileNameStd ) ).arg (
537 QString ( Ex.what() ) ) );
538 }
539}
void SaveSchema(const std::string &file) const
void CreateNewSchema(const std::string &SchemaName) const

◆ CustomContextMenuFileView

void dbse::SchemaMainWindow::CustomContextMenuFileView ( QPoint Pos)
privateslot

Definition at line 834 of file SchemaMainWindow.cpp.

835{
836 if ( ContextMenuFileView == nullptr )
837 {
838 ContextMenuFileView = new QMenu ( this );
839
840 QAction * Act = new QAction ( tr ( "Set as Active Schema" ), this );
841 connect ( Act, SIGNAL ( triggered() ), this, SLOT ( SetSchemaFileActive() ) );
842 QAction * Sav = new QAction ( tr ( "Save Schema File" ), this );
843 connect ( Sav, SIGNAL ( triggered() ), this, SLOT ( SaveSchemaFile() ) );
844 QAction * Inc = new QAction ( tr ( "Show/Update include file list" ), this );
845 connect ( Inc, SIGNAL ( triggered() ), this, SLOT ( LaunchIncludeEditor() ) );
846
847 ContextMenuFileView->addAction ( Act );
848 ContextMenuFileView->addAction ( Inc );
849 ContextMenuFileView->addAction ( Sav );
850 }
851
852 QModelIndex Index = ui->FileView->currentIndex();
853
854 if ( Index.isValid() )
855 {
856 ContextMenuFileView->exec ( ui->FileView->mapToGlobal ( Pos ) );
857 }
858}

◆ CustomContextMenuTableView

void dbse::SchemaMainWindow::CustomContextMenuTableView ( QPoint Pos)
privateslot

Definition at line 860 of file SchemaMainWindow.cpp.

861{
862 if ( ContextMenuTableView == nullptr )
863 {
864 ContextMenuTableView = new QMenu ( this );
865
866 QAction * add = new QAction ( tr ( "&Add New Class" ), this );
867 connect ( add, SIGNAL ( triggered() ), this, SLOT ( AddNewClass() ) );
868
869 QAction * remove = new QAction ( tr ( "&Remove Selected Class" ), this );
870 connect ( remove, SIGNAL ( triggered() ), this, SLOT ( RemoveClass() ) );
871
872 QAction * edit = new QAction ( tr ( "&Edit Selected Class" ), this );
873 connect ( edit, SIGNAL ( triggered() ), this, SLOT ( editClass() ) );
874
875 ContextMenuTableView->addAction ( add );
876 ContextMenuTableView->addAction ( edit );
877 ContextMenuTableView->addAction ( remove );
878 }
879
880 QModelIndex Index = ui->ClassTableView->currentIndex();
881
882 if ( Index.isValid() )
883 {
884 ContextMenuTableView->exec ( ui->ClassTableView->mapToGlobal ( Pos ) );
885 }
886}
void remove(QString const &db, QString const &fn)
void add(QString const &db, QString const &fn)

◆ editClass

void dbse::SchemaMainWindow::editClass ( )
privateslot

Definition at line 253 of file SchemaMainWindow.cpp.

253 {
254 QModelIndex Index = ui->ClassTableView->currentIndex();
255 QModelIndex proxyIndex = proxyModel->mapToSource( Index );
256 QStringList Row = TableModel->getRowFromIndex ( proxyIndex );
257
258 if ( !Row.isEmpty() ) {
259 bool widget_found = false;
260 QString class_name = Row.at ( 0 );
262 class_name.toStdString() );
263
264 for ( QWidget * widget : QApplication::allWidgets() ) {
265 auto editor = dynamic_cast<SchemaClassEditor *> ( widget );
266 if ( editor != nullptr ) {
267 if ( ( editor->objectName() ).compare ( class_name ) == 0 ) {
268 editor->raise();
269 editor->setVisible ( true );
270 editor->activateWindow();
271 widget_found = true;
272 }
273 }
274 }
275 if ( !widget_found ) {
276 SchemaClassEditor * editor = new SchemaClassEditor ( class_info );
277 editor->show();
278 }
279 }
280}
QStringList getRowFromIndex(QModelIndex &index)
dunedaq::oks::OksClass * FindClass(std::string ClassName) const
The OKS class.
Definition class.hpp:200

◆ export_current_view

void dbse::SchemaMainWindow::export_current_view ( )
privateslot

Definition at line 338 of file SchemaMainWindow.cpp.

338 {
339 auto tab = dynamic_cast<SchemaTab *> ( ui->TabWidget->currentWidget() );
340
341 auto file = QFileDialog::getSaveFileName(
342 this, tr("Export to SVG"),
344 tr("SVG files (*.svg);;All files (*)"));
345 if (file.isEmpty()) {
346 return;
347 }
348
349 auto spos = file.lastIndexOf('/');
350 if (spos != -1) {
352 m_export_path.truncate(spos);
353 }
354
355 auto scene = tab->GetScene();
356 auto view = tab->GetView();
357
358 QSvgGenerator generator;
359 generator.setFileName(file);
360 auto vpr=view->viewport()->rect();
361 generator.setSize(QSize(vpr.width(),vpr.height()));
362 generator.setViewBox(vpr);
363
364 QPainter painter;
365 painter.begin(&generator);
366 scene->render ( &painter, QRectF(), view->viewport()->rect() );
367 painter.end();
368}

◆ InitialSettings()

void dbse::SchemaMainWindow::InitialSettings ( )
private

Definition at line 54 of file SchemaMainWindow.cpp.

55{
56 ui->setupUi ( this );
57 setWindowTitle ( m_title );
58 ui->UndoView->setStack ( KernelWrapper::GetInstance().GetUndoStack() );
59 ui->ClassTableView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
60 ui->ClassTableView->setDragEnabled ( true );
61 ui->ClassTableView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
62 ui->FileView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
63 ui->FileView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
64 ui->FileView->setSelectionBehavior ( QAbstractItemView::SelectRows );
65 ui->TabWidget->setTabsClosable ( true );
66 ui->ClassTableSearchLine->setProperty ( "placeholderText",
67 QVariant ( QString ( "Type to search" ) ) );
68}

◆ InitialTab()

void dbse::SchemaMainWindow::InitialTab ( )
private

Definition at line 70 of file SchemaMainWindow.cpp.

71{
72 add_tab();
73 ui->TabWidget->removeTab ( 0 );
74}

◆ InitialTabCorner()

void dbse::SchemaMainWindow::InitialTabCorner ( )
private

Definition at line 76 of file SchemaMainWindow.cpp.

77{
78 QPushButton * RightButton = new QPushButton ( "+" );
79 ui->TabWidget->setCornerWidget ( RightButton, Qt::TopLeftCorner );
80 connect ( RightButton, SIGNAL ( clicked() ), this, SLOT ( add_tab() ) );
81}

◆ LaunchClassEditor

void dbse::SchemaMainWindow::LaunchClassEditor ( QModelIndex Index)
privateslot

Definition at line 774 of file SchemaMainWindow.cpp.

775{
776 QModelIndex proxyIndex = proxyModel->mapToSource( Index );
777 QStringList Row = TableModel->getRowFromIndex ( proxyIndex );
778
779 if ( !Row.isEmpty() )
780 {
781 bool WidgetFound = false;
782 QString ClassName = Row.at ( 0 );
783 OksClass * ClassInfo = KernelWrapper::GetInstance().FindClass ( ClassName.toStdString() );
784
785 for ( QWidget * Editor : QApplication::allWidgets() )
786 {
787 SchemaClassEditor * Widget = dynamic_cast<SchemaClassEditor *> ( Editor );
788
789 if ( Widget != nullptr )
790 {
791 if ( ( Widget->objectName() ).compare ( ClassName ) == 0 )
792 {
793 Widget->raise();
794 Widget->setVisible ( true );
795 Widget->activateWindow();
796 WidgetFound = true;
797 }
798 }
799 }
800
801 if ( !WidgetFound )
802 {
803 SchemaClassEditor * Editor = new SchemaClassEditor ( ClassInfo );
804 Editor->show();
805 }
806 }
807}

◆ LaunchIncludeEditor

void dbse::SchemaMainWindow::LaunchIncludeEditor ( )
privateslot

Definition at line 121 of file SchemaMainWindow.cpp.

122{
123 QModelIndex Index = ui->FileView->currentIndex();
124 QStringList Row = FileModel->getRowFromIndex ( Index );
125 auto * file_widget = new dbse::SchemaIncludeFileWidget ( Row.at ( 0 ) );
126 connect (file_widget, &SchemaIncludeFileWidget::files_updated,
128 file_widget->show();
129}
QStringList getRowFromIndex(QModelIndex &index)

◆ LaunchIncludeEditorActiveSchema

void dbse::SchemaMainWindow::LaunchIncludeEditorActiveSchema ( )
privateslot

Definition at line 131 of file SchemaMainWindow.cpp.

132{
133 std::string ActiveSchema = KernelWrapper::GetInstance().GetActiveSchema();
134
135 auto file_widget = new dbse::SchemaIncludeFileWidget ( QString::fromStdString (ActiveSchema) );
136 connect (file_widget, &SchemaIncludeFileWidget::files_updated,
138 file_widget->show();
139}
std::string GetActiveSchema() const

◆ LoadView

void dbse::SchemaMainWindow::LoadView ( )
privateslot

Definition at line 697 of file SchemaMainWindow.cpp.

697 {
698 QString ViewPath = QFileDialog::getOpenFileName (
699 this,
700 tr ("Open view file"),
702 tr("View files (*.view);;All files (*)"));
703
704 if ( !ViewPath.isEmpty() )
705 {
706 auto spos = ViewPath.lastIndexOf('/');
707 if (spos != -1) {
708 m_view_dir = ViewPath;
709 m_view_dir.truncate(spos);
710 }
711 QFile ViewFile ( ViewPath );
712 ViewFile.open ( QIODevice::ReadOnly );
713
714 auto text = QFileInfo(ViewPath).baseName();
715 auto tab = dynamic_cast<SchemaTab *> ( ui->TabWidget->currentWidget() );
716 if (!tab->getName().isEmpty() || tab->GetScene()->IsModified()) {
717 add_tab();
718 tab = dynamic_cast<SchemaTab *> ( ui->TabWidget->currentWidget() );
719 }
720 auto index = ui->TabWidget->currentIndex();
721 ui->TabWidget->setTabText(index, text);
722 tab->setName(text);
723 tab->setFileName(ViewPath);
724
725 QStringList ClassesNames;
726 QList<QPointF> Positions;
727 QList<QPointF> note_positions;
728 QStringList notes;
729 while ( !ViewFile.atEnd() )
730 {
731 QString Line ( ViewFile.readLine() );
732 if (!Line.isEmpty()) {
733 QStringList ObjectDescription = Line.split ( "," );
734 QPointF Position;
735 Position.setX ( ObjectDescription.at ( 1 ).toInt() );
736 Position.setY ( ObjectDescription.at ( 2 ).toInt() );
737 if (ObjectDescription.at ( 0 ) == "#") {
738 note_positions.append (Position);
739 auto text = ObjectDescription.at(3);
740 if (text.back() == '\n') {
741 text.chop(1);
742 }
743 text = text.replace("<br>", "\n");
744 text = text.replace("<comma>", ",");
745 notes.append ( text );
746 }
747 else {
748 ClassesNames.append ( ObjectDescription.at ( 0 ) );
749 Positions.append ( Position );
750 }
751 }
752 }
753 ViewFile.close();
754
755 auto message = QString("Loaded view from %1").arg(ViewPath);
756 ui->StatusBar->showMessage( message );
757
758 auto scene = tab->GetScene();
759 scene->CleanItemMap();
760 auto missing = scene->AddItemsToScene ( ClassesNames, Positions );
761 if (!missing.empty()) {
762 QString text{"The following classes in "};
763 text.append(QFileInfo(ViewPath).fileName());
764 text.append(" are not present in the loaded schema:\n ");
765 text.append(missing.join(",\n "));
766 QMessageBox::warning(this, tr("Load View"), text);
767 }
768 scene->ClearModified();
769
770 scene->add_notes(notes, note_positions);
771 }
772}

◆ modifiedView

void dbse::SchemaMainWindow::modifiedView ( bool modified)
slot

Definition at line 588 of file SchemaMainWindow.cpp.

588 {
589 auto index = ui->TabWidget->currentIndex();
590 auto label = ui->TabWidget->tabText(index);
591 if (modified && !label.endsWith("*")) {
592 label += "*";
593 }
594 if (!modified && label.endsWith("*")) {
595 label = label.remove('*');
596 }
597 ui->TabWidget->setTabText(index, label);
598}

◆ NameView

void dbse::SchemaMainWindow::NameView ( )
privateslot

Definition at line 600 of file SchemaMainWindow.cpp.

600 {
601 auto index = ui->TabWidget->currentIndex();
602 bool ok;
603 QString text = QInputDialog::getText(nullptr,
604 "Schema editor: rename class view",
605 "New view name:",
606 QLineEdit::Normal,
607 "New Class View",
608 &ok);
609 if(ok && !text.isEmpty()) {
610 ui->TabWidget->setTabText(index, text);
611 SchemaTab * CurrentTab = dynamic_cast<SchemaTab *> ( ui->TabWidget->currentWidget() );
612 CurrentTab->setName(text);
613 }
614
615 auto newtext = ui->TabWidget->tabText(index);
616}

◆ OpenSchemaFile [1/2]

void dbse::SchemaMainWindow::OpenSchemaFile ( )
privateslot

Definition at line 446 of file SchemaMainWindow.cpp.

447{
448 QFileDialog FileDialog ( this, tr ( "Open File" ), ".", tr ( "XML files (*.xml);;All files (*)" ) );
449 FileDialog.setAcceptMode ( QFileDialog::AcceptOpen );
450 FileDialog.setFileMode ( QFileDialog::AnyFile );
451 FileDialog.setViewMode ( QFileDialog::Detail );
452 QStringList FilesSelected;
453 QString SchemaPath;
454
455 if ( FileDialog.exec() )
456 {
457 FilesSelected = FileDialog.selectedFiles();
458 }
459
460 if ( FilesSelected.size() )
461 {
462 SchemaPath = FilesSelected.value ( 0 );
463 }
464
465 OpenSchemaFile(SchemaPath);
466}

◆ OpenSchemaFile() [2/2]

void dbse::SchemaMainWindow::OpenSchemaFile ( QString SchemaFile)
protected

Definition at line 406 of file SchemaMainWindow.cpp.

406 {
407 if(!SchemaFile.isEmpty()) {
408 try {
409 KernelWrapper::GetInstance().LoadSchema(SchemaFile.toStdString());
410
411#ifdef QT_DEBUG
413#endif
414 }
415 catch(oks::exception &Ex) {
416 QMessageBox::warning(0,
417 "Load Schema",
418 QString("Could not load schema!\n\n").append(QString(Ex.what())),
419 QMessageBox::Ok);
420 }
421 try {
422 KernelWrapper::GetInstance().SetActiveSchema(SchemaFile.toStdString());
423 }
424 catch (oks::CanNotSetActiveFile& exc) {
425 QMessageBox::warning(0,
426 "Load Schema",
427 QString("Could not make schema active!\n\n").append(QString(exc.what())),
428 QMessageBox::Ok);
429 }
430
433
434 update_window_title(QFileInfo(SchemaFile).fileName());
435 ui->CreateNewSchema->setDisabled (true );
436 ui->OpenFileSchema->setDisabled (true );
437 }
438}
void SetActiveSchema(const std::string &ActiveSchema)
void LoadSchema(const std::string &SchemaName) const
void update_window_title(QString text)

◆ PrintCurrentView

void dbse::SchemaMainWindow::PrintCurrentView ( )
privateslot

Definition at line 322 of file SchemaMainWindow.cpp.

323{
324 SchemaTab * CurrentTab = dynamic_cast<SchemaTab *> ( ui->TabWidget->currentWidget() );
325
326 QPrinter printer;
327
328 if ( QPrintDialog ( &printer ).exec() == QDialog::Accepted )
329 {
330 QPainter painter ( &printer );
331 painter.setRenderHint ( QPainter::Antialiasing );
332
333 SchemaGraphicsScene * Scene = CurrentTab->GetScene();
334 QGraphicsView * View = CurrentTab->GetView();
335 Scene->render ( &painter, QRectF(), View->viewport()->rect() );
336 }
337}

◆ RemoveClass

void dbse::SchemaMainWindow::RemoveClass ( )
privateslot

Definition at line 223 of file SchemaMainWindow.cpp.

224{
225 QModelIndex Index = ui->ClassTableView->currentIndex();
226 QModelIndex proxyIndex = proxyModel->mapToSource( Index );
227 QStringList Row = TableModel->getRowFromIndex ( proxyIndex );
228 OksClass * SchemaClass = KernelWrapper::GetInstance().FindClass ( Row.at (
229 0 ).toStdString() );
230
231 if ( SchemaClass->all_sub_classes()->size() != 0 )
232 {
233 QMessageBox::warning ( 0, "Schema editor",
234 QString ( "Cannot delete class because it has sub-classes." ) );
235 return;
236 }
237 else if ( KernelWrapper::GetInstance().AnyClassReferenceThis ( SchemaClass ) )
238 {
239 QMessageBox::warning ( 0, "Schema editor",
240 QString ( "Cannot delete class because some classes references it." ) );
241 return;
242 }
243 else
244 {
245 QString Name = QString::fromStdString ( SchemaClass->get_name() );
246 KernelWrapper::GetInstance().PushRemoveClassCommand ( SchemaClass, SchemaClass->get_name(),
247 SchemaClass->get_description(),
248 SchemaClass->get_is_abstract() );
250 }
251}
void PushRemoveClassCommand(dunedaq::oks::OksClass *Class, std::string ClassName, std::string ClassDescription, bool Abstract)
bool get_is_abstract() const noexcept
Definition class.hpp:384
const FList * all_sub_classes() const noexcept
Definition class.hpp:466
const std::string & get_name() const noexcept
Definition class.hpp:363
const std::string & get_description() const noexcept
Definition class.hpp:368

◆ RemoveTab

void dbse::SchemaMainWindow::RemoveTab ( int i)
privateslot

Definition at line 813 of file SchemaMainWindow.cpp.

814{
815 if ( index == -1 || ( ( ui->TabWidget->count() == 1 ) && index == 0 ) ) {
816 return;
817 }
818
819 auto tab = dynamic_cast<SchemaTab *> (ui->TabWidget->widget(index));
820 if (tab->GetScene()->IsModified()) {
821 auto choice = QMessageBox::question (
822 0, tr ( "SchemaEditor" ),
823 QString ( "There are unsaved changes in the schema view:\n"
824 "Do you really want to delete this schema view?\n" ),
825 QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel );
826 if (choice == QMessageBox::Cancel) {
827 return;
828 }
829 }
830 ui->TabWidget->removeTab ( index );
831 delete tab;
832}

◆ SaveModifiedSchema

void dbse::SchemaMainWindow::SaveModifiedSchema ( )
privateslot

Definition at line 467 of file SchemaMainWindow.cpp.

468{
469 try
470 {
472 //std::format msg("{} schema files successfully saved", nsaved)
473 std::ostringstream ostream;
474 ostream << "Schema files:\n" + saved + " successfully saved";
475 std::string msg = ostream.str();
476 QMessageBox::information ( 0, "Schema editor",
477 QString ( msg.c_str() ) );
478
479 }
480 catch ( oks::exception & Ex )
481 {
482 QMessageBox::warning ( 0, "Schema editor",
483 QString ( "Could not save schemas.\n\n%1" ).arg ( QString ( Ex.what() ) ) );
484 }
485 }
std::string SaveModifiedSchema() const

◆ SaveSchema

void dbse::SchemaMainWindow::SaveSchema ( )
privateslot

Definition at line 487 of file SchemaMainWindow.cpp.

488{
490 if (modified.empty())
491 {
492 QMessageBox::information ( 0, "Schema editor",
493 QString ( "No modified schema files need saving" ) );
494
495 }
496 else {
498 }
500}
std::string ModifiedSchemaFiles() const

◆ SaveSchemaFile

void dbse::SchemaMainWindow::SaveSchemaFile ( )
privateslot

Definition at line 306 of file SchemaMainWindow.cpp.

307{
308 QModelIndex Index = ui->FileView->currentIndex();
309 const auto File = FileModel->getRowFromIndex ( Index ).at ( 0 );
310 QString message;
311 try {
312 KernelWrapper::GetInstance().SaveSchema ( File.toStdString() );
313 message = QString ( "File %1 saved" ).arg ( File );
314 }
315 catch (const oks::exception& exc) {
316 message = QString ( "Faled to save file %1" ).arg ( File );
317 }
318 ui->StatusBar->showMessage( message );
320}
Unknown serialization Cannot deserialize message

◆ SaveView

void dbse::SchemaMainWindow::SaveView ( )
privateslot

Definition at line 618 of file SchemaMainWindow.cpp.

618 {
619 SchemaTab * tab = dynamic_cast<SchemaTab *> ( ui->TabWidget->currentWidget() );
620 if ( tab->GetScene()->items().size() != 0 )
621 {
622 auto file_name = tab->getFileName();
623 if (file_name == "./") {
624 SaveViewAs();
625 return;
626 }
627 write_view_file(file_name, tab);
628 }
629}
void write_view_file(const QString &fn, SchemaTab *tab)

◆ SaveViewAs

void dbse::SchemaMainWindow::SaveViewAs ( )
privateslot

Definition at line 630 of file SchemaMainWindow.cpp.

630 {
631 SchemaTab * CurrentTab = dynamic_cast<SchemaTab *> ( ui->TabWidget->currentWidget() );
632 if ( CurrentTab->GetScene()->items().size() != 0 )
633 {
634 auto defName = CurrentTab->getFileName();
635 if (defName == "./") {
636 defName = m_view_dir;
637 }
638 QString FileName = QFileDialog::getSaveFileName (
639 this, tr ( "Save View" ), defName,
640 tr("View files (*.view);;All files (*)") );
641
642 if (! FileName.isEmpty()) {
643 auto spos = FileName.lastIndexOf('/');
644 if (spos != -1) {
645 m_view_dir = FileName;
646 m_view_dir.truncate(spos);
647 }
648
649 if ( !FileName.endsWith ( ".view" ) ) {
650 FileName.append ( ".view" );
651 }
652
653 CurrentTab->setFileName ( FileName );
654 auto text = QFileInfo(FileName).baseName();
655 CurrentTab->setName(text);
656 auto index = ui->TabWidget->currentIndex();
657 ui->TabWidget->setTabText(index, text);
658
659 write_view_file(FileName, CurrentTab);
660 }
661 }
662}

◆ SetController()

void dbse::SchemaMainWindow::SetController ( )
private

Definition at line 83 of file SchemaMainWindow.cpp.

84{
85 connect ( ui->OpenFileSchema, SIGNAL ( triggered() ), this, SLOT ( OpenSchemaFile() ) );
86 connect ( ui->CreateNewSchema, SIGNAL ( triggered() ), this, SLOT ( CreateNewSchema() ) );
87 connect ( ui->AddInclude, SIGNAL ( triggered() ), this, SLOT ( LaunchIncludeEditorActiveSchema() ) );
88 connect ( ui->SaveSchema, SIGNAL ( triggered() ), this, SLOT ( SaveSchema() ) );
89 connect ( ui->SetRelationship, SIGNAL ( triggered ( bool ) ), this,
90 SLOT ( ChangeCursorRelationship ( bool ) ) );
91 connect ( ui->SetInheritance, SIGNAL ( triggered ( bool ) ), this,
92 SLOT ( ChangeCursorInheritance ( bool ) ) );
93 connect ( ui->AddClass, SIGNAL ( triggered() ), this, SLOT ( AddNewClass() ) );
94 connect ( ui->SaveView, SIGNAL ( triggered() ), this, SLOT ( SaveView() ) );
95 connect ( ui->SaveViewAs, SIGNAL ( triggered() ), this, SLOT ( SaveViewAs() ) );
96 connect ( ui->LoadView, SIGNAL ( triggered() ), this, SLOT ( LoadView() ) );
97 connect ( ui->NameView, SIGNAL ( triggered() ), this, SLOT ( NameView() ) );
98 connect ( ui->Exit, SIGNAL ( triggered() ), this, SLOT ( close() ) );
99 connect ( ui->ClassTableView, SIGNAL ( doubleClicked ( QModelIndex ) ), this,
100 SLOT ( LaunchClassEditor ( QModelIndex ) ) );
101 connect ( ui->close_tab, SIGNAL ( triggered() ), this, SLOT ( close_tab() ) );
102
103 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassCreated( QString ) ), this,
104 SLOT ( update_models() ) );
105 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassUpdated ( QString ) ), this,
106 SLOT ( update_models() ) );
107 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassRemoved ( QString ) ), this,
108 SLOT ( update_models() ) );
109 connect ( ui->TabWidget, SIGNAL ( tabCloseRequested ( int ) ), this,
110 SLOT ( RemoveTab ( int ) ) );
111 connect ( ui->FileView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
112 SLOT ( CustomContextMenuFileView ( QPoint ) ) );
113 connect ( ui->ClassTableView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
114 SLOT ( CustomContextMenuTableView ( QPoint ) ) );
115 connect ( ui->PrintView, SIGNAL ( triggered() ), this, SLOT ( PrintCurrentView() ) );
116 connect ( ui->exportView, SIGNAL ( triggered() ), this, SLOT ( export_current_view() ) );
117 connect ( ui->ClassTableSearchLine, SIGNAL( textChanged ( QString ) ), proxyModel, SLOT( setFilterRegExp( QString ) ) );
118
119}
void LaunchClassEditor(QModelIndex Index)
void CustomContextMenuTableView(QPoint Pos)
void ChangeCursorInheritance(bool State)
void CustomContextMenuFileView(QPoint Pos)
void ChangeCursorRelationship(bool State)

◆ SetSchemaFileActive

void dbse::SchemaMainWindow::SetSchemaFileActive ( )
privateslot

Definition at line 282 of file SchemaMainWindow.cpp.

283{
284 QModelIndex index = ui->FileView->currentIndex();
285 QString file = FileModel->getRowFromIndex ( index ).at(0);
286 try {
288 }
289 catch (oks::CanNotSetActiveFile& exc) {
290 QMessageBox::warning(0,
291 "Set Active Schema",
292 QString("Could not make schema active!\n\n").append(QString(exc.what())),
293 QMessageBox::Ok);
294 return;
295 }
297
298 // In case we are highlighting classes in the active file, redraw current
299 // view tab now we've changed active file
300 SchemaTab * current_tab = dynamic_cast<SchemaTab *> ( ui->TabWidget->currentWidget() );
301 SchemaGraphicsScene * scene = current_tab->GetScene();
302 scene->update();
303
305}

◆ ShouldSaveChanges()

int dbse::SchemaMainWindow::ShouldSaveChanges ( ) const
nodiscardprivate

Definition at line 200 of file SchemaMainWindow.cpp.

201{
202 // if ( KernelWrapper::GetInstance().GetUndoStack()->isClean() )
204 if (modified.empty())
205 {
206 return QMessageBox::Discard;
207 }
208
209 std::string msg = "There are unsaved changes in the following files:\n\n"
210 + modified + "Do you want to save the changes in the schema?\n";
211 return QMessageBox::question (
212 0, tr ( "SchemaEditor" ),
213 QString ( msg.c_str() ),
214 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save );
215}

◆ ShouldSaveViewChanges()

int dbse::SchemaMainWindow::ShouldSaveViewChanges ( ) const
nodiscardprivate

Definition at line 176 of file SchemaMainWindow.cpp.

177{
178 QString modified_views;
179 for (int index=0; index<ui->TabWidget->count(); ++index) {
180 auto tab = dynamic_cast<SchemaTab *> (ui->TabWidget->widget(index));
181 if (tab->GetScene()->IsModified()) {
182 auto label = ui->TabWidget->tabText(index);
183 label = label.remove('*');
184 modified_views.append(" " + label + "\n");
185 }
186 }
187 if (!modified_views.isEmpty()) {
188 QString message ( "There are unsaved changes in the schema views:\n");
189 message.append (modified_views);
190 message.append ("Do you want to save the changes in the schema views?\n" );
191 return QMessageBox::question (
192 0, tr ( "SchemaEditor" ),
193 message,
194 QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard );
195 }
196
197 return QMessageBox::Discard;
198}

◆ update_models

void dbse::SchemaMainWindow::update_models ( )
slot

Definition at line 401 of file SchemaMainWindow.cpp.

401 {
404}

◆ update_window_title()

void dbse::SchemaMainWindow::update_window_title ( QString text)
private

Definition at line 440 of file SchemaMainWindow.cpp.

440 {
441 m_title.remove(QRegularExpression(": --.*"));
442 m_title.append(QString(": -- ") + text);
443 setWindowTitle ( m_title );
444}

◆ write_view_file()

void dbse::SchemaMainWindow::write_view_file ( const QString & fn,
SchemaTab * tab )
private

Definition at line 664 of file SchemaMainWindow.cpp.

665 {
666 QFile file ( file_name );
667 file.open ( QIODevice::WriteOnly );
668
669 for ( QGraphicsItem * item : tab->GetScene()->items() ) {
670 auto object = dynamic_cast<SchemaGraphicObject *> ( item );
671 if ( object != nullptr ) {
672 QString description = object->GetClassName() + ","
673 + QString::number ( object->scenePos().x() ) + ","
674 + QString::number ( object->scenePos().y() ) + "\n";
675 file.write ( description.toUtf8() );
676 }
677 else {
678 auto note = dynamic_cast<SchemaGraphicNote*> (item);
679 if ( note != nullptr && !note->text().isEmpty()) {
680 auto text = note->text().replace("\n", "<br>");
681 text = text.replace(",", "<comma>");
682 QString line = "#,"
683 + QString::number ( note->scenePos().x() ) + ","
684 + QString::number ( note->scenePos().y() ) + ","
685 + text + "\n";
686 file.write ( line.toUtf8() );
687 }
688 }
689 }
690
691 file.close();
692 auto message = QString("Saved view to %1").arg(file_name);
693 ui->StatusBar->showMessage( message );
694 tab->GetScene()->ClearModified();
695}

Member Data Documentation

◆ ContextMenuFileView

QMenu* dbse::SchemaMainWindow::ContextMenuFileView
private

Definition at line 36 of file SchemaMainWindow.hpp.

◆ ContextMenuTableView

QMenu* dbse::SchemaMainWindow::ContextMenuTableView
private

Definition at line 37 of file SchemaMainWindow.hpp.

◆ FileModel

CustomFileModel* dbse::SchemaMainWindow::FileModel
private

Definition at line 33 of file SchemaMainWindow.hpp.

◆ m_export_path

QString dbse::SchemaMainWindow::m_export_path {"."}
private

Definition at line 40 of file SchemaMainWindow.hpp.

40{"."};

◆ m_title

QString dbse::SchemaMainWindow::m_title {"DUNE DAQ Configuration Schema editor"}
private

Definition at line 38 of file SchemaMainWindow.hpp.

38{"DUNE DAQ Configuration Schema editor"};

◆ m_view_dir

QString dbse::SchemaMainWindow::m_view_dir {"."}
private

Definition at line 39 of file SchemaMainWindow.hpp.

39{"."};

◆ proxyModel

QSortFilterProxyModel* dbse::SchemaMainWindow::proxyModel
private

Definition at line 35 of file SchemaMainWindow.hpp.

◆ TableModel

CustomTableModel* dbse::SchemaMainWindow::TableModel
private

Definition at line 34 of file SchemaMainWindow.hpp.

◆ ui

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

Definition at line 31 of file SchemaMainWindow.hpp.


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