MainWindow.cpp
204 lines
| 6.6 KiB
| text/x-c
|
CppLexer
r21 | /*------------------------------------------------------------------------------ | |||
r54 | -- This file is a part of the SciQLop Software | |||
-- Copyright (C) 2017, Plasma Physics Laboratory - CNRS | ||||
r21 | -- | |||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 2 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@member.fsf.org | ||||
----------------------------------------------------------------------------*/ | ||||
r54 | #include "MainWindow.h" | |||
#include "ui_MainWindow.h" | ||||
Alexandre Leroux
|
r84 | |||
r1239 | #include <Catalogue/CatalogueController.h> | |||
r1460 | #include <Catalogue2/browser.h> | |||
r1478 | #include <DataSource/DataSourceItem.h> | |||
Alexandre Leroux
|
r84 | #include <DataSource/DataSourceWidget.h> | ||
Alexandre Leroux
|
r463 | #include <Settings/SqpSettingsDialog.h> | ||
Alexandre Leroux
|
r465 | #include <Settings/SqpSettingsGeneralWidget.h> | ||
r101 | #include <SidePane/SqpSidePane.h> | |||
Alexandre Leroux
|
r84 | #include <SqpApplication.h> | ||
r192 | #include <Time/TimeController.h> | |||
r133 | #include <TimeWidget/TimeWidget.h> | |||
Alexandre Leroux
|
r84 | |||
r1462 | #include "toolbar.h" | |||
r21 | #include <QAction> | |||
r1239 | #include <QCloseEvent> | |||
r21 | #include <QDate> | |||
#include <QDir> | ||||
#include <QFileDialog> | ||||
r1239 | #include <QMessageBox> | |||
r101 | #include <QToolBar> | |||
r138 | #include <QToolButton> | |||
r101 | #include <memory.h> | |||
Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") | ||||
r1406 | class MainWindow::MainWindowPrivate | |||
{ | ||||
r101 | public: | |||
r1406 | explicit MainWindowPrivate(MainWindow* mainWindow) | |||
r1478 | : m_GeneralSettingsWidget { new SqpSettingsGeneralWidget { mainWindow } } | |||
r1406 | , m_SettingsDialog { new SqpSettingsDialog { mainWindow } } | |||
r1460 | , m_CatalogExplorer { new CataloguesBrowser { mainWindow } } | |||
Alexandre Leroux
|
r463 | { | ||
} | ||||
Alexandre Leroux
|
r465 | /// General settings widget. MainWindow has the ownership | ||
r1406 | SqpSettingsGeneralWidget* m_GeneralSettingsWidget; | |||
Alexandre Leroux
|
r463 | /// Settings dialog. MainWindow has the ownership | ||
r1406 | SqpSettingsDialog* m_SettingsDialog; | |||
r1094 | /// Catalogue dialog. MainWindow has the ownership | |||
r1460 | CataloguesBrowser* m_CatalogExplorer; | |||
r1239 | ||||
r1406 | bool checkDataToSave(QWidget* parentWidget); | |||
r101 | }; | |||
r1406 | MainWindow::MainWindow(QWidget* parent) | |||
: QMainWindow { parent } | ||||
, m_Ui { new Ui::MainWindow } | ||||
, impl { spimpl::make_unique_impl<MainWindowPrivate>(this) } | ||||
r21 | { | |||
r54 | m_Ui->setupUi(this); | |||
r1458 | setWindowTitle(QString("SciQLop v%1").arg(SCIQLOP_VERSION)); | |||
r56 | ||||
r957 | // //////////////// // | |||
// Menu and Toolbar // | ||||
// //////////////// // | ||||
r102 | this->menuBar()->addAction(tr("File")); | |||
Alexandre Leroux
|
r463 | auto toolsMenu = this->menuBar()->addMenu(tr("Tools")); | ||
toolsMenu->addAction(tr("Settings..."), [this]() { | ||||
Alexandre Leroux
|
r469 | // Loads settings | ||
impl->m_SettingsDialog->loadSettings(); | ||||
// Open settings dialog and save settings if the dialog is accepted | ||||
r1406 | if (impl->m_SettingsDialog->exec() == QDialog::Accepted) | |||
{ | ||||
Alexandre Leroux
|
r469 | impl->m_SettingsDialog->saveSettings(); | ||
} | ||||
Alexandre Leroux
|
r463 | }); | ||
r1462 | auto mainToolBar = new ToolBar(this); | |||
r1499 | mainToolBar->setWindowTitle("Tool bar"); | |||
r1462 | this->addToolBar(mainToolBar); | |||
connect(mainToolBar, &ToolBar::setPlotsInteractionMode, sqpApp, | ||||
&SqpApplication::setPlotsInteractionMode); | ||||
connect(mainToolBar, &ToolBar::setPlotsCursorMode, sqpApp, &SqpApplication::setPlotsCursorMode); | ||||
connect(mainToolBar, &ToolBar::showCataloguesBrowser, | ||||
r1460 | [this]() { impl->m_CatalogExplorer->show(); }); | |||
r1094 | ||||
Alexandre Leroux
|
r465 | // //////// // | ||
// Settings // | ||||
// //////// // | ||||
// Registers "general settings" widget to the settings dialog | ||||
r1406 | impl->m_SettingsDialog->registerWidget( | |||
QStringLiteral("General"), impl->m_GeneralSettingsWidget); | ||||
Alexandre Leroux
|
r465 | |||
Alexandre Leroux
|
r463 | // /////////// // | ||
// Connections // | ||||
// /////////// // | ||||
Alexandre Leroux
|
r84 | // Widgets / controllers connections | ||
r192 | ||||
// Time | ||||
r1462 | // connect(timeWidget, SIGNAL(timeUpdated(DateTimeRange)), &sqpApp->timeController(), | |||
// SLOT(onTimeToUpdate(DateTimeRange))); | ||||
connect(mainToolBar, &ToolBar::timeUpdated, &sqpApp->timeController(), | ||||
&TimeController::setDateTimeRange); | ||||
r192 | ||||
Alexandre Leroux
|
r249 | // Widgets / widgets connections | ||
// For the following connections, we use DirectConnection to allow each widget that can | ||||
// potentially attach a menu to the variable's menu to do so before this menu is displayed. | ||||
// The order of connections is also important, since it determines the order in which each | ||||
// widget will attach its menu | ||||
r1406 | connect(m_Ui->variableInspectorWidget, | |||
SIGNAL(tableMenuAboutToBeDisplayed(QMenu*, const QVector<std::shared_ptr<Variable>>&)), | ||||
m_Ui->view, SLOT(attachVariableMenu(QMenu*, const QVector<std::shared_ptr<Variable>>&)), | ||||
Alexandre Leroux
|
r288 | Qt::DirectConnection); | ||
r21 | } | |||
r1406 | MainWindow::~MainWindow() {} | |||
r21 | ||||
r1406 | void MainWindow::changeEvent(QEvent* e) | |||
r21 | { | |||
QMainWindow::changeEvent(e); | ||||
r1406 | switch (e->type()) | |||
{ | ||||
r21 | case QEvent::LanguageChange: | |||
r54 | m_Ui->retranslateUi(this); | |||
r21 | break; | |||
default: | ||||
break; | ||||
} | ||||
} | ||||
r1239 | ||||
r1406 | void MainWindow::closeEvent(QCloseEvent* event) | |||
r1239 | { | |||
r1406 | if (!impl->checkDataToSave(this)) | |||
{ | ||||
r1239 | event->ignore(); | |||
} | ||||
r1406 | else | |||
{ | ||||
r1239 | event->accept(); | |||
} | ||||
} | ||||
r1406 | void MainWindow::keyPressEvent(QKeyEvent* event) | |||
r1376 | { | |||
switch (event->key()) | ||||
{ | ||||
r1406 | case Qt::Key_F11: | |||
if (this->isFullScreen()) | ||||
{ | ||||
this->showNormal(); | ||||
} | ||||
else | ||||
{ | ||||
this->showFullScreen(); | ||||
} | ||||
break; | ||||
default: | ||||
break; | ||||
r1376 | } | |||
} | ||||
r1406 | bool MainWindow::MainWindowPrivate::checkDataToSave(QWidget* parentWidget) | |||
r1239 | { | |||
r1406 | // auto hasChanges = sqpApp->catalogueController().hasChanges(); | |||
// if (hasChanges) | ||||
// { | ||||
// // There are some unsaved changes | ||||
// switch (QMessageBox::question(parentWidget, tr("Save changes"), | ||||
// tr("The catalogue controller has unsaved changes.\nDo you want to save them ?"), | ||||
// QMessageBox::SaveAll | QMessageBox::Discard | QMessageBox::Cancel, | ||||
// QMessageBox::SaveAll)) | ||||
// { | ||||
// case QMessageBox::SaveAll: | ||||
// sqpApp->catalogueController().saveAll(); | ||||
// break; | ||||
// case QMessageBox::Discard: | ||||
// break; | ||||
// case QMessageBox::Cancel: | ||||
// default: | ||||
// return false; | ||||
// } | ||||
// } | ||||
r1239 | ||||
return true; | ||||
} | ||||