Skip to content
Snippets Groups Projects
Commit 6b388da7 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Refactoring in MainWindow

parent 7ae937ac
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
ApplicationModels::ApplicationModels(QObject *parent) ApplicationModels::ApplicationModels(QObject *parent)
: QObject(parent) : QObject(parent)
, m_materialModel(0) , m_materialModel(0)
, m_materialEditor(0) , m_materialSvc(0)
, m_instrumentModel(0) , m_instrumentModel(0)
, m_sampleModel(0) , m_sampleModel(0)
, m_jobModel(0) , m_jobModel(0)
...@@ -35,12 +35,36 @@ ApplicationModels::ApplicationModels(QObject *parent) ...@@ -35,12 +35,36 @@ ApplicationModels::ApplicationModels(QObject *parent)
{ {
createModels(); createModels();
testGUIObjectBuilder(); testGUIObjectBuilder();
} }
ApplicationModels::~ApplicationModels() ApplicationModels::~ApplicationModels()
{ {
delete m_materialEditor; delete m_materialSvc;
}
MaterialModel *ApplicationModels::materialModel()
{
return m_materialModel;
}
InstrumentModel *ApplicationModels::instrumentModel()
{
return m_instrumentModel;
}
SampleModel *ApplicationModels::sampleModel()
{
return m_sampleModel;
}
JobModel *ApplicationModels::jobModel()
{
return m_jobModel;
}
FitModel *ApplicationModels::fitModel()
{
return m_fitModel;
} }
//! creates and initializes models //! creates and initializes models
...@@ -94,11 +118,7 @@ void ApplicationModels::createMaterialModel() ...@@ -94,11 +118,7 @@ void ApplicationModels::createMaterialModel()
{ {
delete m_materialModel; delete m_materialModel;
m_materialModel = new MaterialModel(this); m_materialModel = new MaterialModel(this);
// m_materialModel->addMaterial("Default", 1e-3, 1e-5); m_materialSvc = new MaterialSvc(m_materialModel);
// m_materialModel->addMaterial("Air", 0.0, 0.0);
// m_materialModel->addMaterial("Particle", 6e-4, 2e-8);
// m_materialModel->addMaterial("Substrate", 6e-6, 2e-8);
m_materialEditor = new MaterialSvc(m_materialModel);
} }
void ApplicationModels::createSampleModel() void ApplicationModels::createSampleModel()
......
...@@ -34,11 +34,11 @@ public: ...@@ -34,11 +34,11 @@ public:
ApplicationModels(QObject *parent); ApplicationModels(QObject *parent);
~ApplicationModels(); ~ApplicationModels();
MaterialModel *materialModel() { return m_materialModel; } MaterialModel *materialModel();
InstrumentModel *instrumentModel() { return m_instrumentModel; } InstrumentModel *instrumentModel();
SampleModel *sampleModel() { return m_sampleModel; } SampleModel *sampleModel();
JobModel *jobModel() { return m_jobModel; } JobModel *jobModel();
FitModel *fitModel() { return m_fitModel; } FitModel *fitModel();
void resetModels(); void resetModels();
...@@ -52,13 +52,11 @@ private: ...@@ -52,13 +52,11 @@ private:
void testGUIObjectBuilder(); void testGUIObjectBuilder();
MaterialModel *m_materialModel; MaterialModel *m_materialModel;
MaterialSvc *m_materialEditor; MaterialSvc *m_materialSvc;
InstrumentModel *m_instrumentModel; InstrumentModel *m_instrumentModel;
SampleModel *m_sampleModel; SampleModel *m_sampleModel;
JobModel *m_jobModel; JobModel *m_jobModel;
FitModel *m_fitModel; FitModel *m_fitModel;
}; };
#endif #endif
...@@ -38,20 +38,6 @@ ...@@ -38,20 +38,6 @@
#include "ModelMapper.h" #include "ModelMapper.h"
#include "DetectorItems.h" #include "DetectorItems.h"
// FIXME_DAVID Rename Ivona's FitView into ObsoleteFitView. And use nice name FitView for own purpose.
// -- suggestion: for consistency use prefix Obsolete for all classes you are goind to throw soon
// -- you may want to add to all Ivona's classes prefix Obsolete. Don't forget about 'ifndef' header guards
// FIXME_DAVID Move your activity from TestView to FitView.
// - FitView should contain QTabWidget with 3 tabs:
// - 1) ImportDataWidget (empty for the moment) 2) FitSettingsWidget 3) RunFitWidget
// FIXME_DAVID FitSettingsWidget should contain
// - FitParametersWidget (for the moment), and later sample/instrument selector + MinimizerSettingsWidgert
TestView::TestView(MainWindow *mainWindow) TestView::TestView(MainWindow *mainWindow)
: QWidget(mainWindow) : QWidget(mainWindow)
, m_mainWindow(mainWindow) , m_mainWindow(mainWindow)
......
...@@ -50,6 +50,9 @@ ...@@ -50,6 +50,9 @@
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: Manhattan::FancyMainWindow(parent) : Manhattan::FancyMainWindow(parent)
, m_applicationModels(new ApplicationModels(this))
, m_projectManager(new ProjectManager(this))
, m_actionManager(new ActionManager(this))
, m_tabWidget(0) , m_tabWidget(0)
, m_welcomeView(0) , m_welcomeView(0)
, m_instrumentView(0) , m_instrumentView(0)
...@@ -58,9 +61,6 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -58,9 +61,6 @@ MainWindow::MainWindow(QWidget *parent)
, m_jobView(0) , m_jobView(0)
, m_fitView(0) , m_fitView(0)
, m_progressBar(0) , m_progressBar(0)
, m_actionManager(0)
, m_projectManager(0)
, m_applicationModels(new ApplicationModels(this))
, m_toolTipDataBase(new ToolTipDataBase(this)) , m_toolTipDataBase(new ToolTipDataBase(this))
, m_updateNotifier(new UpdateNotifier(this)) , m_updateNotifier(new UpdateNotifier(this))
{ {
...@@ -76,12 +76,11 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -76,12 +76,11 @@ MainWindow::MainWindow(QWidget *parent)
Manhattan::Utils::StyleHelper::setBaseColor(QColor(Constants::MAIN_THEME_COLOR)); Manhattan::Utils::StyleHelper::setBaseColor(QColor(Constants::MAIN_THEME_COLOR));
setDockNestingEnabled(true); setDockNestingEnabled(true);
setAcceptDrops(true);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea); setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
m_projectManager = new ProjectManager(this);
m_actionManager = new ActionManager(this);
readSettings(); readSettings();
m_tabWidget = new Manhattan::FancyTabWidget(this); m_tabWidget = new Manhattan::FancyTabWidget(this);
...@@ -113,8 +112,6 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -113,8 +112,6 @@ MainWindow::MainWindow(QWidget *parent)
setCentralWidget(m_tabWidget); setCentralWidget(m_tabWidget);
setAcceptDrops(true);
// signals/slots // signals/slots
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(onChangeTabWidget(int))); connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(onChangeTabWidget(int)));
connect(m_jobView, SIGNAL(focusRequest(int)), this, SLOT(onFocusRequest(int))); connect(m_jobView, SIGNAL(focusRequest(int)), this, SLOT(onFocusRequest(int)));
...@@ -149,6 +146,40 @@ FitModel *MainWindow::getFitModel() ...@@ -149,6 +146,40 @@ FitModel *MainWindow::getFitModel()
return models()->fitModel(); return models()->fitModel();
} }
ApplicationModels *MainWindow::models()
{
return m_applicationModels;
}
//! updates views which depend on others
void MainWindow::onChangeTabWidget(int index)
{
if(index == WELCOME)
{
m_welcomeView->updateRecentProjectPanel();
}
else if (index == INSTRUMENT) {
m_instrumentView->updateView();
}
else if(index == SIMULATION) {
m_simulationView->updateSimulationViewElements();
}
}
void MainWindow::onFocusRequest(int index)
{
m_tabWidget->setCurrentIndex(index);
}
void MainWindow::openRecentProject()
{
if (const QAction *action = qobject_cast<const QAction*>(sender())) {
QString file = action->data().value<QString>();
qDebug() << "MainWindow::openRecentProject() -> " << file;
m_projectManager->openProject(file);
}
}
void MainWindow::readSettings() void MainWindow::readSettings()
{ {
QSettings settings; QSettings settings;
...@@ -180,35 +211,10 @@ void MainWindow::onRunSimulationShortcut() ...@@ -180,35 +211,10 @@ void MainWindow::onRunSimulationShortcut()
m_simulationView->onRunSimulationShortcut(); m_simulationView->onRunSimulationShortcut();
} }
void MainWindow::openRecentProject() void MainWindow::onAboutApplication()
{
if (const QAction *action = qobject_cast<const QAction*>(sender())) {
QString file = action->data().value<QString>();
qDebug() << "MainWindow::openRecentProject() -> " << file;
m_projectManager->openProject(file);
}
}
void MainWindow::onChangeTabWidget(int index)
{
// update views which depend on others
(void)index;
if(index == WELCOME)
{
m_welcomeView->updateRecentProjectPanel();
}
else if (index == INSTRUMENT) {
m_instrumentView->updateView();
}
else if(index == SIMULATION) {
m_simulationView->updateSimulationViewElements();
}
}
void MainWindow::onFocusRequest(int index)
{ {
m_tabWidget->setCurrentIndex(index); AboutApplicationDialog dialog(this);
dialog.exec();
} }
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
...@@ -232,17 +238,6 @@ void MainWindow::closeEvent(QCloseEvent *event) ...@@ -232,17 +238,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
} }
} }
void MainWindow::onAboutApplication()
{
AboutApplicationDialog dialog(this);
dialog.exec();
}
void MainWindow::resetModels()
{
models()->resetModels();
}
void MainWindow::showEvent(QShowEvent *event) void MainWindow::showEvent(QShowEvent *event)
{ {
QWidget::showEvent( event ); QWidget::showEvent( event );
......
...@@ -26,58 +26,49 @@ namespace Manhattan { ...@@ -26,58 +26,49 @@ namespace Manhattan {
class ProgressBar; class ProgressBar;
} }
class TaskSelectorWidget;
class WelcomeView; class WelcomeView;
class InstrumentView; class InstrumentView;
class SampleView; class SampleView;
class PyScriptView;
class SimulationView; class SimulationView;
class JobView; class JobView;
class Instrument; class FitView;
class ISample;
class ActionManager;
class ProjectManager;
class QCloseEvent;
class QSettings;
class InstrumentModel;
class MaterialSvc;
class ToolTipDataBase;
class MaterialModel; class MaterialModel;
class MaterialSvc;
class SampleModel; class SampleModel;
class FitView; class InstrumentModel;
class JobModel; class JobModel;
class UpdateNotifier;
class FitModel; class FitModel;
class ApplicationModels; class ApplicationModels;
class ProjectManager;
class ActionManager;
class QSettings;
class ToolTipDataBase;
class UpdateNotifier;
class BA_CORE_API_ MainWindow : public Manhattan::FancyMainWindow class BA_CORE_API_ MainWindow : public Manhattan::FancyMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
enum ETabViewId { WELCOME, INSTRUMENT, SAMPLE, SIMULATION, JOB, FIT, TESTVIEW}; enum ETabViewId {WELCOME, INSTRUMENT, SAMPLE, SIMULATION, JOB, FIT, TESTVIEW};
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
// MaterialModel *getMaterialModel() { return m_materialModel; }
// InstrumentModel *instrumentModel() { return m_instrumentModel; }
// SampleModel *sampleModel() { return m_sampleModel; }
// JobModel *jobModel() { return m_jobModel; }
// FitModel *getFitModel() { return m_fitModel; }
MaterialModel *getMaterialModel(); MaterialModel *getMaterialModel();
InstrumentModel *instrumentModel(); InstrumentModel *instrumentModel();
SampleModel *sampleModel(); SampleModel *sampleModel();
JobModel *jobModel(); JobModel *jobModel();
FitModel *getFitModel(); FitModel *getFitModel();
ApplicationModels *models();
Manhattan::ProgressBar *getProgressBar() { return m_progressBar; } Manhattan::ProgressBar *getProgressBar() { return m_progressBar; }
ActionManager *getActionManager() { return m_actionManager; } ActionManager *getActionManager() { return m_actionManager; }
ProjectManager *getProjectManager() { return m_projectManager; } ProjectManager *getProjectManager() { return m_projectManager; }
UpdateNotifier *getUpdateNotifier() { return m_updateNotifier; } UpdateNotifier *getUpdateNotifier() { return m_updateNotifier; }
ApplicationModels *models() { return m_applicationModels; }
public slots: public slots:
void onChangeTabWidget(int index); void onChangeTabWidget(int index);
...@@ -87,31 +78,26 @@ public slots: ...@@ -87,31 +78,26 @@ public slots:
void writeSettings(); void writeSettings();
void onRunSimulationShortcut(); void onRunSimulationShortcut();
void onAboutApplication(); void onAboutApplication();
void resetModels();
protected: protected:
virtual void closeEvent(QCloseEvent *event); virtual void closeEvent(QCloseEvent *event);
virtual void showEvent(QShowEvent *event);
private: private:
ApplicationModels *m_applicationModels;
ProjectManager *m_projectManager;
ActionManager *m_actionManager;
Manhattan::FancyTabWidget *m_tabWidget; Manhattan::FancyTabWidget *m_tabWidget;
WelcomeView *m_welcomeView; WelcomeView *m_welcomeView;
InstrumentView *m_instrumentView; InstrumentView *m_instrumentView;
SampleView *m_sampleView; SampleView *m_sampleView;
SimulationView *m_simulationView; SimulationView *m_simulationView;
JobView *m_jobView; JobView *m_jobView;
FitView *m_fitView; FitView *m_fitView;
Manhattan::ProgressBar *m_progressBar; Manhattan::ProgressBar *m_progressBar;
ActionManager *m_actionManager; //!< responsible for menus and actions
ProjectManager *m_projectManager; //!< handles activity related to opening/saving projects
ApplicationModels *m_applicationModels;
ToolTipDataBase *m_toolTipDataBase; ToolTipDataBase *m_toolTipDataBase;
UpdateNotifier *m_updateNotifier; UpdateNotifier *m_updateNotifier;
virtual void showEvent(QShowEvent *event);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "WarningMessageService.h" #include "WarningMessageService.h"
#include "MessageContainer.h" #include "MessageContainer.h"
#include "GUIMessage.h" #include "GUIMessage.h"
#include "ApplicationModels.h"
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
#include <QSettings> #include <QSettings>
...@@ -314,7 +315,7 @@ void ProjectManager::deleteCurrentProject() ...@@ -314,7 +315,7 @@ void ProjectManager::deleteCurrentProject()
{ {
delete m_project_document; delete m_project_document;
m_project_document = 0; m_project_document = 0;
m_mainWindow->resetModels(); m_mainWindow->models()->resetModels();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment