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() ) );
104 SLOT ( update_models() ) );
106 SLOT ( update_models() ) );
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 ) ) );
339 auto tab =
dynamic_cast<SchemaTab *
> ( ui->TabWidget->currentWidget() );
341 auto file = QFileDialog::getSaveFileName(
342 this, tr(
"Export to SVG"),
344 tr(
"SVG files (*.svg);;All files (*)"));
345 if (file.isEmpty()) {
349 auto spos = file.lastIndexOf(
'/');
351 m_export_path = file;
352 m_export_path.truncate(spos);
355 auto scene = tab->GetScene();
356 auto view = tab->GetView();
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);
365 painter.begin(&generator);
366 scene->render ( &painter, QRectF(), view->viewport()->rect() );
666 QFile file ( file_name );
667 file.open ( QIODevice::WriteOnly );
669 for ( QGraphicsItem * item : tab->
GetScene()->items() ) {
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() );
679 if ( note !=
nullptr && !note->text().isEmpty()) {
680 auto text = note->text().replace(
"\n",
"<br>");
681 text = text.replace(
",",
"<comma>");
683 + QString::number ( note->scenePos().x() ) +
","
684 + QString::number ( note->scenePos().y() ) +
","
686 file.write ( line.toUtf8() );
692 auto message = QString(
"Saved view to %1").arg(file_name);
693 ui->StatusBar->showMessage( message );
698 QString ViewPath = QFileDialog::getOpenFileName (
700 tr (
"Open view file"),
702 tr(
"View files (*.view);;All files (*)"));
704 if ( !ViewPath.isEmpty() )
706 auto spos = ViewPath.lastIndexOf(
'/');
708 m_view_dir = ViewPath;
709 m_view_dir.truncate(spos);
711 QFile ViewFile ( ViewPath );
712 ViewFile.open ( QIODevice::ReadOnly );
714 auto text = QFileInfo(ViewPath).baseName();
715 auto tab =
dynamic_cast<SchemaTab *
> ( ui->TabWidget->currentWidget() );
716 if (!tab->getName().isEmpty() || tab->GetScene()->IsModified()) {
718 tab =
dynamic_cast<SchemaTab *
> ( ui->TabWidget->currentWidget() );
720 auto index = ui->TabWidget->currentIndex();
721 ui->TabWidget->setTabText(index, text);
723 tab->setFileName(ViewPath);
725 QStringList ClassesNames;
726 QList<QPointF> Positions;
727 QList<QPointF> note_positions;
729 while ( !ViewFile.atEnd() )
731 QString Line ( ViewFile.readLine() );
732 if (!Line.isEmpty()) {
733 QStringList ObjectDescription = Line.split (
"," );
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') {
743 text = text.replace(
"<br>",
"\n");
744 text = text.replace(
"<comma>",
",");
745 notes.append ( text );
748 ClassesNames.append ( ObjectDescription.at ( 0 ) );
749 Positions.append ( Position );
755 auto message = QString(
"Loaded view from %1").arg(ViewPath);
756 ui->StatusBar->showMessage( message );
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);
768 scene->ClearModified();
770 scene->add_notes(notes, note_positions);
836 if ( ContextMenuFileView ==
nullptr )
838 ContextMenuFileView =
new QMenu (
this );
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() ) );
847 ContextMenuFileView->addAction ( Act );
848 ContextMenuFileView->addAction ( Inc );
849 ContextMenuFileView->addAction ( Sav );
852 QModelIndex Index = ui->FileView->currentIndex();
854 if ( Index.isValid() )
856 ContextMenuFileView->exec ( ui->FileView->mapToGlobal ( Pos ) );
862 if ( ContextMenuTableView ==
nullptr )
864 ContextMenuTableView =
new QMenu (
this );
866 QAction * add =
new QAction ( tr (
"&Add New Class" ),
this );
867 connect ( add, SIGNAL ( triggered() ),
this, SLOT ( AddNewClass() ) );
869 QAction * remove =
new QAction ( tr (
"&Remove Selected Class" ),
this );
870 connect ( remove, SIGNAL ( triggered() ),
this, SLOT ( RemoveClass() ) );
872 QAction * edit =
new QAction ( tr (
"&Edit Selected Class" ),
this );
873 connect ( edit, SIGNAL ( triggered() ),
this, SLOT ( editClass() ) );
875 ContextMenuTableView->addAction ( add );
876 ContextMenuTableView->addAction ( edit );
877 ContextMenuTableView->addAction ( remove );
880 QModelIndex Index = ui->ClassTableView->currentIndex();
882 if ( Index.isValid() )
884 ContextMenuTableView->exec ( ui->ClassTableView->mapToGlobal ( Pos ) );
SchemaMainWindow(QString SchemaFile, QWidget *parent=nullptr)
void write_view_file(const QString &fn, SchemaTab *tab)