From e7ac68d40972065dc54a94d53ae14319cba3fc7a Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Thu, 11 Apr 2024 19:37:25 +0300 Subject: [PATCH] Support alternating table row colors in SCH_PIN_TABLE_DATA_MODEL. See https://gitlab.com/kicad/code/kicad/-/issues/17482 --- eeschema/dialogs/dialog_symbol_properties.cpp | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index 28e361b0c9..48a5c2ae2d 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -195,26 +195,55 @@ public: } } - wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind ) override + wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) override { + // This is needed to support alternating row colors + auto enhanceAttr = [this, &aRow, &aCol, + &aKind]( wxGridCellAttr* aInputAttr ) -> wxGridCellAttr* + { + if( aInputAttr == nullptr ) + return nullptr; + + wxGridCellAttr* attr = aInputAttr; + + if( wxGridCellAttrProvider* provider = GetAttrProvider() ) + { + wxGridCellAttr* providerAttr = provider->GetAttr( aRow, aCol, aKind ); + + if( providerAttr ) + { + attr = new wxGridCellAttr; + attr->SetKind( wxGridCellAttr::Merged ); + + attr->MergeWith( aInputAttr ); + aInputAttr->DecRef(); + + attr->MergeWith( providerAttr ); + providerAttr->DecRef(); + } + } + + return attr; + }; + switch( aCol ) { case COL_NUMBER: case COL_BASE_NAME: m_readOnlyAttr->IncRef(); - return m_readOnlyAttr; + return enhanceAttr( m_readOnlyAttr ); case COL_ALT_NAME: m_nameAttrs[ aRow ]->IncRef(); - return m_nameAttrs[ aRow ]; + return enhanceAttr( m_nameAttrs[ aRow ] ); case COL_TYPE: m_typeAttr->IncRef(); - return m_typeAttr; + return enhanceAttr( m_typeAttr ); case COL_SHAPE: m_shapeAttr->IncRef(); - return m_shapeAttr; + return enhanceAttr( m_shapeAttr ); default: wxFAIL;