mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#8859 AppFwk : Enable TableView as optional drop target
A TableView can receive drag/drop data. The drop operations finds the PdmObject for a row, and delegates handling of the drop operation to this object.
This commit is contained in:
parent
4ef1f73a58
commit
feb1c417c5
@ -9,6 +9,8 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class QMimeData;
|
||||||
|
|
||||||
namespace caf
|
namespace caf
|
||||||
{
|
{
|
||||||
class PdmObjectCapability;
|
class PdmObjectCapability;
|
||||||
@ -106,6 +108,9 @@ public:
|
|||||||
|
|
||||||
virtual void onChildAdded( caf::PdmFieldHandle* containerForNewObject ){};
|
virtual void onChildAdded( caf::PdmFieldHandle* containerForNewObject ){};
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
handleDroppedMimeData( const QMimeData* data, Qt::DropAction action, caf::PdmFieldHandle* destinationField ){};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addField( PdmFieldHandle* field, const QString& keyword );
|
void addField( PdmFieldHandle* field, const QString& keyword );
|
||||||
|
|
||||||
|
@ -164,6 +164,11 @@ void PdmUiTableViewEditor::configureAndUpdateUi( const QString& uiConfigName )
|
|||||||
QPalette myPalette( m_tableView->palette() );
|
QPalette myPalette( m_tableView->palette() );
|
||||||
myPalette.setColor( QPalette::Base, editorAttrib.baseColor );
|
myPalette.setColor( QPalette::Base, editorAttrib.baseColor );
|
||||||
m_tableView->setPalette( myPalette );
|
m_tableView->setPalette( myPalette );
|
||||||
|
|
||||||
|
// Drop target settings
|
||||||
|
m_tableView->setAcceptDrops( editorAttrib.enableDropTarget );
|
||||||
|
m_tableView->setDropIndicatorShown( editorAttrib.enableDropTarget );
|
||||||
|
m_tableModelPdm->enableDropTarget( editorAttrib.enableDropTarget );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tableModelPdm->setArrayFieldAndBuildEditors( childArrayFH, uiConfigName );
|
m_tableModelPdm->setArrayFieldAndBuildEditors( childArrayFH, uiConfigName );
|
||||||
|
@ -92,6 +92,7 @@ public:
|
|||||||
, minimumHeight( -1 )
|
, minimumHeight( -1 )
|
||||||
, alwaysEnforceResizePolicy( false )
|
, alwaysEnforceResizePolicy( false )
|
||||||
, resizePolicy( NO_AUTOMATIC_RESIZE )
|
, resizePolicy( NO_AUTOMATIC_RESIZE )
|
||||||
|
, enableDropTarget( false )
|
||||||
{
|
{
|
||||||
QPalette myPalette;
|
QPalette myPalette;
|
||||||
baseColor = myPalette.color( QPalette::Active, QPalette::Base );
|
baseColor = myPalette.color( QPalette::Active, QPalette::Base );
|
||||||
@ -106,6 +107,7 @@ public:
|
|||||||
QColor baseColor;
|
QColor baseColor;
|
||||||
bool alwaysEnforceResizePolicy;
|
bool alwaysEnforceResizePolicy;
|
||||||
ResizePolicy resizePolicy;
|
ResizePolicy resizePolicy;
|
||||||
|
bool enableDropTarget;
|
||||||
};
|
};
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -57,8 +57,9 @@ namespace caf
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
PdmUiTableViewQModel::PdmUiTableViewQModel( QWidget* parent )
|
PdmUiTableViewQModel::PdmUiTableViewQModel( QWidget* parent )
|
||||||
: QAbstractTableModel( parent )
|
: QAbstractTableModel( parent )
|
||||||
|
, m_pdmList( nullptr )
|
||||||
|
, m_dropTargetEnabled( false )
|
||||||
{
|
{
|
||||||
m_pdmList = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -141,6 +142,12 @@ Qt::ItemFlags PdmUiTableViewQModel::flags( const QModelIndex& index ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( m_dropTargetEnabled )
|
||||||
|
{
|
||||||
|
flagMask |= Qt::ItemIsDropEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
return flagMask;
|
return flagMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,6 +668,63 @@ void PdmUiTableViewQModel::createPersistentPushButtonWidgets( QTableView* tableV
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void PdmUiTableViewQModel::enableDropTarget( bool enable )
|
||||||
|
{
|
||||||
|
m_dropTargetEnabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool PdmUiTableViewQModel::dropMimeData( const QMimeData* data,
|
||||||
|
Qt::DropAction action,
|
||||||
|
int row,
|
||||||
|
int column,
|
||||||
|
const QModelIndex& parent )
|
||||||
|
{
|
||||||
|
// The receiving model index is specified by the parent. Find object and field from parent, and send QMimeData to
|
||||||
|
// this object
|
||||||
|
|
||||||
|
if ( !m_dropTargetEnabled ) return false;
|
||||||
|
|
||||||
|
auto pdmObject = pdmObjectForRow( parent.row() );
|
||||||
|
auto field = getField( parent );
|
||||||
|
|
||||||
|
if ( pdmObject )
|
||||||
|
{
|
||||||
|
pdmObject->handleDroppedMimeData( data, action, field );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
Qt::DropActions PdmUiTableViewQModel::supportedDropActions() const
|
||||||
|
{
|
||||||
|
return Qt::CopyAction | Qt::MoveAction | Qt::LinkAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool PdmUiTableViewQModel::canDropMimeData( const QMimeData* data,
|
||||||
|
Qt::DropAction action,
|
||||||
|
int row,
|
||||||
|
int column,
|
||||||
|
const QModelIndex& parent ) const
|
||||||
|
{
|
||||||
|
// This function can be extended to validate incoming QMimeData and see if this data is matching with the drop
|
||||||
|
// target. For now, all data is allowed to be dropped when drop target is enabled
|
||||||
|
|
||||||
|
return m_dropTargetEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -100,6 +100,16 @@ public:
|
|||||||
bool isRepresentingBoolean( const QModelIndex& index ) const;
|
bool isRepresentingBoolean( const QModelIndex& index ) const;
|
||||||
|
|
||||||
void createPersistentPushButtonWidgets( QTableView* tableView );
|
void createPersistentPushButtonWidgets( QTableView* tableView );
|
||||||
|
void enableDropTarget( bool enable );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent ) override;
|
||||||
|
Qt::DropActions supportedDropActions() const override;
|
||||||
|
bool canDropMimeData( const QMimeData* data,
|
||||||
|
Qt::DropAction action,
|
||||||
|
int row,
|
||||||
|
int column,
|
||||||
|
const QModelIndex& parent ) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int getFieldIndex( PdmFieldHandle* field ) const;
|
int getFieldIndex( PdmFieldHandle* field ) const;
|
||||||
@ -117,6 +127,7 @@ private:
|
|||||||
PdmPointer<PdmObjectHandle> m_ownerObject;
|
PdmPointer<PdmObjectHandle> m_ownerObject;
|
||||||
PdmChildArrayFieldHandle* m_pdmList;
|
PdmChildArrayFieldHandle* m_pdmList;
|
||||||
QString m_currentConfigName;
|
QString m_currentConfigName;
|
||||||
|
bool m_dropTargetEnabled;
|
||||||
|
|
||||||
std::map<QString, PdmUiFieldEditorHandle*> m_fieldEditors;
|
std::map<QString, PdmUiFieldEditorHandle*> m_fieldEditors;
|
||||||
std::vector<int> m_modelColumnIndexToFieldIndex;
|
std::vector<int> m_modelColumnIndexToFieldIndex;
|
||||||
|
Loading…
Reference in New Issue
Block a user