#1190 Improved copy command feature

This commit is contained in:
Magne Sjaastad 2017-02-06 13:33:56 +01:00
parent c28ed7f206
commit 8bc1a3ee3d
3 changed files with 114 additions and 4 deletions

View File

@ -19,8 +19,19 @@
#include "RicCopyReferencesToClipboardFeature.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimGeoMechView.h"
#include "RimMimeData.h"
#include "RimSummaryCurve.h"
#include "RimSummaryCurveFilter.h"
#include "RimSummaryPlot.h"
#include "RimWellAllocationPlot.h"
#include "RimWellLogCurve.h"
#include "RimWellLogPlot.h"
#include "RimWellLogTrack.h"
#include "cafPdmObject.h"
#include "cafPdmUiItem.h"
#include "cafSelectionManager.h"
@ -40,7 +51,7 @@ CAF_CMD_SOURCE_INIT(RicCopyReferencesToClipboardFeature, "RicCopyReferencesToCli
//--------------------------------------------------------------------------------------------------
bool RicCopyReferencesToClipboardFeature::isCommandEnabled()
{
return true;
return isAnyCopyableObjectSelected();
}
//--------------------------------------------------------------------------------------------------
@ -48,8 +59,22 @@ bool RicCopyReferencesToClipboardFeature::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicCopyReferencesToClipboardFeature::onActionTriggered(bool isChecked)
{
if (!isAnyCopyableObjectSelected()) return;
std::vector<QString> referenceList;
SelectionManager::instance()->selectionAsReferences(referenceList);
std::vector<PdmObject*> selectedFormationNamesCollObjs;
caf::SelectionManager::instance()->objectsByType(&selectedFormationNamesCollObjs);
for (PdmObject* pdmObject : selectedFormationNamesCollObjs)
{
if (RicCopyReferencesToClipboardFeature::isCopyOfObjectSupported(pdmObject))
{
QString itemRef = PdmReferenceHelper::referenceFromRootToObject(SelectionManager::instance()->pdmRootObject(), pdmObject);
referenceList.push_back(itemRef);
}
}
MimeDataWithReferences* myObject = new MimeDataWithReferences;
myObject->setReferences(referenceList);
@ -71,4 +96,74 @@ void RicCopyReferencesToClipboardFeature::setupActionLook(QAction* actionToSetup
actionToSetup->setShortcuts(QKeySequence::Copy);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCopyReferencesToClipboardFeature::isAnyCopyableObjectSelected()
{
std::vector<PdmObject*> selectedFormationNamesCollObjs;
caf::SelectionManager::instance()->objectsByType(&selectedFormationNamesCollObjs);
for (PdmObject* pdmObject : selectedFormationNamesCollObjs)
{
if (RicCopyReferencesToClipboardFeature::isCopyOfObjectSupported(pdmObject))
{
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCopyReferencesToClipboardFeature::isCopyOfObjectSupported(PdmObject* pdmObject)
{
RimWellAllocationPlot* wellAllocPlot = nullptr;
pdmObject->firstAncestorOrThisOfType(wellAllocPlot);
if (dynamic_cast<RimGeoMechView*>(pdmObject))
{
return true;
}
else if (dynamic_cast<RimEclipseView*>(pdmObject))
{
return true;
}
else if (dynamic_cast<RimEclipseCase*>(pdmObject))
{
return true;
}
else if (dynamic_cast<RimSummaryPlot*>(pdmObject))
{
return true;
}
else if (dynamic_cast<RimSummaryCurve*>(pdmObject))
{
return true;
}
else if (dynamic_cast<RimSummaryCurveFilter*>(pdmObject))
{
return true;
}
else if (dynamic_cast<RimWellLogCurve*>(pdmObject))
{
if (!wellAllocPlot) return true;
}
else if (dynamic_cast<RimWellLogTrack*>(pdmObject))
{
if (!wellAllocPlot) return true;
}
else if (dynamic_cast<RimWellLogPlot*>(pdmObject))
{
if (!wellAllocPlot) return true;
}
return false;
}
} // end namespace caf

View File

@ -25,6 +25,8 @@
namespace caf
{
class PdmObject;
//==================================================================================================
///
//==================================================================================================
@ -37,6 +39,10 @@ protected:
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
private:
static bool isAnyCopyableObjectSelected();
static bool isCopyOfObjectSupported(PdmObject* pdmObject);
};

View File

@ -372,6 +372,17 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
// Command supporting multiple selected objects
if (uiItems.size() > 0)
{
// Work in progress -- Start
// All commands should be aware of selection of multiple objects
// Based on the selection, the command feature can decide if the command
// can be executed, communicated by isCommandEnabled(). When a command feature
// is aware of multiple selected items, move the command to this list
// without using dyncamic_cast.
commandIds << "RicCopyReferencesToClipboardFeature";
// Work in progress -- End
caf::PdmUiItem* uiItem = uiItems[0];
if (dynamic_cast<RimWellLogFileChannel*>(uiItem))
{
@ -388,7 +399,6 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
else if (dynamic_cast<RimSummaryCurve*>(uiItem) ||
dynamic_cast<RimSummaryCurveFilter*>(uiItem) )
{
commandIds << "RicCopyReferencesToClipboardFeature";
commandIds << "RicSummaryCurveSwitchAxisFeature";
}
@ -396,7 +406,6 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
dynamic_cast<RimWellLogTrack*>(uiItem) ||
dynamic_cast<RimWellLogPlot*>(uiItem))
{
commandIds << "RicCopyReferencesToClipboardFeature";
commandIds << "RicExportToLasFileFeature";
commandIds << "RicChangeDataSourceFeature";
}