Skip to content

Commit

Permalink
PathListingWidget : Display BoolData as checkboxes
Browse files Browse the repository at this point in the history
This improves presentation in the LightEditor and RenderPassEditor in particular.
  • Loading branch information
johnhaddon committed Mar 4, 2024
1 parent c1b975f commit 2409d41
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Improvements
- Grouped display can be enabled by default in a startup file by using `Gaffer.Metadata.registerValue( GafferSceneUI.RenderPassEditor.Settings, "displayGrouped", "userDefault", IECore.BoolData( True ) )`.
- Dragging cells selected from the "Name" column now provides a list of the selected render pass names, rather than their paths.
- Disabled render pass names are now dimmed to more clearly indicate their state.
- RenderPassEditor, LightEditor, PathListingWidget : Boolean values are now displayed as checkboxes rather than `0` or `1`.

API
---
Expand Down
30 changes: 29 additions & 1 deletion src/GafferUIModule/PathListingWidgetBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,27 @@ QVariant dataToVariant( const IECore::Data *value, int role )
}
}

if( role == Qt::CheckStateRole )
{
if( auto d = IECore::runTimeCast<const IECore::BoolData>( value ) )
{
return d->readable() ? Qt::Checked : Qt::Unchecked;
}
return QVariant();
}

switch( value->typeId() )
{
case IECore::StringDataTypeId :
return static_cast<const IECore::StringData *>( value )->readable().c_str();
case IECore::BoolDataTypeId :
if( role == Qt::DisplayRole )
{
// We'll be displaying this as a checkbox via CheckStateRole - no
// need to display the value as text as well.
return QVariant();
}
return static_cast<const IECore::BoolData *>( value )->readable();
case IECore::IntDataTypeId :
return static_cast<const IECore::IntData *>( value )->readable();
case IECore::UIntDataTypeId :
Expand Down Expand Up @@ -339,11 +356,15 @@ QVariant dataToVariant( const IECore::Data *value, int role )
struct CellVariants
{

static constexpr Qt::ItemDataRole SortRole = Qt::UserRole;

CellVariants( const GafferUI::PathColumn::CellData &cellData )
: m_display( dataToVariant( cellData.value.get(), Qt::DisplayRole ) ),
m_checkState( dataToVariant( cellData.value.get(), Qt::CheckStateRole ) ),
m_decoration( dataToVariant( cellData.icon.get(), Qt::DecorationRole ) ),
m_background( dataToVariant( cellData.background.get(), Qt::BackgroundRole ) ),
m_toolTip( dataToVariant( cellData.toolTip.get(), Qt::ToolTipRole ) ),
m_sort( m_display.isValid() ? m_display : m_checkState ),
m_foreground( dataToVariant( cellData.foreground.get(), Qt::ForegroundRole ) )
{
}
Expand All @@ -358,12 +379,16 @@ struct CellVariants
{
case Qt::DisplayRole :
return m_display;
case Qt::CheckStateRole :
return m_checkState;
case Qt::DecorationRole :
return m_decoration;
case Qt::BackgroundRole :
return m_background;
case Qt::ToolTipRole :
return m_toolTip;
case SortRole :
return m_sort;
case Qt::ForegroundRole :
return m_foreground;
default :
Expand All @@ -375,6 +400,7 @@ struct CellVariants
{
return
m_display == rhs.m_display &&
m_checkState == rhs.m_checkState &&
m_decoration == rhs.m_decoration &&
m_background == rhs.m_background &&
m_toolTip == rhs.m_toolTip &&
Expand All @@ -385,9 +411,11 @@ struct CellVariants
private :

QVariant m_display;
QVariant m_checkState;
QVariant m_decoration;
QVariant m_background;
QVariant m_toolTip;
QVariant m_sort;
QVariant m_foreground;

};
Expand Down Expand Up @@ -1280,7 +1308,7 @@ class PathModel : public QAbstractItemModel
{
return QVariant();
}
return data[model->m_sortColumn].variant( Qt::DisplayRole );
return data[model->m_sortColumn].variant( CellVariants::SortRole );
}

// Updates data and returns the value that should be used for sorting.
Expand Down

0 comments on commit 2409d41

Please sign in to comment.