#4599 Add "Collapse Others Views/Plots" to context menu of views and plots

This commit is contained in:
Magne Sjaastad
2019-08-20 10:39:23 +02:00
parent d065014571
commit d86a53f732
7 changed files with 243 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ ${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
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -13,6 +14,7 @@ ${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
)
list(APPEND CODE_HEADER_FILES

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

@@ -930,6 +930,11 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder.addSeparator();
}
menuBuilder << "RicToggleItemsOnOthersOffFeature";
if (RicToggleItemsFeatureImpl::isToggleCommandsAvailable())
{
menuBuilder << "RicCollapseSiblingsFeature";
}
}
if ( caf::CmdFeatureManager::instance()->getCommandFeature("RicDeleteItemFeature")->canFeatureBeExecuted() )

View File

@@ -84,6 +84,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuWellPathComponentPlotItem.h
${CMAKE_CURRENT_LIST_DIR}/RiuMeasurementViewEventFilter.h
${CMAKE_CURRENT_LIST_DIR}/RiuDraggableOverlayFrame.h
${CMAKE_CURRENT_LIST_DIR}/RiuMdiMaximizeWindowGuard.h
${CMAKE_CURRENT_LIST_DIR}/RiuMainWindowTools.h
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -167,6 +168,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuWellPathComponentPlotItem.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuDraggableOverlayFrame.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuMdiMaximizeWindowGuard.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuMainWindowTools.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -0,0 +1,85 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- 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 "RiuMainWindowTools.h"
#include "RiaGuiApplication.h"
#include "RiuMainWindow.h"
#include "RiuPlotMainWindow.h"
#include "cafPdmUiTreeOrdering.h"
#include "cafPdmUiTreeView.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainWindowTools::collapseSiblings(const caf::PdmUiItem* sourceUiItem)
{
if (!sourceUiItem) return;
if (!RiaGuiApplication::isRunning()) return;
{
caf::PdmUiTreeView* sourceTreeView = nullptr;
caf::PdmUiTreeOrdering* sourceTreeOrderingItem = nullptr;
{
QModelIndex modIndex;
if (RiuMainWindow::instance())
{
modIndex = RiuMainWindow::instance()->projectTreeView()->findModelIndex(sourceUiItem);
}
if (modIndex.isValid())
{
sourceTreeView = RiuMainWindow::instance()->projectTreeView();
}
else
{
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow();
if (mpw)
{
modIndex = mpw->projectTreeView()->findModelIndex(sourceUiItem);
if (modIndex.isValid())
{
sourceTreeView = mpw->projectTreeView();
}
}
}
if (!modIndex.isValid()) return;
sourceTreeOrderingItem = static_cast<caf::PdmUiTreeOrdering*>(modIndex.internalPointer());
}
if (sourceTreeView && sourceTreeOrderingItem && sourceTreeOrderingItem->parent())
{
for (int i = 0; i < sourceTreeOrderingItem->parent()->childCount(); i++)
{
auto siblingTreeOrderingItem = sourceTreeOrderingItem->parent()->child(i);
if (siblingTreeOrderingItem != sourceTreeOrderingItem)
{
sourceTreeView->setExpanded(siblingTreeOrderingItem->activeItem(), false);
}
}
}
}
}

View File

@@ -0,0 +1,30 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- 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
namespace caf
{
class PdmUiItem;
} // namespace caf
class RiuMainWindowTools
{
public:
static void collapseSiblings(const caf::PdmUiItem* uiItem);
};