mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#361) Refactored "On" as a start on the toggle commands
This commit is contained in:
parent
4606a3de8b
commit
eadf1ca300
@ -105,6 +105,7 @@ list( APPEND REFERENCED_CMAKE_FILES
|
|||||||
GeoMech/GeoMechVisualization/CMakeLists_files.cmake
|
GeoMech/GeoMechVisualization/CMakeLists_files.cmake
|
||||||
Commands/CMakeLists_files.cmake
|
Commands/CMakeLists_files.cmake
|
||||||
Commands/OperationsUsingObjReferences/CMakeLists_files.cmake
|
Commands/OperationsUsingObjReferences/CMakeLists_files.cmake
|
||||||
|
Commands/ToggleCommands/CMakeLists_files.cmake
|
||||||
)
|
)
|
||||||
|
|
||||||
# Include source file lists from *.cmake files
|
# Include source file lists from *.cmake files
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
# Use this workaround until we're on 2.8.3 on all platforms and can use CMAKE_CURRENT_LIST_DIR directly
|
||||||
|
if (${CMAKE_VERSION} VERSION_GREATER "2.8.2")
|
||||||
|
set(CEE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}/)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set (SOURCE_GROUP_HEADER_FILES
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicToggleItemsFeatureImpl.h
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicToggleItemsOnFeature.h
|
||||||
|
|
||||||
|
#${CEE_CURRENT_LIST_DIR}RicToggleItemsOffFeature.h
|
||||||
|
#${CEE_CURRENT_LIST_DIR}RicToggleItemsFeature.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set (SOURCE_GROUP_SOURCE_FILES
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicToggleItemsFeatureImpl.cpp
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicToggleItemsOnFeature.cpp
|
||||||
|
|
||||||
|
#${CEE_CURRENT_LIST_DIR}RicToggleItemsOffFeature.cpp
|
||||||
|
#${CEE_CURRENT_LIST_DIR}RicToggleItemsFeature.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
list(APPEND CODE_HEADER_FILES
|
||||||
|
${SOURCE_GROUP_HEADER_FILES}
|
||||||
|
)
|
||||||
|
|
||||||
|
list(APPEND CODE_SOURCE_FILES
|
||||||
|
${SOURCE_GROUP_SOURCE_FILES}
|
||||||
|
)
|
||||||
|
|
||||||
|
source_group( "ToggleCommands" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CEE_CURRENT_LIST_DIR}CMakeLists_files.cmake )
|
@ -0,0 +1,146 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2015- Statoil ASA
|
||||||
|
// Copyright (C) 2015- Ceetron Solutions 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 <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RicToggleItemsFeatureImpl.h"
|
||||||
|
#include <vector>
|
||||||
|
#include "cafPdmUiObjectHandle.h"
|
||||||
|
#include "cafSelectionManager.h"
|
||||||
|
#include "cafPdmUiItem.h"
|
||||||
|
#include <QModelIndex>
|
||||||
|
#include "RiuMainWindow.h"
|
||||||
|
#include "cafPdmUiTreeView.h"
|
||||||
|
#include "cafPdmUiTreeOrdering.h"
|
||||||
|
#include "cafPdmUiFieldHandle.h"
|
||||||
|
|
||||||
|
bool RicToggleItemsFeatureImpl::isToggleCommandsAvailable()
|
||||||
|
{
|
||||||
|
std::vector<caf::PdmUiItem*> selectedItems;
|
||||||
|
caf::SelectionManager::instance()->selectedItems(selectedItems);
|
||||||
|
|
||||||
|
if (selectedItems.size() == 1)
|
||||||
|
{
|
||||||
|
caf::PdmUiObjectHandle* uiObjectHandle = dynamic_cast<caf::PdmUiObjectHandle*>(selectedItems[0]);
|
||||||
|
QModelIndex modIndex = RiuMainWindow::instance()->projectTreeView()->findModelIndex(selectedItems[0]);
|
||||||
|
caf::PdmUiTreeOrdering* treeItem = static_cast<caf::PdmUiTreeOrdering*>(modIndex.internalPointer());
|
||||||
|
|
||||||
|
for (int cIdx = 0; cIdx < treeItem->childCount(); ++ cIdx)
|
||||||
|
{
|
||||||
|
caf::PdmUiTreeOrdering* child = treeItem->child(cIdx);
|
||||||
|
if (!child) continue;
|
||||||
|
if (!child->isRepresentingObject()) continue;
|
||||||
|
|
||||||
|
caf::PdmObjectHandle* childObj = child->object();
|
||||||
|
caf::PdmUiObjectHandle* uiObjectHandleChild = uiObj(childObj);
|
||||||
|
|
||||||
|
if (uiObjectHandleChild && uiObjectHandleChild->objectToggleField())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < selectedItems.size(); ++i)
|
||||||
|
{
|
||||||
|
caf::PdmUiObjectHandle* uiObjectHandle = dynamic_cast<caf::PdmUiObjectHandle*>(selectedItems[i]);
|
||||||
|
|
||||||
|
if (uiObjectHandle && uiObjectHandle->objectToggleField())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RicToggleItemsFeatureImpl::isToggleCommandsForSubItems()
|
||||||
|
{
|
||||||
|
std::vector<caf::PdmUiItem*> selectedItems;
|
||||||
|
caf::SelectionManager::instance()->selectedItems(selectedItems);
|
||||||
|
if (isToggleCommandsAvailable() && selectedItems.size() == 1)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Set toggle state for list of model indices.
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicToggleItemsFeatureImpl::setObjectToggleStateForSelection(SelectionToggleType state)
|
||||||
|
{
|
||||||
|
std::vector<caf::PdmUiItem*> selectedItems;
|
||||||
|
caf::SelectionManager::instance()->selectedItems(selectedItems);
|
||||||
|
if (selectedItems.size() == 1)
|
||||||
|
{
|
||||||
|
// If only one item is selected, loop over its children, and toggle them instead of the
|
||||||
|
// selected item directly
|
||||||
|
|
||||||
|
// We need to get the children through the tree view, because that is where the actually shown children is
|
||||||
|
|
||||||
|
caf::PdmUiObjectHandle* uiObjectHandle = dynamic_cast<caf::PdmUiObjectHandle*>(selectedItems[0]);
|
||||||
|
QModelIndex modIndex = RiuMainWindow::instance()->projectTreeView()->findModelIndex(selectedItems[0]);
|
||||||
|
caf::PdmUiTreeOrdering* treeItem = reinterpret_cast<caf::PdmUiTreeOrdering*>(modIndex.internalPointer());
|
||||||
|
|
||||||
|
for (int cIdx = 0; cIdx < treeItem->childCount(); ++ cIdx)
|
||||||
|
{
|
||||||
|
caf::PdmUiTreeOrdering* child = treeItem->child(cIdx);
|
||||||
|
if (!child) continue;
|
||||||
|
if (!child->isRepresentingObject()) continue;
|
||||||
|
|
||||||
|
caf::PdmObjectHandle* childObj = child->object();
|
||||||
|
caf::PdmUiObjectHandle* uiObjectHandleChild = uiObj(childObj);
|
||||||
|
|
||||||
|
if (uiObjectHandleChild && uiObjectHandleChild->objectToggleField())
|
||||||
|
{
|
||||||
|
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>*>(uiObjectHandleChild->objectToggleField());
|
||||||
|
|
||||||
|
caf::PdmUiFieldHandle* uiFieldHandle = field->uiCapability();
|
||||||
|
if (uiFieldHandle)
|
||||||
|
{
|
||||||
|
if (state == TOGGLE_ON) uiFieldHandle->setValueFromUi(true);
|
||||||
|
if (state == TOGGLE_OFF) uiFieldHandle->setValueFromUi(false);
|
||||||
|
if (state == TOGGLE) uiFieldHandle->setValueFromUi(!(field->v()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < selectedItems.size(); ++i)
|
||||||
|
{
|
||||||
|
caf::PdmUiObjectHandle* uiObjectHandle = dynamic_cast< caf::PdmUiObjectHandle*>(selectedItems[i]);
|
||||||
|
|
||||||
|
if (uiObjectHandle && uiObjectHandle->objectToggleField())
|
||||||
|
{
|
||||||
|
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>* >(uiObjectHandle->objectToggleField());
|
||||||
|
|
||||||
|
caf::PdmUiFieldHandle* uiFieldHandle = field->uiCapability();
|
||||||
|
if (uiFieldHandle)
|
||||||
|
{
|
||||||
|
if (state == TOGGLE_ON) uiFieldHandle->setValueFromUi(true);
|
||||||
|
if (state == TOGGLE_OFF) uiFieldHandle->setValueFromUi(false);
|
||||||
|
if (state == TOGGLE) uiFieldHandle->setValueFromUi(!(field->v()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2015- Statoil ASA
|
||||||
|
// Copyright (C) 2015- Ceetron Solutions 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 <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
///
|
||||||
|
//==================================================================================================
|
||||||
|
class RicToggleItemsFeatureImpl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum SelectionToggleType
|
||||||
|
{
|
||||||
|
TOGGLE_ON,
|
||||||
|
TOGGLE_OFF,
|
||||||
|
TOGGLE,
|
||||||
|
TOGGLE_UNDEFINED
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool isToggleCommandsAvailable();
|
||||||
|
static bool isToggleCommandsForSubItems();
|
||||||
|
static void setObjectToggleStateForSelection(SelectionToggleType state);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,60 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2015- Statoil ASA
|
||||||
|
// Copyright (C) 2015- Ceetron Solutions 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 <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RicToggleItemsOnFeature.h"
|
||||||
|
|
||||||
|
#include "cafSelectionManager.h"
|
||||||
|
|
||||||
|
#include "RicToggleItemsFeatureImpl.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
|
||||||
|
namespace caf
|
||||||
|
{
|
||||||
|
|
||||||
|
CAF_CMD_SOURCE_INIT(RicToggleItemsOnFeature, "RicToggleItemsOnFeature");
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RicToggleItemsOnFeature::isCommandEnabled()
|
||||||
|
{
|
||||||
|
return RicToggleItemsFeatureImpl::isToggleCommandsAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicToggleItemsOnFeature::onActionTriggered(bool isChecked)
|
||||||
|
{
|
||||||
|
RicToggleItemsFeatureImpl::setObjectToggleStateForSelection(RicToggleItemsFeatureImpl::TOGGLE_ON);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicToggleItemsOnFeature::setupActionLook(QAction* actionToSetup)
|
||||||
|
{
|
||||||
|
if (RicToggleItemsFeatureImpl::isToggleCommandsForSubItems())
|
||||||
|
actionToSetup->setText("Sub Items On");
|
||||||
|
else
|
||||||
|
actionToSetup->setText("On");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace caf
|
@ -0,0 +1,43 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2015- Statoil ASA
|
||||||
|
// Copyright (C) 2015- Ceetron Solutions 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 <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cafCmdFeature.h"
|
||||||
|
|
||||||
|
namespace caf
|
||||||
|
{
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
///
|
||||||
|
//==================================================================================================
|
||||||
|
class RicToggleItemsOnFeature : public CmdFeature
|
||||||
|
{
|
||||||
|
CAF_CMD_HEADER_INIT;
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Overrides
|
||||||
|
virtual bool isCommandEnabled();
|
||||||
|
virtual void onActionTriggered( bool isChecked );
|
||||||
|
virtual void setupActionLook( QAction* actionToSetup );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // end namespace caf
|
@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include "cafCmdFeature.h"
|
#include "cafCmdFeature.h"
|
||||||
|
#include "ToggleCommands\RicToggleItemsFeatureImpl.h"
|
||||||
|
|
||||||
|
|
||||||
CAF_PDM_SOURCE_INIT(RimProject, "ResInsightProject");
|
CAF_PDM_SOURCE_INIT(RimProject, "ResInsightProject");
|
||||||
@ -649,6 +650,13 @@ void RimProject::actionsBasedOnSelection(QMenu& contextMenu)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (RicToggleItemsFeatureImpl::isToggleCommandsAvailable())
|
||||||
|
{
|
||||||
|
commandIds << "Separator";
|
||||||
|
commandIds << "RicToggleItemsOnFeature";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
|
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
|
||||||
for (int i = 0; i < commandIds.size(); i++)
|
for (int i = 0; i < commandIds.size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -90,7 +90,7 @@ public:
|
|||||||
void forceProjectTreeRepaint();
|
void forceProjectTreeRepaint();
|
||||||
|
|
||||||
RimUiTreeModelPdm* uiPdmModel_OBSOLETE() { return m_OBSOLETE_treeModelPdm;}
|
RimUiTreeModelPdm* uiPdmModel_OBSOLETE() { return m_OBSOLETE_treeModelPdm;}
|
||||||
|
caf::PdmUiTreeView* projectTreeView() { return m_projectTreeView;}
|
||||||
RiuProcessMonitor* processMonitor();
|
RiuProcessMonitor* processMonitor();
|
||||||
|
|
||||||
void hideAllDockWindows();
|
void hideAllDockWindows();
|
||||||
|
Loading…
Reference in New Issue
Block a user