Rename ApplicationCode to ApplicationLibCode

This commit is contained in:
Gaute Lindkvist
2021-01-06 14:55:29 +01:00
parent 751df1a421
commit 81699db187
3242 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicToggleItemsFeatureImpl.h
${CMAKE_CURRENT_LIST_DIR}/RicToggleItemsOnFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicToggleItemsOffFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicToggleItemsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicToggleItemsOnOthersOffFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCollapseSiblingsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicMoveItemsToTopFeature.h
)
set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicToggleItemsFeatureImpl.cpp
${CMAKE_CURRENT_LIST_DIR}/RicToggleItemsOnFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicToggleItemsOffFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicToggleItemsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicToggleItemsOnOthersOffFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCollapseSiblingsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicMoveItemsToTopFeature.cpp
)
list(APPEND COMMAND_CODE_HEADER_FILES
${SOURCE_GROUP_HEADER_FILES}
)
list(APPEND COMMAND_CODE_SOURCE_FILES
${SOURCE_GROUP_SOURCE_FILES}
)
source_group( "CommandFeature\\ToggleItems" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )

View File

@@ -0,0 +1,85 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicCollapseSiblingsFeature.h"
#include "Rim3dView.h"
#include "RimSummaryPlot.h"
#include "RiuMainWindowTools.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicCollapseSiblingsFeature, "RicCollapseSiblingsFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCollapseSiblingsFeature::isCommandEnabled()
{
{
auto selectedItem = dynamic_cast<Rim3dView*>( caf::SelectionManager::instance()->selectedItem() );
if ( selectedItem ) return true;
}
{
auto selectedItem = dynamic_cast<RimSummaryPlot*>( caf::SelectionManager::instance()->selectedItem() );
if ( selectedItem ) return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCollapseSiblingsFeature::onActionTriggered( bool isChecked )
{
auto selectedItem = caf::SelectionManager::instance()->selectedItem();
RiuMainWindowTools::collapseSiblings( selectedItem );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCollapseSiblingsFeature::setupActionLook( QAction* actionToSetup )
{
QString objectName = "Items";
{
auto selectedItem = dynamic_cast<Rim3dView*>( caf::SelectionManager::instance()->selectedItem() );
if ( selectedItem )
{
objectName = "Views";
}
}
{
auto selectedItem = dynamic_cast<RimSummaryPlot*>( caf::SelectionManager::instance()->selectedItem() );
if ( selectedItem )
{
objectName = "Plots";
}
}
actionToSetup->setText( "Collapse Other " + objectName );
// actionToSetup->setIcon(QIcon(":/ToggleOn16x16.png"));
}

View File

@@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicCollapseSiblingsFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@@ -0,0 +1,157 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicMoveItemsToTopFeature.h"
#include "RiaGuiApplication.h"
#include "RicToggleItemsFeatureImpl.h"
#include "RiuMainWindow.h"
#include "cafPdmFieldReorderCapability.h"
#include "cafPdmObject.h"
#include "cafPdmObjectHandle.h"
#include "cafPdmPtrArrayFieldHandle.h"
#include "cafPdmUiObjectHandle.h"
#include "cafPdmUiTreeView.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicMoveItemsToTopFeature, "RicMoveItemsToTopFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicMoveItemsToTopFeature::isCommandEnabled()
{
using namespace caf;
std::vector<caf::PdmUiItem*> selectedItems;
caf::SelectionManager::instance()->selectedItems( selectedItems );
if ( !selectedItems.empty() )
{
auto pdmObject = RicMoveItemsToTopFeature::objectHandleFromUiItem( selectedItems[0] );
auto reorderability = PdmFieldReorderCapability::reorderCapabilityOfParentContainer( pdmObject );
if ( reorderability )
{
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicMoveItemsToTopFeature::onActionTriggered( bool isChecked )
{
using namespace caf;
std::vector<caf::PdmUiItem*> selectedItems;
caf::SelectionManager::instance()->selectedItems( selectedItems );
if ( !selectedItems.empty() )
{
auto pdmObject = RicMoveItemsToTopFeature::objectHandleFromUiItem( selectedItems[0] );
auto reorderability = PdmFieldReorderCapability::reorderCapabilityOfParentContainer( pdmObject );
if ( reorderability )
{
PdmPtrArrayFieldHandle* arrayField = dynamic_cast<PdmPtrArrayFieldHandle*>( pdmObject->parentField() );
CAF_ASSERT( arrayField );
bool anyObjectMoved = false;
std::vector<caf::PdmUiItem*> reverseOrder( selectedItems );
std::reverse( reverseOrder.begin(), reverseOrder.end() );
for ( auto uiItem : reverseOrder )
{
auto currentObject = dynamic_cast<PdmObject*>( uiItem );
if ( currentObject )
{
size_t indexToMove = arrayField->size() + 1;
for ( auto i = 0u; i < arrayField->size(); i++ )
{
if ( arrayField->at( i ) == currentObject )
{
indexToMove = i;
continue;
}
}
if ( reorderability->canItemBeMovedUp( indexToMove ) )
{
reorderability->moveItemToTop( indexToMove );
anyObjectMoved = true;
}
}
}
if ( anyObjectMoved )
{
std::vector<const caf::PdmUiItem*> constSelectedItems;
for ( auto s : selectedItems )
{
constSelectedItems.push_back( s );
}
caf::PdmUiTreeView* uiTreeView = RiaGuiApplication::activeMainWindow()->projectTreeView();
if ( !constSelectedItems.empty() )
{
QModelIndex itemIndex = uiTreeView->findModelIndex( constSelectedItems[0] );
QModelIndex parentIndex = itemIndex.parent();
uiTreeView->updateSubTree( parentIndex );
}
// Restore selection highlight after reordering
uiTreeView->selectItems( constSelectedItems );
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicMoveItemsToTopFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Move to Top" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObjectHandle* RicMoveItemsToTopFeature::objectHandleFromUiItem( caf::PdmUiItem* uiItem )
{
using namespace caf;
PdmUiObjectHandle* uiObjectHandle = dynamic_cast<PdmUiObjectHandle*>( uiItem );
if ( uiObjectHandle )
{
PdmObjectHandle* pdmObject = uiObjectHandle->objectHandle();
return pdmObject;
}
return nullptr;
}

View File

@@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
namespace caf
{
class PdmObjectHandle;
class PdmUiItem;
} // namespace caf
//==================================================================================================
///
//==================================================================================================
class RicMoveItemsToTopFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
static caf::PdmObjectHandle* objectHandleFromUiItem( caf::PdmUiItem* uiItem );
};

View File

@@ -0,0 +1,57 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicToggleItemsFeature.h"
#include "RicToggleItemsFeatureImpl.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicToggleItemsFeature, "RicToggleItemsFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicToggleItemsFeature::isCommandEnabled()
{
return RicToggleItemsFeatureImpl::isToggleCommandsAvailable();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicToggleItemsFeature::onActionTriggered( bool isChecked )
{
RicToggleItemsFeatureImpl::setObjectToggleStateForSelection( RicToggleItemsFeatureImpl::TOGGLE_SUBITEMS );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicToggleItemsFeature::setupActionLook( QAction* actionToSetup )
{
if ( RicToggleItemsFeatureImpl::isToggleCommandsForSubItems() )
actionToSetup->setText( "Toggle Sub Items" );
else
actionToSetup->setText( "Toggle" );
actionToSetup->setIcon( QIcon( ":/ToggleOnOff16x16.png" ) );
}

View File

@@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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"
//==================================================================================================
///
//==================================================================================================
class RicToggleItemsFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@@ -0,0 +1,206 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RiaFeatureCommandContext.h"
#include "RiaGuiApplication.h"
#include "RiuMainWindow.h"
#include "RiuPlotMainWindow.h"
#include "cafPdmUiFieldHandle.h"
#include "cafPdmUiItem.h"
#include "cafPdmUiObjectHandle.h"
#include "cafPdmUiTreeOrdering.h"
#include "cafPdmUiTreeView.h"
#include "cafSelectionManager.h"
#include <QModelIndex>
#include <vector>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicToggleItemsFeatureImpl::isToggleCommandsAvailable()
{
std::vector<caf::PdmUiItem*> selectedItems;
caf::SelectionManager::instance()->selectedItems( selectedItems );
if ( selectedItems.size() == 1 )
{
caf::PdmUiTreeOrdering* treeItem = findTreeItemFromSelectedUiItem( selectedItems[0] );
if ( !treeItem ) return false;
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() &&
!uiObjectHandleChild->objectToggleField()->uiCapability()->isUiReadOnly() )
{
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 ( state != TOGGLE && 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::PdmUiTreeOrdering* treeItem = findTreeItemFromSelectedUiItem( selectedItems[0] );
if ( !treeItem ) return;
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() );
if ( state == TOGGLE_ON ) field->setValueWithFieldChanged( true );
if ( state == TOGGLE_OFF ) field->setValueWithFieldChanged( false );
if ( state == TOGGLE_SUBITEMS ) field->setValueWithFieldChanged( !( 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() );
if ( state == TOGGLE_ON ) field->setValueWithFieldChanged( true );
if ( state == TOGGLE_OFF ) field->setValueWithFieldChanged( false );
if ( state == TOGGLE_SUBITEMS || state == TOGGLE )
{
field->setValueWithFieldChanged( !( field->v() ) );
}
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmUiTreeView* RicToggleItemsFeatureImpl::findTreeView( const caf::PdmUiItem* uiItem )
{
{
RiaFeatureCommandContext* context = RiaFeatureCommandContext::instance();
caf::PdmUiTreeView* customActiveTreeView = dynamic_cast<caf::PdmUiTreeView*>( context->object() );
if ( customActiveTreeView )
{
return customActiveTreeView;
}
}
{
QModelIndex modIndex = RiuMainWindow::instance()->projectTreeView()->findModelIndex( uiItem );
if ( modIndex.isValid() )
{
return RiuMainWindow::instance()->projectTreeView();
}
}
RiuPlotMainWindow* mainPlotWindow = RiaGuiApplication::instance()->mainPlotWindow();
if ( mainPlotWindow )
{
QModelIndex modIndex = mainPlotWindow->projectTreeView()->findModelIndex( uiItem );
if ( modIndex.isValid() )
{
return mainPlotWindow->projectTreeView();
}
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
/// Finds the tree item in either the 3D main window or plot main window project tree view
//--------------------------------------------------------------------------------------------------
caf::PdmUiTreeOrdering* RicToggleItemsFeatureImpl::findTreeItemFromSelectedUiItem( const caf::PdmUiItem* uiItem )
{
caf::PdmUiTreeView* pdmUiTreeView = findTreeView( uiItem );
if ( pdmUiTreeView )
{
QModelIndex modIndex = pdmUiTreeView->findModelIndex( uiItem );
return static_cast<caf::PdmUiTreeOrdering*>( modIndex.internalPointer() );
}
return nullptr;
}

View File

@@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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
namespace caf
{
class PdmUiItem;
class PdmUiTreeOrdering;
class PdmUiTreeView;
}; // namespace caf
//==================================================================================================
///
//==================================================================================================
class RicToggleItemsFeatureImpl
{
public:
enum SelectionToggleType
{
TOGGLE_ON,
TOGGLE_OFF,
TOGGLE_SUBITEMS,
TOGGLE,
TOGGLE_UNDEFINED
};
static bool isToggleCommandsAvailable();
static bool isToggleCommandsForSubItems();
static void setObjectToggleStateForSelection( SelectionToggleType state );
private:
static caf::PdmUiTreeView* findTreeView( const caf::PdmUiItem* uiItem );
static caf::PdmUiTreeOrdering* findTreeItemFromSelectedUiItem( const caf::PdmUiItem* uiItem );
};

View File

@@ -0,0 +1,57 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicToggleItemsOffFeature.h"
#include "RicToggleItemsFeatureImpl.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicToggleItemsOffFeature, "RicToggleItemsOffFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicToggleItemsOffFeature::isCommandEnabled()
{
return RicToggleItemsFeatureImpl::isToggleCommandsAvailable();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicToggleItemsOffFeature::onActionTriggered( bool isChecked )
{
RicToggleItemsFeatureImpl::setObjectToggleStateForSelection( RicToggleItemsFeatureImpl::TOGGLE_OFF );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicToggleItemsOffFeature::setupActionLook( QAction* actionToSetup )
{
if ( RicToggleItemsFeatureImpl::isToggleCommandsForSubItems() )
actionToSetup->setText( "Sub Items Off" );
else
actionToSetup->setText( "Off" );
actionToSetup->setIcon( QIcon( ":/ToggleOff16x16.png" ) );
}

View File

@@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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"
//==================================================================================================
///
//==================================================================================================
class RicToggleItemsOffFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@@ -0,0 +1,57 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicToggleItemsFeatureImpl.h"
#include "cafSelectionManager.h"
#include <QAction>
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" );
actionToSetup->setIcon( QIcon( ":/ToggleOn16x16.png" ) );
}

View File

@@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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"
//==================================================================================================
///
//==================================================================================================
class RicToggleItemsOnFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@@ -0,0 +1,139 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicToggleItemsOnOthersOffFeature.h"
#include "RicToggleItemsFeatureImpl.h"
#include "cafSelectionManager.h"
#include "cafPdmObject.h"
#include "cafPdmObjectHandle.h"
#include "cafPdmUiItem.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicToggleItemsOnOthersOffFeature, "RicToggleItemsOnOthersOffFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicToggleItemsOnOthersOffFeature::isCommandEnabled()
{
std::vector<caf::PdmObject*> selectedObjects;
caf::SelectionManager::instance()->objectsByType( &selectedObjects );
caf::PdmFieldHandle* commonParent = commonParentForAllSelections( selectedObjects );
std::vector<caf::PdmObjectHandle*> children = childObjects( commonParent );
return commonParent != nullptr && children.size() > 0 && objectToggleField( children.front() ) &&
children.size() > selectedObjects.size();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicToggleItemsOnOthersOffFeature::onActionTriggered( bool isChecked )
{
std::vector<caf::PdmObject*> selectedObjects;
caf::SelectionManager::instance()->objectsByType( &selectedObjects );
// First toggle off all siblings
caf::PdmFieldHandle* commonParent = commonParentForAllSelections( selectedObjects );
for ( caf::PdmObjectHandle* child : childObjects( commonParent ) )
{
caf::PdmField<bool>* field = objectToggleField( child );
if ( field )
{
field->setValueWithFieldChanged( false );
}
}
// Then toggle on the selected item(s)
for ( caf::PdmObject* selectedObject : selectedObjects )
{
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>*>( selectedObject->objectToggleField() );
field->setValueWithFieldChanged( true );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicToggleItemsOnOthersOffFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "On - Others Off" );
actionToSetup->setIcon( QIcon( ":/ToggleOnOthersOff16x16.png" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle*
RicToggleItemsOnOthersOffFeature::commonParentForAllSelections( const std::vector<caf::PdmObject*>& selectedObjects )
{
caf::PdmFieldHandle* commonParent = nullptr;
for ( caf::PdmObject* obj : selectedObjects )
{
caf::PdmFieldHandle* parent = obj->parentField();
if ( parent )
{
if ( !commonParent )
{
commonParent = parent;
}
else if ( parent != commonParent )
{
// Different parents detected
return nullptr;
}
}
}
return commonParent;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<caf::PdmObjectHandle*> RicToggleItemsOnOthersOffFeature::childObjects( caf::PdmFieldHandle* parent )
{
std::vector<caf::PdmObjectHandle*> children;
if ( parent )
{
parent->childObjects( &children );
}
return children;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmField<bool>* RicToggleItemsOnOthersOffFeature::objectToggleField( caf::PdmObjectHandle* objectHandle )
{
caf::PdmUiObjectHandle* childUiObject = uiObj( objectHandle );
if ( childUiObject && childUiObject->objectToggleField() )
{
return dynamic_cast<caf::PdmField<bool>*>( childUiObject->objectToggleField() );
}
return nullptr;
}

View File

@@ -0,0 +1,49 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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"
#include "cafPdmField.h"
namespace caf
{
class PdmFieldHandle;
class PdmObject;
class PdmObjectHandle;
} // namespace caf
//==================================================================================================
///
//==================================================================================================
class RicToggleItemsOnOthersOffFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
caf::PdmFieldHandle* commonParentForAllSelections( const std::vector<caf::PdmObject*>& selectedObjects );
std::vector<caf::PdmObjectHandle*> childObjects( caf::PdmFieldHandle* parent );
caf::PdmField<bool>* objectToggleField( caf::PdmObjectHandle* objectHandle );
};