Line data Source code
1 : /// Including Schema Editor
2 : #include "dbe/SchemaMainWindow.hpp"
3 : #include "dbe/SchemaClassEditor.hpp"
4 : #include "dbe/SchemaFileInfo.hpp"
5 : #include "dbe/SchemaGraphicsScene.hpp"
6 : #include "dbe/SchemaKernelWrapper.hpp"
7 : #include "dbe/SchemaMethodImplementationEditor.hpp"
8 : #include "dbe/SchemaRelationshipEditor.hpp"
9 : #include "dbe/SchemaStyle.hpp"
10 : #include "dbe/SchemaTab.hpp"
11 :
12 : #include "oks/kernel.hpp" // for CanNotSetActiveFile exception
13 :
14 : /// Including Auto-Generated Files
15 : #include "ui_SchemaMainWindow.h"
16 : /// Including QT Headers
17 : #include "QInputDialog"
18 : #include <QCloseEvent>
19 : #include <QFileDialog>
20 : #include <QGraphicsScene>
21 : #include <QHeaderView>
22 : #include <QMessageBox>
23 : #include <QPrintDialog>
24 : #include <QPrinter>
25 : #include <QPushButton>
26 : #include <QSettings>
27 : #include <QSvgGenerator>
28 :
29 : // #include <format>
30 : #include <sstream>
31 :
32 : using namespace dunedaq;
33 : using namespace dunedaq::oks;
34 :
35 0 : dbse::SchemaMainWindow::SchemaMainWindow(QString SchemaFile, QWidget* parent)
36 : : QMainWindow(parent)
37 0 : , ui(new Ui::SchemaMainWindow)
38 0 : , FileModel(nullptr)
39 0 : , TableModel(nullptr)
40 0 : , m_proxyModel(new QSortFilterProxyModel())
41 0 : , ContextMenuFileView(nullptr)
42 0 : , ContextMenuTableView(nullptr)
43 : {
44 0 : InitialSettings();
45 0 : m_default_state = saveState();
46 0 : m_default_geometry = saveGeometry();
47 0 : m_default_size = QSize(1400, 880);
48 0 : QCoreApplication::setOrganizationName("dunedaq");
49 0 : QCoreApplication::setApplicationName("dbse");
50 0 : SchemaStyle::load();
51 0 : restore_layout();
52 :
53 0 : InitialTab();
54 0 : InitialTabCorner();
55 0 : SetController();
56 0 : setFocusPolicy(Qt::StrongFocus);
57 :
58 0 : OpenSchemaFile(SchemaFile);
59 0 : }
60 :
61 0 : dbse::SchemaMainWindow::~SchemaMainWindow() = default;
62 :
63 : void
64 0 : dbse::SchemaMainWindow::InitialSettings()
65 : {
66 0 : ui->setupUi(this);
67 0 : setWindowTitle(m_title);
68 0 : ui->UndoView->setStack(KernelWrapper::GetInstance().GetUndoStack());
69 0 : ui->ClassTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
70 0 : ui->ClassTableView->setDragEnabled(true);
71 0 : ui->ClassTableView->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
72 0 : ui->FileView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
73 0 : ui->FileView->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
74 0 : ui->FileView->setSelectionBehavior(QAbstractItemView::SelectRows);
75 0 : ui->TabWidget->setTabsClosable(true);
76 0 : ui->ClassTableSearchLine->setProperty("placeholderText", QVariant(QString("Search for classes regex")));
77 0 : ui->ClassTableSearchLine->setClearButtonEnabled(true);
78 0 : m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
79 :
80 0 : QString DUNEDAQ_DB_PATH = getenv("DUNEDAQ_DB_PATH");
81 0 : auto path_list = DUNEDAQ_DB_PATH.split(QLatin1Char(':'), Qt::SkipEmptyParts);
82 0 : for (QString& path : path_list) {
83 0 : if (!path.endsWith("/")) {
84 0 : path.append("/");
85 : }
86 0 : m_path_urls.append(QUrl::fromLocalFile(path));
87 : }
88 0 : }
89 :
90 : void
91 0 : dbse::SchemaMainWindow::InitialTab()
92 : {
93 0 : add_tab();
94 0 : ui->TabWidget->removeTab(0);
95 0 : }
96 :
97 : void
98 0 : dbse::SchemaMainWindow::InitialTabCorner()
99 : {
100 0 : QPushButton* new_tab_button = new QPushButton("+");
101 0 : new_tab_button->setToolTip("Open new schema view tab");
102 0 : ui->TabWidget->setCornerWidget(new_tab_button, Qt::TopLeftCorner);
103 0 : connect(new_tab_button, SIGNAL(clicked()), this, SLOT(add_tab()));
104 0 : }
105 :
106 : void
107 0 : dbse::SchemaMainWindow::SetController()
108 : {
109 0 : connect(ui->OpenFileSchema, SIGNAL(triggered()), this, SLOT(OpenSchemaFile()));
110 0 : connect(ui->CreateNewSchema, SIGNAL(triggered()), this, SLOT(CreateNewSchema()));
111 0 : connect(ui->ShowSchema, SIGNAL(triggered()), this, SLOT(show_file_info_active_schema()));
112 0 : connect(ui->SaveSchema, SIGNAL(triggered()), this, SLOT(SaveSchema()));
113 0 : connect(ui->actionSave_layout, SIGNAL(triggered()), this, SLOT(save_layout()));
114 0 : connect(ui->actionRestore_layout, SIGNAL(triggered()), this, SLOT(restore_layout()));
115 0 : connect(ui->actionDefault_layout, SIGNAL(triggered()), this, SLOT(default_layout()));
116 0 : connect(ui->SetRelationship, SIGNAL(triggered(bool)), this, SLOT(ChangeCursorRelationship(bool)));
117 0 : connect(ui->SetInheritance, SIGNAL(triggered(bool)), this, SLOT(ChangeCursorInheritance(bool)));
118 0 : connect(ui->AddClass, SIGNAL(triggered()), this, SLOT(AddNewClass()));
119 0 : connect(ui->SaveView, SIGNAL(triggered()), this, SLOT(SaveView()));
120 0 : connect(ui->SaveViewAs, SIGNAL(triggered()), this, SLOT(SaveViewAs()));
121 0 : connect(ui->LoadView, SIGNAL(triggered()), this, SLOT(LoadView()));
122 0 : connect(ui->NameView, SIGNAL(triggered()), this, SLOT(NameView()));
123 0 : connect(ui->Exit, SIGNAL(triggered()), this, SLOT(close()));
124 :
125 0 : connect(ui->actionSettings, SIGNAL(triggered()), this, SLOT(edit_settings()));
126 :
127 0 : connect(ui->displayClasses, SIGNAL(triggered(bool)), ui->ClassWidget, SLOT(setVisible(bool)));
128 0 : connect(ui->displayDiagrams, SIGNAL(triggered(bool)), ui->TabWidget, SLOT(setVisible(bool)));
129 0 : connect(ui->displayInfo_tabs, SIGNAL(triggered(bool)), ui->DockWidget, SLOT(setVisible(bool)));
130 0 : connect(ui->displayToolbar, SIGNAL(triggered(bool)), ui->MainToolBar, SLOT(setVisible(bool)));
131 0 : connect(ui->displayStatus_bar, SIGNAL(triggered(bool)), ui->StatusBar, SLOT(setVisible(bool)));
132 :
133 0 : connect(ui->ClassWidget, SIGNAL(visibilityChanged(bool)), ui->displayClasses, SLOT(setChecked(bool)));
134 0 : connect(ui->DockWidget, SIGNAL(visibilityChanged(bool)), ui->displayInfo_tabs, SLOT(setChecked(bool)));
135 0 : connect(ui->MainToolBar, SIGNAL(visibilityChanged(bool)), ui->displayToolbar, SLOT(setChecked(bool)));
136 :
137 0 : connect(ui->ClassTableView, SIGNAL(activated(QModelIndex)), this, SLOT(LaunchClassEditor(QModelIndex)));
138 0 : connect(ui->close_tab, SIGNAL(triggered()), this, SLOT(close_tab()));
139 :
140 0 : connect(&KernelWrapper::GetInstance(), SIGNAL(ClassCreated(QString)), this, SLOT(update_models()));
141 0 : connect(&KernelWrapper::GetInstance(), SIGNAL(ClassUpdated(QString)), this, SLOT(update_models()));
142 0 : connect(&KernelWrapper::GetInstance(), SIGNAL(ClassRemoved(QString)), this, SLOT(update_models()));
143 0 : connect(&KernelWrapper::GetInstance(), SIGNAL(active_updated()), this, SLOT(update_models()));
144 0 : connect(ui->TabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(RemoveTab(int)));
145 :
146 0 : connect(ui->FileView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CustomContextMenuFileView(QPoint)));
147 0 : connect(ui->FileView, SIGNAL(activated(QModelIndex)), this, SLOT(show_file_info(QModelIndex)));
148 :
149 0 : connect(
150 0 : ui->ClassTableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CustomContextMenuTableView(QPoint)));
151 0 : connect(ui->PrintView, SIGNAL(triggered()), this, SLOT(PrintCurrentView()));
152 0 : connect(ui->exportView, SIGNAL(triggered()), this, SLOT(export_current_view()));
153 0 : connect(ui->ClassTableSearchLine, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterRegExp(QString)));
154 0 : connect(ui->case_sensitive, SIGNAL(stateChanged(int)), this, SLOT(toggle_case_sensitive(int)));
155 0 : }
156 :
157 : void
158 0 : dbse::SchemaMainWindow::show_file_info_active_schema()
159 : {
160 0 : show_file_info(QString::fromStdString(KernelWrapper::GetInstance().GetActiveSchema()));
161 0 : }
162 :
163 : void
164 0 : dbse::SchemaMainWindow::show_file_info()
165 : {
166 0 : QModelIndex index = ui->FileView->currentIndex();
167 0 : show_file_info(index);
168 0 : }
169 : void
170 0 : dbse::SchemaMainWindow::show_file_info(QModelIndex index)
171 : {
172 0 : QStringList row = FileModel->getRowFromIndex(index);
173 0 : show_file_info(row.at(0));
174 0 : }
175 : void
176 0 : dbse::SchemaMainWindow::show_file_info(QString fn)
177 : {
178 0 : bool widget_found = false;
179 0 : for (QWidget* widget : QApplication::allWidgets()) {
180 0 : auto sfi = dynamic_cast<SchemaFileInfo*>(widget);
181 0 : if (sfi != nullptr) {
182 0 : if ((sfi->objectName()).compare(fn) == 0) {
183 0 : sfi->raise();
184 0 : sfi->setVisible(true);
185 0 : sfi->activateWindow();
186 : widget_found = true;
187 : break;
188 : }
189 : }
190 0 : }
191 0 : if (!widget_found) {
192 0 : auto info = new SchemaFileInfo(fn.toStdString());
193 0 : connect(info, &SchemaFileInfo::files_updated, this, &SchemaMainWindow::update_models);
194 0 : connect(info, &SchemaFileInfo::new_window, this, &SchemaMainWindow::connect_file_info);
195 0 : info->show();
196 : }
197 0 : }
198 : void
199 0 : dbse::SchemaMainWindow::connect_file_info(SchemaFileInfo* win)
200 : {
201 0 : connect(win, &SchemaFileInfo::files_updated, this, &SchemaMainWindow::update_models);
202 0 : }
203 : void
204 0 : dbse::SchemaMainWindow::BuildFileModel()
205 : {
206 0 : QStringList Headers{ "File Name", "Access", "Status" };
207 :
208 0 : if (FileModel != nullptr) {
209 0 : delete FileModel;
210 : }
211 0 : FileModel = new CustomFileModel(Headers);
212 :
213 0 : ui->FileView->setModel(FileModel);
214 0 : ui->FileView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
215 0 : ui->FileView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
216 0 : ui->FileView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
217 0 : }
218 :
219 : void
220 0 : dbse::SchemaMainWindow::BuildTableModel()
221 : {
222 0 : QStringList Headers{ "Class Name" };
223 :
224 0 : if (TableModel != nullptr) {
225 0 : delete TableModel;
226 : }
227 0 : TableModel = new CustomTableModel(Headers);
228 :
229 0 : m_proxyModel->setSourceModel(TableModel);
230 0 : ui->ClassTableView->setModel(m_proxyModel);
231 0 : }
232 :
233 : int
234 0 : dbse::SchemaMainWindow::ShouldSaveViewChanges() const
235 : {
236 0 : QString modified_views;
237 0 : for (int index = 0; index < ui->TabWidget->count(); ++index) {
238 0 : auto tab = dynamic_cast<SchemaTab*>(ui->TabWidget->widget(index));
239 0 : if (tab->GetScene()->IsModified()) {
240 0 : auto label = ui->TabWidget->tabText(index);
241 0 : label = label.remove('*');
242 0 : modified_views.append(" " + label + "\n");
243 0 : }
244 : }
245 0 : if (!modified_views.isEmpty()) {
246 0 : QString message("There are unsaved changes in the schema views:\n");
247 0 : message.append(modified_views);
248 0 : message.append("Do you want to save the changes in the schema views?\n");
249 0 : return QMessageBox::question(
250 0 : 0, tr("SchemaEditor"), message, QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard);
251 0 : }
252 :
253 : return QMessageBox::Discard;
254 0 : }
255 :
256 : int
257 0 : dbse::SchemaMainWindow::ShouldSaveChanges() const
258 : {
259 : // if ( KernelWrapper::GetInstance().GetUndoStack()->isClean() )
260 0 : auto modified = KernelWrapper::GetInstance().ModifiedSchemaFiles();
261 0 : if (modified.empty()) {
262 : return QMessageBox::Discard;
263 : }
264 :
265 0 : std::string msg = "There are unsaved changes in the following files:\n\n" + modified +
266 0 : "Do you want to save the changes in the schema?\n";
267 0 : return QMessageBox::question(0,
268 0 : tr("SchemaEditor"),
269 0 : QString(msg.c_str()),
270 0 : QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
271 : QMessageBox::Save);
272 0 : }
273 :
274 : void
275 0 : dbse::SchemaMainWindow::AddNewClass()
276 : {
277 0 : SchemaClassEditor::createNewClass();
278 0 : BuildFileModel();
279 0 : }
280 :
281 : void
282 0 : dbse::SchemaMainWindow::RemoveClass()
283 : {
284 0 : QModelIndex Index = ui->ClassTableView->currentIndex();
285 0 : QModelIndex proxyIndex = m_proxyModel->mapToSource(Index);
286 0 : QStringList Row = TableModel->getRowFromIndex(proxyIndex);
287 0 : OksClass* SchemaClass = KernelWrapper::GetInstance().FindClass(Row.at(0).toStdString());
288 :
289 0 : if (SchemaClass->all_sub_classes()->size() != 0) {
290 0 : QMessageBox::warning(0, "Schema editor", QString("Cannot delete class because it has sub-classes."));
291 0 : return;
292 0 : } else if (KernelWrapper::GetInstance().AnyClassReferenceThis(SchemaClass)) {
293 0 : QMessageBox::warning(0, "Schema editor", QString("Cannot delete class because some classes references it."));
294 0 : return;
295 : } else {
296 0 : QString Name = QString::fromStdString(SchemaClass->get_name());
297 0 : KernelWrapper::GetInstance().PushRemoveClassCommand(
298 0 : SchemaClass, SchemaClass->get_name(), SchemaClass->get_description(), SchemaClass->get_is_abstract());
299 0 : BuildFileModel();
300 0 : }
301 0 : }
302 :
303 : void
304 0 : dbse::SchemaMainWindow::editClass()
305 : {
306 0 : QModelIndex Index = ui->ClassTableView->currentIndex();
307 0 : QModelIndex proxyIndex = m_proxyModel->mapToSource(Index);
308 0 : QStringList Row = TableModel->getRowFromIndex(proxyIndex);
309 :
310 0 : if (!Row.isEmpty()) {
311 0 : bool widget_found = false;
312 0 : QString class_name = Row.at(0);
313 0 : OksClass* class_info = KernelWrapper::GetInstance().FindClass(class_name.toStdString());
314 :
315 0 : for (QWidget* widget : QApplication::allWidgets()) {
316 0 : auto editor = dynamic_cast<SchemaClassEditor*>(widget);
317 0 : if (editor != nullptr) {
318 0 : if ((editor->objectName()).compare(class_name) == 0) {
319 0 : editor->raise();
320 0 : editor->setVisible(true);
321 0 : editor->activateWindow();
322 : widget_found = true;
323 : }
324 : }
325 0 : }
326 0 : if (!widget_found) {
327 0 : SchemaClassEditor* editor = new SchemaClassEditor(class_info);
328 0 : editor->show();
329 : }
330 0 : }
331 0 : }
332 :
333 : void
334 0 : dbse::SchemaMainWindow::SetSchemaFileActive()
335 : {
336 0 : QModelIndex index = ui->FileView->currentIndex();
337 0 : QString file = FileModel->getRowFromIndex(index).at(0);
338 0 : try {
339 0 : KernelWrapper::GetInstance().SetActiveSchema(file.toStdString());
340 0 : } catch (oks::CanNotSetActiveFile& exc) {
341 0 : QMessageBox::warning(0,
342 : "Set Active Schema",
343 0 : QString("Could not make schema active!\n\n").append(QString(exc.what())),
344 : QMessageBox::Ok);
345 0 : return;
346 0 : }
347 0 : update_window_title(file);
348 :
349 : // In case we are highlighting classes in the active file, redraw current
350 : // view tab now we've changed active file
351 0 : SchemaTab* current_tab = dynamic_cast<SchemaTab*>(ui->TabWidget->currentWidget());
352 0 : SchemaGraphicsScene* scene = current_tab->GetScene();
353 0 : scene->update();
354 :
355 0 : BuildFileModel();
356 0 : }
357 :
358 : bool
359 0 : dbse::SchemaMainWindow::check_schema_file(QString qfilename)
360 : {
361 0 : std::string filename = qfilename.toStdString();
362 0 : std::set<std::string> includes;
363 0 : KernelWrapper::GetInstance().get_all_includes(filename, includes);
364 :
365 0 : QString advice{ "<br><br>Use the File info window to fix the problem." };
366 0 : for (auto cls : KernelWrapper::GetInstance().get_schema_classes(filename)) {
367 0 : auto relationships = cls->direct_relationships();
368 0 : if (relationships != nullptr) {
369 0 : for (auto rel : *relationships) {
370 0 : auto rel_class = rel->get_class_type();
371 0 : if (rel_class == nullptr) {
372 0 : QString warning = "<b>Warning</b> class <i>" + QString::fromStdString(cls->get_name()) +
373 0 : "</i> has relationship " + QString::fromStdString(rel->get_name()) +
374 0 : " referring to class <i>" + QString::fromStdString(rel->get_type()) +
375 0 : "</i> which is not loaded<br>";
376 0 : QMessageBox::warning(0, "Check Schema", warning + advice, QMessageBox::Ok);
377 0 : show_file_info(qfilename);
378 0 : return false;
379 0 : }
380 0 : auto file = rel_class->get_file()->get_full_file_name();
381 0 : if (file != filename && !includes.contains(file)) {
382 0 : QString warning = "<b>Warning</b> class <i>" + QString::fromStdString(cls->get_name()) +
383 0 : "</i> has relationship " + QString::fromStdString(rel->get_name()) +
384 0 : " referring to class <i>" + QString::fromStdString(rel->get_class_type()->get_name()) +
385 0 : "</i> from " + QString::fromStdString(file) + " which is not included by " + qfilename;
386 0 : QMessageBox::warning(0, "Check Schema", warning + advice, QMessageBox::Ok);
387 0 : show_file_info(qfilename);
388 0 : return false;
389 0 : }
390 0 : }
391 : }
392 :
393 0 : auto super_classes = cls->direct_super_classes();
394 0 : if (super_classes != nullptr) {
395 0 : for (auto sc : *super_classes) {
396 0 : auto sclass = KernelWrapper::GetInstance().FindClass(*sc);
397 0 : if (sclass == nullptr) {
398 0 : QString warning = "<b>Warning</b> class <i>" + QString::fromStdString(cls->get_name()) +
399 0 : "</i> refers to super class <i>" + QString::fromStdString(*sc) +
400 0 : "</i> which is not known<br>";
401 0 : QMessageBox::warning(0, "Check Schema", warning + advice, QMessageBox::Ok);
402 0 : show_file_info(qfilename);
403 0 : return false;
404 0 : }
405 0 : auto file = sclass->get_file()->get_full_file_name();
406 0 : if (file != filename && !includes.contains(file)) {
407 0 : QString warning = "<b>Warning</b> class <i>" + QString::fromStdString(cls->get_name()) +
408 0 : "</i> refers to super class <i>" + QString::fromStdString(*sc) + "</i> from " +
409 0 : QString::fromStdString(file) + " which is not included by" + qfilename;
410 0 : QMessageBox::warning(0, "Check Schema", warning + advice, QMessageBox::Ok);
411 0 : show_file_info(qfilename);
412 0 : return false;
413 0 : }
414 0 : }
415 : }
416 0 : }
417 0 : return true;
418 0 : }
419 :
420 : bool
421 0 : dbse::SchemaMainWindow::save_schema_file(QString filename)
422 : {
423 0 : if (!check_schema_file(filename)) {
424 : return false;
425 : }
426 0 : bool status;
427 0 : QString message;
428 0 : try {
429 0 : KernelWrapper::GetInstance().SaveSchema(filename.toStdString());
430 0 : message = QString("File %1 saved").arg(filename);
431 0 : status = true;
432 0 : } catch (const oks::exception& exc) {
433 0 : message = QString("Failed to save file %1").arg(filename);
434 0 : status = false;
435 0 : }
436 0 : ui->StatusBar->showMessage(message);
437 0 : return status;
438 0 : }
439 :
440 : void
441 0 : dbse::SchemaMainWindow::SaveSchemaFile()
442 : {
443 0 : QModelIndex index = ui->FileView->currentIndex();
444 0 : const auto file = FileModel->getRowFromIndex(index).at(0);
445 0 : save_schema_file(file);
446 0 : BuildFileModel();
447 0 : }
448 :
449 : void
450 0 : dbse::SchemaMainWindow::PrintCurrentView()
451 : {
452 0 : SchemaTab* CurrentTab = dynamic_cast<SchemaTab*>(ui->TabWidget->currentWidget());
453 :
454 0 : if (m_printer == nullptr) {
455 0 : m_printer = new QPrinter;
456 : }
457 :
458 0 : if (QPrintDialog(m_printer).exec() == QDialog::Accepted) {
459 0 : QPainter painter(m_printer);
460 0 : painter.setRenderHint(QPainter::Antialiasing);
461 :
462 0 : SchemaGraphicsScene* Scene = CurrentTab->GetScene();
463 0 : QGraphicsView* View = CurrentTab->GetView();
464 0 : Scene->render(&painter, QRectF(), View->viewport()->rect());
465 0 : }
466 0 : }
467 : void
468 0 : dbse::SchemaMainWindow::export_current_view()
469 : {
470 0 : auto tab = dynamic_cast<SchemaTab*>(ui->TabWidget->currentWidget());
471 :
472 0 : auto file =
473 0 : QFileDialog::getSaveFileName(this, tr("Export to SVG"), m_export_path, tr("SVG files (*.svg);;All files (*)"));
474 0 : if (file.isEmpty()) {
475 0 : return;
476 : }
477 :
478 0 : auto spos = file.lastIndexOf('/');
479 0 : if (spos != -1) {
480 0 : m_export_path = file;
481 0 : m_export_path.truncate(spos);
482 : }
483 :
484 0 : if (!file.endsWith(".svg")) {
485 0 : file.append(".svg");
486 : }
487 0 : QSvgGenerator generator;
488 0 : generator.setFileName(file);
489 0 : auto view = tab->GetView();
490 0 : auto vpr = view->viewport()->rect();
491 0 : generator.setSize(QSize(vpr.width(), vpr.height()));
492 0 : generator.setViewBox(vpr);
493 :
494 0 : QPainter painter;
495 0 : painter.begin(&generator);
496 0 : auto scene = tab->GetScene();
497 0 : scene->render(&painter, QRectF(), view->viewport()->rect());
498 0 : painter.end();
499 0 : }
500 :
501 : void
502 0 : dbse::SchemaMainWindow::closeEvent(QCloseEvent* event)
503 : {
504 0 : int UserChoice = ShouldSaveChanges();
505 :
506 0 : if (UserChoice == QMessageBox::Save) {
507 0 : if (!SaveModifiedSchema()) {
508 0 : event->ignore();
509 0 : return;
510 : }
511 0 : } else if (UserChoice == QMessageBox::Cancel) {
512 0 : event->ignore();
513 0 : return;
514 : }
515 :
516 0 : UserChoice = ShouldSaveViewChanges();
517 0 : if (UserChoice == QMessageBox::Cancel) {
518 0 : event->ignore();
519 0 : return;
520 : }
521 :
522 0 : KernelWrapper::GetInstance().CloseAllSchema();
523 :
524 0 : if (m_save_layout_on_exit) {
525 0 : save_layout();
526 : }
527 :
528 0 : for (QWidget* Widget : QApplication::allWidgets()) {
529 0 : Widget->close();
530 0 : }
531 :
532 0 : event->accept();
533 : }
534 :
535 : void
536 0 : dbse::SchemaMainWindow::update_models()
537 : {
538 0 : BuildFileModel();
539 0 : BuildTableModel();
540 0 : }
541 :
542 : void
543 0 : dbse::SchemaMainWindow::OpenSchemaFile(QString SchemaFile)
544 : {
545 0 : OksFile* file{ nullptr };
546 0 : if (!SchemaFile.isEmpty()) {
547 0 : try {
548 0 : file = KernelWrapper::GetInstance().LoadSchema(SchemaFile.toStdString());
549 :
550 0 : if (m_schema_directory == QString(".")) {
551 0 : std::vector<std::string> fnames;
552 0 : KernelWrapper::GetInstance().GetSchemaFiles(fnames);
553 0 : std::string dir = fnames[0].substr(0, fnames[0].find_last_of('/'));
554 0 : m_schema_directory.setPath(QString::fromStdString(dir));
555 0 : }
556 :
557 : #ifdef QT_DEBUG
558 : /// KernelWrapper::GetInstance().ShowSchemaClasses();
559 : #endif
560 0 : } catch (oks::exception& Ex) {
561 0 : QMessageBox::warning(
562 0 : 0, "Load Schema", QString("Could not load schema!\n\n").append(QString(Ex.what())), QMessageBox::Ok);
563 0 : }
564 :
565 0 : if (KernelWrapper::GetInstance().GetActiveSchema().empty()) {
566 0 : try {
567 0 : KernelWrapper::GetInstance().SetActiveSchema(SchemaFile.toStdString());
568 0 : } catch (oks::CanNotSetActiveFile& exc) {
569 0 : QMessageBox::warning(
570 0 : 0, "Load Schema", QString("Could not make schema active!\n\n").append(QString(exc.what())), QMessageBox::Ok);
571 0 : }
572 : }
573 :
574 0 : BuildTableModel();
575 0 : BuildFileModel();
576 :
577 0 : update_window_title(QFileInfo(SchemaFile).fileName());
578 : // ui->CreateNewSchema->setDisabled (true );
579 : // ui->OpenFileSchema->setDisabled (true );
580 0 : if (file != nullptr) {
581 0 : check_schema_file(QString::fromStdString(file->get_full_file_name()));
582 : }
583 : }
584 0 : }
585 :
586 : void
587 0 : dbse::SchemaMainWindow::update_window_title(QString text)
588 : {
589 0 : m_title.remove(QRegularExpression(": --.*"));
590 0 : m_title.append(QString(": -- ") + text);
591 0 : setWindowTitle(m_title);
592 0 : }
593 :
594 : void
595 0 : dbse::SchemaMainWindow::OpenSchemaFile()
596 : {
597 0 : QFileDialog FileDialog(this, tr("Open Schema File"), ".", tr("XML schema files (*.schema.xml);;All files (*)"));
598 0 : FileDialog.setAcceptMode(QFileDialog::AcceptOpen);
599 0 : FileDialog.setFileMode(QFileDialog::AnyFile);
600 0 : FileDialog.setViewMode(QFileDialog::Detail);
601 0 : FileDialog.setDirectory(m_schema_directory);
602 0 : FileDialog.setSidebarUrls(m_path_urls);
603 0 : QStringList FilesSelected;
604 0 : QString SchemaPath;
605 :
606 0 : if (FileDialog.exec()) {
607 0 : FilesSelected = FileDialog.selectedFiles();
608 : }
609 :
610 0 : if (FilesSelected.size()) {
611 0 : m_schema_directory = FileDialog.directory();
612 0 : SchemaPath = FilesSelected.value(0);
613 : }
614 :
615 0 : OpenSchemaFile(SchemaPath);
616 0 : }
617 :
618 : bool
619 0 : dbse::SchemaMainWindow::SaveModifiedSchema()
620 : {
621 0 : bool result = true;
622 0 : for (auto file : KernelWrapper::GetInstance().get_modified_schema_files()) {
623 0 : if (!save_schema_file(QString::fromStdString(file))) {
624 0 : result = false;
625 : }
626 0 : }
627 0 : BuildFileModel();
628 0 : return result;
629 : }
630 :
631 : void
632 0 : dbse::SchemaMainWindow::SaveSchema()
633 : {
634 0 : auto modified = KernelWrapper::GetInstance().ModifiedSchemaFiles();
635 0 : if (modified.empty()) {
636 0 : QMessageBox::information(0, "Schema editor", QString("No modified schema files need saving"));
637 :
638 : } else {
639 0 : SaveModifiedSchema();
640 : }
641 0 : BuildFileModel();
642 0 : }
643 :
644 : void
645 0 : dbse::SchemaMainWindow::CreateNewSchema()
646 : {
647 0 : QFileDialog FileDialog(this, tr("Create New schema File"), ".", tr("XML schema files (*.schema.xml);;All files (*)"));
648 0 : FileDialog.setAcceptMode(QFileDialog::AcceptSave);
649 0 : FileDialog.setFileMode(QFileDialog::AnyFile);
650 0 : FileDialog.setViewMode(QFileDialog::Detail);
651 0 : FileDialog.setDirectory(m_schema_directory);
652 0 : FileDialog.setSidebarUrls(m_path_urls);
653 0 : FileDialog.setLabelText(QFileDialog::Accept, "Create");
654 0 : if (!FileDialog.exec()) {
655 : return;
656 : }
657 :
658 0 : QStringList FilesSelected = FileDialog.selectedFiles();
659 0 : if (FilesSelected.isEmpty()) {
660 0 : QMessageBox::warning(0, "Schema editor", QString("Please provide a name for the schema !"));
661 0 : return;
662 : }
663 :
664 0 : QString FileName = FilesSelected.at(0);
665 0 : if (!FileName.endsWith(".schema.xml")) {
666 0 : FileName.append(".schema.xml");
667 : }
668 :
669 0 : QFile FileInfo(FileName);
670 0 : std::string FileNameStd = FileInfo.fileName().toStdString();
671 :
672 0 : try {
673 0 : KernelWrapper::GetInstance().CreateNewSchema(FileNameStd);
674 0 : KernelWrapper::GetInstance().SaveSchema(FileNameStd);
675 0 : BuildTableModel();
676 0 : BuildFileModel();
677 0 : ui->CreateNewSchema->setDisabled(true);
678 0 : ui->OpenFileSchema->setDisabled(true);
679 0 : } catch (oks::exception& Ex) {
680 0 : QMessageBox::warning(
681 : 0,
682 : "Schema editor",
683 0 : QString("Could not create file : %1.\n\n%2").arg(QString::fromStdString(FileNameStd)).arg(QString(Ex.what())));
684 0 : }
685 0 : }
686 :
687 : void
688 0 : dbse::SchemaMainWindow::ChangeCursorRelationship(bool State)
689 : {
690 0 : if (ui->SetInheritance->isChecked()) {
691 0 : ui->SetInheritance->setChecked(false);
692 : }
693 :
694 0 : if (State) {
695 0 : ui->TabWidget->setCursor(Qt::CrossCursor);
696 : } else {
697 0 : ui->TabWidget->setCursor(Qt::ArrowCursor);
698 : }
699 :
700 0 : KernelWrapper::GetInstance().SetInheritanceMode(false);
701 0 : }
702 :
703 : void
704 0 : dbse::SchemaMainWindow::ChangeCursorInheritance(bool State)
705 : {
706 0 : if (ui->SetRelationship->isChecked()) {
707 0 : ui->SetRelationship->setChecked(false);
708 : }
709 :
710 0 : if (State) {
711 0 : ui->TabWidget->setCursor(Qt::CrossCursor);
712 : } else {
713 0 : ui->TabWidget->setCursor(Qt::ArrowCursor);
714 : }
715 :
716 0 : KernelWrapper::GetInstance().SetInheritanceMode(true);
717 0 : }
718 :
719 : void
720 0 : dbse::SchemaMainWindow::add_tab()
721 : {
722 0 : auto index = ui->TabWidget->addTab(new SchemaTab(), "unnamed Schema View");
723 0 : ui->TabWidget->setCurrentIndex(index);
724 0 : auto tab = dynamic_cast<SchemaTab*>(ui->TabWidget->currentWidget());
725 0 : connect(tab->GetScene(), &SchemaGraphicsScene::sceneModified, this, &dbse::SchemaMainWindow::modifiedView);
726 0 : connect(tab->GetScene(), &SchemaGraphicsScene::saveRequested, this, &dbse::SchemaMainWindow::SaveView);
727 0 : }
728 :
729 : void
730 0 : dbse::SchemaMainWindow::modifiedView(bool modified)
731 : {
732 0 : auto index = ui->TabWidget->currentIndex();
733 0 : auto label = ui->TabWidget->tabText(index);
734 0 : if (modified && !label.endsWith("*")) {
735 0 : label += "*";
736 : }
737 0 : if (!modified && label.endsWith("*")) {
738 0 : label = label.remove('*');
739 : }
740 0 : ui->TabWidget->setTabText(index, label);
741 0 : }
742 :
743 : void
744 0 : dbse::SchemaMainWindow::NameView()
745 : {
746 0 : auto index = ui->TabWidget->currentIndex();
747 0 : bool ok;
748 0 : QString text = QInputDialog::getText(
749 0 : nullptr, "Schema editor: rename class view", "New view name:", QLineEdit::Normal, "New Class View", &ok);
750 0 : if (ok && !text.isEmpty()) {
751 0 : ui->TabWidget->setTabText(index, text);
752 0 : SchemaTab* CurrentTab = dynamic_cast<SchemaTab*>(ui->TabWidget->currentWidget());
753 0 : CurrentTab->setName(text);
754 : }
755 :
756 0 : auto newtext = ui->TabWidget->tabText(index);
757 0 : }
758 :
759 : void
760 0 : dbse::SchemaMainWindow::SaveView()
761 : {
762 0 : SchemaTab* tab = dynamic_cast<SchemaTab*>(ui->TabWidget->currentWidget());
763 0 : if (tab->GetScene()->items().size() != 0) {
764 0 : auto file_name = tab->getFileName();
765 0 : if (file_name == "./") {
766 0 : SaveViewAs();
767 0 : return;
768 : }
769 0 : write_view_file(file_name, tab);
770 0 : }
771 : }
772 : void
773 0 : dbse::SchemaMainWindow::SaveViewAs()
774 : {
775 0 : SchemaTab* CurrentTab = dynamic_cast<SchemaTab*>(ui->TabWidget->currentWidget());
776 0 : if (CurrentTab->GetScene()->items().size() != 0) {
777 0 : auto defName = CurrentTab->getFileName();
778 0 : if (defName == "./") {
779 0 : defName = m_view_dir;
780 : }
781 0 : QString FileName =
782 0 : QFileDialog::getSaveFileName(this, tr("Save View"), defName, tr("View files (*.view);;All files (*)"));
783 :
784 0 : if (!FileName.isEmpty()) {
785 0 : auto spos = FileName.lastIndexOf('/');
786 0 : if (spos != -1) {
787 0 : m_view_dir = FileName;
788 0 : m_view_dir.truncate(spos);
789 : }
790 :
791 0 : if (!FileName.endsWith(".view")) {
792 0 : FileName.append(".view");
793 : }
794 :
795 0 : CurrentTab->setFileName(FileName);
796 0 : auto text = QFileInfo(FileName).baseName();
797 0 : CurrentTab->setName(text);
798 0 : auto index = ui->TabWidget->currentIndex();
799 0 : ui->TabWidget->setTabText(index, text);
800 :
801 0 : write_view_file(FileName, CurrentTab);
802 0 : }
803 0 : }
804 0 : }
805 :
806 : void
807 0 : dbse::SchemaMainWindow::write_view_file(const QString& file_name, SchemaTab* tab)
808 : {
809 0 : QFile file(file_name);
810 0 : file.open(QIODevice::WriteOnly);
811 :
812 0 : for (QGraphicsItem* item : tab->GetScene()->items()) {
813 0 : auto object = dynamic_cast<SchemaGraphicObject*>(item);
814 0 : if (object != nullptr) {
815 0 : QString description = object->GetClassName() + "," + QString::number(object->scenePos().x()) + "," +
816 0 : QString::number(object->scenePos().y()) + "\n";
817 0 : file.write(description.toUtf8());
818 0 : } else {
819 0 : auto note = dynamic_cast<SchemaGraphicNote*>(item);
820 0 : if (note != nullptr && !note->text().isEmpty()) {
821 0 : auto text = note->text().replace("\n", "<br>");
822 0 : text = text.replace(",", "<comma>");
823 0 : QString line = "#," + QString::number(note->scenePos().x()) + "," + QString::number(note->scenePos().y()) +
824 0 : "," + text + "\n";
825 0 : file.write(line.toUtf8());
826 0 : }
827 : }
828 0 : }
829 :
830 0 : file.close();
831 0 : auto message = QString("Saved view to %1").arg(file_name);
832 0 : ui->StatusBar->showMessage(message);
833 0 : tab->GetScene()->ClearModified();
834 0 : }
835 :
836 : void
837 0 : dbse::SchemaMainWindow::LoadView()
838 : {
839 0 : QString ViewPath =
840 0 : QFileDialog::getOpenFileName(this, tr("Open view file"), m_view_dir, tr("View files (*.view);;All files (*)"));
841 :
842 0 : if (!ViewPath.isEmpty()) {
843 0 : auto spos = ViewPath.lastIndexOf('/');
844 0 : if (spos != -1) {
845 0 : m_view_dir = ViewPath;
846 0 : m_view_dir.truncate(spos);
847 : }
848 0 : QFile ViewFile(ViewPath);
849 0 : ViewFile.open(QIODevice::ReadOnly);
850 :
851 0 : auto text = QFileInfo(ViewPath).baseName();
852 0 : auto tab = dynamic_cast<SchemaTab*>(ui->TabWidget->currentWidget());
853 0 : if (!tab->getName().isEmpty() || tab->GetScene()->IsModified()) {
854 0 : add_tab();
855 0 : tab = dynamic_cast<SchemaTab*>(ui->TabWidget->currentWidget());
856 : }
857 0 : auto index = ui->TabWidget->currentIndex();
858 0 : ui->TabWidget->setTabText(index, text);
859 0 : tab->setName(text);
860 0 : tab->setFileName(ViewPath);
861 :
862 0 : QStringList ClassesNames;
863 0 : QList<QPointF> Positions;
864 0 : QList<QPointF> note_positions;
865 0 : QStringList notes;
866 0 : while (!ViewFile.atEnd()) {
867 0 : QString Line(ViewFile.readLine());
868 0 : if (!Line.isEmpty()) {
869 0 : QStringList ObjectDescription = Line.split(",");
870 0 : QPointF Position;
871 0 : Position.setX(ObjectDescription.at(1).toInt());
872 0 : Position.setY(ObjectDescription.at(2).toInt());
873 0 : if (ObjectDescription.at(0) == "#") {
874 0 : note_positions.append(Position);
875 0 : auto note_text = ObjectDescription.at(3);
876 0 : if (note_text.back() == '\n') {
877 0 : note_text.chop(1);
878 : }
879 0 : note_text = note_text.replace("<br>", "\n");
880 0 : note_text = note_text.replace("<comma>", ",");
881 0 : notes.append(note_text);
882 0 : } else {
883 0 : ClassesNames.append(ObjectDescription.at(0));
884 0 : Positions.append(Position);
885 : }
886 0 : }
887 0 : }
888 0 : ViewFile.close();
889 :
890 0 : auto message = QString("Loaded view from %1").arg(ViewPath);
891 0 : ui->StatusBar->showMessage(message);
892 :
893 0 : auto scene = tab->GetScene();
894 0 : scene->CleanItemMap();
895 0 : auto missing = scene->AddItemsToScene(ClassesNames, Positions);
896 0 : if (!missing.empty()) {
897 0 : QString warning_text{ "The following classes in " };
898 0 : warning_text.append(QFileInfo(ViewPath).fileName());
899 0 : warning_text.append(" are not present in the loaded schema:\n ");
900 0 : warning_text.append(missing.join(",\n "));
901 0 : QMessageBox::warning(this, tr("Load View"), warning_text);
902 0 : }
903 0 : scene->ClearModified();
904 :
905 0 : scene->add_notes(notes, note_positions);
906 0 : }
907 0 : }
908 :
909 : void
910 0 : dbse::SchemaMainWindow::LaunchClassEditor(QModelIndex Index)
911 : {
912 0 : QModelIndex proxyIndex = m_proxyModel->mapToSource(Index);
913 0 : QStringList Row = TableModel->getRowFromIndex(proxyIndex);
914 :
915 0 : if (!Row.isEmpty()) {
916 0 : SchemaClassEditor::launch(Row.at(0));
917 : }
918 0 : }
919 :
920 : void
921 0 : dbse::SchemaMainWindow::close_tab()
922 : {
923 0 : RemoveTab(ui->TabWidget->currentIndex());
924 0 : }
925 :
926 : void
927 0 : dbse::SchemaMainWindow::RemoveTab(int index)
928 : {
929 0 : if (index == -1) {
930 : return;
931 : }
932 :
933 0 : auto tab = dynamic_cast<SchemaTab*>(ui->TabWidget->widget(index));
934 0 : if (tab->GetScene()->IsModified()) {
935 0 : auto choice = QMessageBox::question(0,
936 0 : tr("SchemaEditor"),
937 0 : QString("There are unsaved changes in the schema view:\n"
938 0 : "Do you really want to delete this schema view?\n"),
939 : QMessageBox::Discard | QMessageBox::Cancel,
940 : QMessageBox::Cancel);
941 0 : if (choice == QMessageBox::Cancel) {
942 : return;
943 : }
944 : }
945 0 : ui->TabWidget->removeTab(index);
946 0 : delete tab;
947 0 : if (ui->TabWidget->count() == 0) {
948 0 : add_tab();
949 : }
950 : }
951 :
952 : void
953 0 : dbse::SchemaMainWindow::CustomContextMenuFileView(QPoint Pos)
954 : {
955 0 : if (ContextMenuFileView == nullptr) {
956 0 : ContextMenuFileView = new QMenu(this);
957 :
958 0 : QAction* Act = new QAction(tr("Set as Active Schema"), this);
959 0 : connect(Act, SIGNAL(triggered()), this, SLOT(SetSchemaFileActive()));
960 0 : QAction* Sav = new QAction(tr("Save Schema File"), this);
961 0 : connect(Sav, SIGNAL(triggered()), this, SLOT(SaveSchemaFile()));
962 0 : QAction* info = new QAction(tr("Show file info"), this);
963 0 : connect(info, SIGNAL(triggered()), this, SLOT(show_file_info()));
964 :
965 0 : ContextMenuFileView->addAction(info);
966 0 : ContextMenuFileView->addAction(Act);
967 0 : ContextMenuFileView->addAction(Sav);
968 : }
969 :
970 0 : QModelIndex index = ui->FileView->currentIndex();
971 :
972 0 : if (index.isValid()) {
973 0 : QStringList row = FileModel->getRowFromIndex(index);
974 0 : if (row.at(1) == "RW") {
975 0 : ContextMenuFileView->actions().at(2)->setVisible(true);
976 0 : if (!row.at(2).contains("Active")) {
977 0 : ContextMenuFileView->actions().at(1)->setVisible(true);
978 : } else {
979 0 : ContextMenuFileView->actions().at(1)->setVisible(false);
980 : }
981 : } else {
982 0 : ContextMenuFileView->actions().at(2)->setVisible(false);
983 0 : ContextMenuFileView->actions().at(1)->setVisible(false);
984 : }
985 0 : ContextMenuFileView->exec(ui->FileView->mapToGlobal(Pos));
986 0 : }
987 0 : }
988 :
989 : void
990 0 : dbse::SchemaMainWindow::CustomContextMenuTableView(QPoint Pos)
991 : {
992 0 : if (ContextMenuTableView == nullptr) {
993 0 : ContextMenuTableView = new QMenu(this);
994 :
995 0 : QAction* add = new QAction(tr("&Add New Class"), this);
996 0 : connect(add, SIGNAL(triggered()), this, SLOT(AddNewClass()));
997 :
998 0 : QAction* remove = new QAction(tr("&Remove Selected Class"), this);
999 0 : connect(remove, SIGNAL(triggered()), this, SLOT(RemoveClass()));
1000 :
1001 0 : QAction* edit = new QAction(tr("&Edit Selected Class"), this);
1002 0 : connect(edit, SIGNAL(triggered()), this, SLOT(editClass()));
1003 :
1004 0 : ContextMenuTableView->addAction(add);
1005 0 : ContextMenuTableView->addAction(edit);
1006 0 : ContextMenuTableView->addAction(remove);
1007 : }
1008 :
1009 0 : QModelIndex Index = ui->ClassTableView->currentIndex();
1010 :
1011 0 : if (Index.isValid()) {
1012 0 : ContextMenuTableView->exec(ui->ClassTableView->mapToGlobal(Pos));
1013 : }
1014 0 : }
1015 :
1016 : void
1017 0 : dbse::SchemaMainWindow::toggle_case_sensitive(int /*state*/)
1018 : {
1019 0 : if (ui->case_sensitive->isChecked()) {
1020 0 : m_proxyModel->setFilterCaseSensitivity(Qt::CaseSensitive);
1021 : } else {
1022 0 : m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
1023 : }
1024 0 : }
1025 : void
1026 0 : dbse::SchemaMainWindow::update_view()
1027 : {
1028 0 : auto tab = dynamic_cast<SchemaTab*>(ui->TabWidget->currentWidget());
1029 0 : tab->GetScene()->update();
1030 :
1031 0 : BuildTableModel();
1032 0 : BuildFileModel();
1033 0 : }
1034 :
1035 : void
1036 0 : dbse::SchemaMainWindow::edit_settings()
1037 : {
1038 0 : if (m_settings == nullptr) {
1039 0 : m_settings = new SchemaSettings(this);
1040 0 : connect(m_settings, SIGNAL(settings_updated()), this, SLOT(update_view()));
1041 : }
1042 0 : m_settings->show();
1043 0 : }
1044 :
1045 : void
1046 0 : dbse::SchemaMainWindow::save_layout()
1047 : {
1048 0 : QSettings settings;
1049 0 : settings.beginGroup("MainWindow-layout");
1050 0 : settings.setValue("size", size());
1051 0 : settings.setValue("pos", pos());
1052 0 : settings.setValue("geometry", saveGeometry());
1053 0 : settings.setValue("state", saveState());
1054 0 : settings.setValue("diagrams-visible", ui->TabWidget->isVisible());
1055 0 : settings.setValue("statusbar-visible", ui->StatusBar->isVisible());
1056 0 : settings.endGroup();
1057 0 : }
1058 :
1059 : void
1060 0 : dbse::SchemaMainWindow::restore_layout()
1061 : {
1062 0 : QSettings settings;
1063 0 : settings.beginGroup("MainWindow-layout");
1064 0 : if (settings.contains("size")) {
1065 0 : resize(settings.value("size").toSize());
1066 : }
1067 0 : if (settings.contains("pos")) {
1068 0 : move(settings.value("pos").toPoint());
1069 : }
1070 0 : if (settings.contains("geometry")) {
1071 0 : restoreGeometry(settings.value("geometry").toByteArray());
1072 : }
1073 0 : if (settings.contains("state")) {
1074 0 : restoreState(settings.value("state").toByteArray());
1075 : }
1076 :
1077 0 : auto visible = settings.value("diagrams-visible", true).toBool();
1078 0 : ui->displayDiagrams->setChecked(visible);
1079 0 : ui->TabWidget->setVisible(visible);
1080 :
1081 0 : visible = settings.value("statusbar-visible", true).toBool();
1082 0 : ui->StatusBar->setVisible(visible);
1083 0 : ui->displayStatus_bar->setChecked(visible);
1084 :
1085 0 : ui->displayToolbar->setChecked(ui->MainToolBar->isVisible());
1086 0 : settings.endGroup();
1087 :
1088 0 : settings.beginGroup("MainWindow");
1089 0 : m_save_layout_on_exit = settings.value("saveLayout", false).toBool();
1090 0 : settings.endGroup();
1091 0 : }
1092 :
1093 : void
1094 0 : dbse::SchemaMainWindow::default_layout()
1095 : {
1096 0 : restoreGeometry(m_default_geometry);
1097 0 : restoreState(m_default_state);
1098 0 : resize(m_default_size);
1099 :
1100 0 : ui->displayDiagrams->setChecked(true);
1101 0 : ui->TabWidget->setVisible(true);
1102 0 : ui->StatusBar->setVisible(true);
1103 0 : ui->displayStatus_bar->setChecked(true);
1104 0 : }
|