Merge pull request #8459 from OPM/8458-summary-drop-target

Closes #8458
This commit is contained in:
Magne Sjaastad
2022-01-21 14:32:51 +01:00
committed by GitHub
parent b0470d38ee
commit d5b17976ed
16 changed files with 272 additions and 25 deletions

View File

@@ -50,6 +50,8 @@ class PdmUiDragDropInterface
public:
virtual ~PdmUiDragDropInterface() = 0;
static QString mimeTypeForObjectReferenceList() { return "ObjectReferenceList"; }
protected:
friend class PdmUiTreeViewQModel;
friend class PdmUiTreeViewWidget;

View File

@@ -45,6 +45,7 @@
#include "cafPdmUiTreeViewEditor.h"
#include <QDragMoveEvent>
#include <QMimeData>
#include <QTreeView>
namespace caf
@@ -852,7 +853,35 @@ QMimeData* PdmUiTreeViewQModel::mimeData( const QModelIndexList& indexes ) const
{
if ( m_dragDropInterface )
{
return m_dragDropInterface->mimeData( indexes );
QStringList objectPaths;
for ( const auto& i : indexes )
{
auto uiObjHandle = dynamic_cast<PdmUiObjectHandle*>( uiItemFromModelIndex( i ) );
if ( uiObjHandle && uiObjHandle->objectHandle() )
{
auto objHandle = uiObjHandle->objectHandle();
auto root = PdmReferenceHelper::findRoot( objHandle );
auto path = PdmReferenceHelper::referenceFromRootToObject( root, objHandle );
objectPaths.push_back( path );
}
}
auto mimeDataObject = m_dragDropInterface->mimeData( indexes );
QByteArray data;
QDataStream dataStreamWrite( &data, QIODevice::WriteOnly );
dataStreamWrite << objectPaths;
QString mimeType = PdmUiDragDropInterface::mimeTypeForObjectReferenceList();
// The QModelIndexList is useful for drag and drop internally in one tree widget. If we
// drag from a tree into other widgets, it is useful to have the full path as text from root to object.
mimeDataObject->setData( mimeType, data );
return mimeDataObject;
}
else
{