#1306 Added general "Delete Sub Items" feature

This commit is contained in:
Magne Sjaastad 2017-03-08 12:06:05 +01:00
parent a81980c235
commit d547079847
4 changed files with 148 additions and 0 deletions

View File

@ -42,6 +42,7 @@ ${CEE_CURRENT_LIST_DIR}RicExportMultipleSnapshotsFeature.h
${CEE_CURRENT_LIST_DIR}RicDeleteItemExec.h
${CEE_CURRENT_LIST_DIR}RicDeleteItemExecData.h
${CEE_CURRENT_LIST_DIR}RicDeleteItemFeature.h
${CEE_CURRENT_LIST_DIR}RicDeleteSubItemsFeature.h
${CEE_CURRENT_LIST_DIR}RicCommandFeature.h
)
@ -80,6 +81,8 @@ ${CEE_CURRENT_LIST_DIR}RicExportMultipleSnapshotsFeature.cpp
${CEE_CURRENT_LIST_DIR}RicDeleteItemExec.cpp
${CEE_CURRENT_LIST_DIR}RicDeleteItemExecData.cpp
${CEE_CURRENT_LIST_DIR}RicDeleteItemFeature.cpp
${CEE_CURRENT_LIST_DIR}RicDeleteSubItemsFeature.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -0,0 +1,96 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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 "RicDeleteSubItemsFeature.h"
#include <QAction>
#include "RimSummaryPlotCollection.h"
#include "cafPdmUiItem.h"
#include "cafSelectionManager.h"
#include "cafAssert.h"
CAF_CMD_SOURCE_INIT(RicDeleteSubItemsFeature, "RicDeleteSubItemsFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicDeleteSubItemsFeature::isCommandEnabled()
{
std::vector<caf::PdmUiItem*> items;
caf::SelectionManager::instance()->selectedItems(items);
if (items.empty()) return false;
for (auto* item : items)
{
if (!RicDeleteSubItemsFeature::hasDeletableSubItems(item)) return false;
}
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDeleteSubItemsFeature::onActionTriggered(bool isChecked)
{
std::vector<caf::PdmUiItem*> items;
caf::SelectionManager::instance()->selectedItems(items);
CAF_ASSERT(items.size() > 0);
for (auto item : items)
{
if (!RicDeleteSubItemsFeature::hasDeletableSubItems(item)) continue;
RimSummaryPlotCollection* summaryPlotColl = dynamic_cast<RimSummaryPlotCollection*>(item);
if (summaryPlotColl)
{
summaryPlotColl->summaryPlots.deleteAllChildObjects();
summaryPlotColl->updateConnectedEditors();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDeleteSubItemsFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Delete Sub Items");
actionToSetup->setIcon(QIcon(":/Erase.png"));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicDeleteSubItemsFeature::hasDeletableSubItems(caf::PdmUiItem* uiItem)
{
RimSummaryPlotCollection* summaryPlotColl = dynamic_cast<RimSummaryPlotCollection*>(uiItem);
if (summaryPlotColl && summaryPlotColl->summaryPlots().size() > 0)
{
return true;
}
return false;
}

View File

@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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 PdmUiItem;
}
//==================================================================================================
///
//==================================================================================================
class RicDeleteSubItemsFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
private:
static bool hasDeletableSubItems(caf::PdmUiItem* uiItem);
};

View File

@ -446,6 +446,12 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
commandIds << "RicDeleteItemFeature";
}
if (caf::CmdFeatureManager::instance()->getCommandFeature("RicDeleteSubItemsFeature")->canFeatureBeExecuted())
{
commandIds << "Separator";
commandIds << "RicDeleteSubItemsFeature";
}
if (caf::CmdFeatureManager::instance()->getCommandFeature("RicWellPathDeleteFeature")->canFeatureBeExecuted())
{
// Special delete command for Well paths