From 41235a2f005dfcc7c8fba54a805264febe362e01 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 17 Jun 2019 09:02:26 +0200 Subject: [PATCH] #4490 Command Features : Add support for setting application state to be used in features --- .../Application/CMakeLists_files.cmake | 2 + .../Application/RiaFeatureCommandContext.cpp | 70 +++++++++++++++++++ .../Application/RiaFeatureCommandContext.h | 54 ++++++++++++++ .../WellPathImportSsihubTestApp/TestTools.h | 28 -------- 4 files changed, 126 insertions(+), 28 deletions(-) create mode 100644 ApplicationCode/Application/RiaFeatureCommandContext.cpp create mode 100644 ApplicationCode/Application/RiaFeatureCommandContext.h delete mode 100644 ApplicationCode/WellPathImportSsihubTestApp/TestTools.h diff --git a/ApplicationCode/Application/CMakeLists_files.cmake b/ApplicationCode/Application/CMakeLists_files.cmake index c575b75c48..dd3a8ddcbc 100644 --- a/ApplicationCode/Application/CMakeLists_files.cmake +++ b/ApplicationCode/Application/CMakeLists_files.cmake @@ -15,6 +15,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.h ${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.h ${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.h ${CMAKE_CURRENT_LIST_DIR}/RiaEclipseFileNameTools.h +${CMAKE_CURRENT_LIST_DIR}/RiaFeatureCommandContext.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -34,6 +35,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaEclipseFileNameTools.cpp +${CMAKE_CURRENT_LIST_DIR}/RiaFeatureCommandContext.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Application/RiaFeatureCommandContext.cpp b/ApplicationCode/Application/RiaFeatureCommandContext.cpp new file mode 100644 index 0000000000..d671195dca --- /dev/null +++ b/ApplicationCode/Application/RiaFeatureCommandContext.cpp @@ -0,0 +1,70 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RiaFeatureCommandContext.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaFeatureCommandContext::RiaFeatureCommandContext() {} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaFeatureCommandContext::~RiaFeatureCommandContext() {} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaFeatureCommandContext::setObject(QObject* object) +{ + m_pointerToQObject = object; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QObject* RiaFeatureCommandContext::object() const +{ + return m_pointerToQObject; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaFeatureCommandContext* RiaFeatureCommandContext::instance() +{ + static RiaFeatureCommandContext* commandFileExecutorInstance = new RiaFeatureCommandContext(); + return commandFileExecutorInstance; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaFeatureCommandContextHelper::RiaFeatureCommandContextHelper(QObject* object) +{ + RiaFeatureCommandContext::instance()->setObject(object); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaFeatureCommandContextHelper::~RiaFeatureCommandContextHelper() +{ + RiaFeatureCommandContext::instance()->setObject(nullptr); +} diff --git a/ApplicationCode/Application/RiaFeatureCommandContext.h b/ApplicationCode/Application/RiaFeatureCommandContext.h new file mode 100644 index 0000000000..9ac89ddb4d --- /dev/null +++ b/ApplicationCode/Application/RiaFeatureCommandContext.h @@ -0,0 +1,54 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +class RiaFeatureCommandContext +{ + friend class RiaFeatureCommandContextHelper; + +public: + QObject* object() const; + + static RiaFeatureCommandContext* instance(); + +private: + RiaFeatureCommandContext(); + ~RiaFeatureCommandContext(); + + void setObject(QObject* object); + +private: + QPointer m_pointerToQObject; +}; + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +class RiaFeatureCommandContextHelper +{ +public: + RiaFeatureCommandContextHelper(QObject* object); + ~RiaFeatureCommandContextHelper(); +}; diff --git a/ApplicationCode/WellPathImportSsihubTestApp/TestTools.h b/ApplicationCode/WellPathImportSsihubTestApp/TestTools.h deleted file mode 100644 index 805d012b43..0000000000 --- a/ApplicationCode/WellPathImportSsihubTestApp/TestTools.h +++ /dev/null @@ -1,28 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS -// -// 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 -// for more details. -// -///////////////////////////////////////////////////////////////////////////////// - -#pragma once - -class RimWellPathImport; - -class TestTools -{ -public: - static RimWellPathImport* createMockObject(); -}; -