#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