#846 Created save/close project and exit features

This commit is contained in:
Magne Sjaastad 2016-10-05 13:36:12 +02:00
parent 0ca0179c5a
commit 8ffe1303df
11 changed files with 410 additions and 29 deletions

View File

@ -12,6 +12,10 @@ ${CEE_CURRENT_LIST_DIR}RicTileWindowsFeature.h
${CEE_CURRENT_LIST_DIR}RicTilePlotWindowsFeature.h
${CEE_CURRENT_LIST_DIR}RicOpenProjectFeature.h
${CEE_CURRENT_LIST_DIR}RicOpenLastUsedFileFeature.h
${CEE_CURRENT_LIST_DIR}RicSaveProjectFeature.h
${CEE_CURRENT_LIST_DIR}RicSaveProjectAsFeature.h
${CEE_CURRENT_LIST_DIR}RicExitApplicationFeature.h
${CEE_CURRENT_LIST_DIR}RicCloseProjectFeature.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -22,6 +26,10 @@ ${CEE_CURRENT_LIST_DIR}RicTileWindowsFeature.cpp
${CEE_CURRENT_LIST_DIR}RicTilePlotWindowsFeature.cpp
${CEE_CURRENT_LIST_DIR}RicOpenProjectFeature.cpp
${CEE_CURRENT_LIST_DIR}RicOpenLastUsedFileFeature.cpp
${CEE_CURRENT_LIST_DIR}RicSaveProjectFeature.cpp
${CEE_CURRENT_LIST_DIR}RicSaveProjectAsFeature.cpp
${CEE_CURRENT_LIST_DIR}RicExitApplicationFeature.cpp
${CEE_CURRENT_LIST_DIR}RicCloseProjectFeature.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight 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 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicCloseProjectFeature.h"
#include "RiaApplication.h"
#include <QAction>
CAF_CMD_SOURCE_INIT(RicCloseProjectFeature, "RicCloseProjectFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCloseProjectFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseProjectFeature::onActionTriggered(bool isChecked)
{
RiaApplication* app = RiaApplication::instance();
app->closeProject();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseProjectFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("&Close Project");
}

View File

@ -0,0 +1,38 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight 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 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicCloseProjectFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
virtual bool isCommandEnabled() override;
virtual void onActionTriggered( bool isChecked ) override;
virtual void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -0,0 +1,50 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight 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 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicExitApplicationFeature.h"
#include "RiaApplication.h"
#include <QAction>
CAF_CMD_SOURCE_INIT(RicExitApplicationFeature, "RicExitApplicationFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicExitApplicationFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExitApplicationFeature::onActionTriggered(bool isChecked)
{
RiaApplication* app = RiaApplication::instance();
app->closeAllWindows();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExitApplicationFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("E&xit");
}

View File

@ -0,0 +1,38 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight 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 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicExitApplicationFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
virtual bool isCommandEnabled() override;
virtual void onActionTriggered( bool isChecked ) override;
virtual void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -0,0 +1,57 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight 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 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicSaveProjectAsFeature.h"
#include "RicSaveProjectFeature.h"
#include "RiaApplication.h"
#include <QAction>
CAF_CMD_SOURCE_INIT(RicSaveProjectAsFeature, "RicSaveProjectAsFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSaveProjectAsFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveProjectAsFeature::onActionTriggered(bool isChecked)
{
RiaApplication* app = RiaApplication::instance();
RicSaveProjectFeature::storeTreeViewState();
app->saveProjectPromptForFileName();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveProjectAsFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Save Project &As");
actionToSetup->setIcon(QIcon(":/Save.png"));
}

View File

@ -0,0 +1,38 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight 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 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicSaveProjectAsFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
virtual bool isCommandEnabled() override;
virtual void onActionTriggered( bool isChecked ) override;
virtual void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -0,0 +1,84 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight 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 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicSaveProjectFeature.h"
#include "RiaApplication.h"
#include "RimTreeViewStateSerializer.h"
#include "RimProject.h"
#include "RiuMainWindow.h"
#include "cafPdmUiTreeView.h"
#include <QAction>
#include <QTreeView>
CAF_CMD_SOURCE_INIT(RicSaveProjectFeature, "RicSaveProjectFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSaveProjectFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveProjectFeature::onActionTriggered(bool isChecked)
{
RiaApplication* app = RiaApplication::instance();
RicSaveProjectFeature::storeTreeViewState();
app->saveProject();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveProjectFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("&Save Project");
actionToSetup->setIcon(QIcon(":/Save.png"));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveProjectFeature::storeTreeViewState()
{
caf::PdmUiTreeView* projectTreeView = RiuMainWindow::instance()->projectTreeView();
if (projectTreeView)
{
QString treeViewState;
RimTreeViewStateSerializer::storeTreeViewStateToString(projectTreeView->treeView(), treeViewState);
QModelIndex mi = projectTreeView->treeView()->currentIndex();
QString encodedModelIndexString;
RimTreeViewStateSerializer::encodeStringFromModelIndex(mi, encodedModelIndexString);
RiaApplication::instance()->project()->treeViewState = treeViewState;
RiaApplication::instance()->project()->currentModelIndexPath = encodedModelIndexString;
}
}

View File

@ -0,0 +1,41 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight 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 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicSaveProjectFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
public:
static void storeTreeViewState();
protected:
// Overrides
virtual bool isCommandEnabled() override;
virtual void onActionTriggered( bool isChecked ) override;
virtual void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -248,13 +248,6 @@ void RiuMainWindow::createActions()
m_showRegressionTestDialog = new QAction("Regression Test Dialog", this);
m_executePaintEventPerformanceTest = new QAction("&Paint Event Performance Test", this);
m_saveProjectAction = new QAction(QIcon(":/Save.png"), "&Save Project", this);
m_saveProjectAsAction = new QAction(QIcon(":/Save.png"), "Save Project &As", this);
m_closeProjectAction = new QAction("&Close Project", this);
m_exitAction = new QAction("E&xit", this);
connect(m_importGeoMechCaseAction, SIGNAL(triggered()), SLOT(slotImportGeoMechModel()));
connect(m_mockModelAction, SIGNAL(triggered()), SLOT(slotMockModel()));
@ -271,13 +264,6 @@ void RiuMainWindow::createActions()
connect(m_showRegressionTestDialog, SIGNAL(triggered()), SLOT(slotShowRegressionTestDialog()));
connect(m_executePaintEventPerformanceTest, SIGNAL(triggered()), SLOT(slotExecutePaintEventPerformanceTest()));
connect(m_saveProjectAction, SIGNAL(triggered()), SLOT(slotSaveProject()));
connect(m_saveProjectAsAction, SIGNAL(triggered()), SLOT(slotSaveProjectAs()));
connect(m_closeProjectAction, SIGNAL(triggered()), SLOT(slotCloseProject()));
connect(m_exitAction, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows()));
// Edit actions
m_editPreferences = new QAction("&Preferences...", this);
connect(m_editPreferences, SIGNAL(triggered()), SLOT(slotEditPreferences()));
@ -399,8 +385,8 @@ void RiuMainWindow::createMenus()
exportMenu->addAction(m_snapshotAllViewsToFile);
fileMenu->addSeparator();
fileMenu->addAction(m_saveProjectAction);
fileMenu->addAction(m_saveProjectAsAction);
fileMenu->addAction(cmdFeatureMgr->action("RicSaveProjectFeature"));
fileMenu->addAction(cmdFeatureMgr->action("RicSaveProjectAsFeature"));
std::vector<QAction*> recentFileActions = RiaApplication::instance()->recentFileActions();
for (auto act : recentFileActions)
@ -412,9 +398,9 @@ void RiuMainWindow::createMenus()
QMenu* testMenu = fileMenu->addMenu("&Testing");
fileMenu->addSeparator();
fileMenu->addAction(m_closeProjectAction);
fileMenu->addAction(cmdFeatureMgr->action("RicCloseProjectFeature"));
fileMenu->addSeparator();
fileMenu->addAction(m_exitAction);
fileMenu->addAction(cmdFeatureMgr->action("RicExitApplicationFeature"));
connect(fileMenu, SIGNAL(aboutToShow()), SLOT(slotRefreshFileActions()));
@ -480,8 +466,7 @@ void RiuMainWindow::createToolBars()
m_standardToolBar->addAction(cmdFeatureMgr->action("RicImportEclipseCaseFeature"));
m_standardToolBar->addAction(cmdFeatureMgr->action("RicImportInputEclipseCaseFeature"));
m_standardToolBar->addAction(cmdFeatureMgr->action("RicOpenProjectFeature"));
//m_standardToolBar->addAction(m_openLastUsedProjectAction);
m_standardToolBar->addAction(m_saveProjectAction);
m_standardToolBar->addAction(cmdFeatureMgr->action("RicSaveProjectFeature"));
// Snapshots
m_snapshotToolbar = addToolBar(tr("View Snapshots"));
@ -672,11 +657,6 @@ void RiuMainWindow::slotRefreshFileActions()
{
RiaApplication* app = RiaApplication::instance();
bool projectExists = true;
m_saveProjectAction->setEnabled(projectExists);
m_saveProjectAsAction->setEnabled(projectExists);
m_closeProjectAction->setEnabled(projectExists);
bool projectFileExists = QFile::exists(app->project()->fileName());
caf::CmdFeatureManager* cmdFeatureMgr = caf::CmdFeatureManager::instance();

View File

@ -140,10 +140,6 @@ private:
private:
// File actions
QAction* m_importGeoMechCaseAction;
QAction* m_saveProjectAction;
QAction* m_saveProjectAsAction;
QAction* m_closeProjectAction;
QAction* m_exitAction;
// Edit actions
QAction* m_editPreferences;