Skip to content

Commit

Permalink
Merge pull request #6257 from murraystevenson/inspectorColumnDrag
Browse files Browse the repository at this point in the history
Inspector direct editing
  • Loading branch information
murraystevenson authored Feb 14, 2025
2 parents 5bab8f9 + 488fd35 commit a3613e1
Show file tree
Hide file tree
Showing 21 changed files with 1,167 additions and 141 deletions.
7 changes: 6 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
1.5.x.x (relative to 1.5.5.0)
=======

Features
--------

- AttributeEditor, LightEditor, RenderPassEditor : Added drag and drop editing. Edits can be created or updated by dropping a value into a cell. Cells representing a set expression or string array can be modified by holding <kbd>Shift</kbd> to append to an existing edit, or <kbd>Control</kbd> may be held to remove from an existing edit.

Fixes
-----

Expand All @@ -12,7 +17,7 @@ API
- SceneAlgo :
- Added `parallelReduceLocations()` for implementing functions that need to combine results while traversing a ScenePlug.
- Added `hierarchyHash()` for hashing all children of a scene location.

- PathColumn : Added `dragEnterSignal()`, `dragMoveSignal()`, `dragLeaveSignal()` and `dropSignal()`.

1.5.5.0 (relative to 1.5.4.1)
=======
Expand Down
2 changes: 1 addition & 1 deletion include/GafferSceneUI/Private/AttributeInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class GAFFERSCENEUI_API AttributeInspector : public Inspector
IECore::ConstObjectPtr value( const GafferScene::SceneAlgo::History *history) const override;
IECore::ConstObjectPtr fallbackValue( const GafferScene::SceneAlgo::History *history, std::string &description ) const override;
Gaffer::ValuePlugPtr source( const GafferScene::SceneAlgo::History *history, std::string &editWarning ) const override;
EditFunctionOrFailure editFunction( Gaffer::EditScope *scope, const GafferScene::SceneAlgo::History *history) const override;
AcquireEditFunctionOrFailure acquireEditFunction( Gaffer::EditScope *scope, const GafferScene::SceneAlgo::History *history ) const override;

bool attributeExists() const;

Expand Down
36 changes: 29 additions & 7 deletions include/GafferSceneUI/Private/Inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class GAFFERSCENEUI_API Inspector : public IECore::RefCounted, public Gaffer::Si
/// history class?
virtual Gaffer::ValuePlugPtr source( const GafferScene::SceneAlgo::History *history, std::string &editWarning ) const;

using EditFunction = std::function<Gaffer::ValuePlugPtr ( bool createIfNecessary )>;
using EditFunctionOrFailure = std::variant<EditFunction, std::string>;
using AcquireEditFunction = std::function<Gaffer::ValuePlugPtr ( bool createIfNecessary )>;
using AcquireEditFunctionOrFailure = std::variant<AcquireEditFunction, std::string>;
/// Should be implemented to return a function that will acquire
/// an edit from the EditScope at the specified point in the history.
/// If this is not possible, should return an error explaining why
Expand All @@ -181,7 +181,7 @@ class GAFFERSCENEUI_API Inspector : public IECore::RefCounted, public Gaffer::Si
/// > Note : Where an EditScope already contains an edit, it is expected
/// > that this will be dealt with in `source()`, returning a result
/// > that edits the processor itself.
virtual EditFunctionOrFailure editFunction( Gaffer::EditScope *editScope, const GafferScene::SceneAlgo::History *history ) const;
virtual AcquireEditFunctionOrFailure acquireEditFunction( Gaffer::EditScope *editScope, const GafferScene::SceneAlgo::History *history ) const;

using DisableEditFunction = std::function<void ()>;
using DisableEditFunctionOrFailure = std::variant<DisableEditFunction, std::string>;
Expand All @@ -191,6 +191,18 @@ class GAFFERSCENEUI_API Inspector : public IECore::RefCounted, public Gaffer::Si
/// Called with `history->context` as the current context.
virtual DisableEditFunctionOrFailure disableEditFunction( Gaffer::ValuePlug *plug, const GafferScene::SceneAlgo::History *history ) const;

using CanEditFunction = std::function<bool ( const Gaffer::ValuePlug *plug, const IECore::Object *value, std::string &failureReason )>;
/// Can be implemented to return a function that will return whether
/// `value` can be set on `plug`. If `value` cannot be set on `plug`,
/// `failureReason` should provide the reason why.
virtual CanEditFunction canEditFunction( const GafferScene::SceneAlgo::History *history ) const;

using EditFunction = std::function<void ( Gaffer::ValuePlug *plug, const IECore::Object *value )>;
/// Can be implemented to return a function that will directly
/// edit `plug` to set `value`. Called with `history->context` as the
/// current context.
virtual EditFunction editFunction( const GafferScene::SceneAlgo::History *history ) const;

protected :

Gaffer::EditScope *targetEditScope() const;
Expand Down Expand Up @@ -340,8 +352,9 @@ class GAFFERSCENEUI_API Inspector::Result : public IECore::RefCounted
/// and `false` otherwise.
bool editable() const;
/// If `editable()` returns false, returns the reason why.
/// This should be displayed to the user.
std::string nonEditableReason() const;
/// If `canEdit( value )` returns false, `nonEditableReason( value )`
/// returns the reason why. This should be displayed to the user.
std::string nonEditableReason( const IECore::Object *value = nullptr ) const;

/// Returns a plug that can be used to edit the property
/// represented by this inspector, creating it if necessary.
Expand All @@ -361,6 +374,14 @@ class GAFFERSCENEUI_API Inspector::Result : public IECore::RefCounted
/// `!canDisableEdit()`
void disableEdit() const;

/// Returns whether a direct edit can be made with the
/// specified value.
bool canEdit( const IECore::Object *value, std::string &failureReason ) const;
/// Applies a direct edit with the specified value.
/// Calls `acquireEdit()` to ensure a plug exists to
/// receive the value.
void edit( const IECore::Object *value ) const;

private :

Result( const IECore::ConstObjectPtr &value, const Gaffer::EditScopePtr &editScope );
Expand All @@ -376,10 +397,11 @@ class GAFFERSCENEUI_API Inspector::Result : public IECore::RefCounted

struct Editors
{
/// \todo Rename to `acquireEditFunction`?
EditFunctionOrFailure editFunction;
AcquireEditFunctionOrFailure acquireEditFunction;
std::string editWarning;
DisableEditFunctionOrFailure disableEditFunction;
CanEditFunction canEditFunction;
EditFunction editFunction;
};

std::optional<Editors> m_editors;
Expand Down
2 changes: 1 addition & 1 deletion include/GafferSceneUI/Private/OptionInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class GAFFERSCENEUI_API OptionInspector : public Inspector
IECore::ConstObjectPtr value( const GafferScene::SceneAlgo::History *history ) const override;
IECore::ConstObjectPtr fallbackValue( const GafferScene::SceneAlgo::History *history, std::string &description ) const override;
Gaffer::ValuePlugPtr source( const GafferScene::SceneAlgo::History *history, std::string &editWarning ) const override;
EditFunctionOrFailure editFunction( Gaffer::EditScope *scope, const GafferScene::SceneAlgo::History *history ) const override;
AcquireEditFunctionOrFailure acquireEditFunction( Gaffer::EditScope *scope, const GafferScene::SceneAlgo::History *history ) const override;

private :

Expand Down
2 changes: 1 addition & 1 deletion include/GafferSceneUI/Private/ParameterInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class GAFFERSCENEUI_API ParameterInspector : public AttributeInspector
IECore::ConstObjectPtr value( const GafferScene::SceneAlgo::History *history ) const override;
IECore::ConstObjectPtr fallbackValue( const GafferScene::SceneAlgo::History *history, std::string &description ) const override;
Gaffer::ValuePlugPtr source( const GafferScene::SceneAlgo::History *history, std::string &editWarning ) const override;
EditFunctionOrFailure editFunction( Gaffer::EditScope *editScope, const GafferScene::SceneAlgo::History *history ) const override;
AcquireEditFunctionOrFailure acquireEditFunction( Gaffer::EditScope *editScope, const GafferScene::SceneAlgo::History *history ) const override;

const IECoreScene::ShaderNetwork::Parameter m_parameter;

Expand Down
13 changes: 3 additions & 10 deletions include/GafferSceneUI/Private/SetMembershipInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ class GAFFERSCENEUI_API SetMembershipInspector : public Inspector
IECore::InternedString setName
);

/// Convenience method to acquire an edit from `inspection` and
/// edit the set membership to include or exclude `path`. Returns true
/// if an edit was made, false otherwise.
bool editSetMembership(
const Result *inspection,
const GafferScene::ScenePlug::ScenePath &path,
GafferScene::EditScopeAlgo::SetMembership setMembership
) const;

IE_CORE_DECLAREMEMBERPTR( SetMembershipInspector );

protected :
Expand All @@ -81,8 +72,10 @@ class GAFFERSCENEUI_API SetMembershipInspector : public Inspector
/// appropriate row of a set membership processor spreadsheet or `nullptr` if none of
/// those are found.
Gaffer::ValuePlugPtr source( const GafferScene::SceneAlgo::History *history, std::string &editWarning ) const override;
EditFunctionOrFailure editFunction( Gaffer::EditScope *scope, const GafferScene::SceneAlgo::History *history ) const override;
AcquireEditFunctionOrFailure acquireEditFunction( Gaffer::EditScope *scope, const GafferScene::SceneAlgo::History *history ) const override;
DisableEditFunctionOrFailure disableEditFunction( Gaffer::ValuePlug *plug, const GafferScene::SceneAlgo::History *history ) const override;
CanEditFunction canEditFunction( const GafferScene::SceneAlgo::History *history ) const override;
EditFunction editFunction( const GafferScene::SceneAlgo::History *history ) const override;

private :

Expand Down
9 changes: 9 additions & 0 deletions include/GafferUI/PathColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
#pragma once

#include "GafferUI/ButtonEvent.h"
#include "GafferUI/DragDropEvent.h"
#include "GafferUI/EventSignalCombiner.h"
#include "GafferUI/Export.h"
#include "GafferUI/Gadget.h"
#include "GafferUI/KeyEvent.h"

#include "Gaffer/Path.h"
Expand Down Expand Up @@ -76,6 +78,7 @@ class GAFFERUI_API PathColumn : public IECore::RefCounted, public Gaffer::Signal
};

explicit PathColumn( SizeMode sizeMode = Default );
~PathColumn();

/// Returns the current column size mode.
SizeMode getSizeMode() const;
Expand Down Expand Up @@ -172,6 +175,12 @@ class GAFFERUI_API PathColumn : public IECore::RefCounted, public Gaffer::Signal
KeySignal &keyPressSignal();
KeySignal &keyReleaseSignal();

using DragDropSignal = Gaffer::Signals::Signal<bool ( PathColumn &column, Gaffer::Path &path, PathListingWidget &widget, const DragDropEvent &event ), EventSignalCombiner<bool>>;
DragDropSignal &dragEnterSignal();
DragDropSignal &dragMoveSignal();
DragDropSignal &dragLeaveSignal();
DragDropSignal &dropSignal();

/// Creation
/// ========

Expand Down
Loading

0 comments on commit a3613e1

Please sign in to comment.