mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-08 23:23:01 -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 <vector>
|
||||
|
||||
class QMimeData;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmObjectCapability;
|
||||
@ -106,6 +108,9 @@ public:
|
||||
|
||||
virtual void onChildAdded( caf::PdmFieldHandle* containerForNewObject ){};
|
||||
|
||||
virtual void
|
||||
handleDroppedMimeData( const QMimeData* data, Qt::DropAction action, caf::PdmFieldHandle* destinationField ){};
|
||||
|
||||
protected:
|
||||
void addField( PdmFieldHandle* field, const QString& keyword );
|
||||
|
||||
|
@ -164,6 +164,11 @@ void PdmUiTableViewEditor::configureAndUpdateUi( const QString& uiConfigName )
|
||||
QPalette myPalette( m_tableView->palette() );
|
||||
myPalette.setColor( QPalette::Base, editorAttrib.baseColor );
|
||||
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 );
|
||||
|
@ -92,6 +92,7 @@ public:
|
||||
, minimumHeight( -1 )
|
||||
, alwaysEnforceResizePolicy( false )
|
||||
, resizePolicy( NO_AUTOMATIC_RESIZE )
|
||||
, enableDropTarget( false )
|
||||
{
|
||||
QPalette myPalette;
|
||||
baseColor = myPalette.color( QPalette::Active, QPalette::Base );
|
||||
@ -106,6 +107,7 @@ public:
|
||||
QColor baseColor;
|
||||
bool alwaysEnforceResizePolicy;
|
||||
ResizePolicy resizePolicy;
|
||||
bool enableDropTarget;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -57,8 +57,9 @@ namespace caf
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiTableViewQModel::PdmUiTableViewQModel( QWidget* 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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
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:
|
||||
int getFieldIndex( PdmFieldHandle* field ) const;
|
||||
@ -117,6 +127,7 @@ private:
|
||||
PdmPointer<PdmObjectHandle> m_ownerObject;
|
||||
PdmChildArrayFieldHandle* m_pdmList;
|
||||
QString m_currentConfigName;
|
||||
bool m_dropTargetEnabled;
|
||||
|
||||
std::map<QString, PdmUiFieldEditorHandle*> m_fieldEditors;
|
||||
std::vector<int> m_modelColumnIndexToFieldIndex;
|
||||
|
Loading…
Reference in New Issue
Block a user