(#361) Refactored "On" as a start on the toggle commands

This commit is contained in:
Jacob Støren 2015-08-18 10:51:13 +02:00
parent 4606a3de8b
commit eadf1ca300
8 changed files with 331 additions and 1 deletions

View File

@ -105,6 +105,7 @@ list( APPEND REFERENCED_CMAKE_FILES
GeoMech/GeoMechVisualization/CMakeLists_files.cmake
Commands/CMakeLists_files.cmake
Commands/OperationsUsingObjReferences/CMakeLists_files.cmake
Commands/ToggleCommands/CMakeLists_files.cmake
)
# Include source file lists from *.cmake files

View File

@ -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 )

View File

@ -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()));
}
}
}
}
}

View File

@ -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);
};

View File

@ -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

View File

@ -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

View File

@ -44,6 +44,7 @@
#include <QDir>
#include "cafCmdFeature.h"
#include "ToggleCommands\RicToggleItemsFeatureImpl.h"
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();
for (int i = 0; i < commandIds.size(); i++)
{

View File

@ -90,7 +90,7 @@ public:
void forceProjectTreeRepaint();
RimUiTreeModelPdm* uiPdmModel_OBSOLETE() { return m_OBSOLETE_treeModelPdm;}
caf::PdmUiTreeView* projectTreeView() { return m_projectTreeView;}
RiuProcessMonitor* processMonitor();
void hideAllDockWindows();