Skip to content

Commit

Permalink
MetadataAlgo : Add special case for bad promoted Spreadsheet metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Nov 1, 2023
1 parent b12d971 commit d0820da
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
30 changes: 30 additions & 0 deletions python/GafferUITest/SpreadsheetUITest.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,5 +884,35 @@ def testRowMetadataNotPromotedRedundantly( self ) :
for plug in Gaffer.Plug.RecursiveRange( promoted[1] ) :
self.assertEqual( Gaffer.Metadata.registeredValues( plug, Gaffer.Metadata.RegistrationTypes.Instance ), [] )

def testMetadataAlgoRemovesNonDefaultRowMetadata( self ) :

spreadsheet = Gaffer.Spreadsheet()
spreadsheet["rows"].addColumn( Gaffer.StringPlug( "column1" ) )
spreadsheet["rows"].addRows( 1 )

# Create Spreadsheet where non-default row has its own metadata that conflicts with the values
# that should be mirrored from the default row. It used to be possible for the user to get into
# this situation because we redundantly promoted metadata onto the non-default rows.

Gaffer.Metadata.registerValue( spreadsheet["rows"][0]["cells"][0], "spreadsheet:columnWidth", 100 )
Gaffer.Metadata.registerValue( spreadsheet["rows"][1]["cells"][0], "spreadsheet:columnWidth", 200 )
Gaffer.Metadata.registerValue( spreadsheet["rows"][0]["cells"][0], "spreadsheet:columnLabel", "Label 1" )
Gaffer.Metadata.registerValue( spreadsheet["rows"][1]["cells"][0], "spreadsheet:columnLabel", "Label 2" )

# Even though the non-default-row values are different to the default row ones, we still want
# `deregisterRedundantValues()` to clean them up, because having different column widths/labels
# on different rows is logically impossible.

Gaffer.MetadataAlgo.deregisterRedundantValues( spreadsheet["rows"] )

for row in spreadsheet["rows"] :
self.assertEqual( Gaffer.Metadata.value( row["cells"][0], "spreadsheet:columnWidth" ), 100 )
self.assertEqual( Gaffer.Metadata.value( row["cells"][0], "spreadsheet:columnLabel" ), "Label 1" )

self.assertEqual(
Gaffer.Metadata.registeredValues( spreadsheet["rows"][1]["cells"][0], Gaffer.Metadata.RegistrationTypes.Instance ),
[]
)

if __name__ == "__main__":
unittest.main()
20 changes: 20 additions & 0 deletions src/Gaffer/MetadataAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "Gaffer/Plug.h"
#include "Gaffer/Reference.h"
#include "Gaffer/ScriptNode.h"
#include "Gaffer/Spreadsheet.h"

#include "IECore/SimpleTypedData.h"

Expand All @@ -62,6 +63,8 @@ IECore::InternedString g_connectionColorKey( "connectionGadget:color" );
IECore::InternedString g_noduleColorKey( "nodule:color" );
const std::string g_annotationPrefix( "annotation:" );
const InternedString g_annotations( "annotations" );
const InternedString g_spreadsheetColumnWidth( "spreadsheet:columnWidth" );
const InternedString g_spreadsheetColumnLabel( "spreadsheet:columnLabel" );

void copy( const Gaffer::GraphComponent *src , Gaffer::GraphComponent *dst , IECore::InternedString key , bool overwrite )
{
Expand Down Expand Up @@ -769,6 +772,23 @@ void deregisterRedundantValues( GraphComponent *graphComponent )
// back to an identical value.
Gaffer::Metadata::deregisterValue( graphComponent, key );
}

// Special-case for badly promoted spreadsheet metadata of old.
if( key == g_spreadsheetColumnWidth || key == g_spreadsheetColumnLabel )
{
if( auto row = graphComponent->ancestor<Spreadsheet::RowPlug>() )
{
if( auto rows = row->parent<Spreadsheet::RowsPlug>() )
{
if( row != rows->defaultRow() )
{
// Override on non-default row doesn't agree with the value
// that should be mirrored from the default row. Remove it.
Gaffer::Metadata::deregisterValue( graphComponent, key );
}
}
}
}
}

for( auto &child : GraphComponent::Range( *graphComponent ) )
Expand Down

0 comments on commit d0820da

Please sign in to comment.