From fbc433deaacccaf2d3b16aa0dc34dcfa52d9cb3f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 10 Mar 2024 21:23:08 +0000 Subject: [PATCH] Make sure to initialize cell start location. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17379 --- eeschema/tools/sch_edit_table_tool.cpp | 3 ++- include/tool/edit_table_tool_base.h | 30 ++++++++++++++++++++++++++ pcbnew/tools/pcb_edit_table_tool.cpp | 3 ++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/eeschema/tools/sch_edit_table_tool.cpp b/eeschema/tools/sch_edit_table_tool.cpp index fa1704109d..66d6fb2444 100644 --- a/eeschema/tools/sch_edit_table_tool.cpp +++ b/eeschema/tools/sch_edit_table_tool.cpp @@ -85,7 +85,8 @@ SCH_TABLECELL* SCH_EDIT_TABLE_TOOL::copyCell( SCH_TABLECELL* aSource ) { SCH_TABLECELL* cell = new SCH_TABLECELL(); - cell->SetEnd( aSource->GetEnd() - aSource->GetStart() ); + cell->SetStart( aSource->GetStart() ); + cell->SetEnd( aSource->GetEnd() ); cell->SetFillMode( aSource->GetFillMode() ); cell->SetFillColor( aSource->GetFillColor() ); diff --git a/include/tool/edit_table_tool_base.h b/include/tool/edit_table_tool_base.h index 0384978d88..b2ac42f666 100644 --- a/include/tool/edit_table_tool_base.h +++ b/include/tool/edit_table_tool_base.h @@ -133,6 +133,7 @@ protected: int row = topmost->GetRow(); T_TABLE* table = static_cast( topmost->GetParent() ); T_COMMIT commit( getToolMgr() ); + VECTOR2I pos = table->GetPosition(); // Make a copy of the source row before things start moving around std::vector sources; @@ -152,8 +153,11 @@ protected: for( int afterRow = table->GetRowCount() - 1; afterRow > row; afterRow-- ) table->SetRowHeight( afterRow, table->GetRowHeight( afterRow - 1 ) ); + table->SetPosition( pos ); table->Normalize(); + getToolMgr()->PostEvent( EVENTS::SelectedEvent ); + commit.Push( _( "Add Row Above" ) ); return 0; @@ -181,6 +185,7 @@ protected: int row = bottommost->GetRow(); T_TABLE* table = static_cast( bottommost->GetParent() ); T_COMMIT commit( getToolMgr() ); + VECTOR2I pos = table->GetPosition(); // Make a copy of the source row before things start moving around std::vector sources; @@ -200,8 +205,11 @@ protected: for( int afterRow = table->GetRowCount() - 1; afterRow > row; afterRow-- ) table->SetRowHeight( afterRow, table->GetRowHeight( afterRow - 1 ) ); + table->SetPosition( pos ); table->Normalize(); + getToolMgr()->PostEvent( EVENTS::SelectedEvent ); + commit.Push( _( "Add Row Below" ) ); return 0; @@ -227,6 +235,7 @@ protected: T_TABLE* table = static_cast( leftmost->GetParent() ); int rowCount = table->GetRowCount(); T_COMMIT commit( getToolMgr() ); + VECTOR2I pos = table->GetPosition(); // Make a copy of the source column before things start moving around std::vector sources; @@ -247,8 +256,11 @@ protected: for( int afterCol = table->GetColCount() - 1; afterCol > col; afterCol-- ) table->SetColWidth( afterCol, table->GetColWidth( afterCol - 1 ) ); + table->SetPosition( pos ); table->Normalize(); + getToolMgr()->PostEvent( EVENTS::SelectedEvent ); + commit.Push( _( "Add Column Before" ) ); return 0; @@ -274,6 +286,7 @@ protected: T_TABLE* table = static_cast( rightmost->GetParent() ); int rowCount = table->GetRowCount(); T_COMMIT commit( getToolMgr() ); + VECTOR2I pos = table->GetPosition(); // Make a copy of the source column before things start moving around std::vector sources; @@ -294,8 +307,11 @@ protected: for( int afterCol = table->GetColCount() - 1; afterCol > col; afterCol-- ) table->SetColWidth( afterCol, table->GetColWidth( afterCol - 1 ) ); + table->SetPosition( pos ); table->Normalize(); + getToolMgr()->PostEvent( EVENTS::SelectedEvent ); + commit.Push( _( "Add Column After" ) ); return 0; @@ -343,6 +359,8 @@ protected: { commit.Modify( table, getScreen() ); + VECTOR2I pos = table->GetPosition(); + clearSelection(); table->DeleteMarkedCells(); @@ -359,7 +377,10 @@ protected: table->SetRowHeight( row, table->GetRowHeight( row + offset ) ); } + table->SetPosition( pos ); table->Normalize(); + + getToolMgr()->PostEvent( EVENTS::SelectedEvent ); } if( deleted.size() > 1 ) @@ -412,6 +433,8 @@ protected: { commit.Modify( table, getScreen() ); + VECTOR2I pos = table->GetPosition(); + clearSelection(); table->DeleteMarkedCells(); table->SetColCount( table->GetColCount() - deleted.size() ); @@ -429,7 +452,10 @@ protected: table->SetColWidth( col, table->GetColWidth( col + offset ) ); } + table->SetPosition( pos ); table->Normalize(); + + getToolMgr()->PostEvent( EVENTS::SelectedEvent ); } if( deleted.size() > 1 ) @@ -504,6 +530,8 @@ protected: table->Normalize(); commit.Push( _( "Merge Cells" ) ); + getToolMgr()->PostEvent( EVENTS::SelectedEvent ); + return 0; } @@ -543,6 +571,8 @@ protected: table->Normalize(); commit.Push( _( "Unmerge Cells" ) ); + getToolMgr()->PostEvent( EVENTS::SelectedEvent ); + return 0; } diff --git a/pcbnew/tools/pcb_edit_table_tool.cpp b/pcbnew/tools/pcb_edit_table_tool.cpp index 21cdf1f13f..cb306a9baf 100644 --- a/pcbnew/tools/pcb_edit_table_tool.cpp +++ b/pcbnew/tools/pcb_edit_table_tool.cpp @@ -49,7 +49,8 @@ PCB_TABLECELL* PCB_EDIT_TABLE_TOOL::copyCell( PCB_TABLECELL* aSource ) { PCB_TABLECELL* cell = new PCB_TABLECELL( aSource->GetParent() ); - cell->SetEnd( aSource->GetEnd() - aSource->GetStart() ); + cell->SetStart( aSource->GetStart() ); + cell->SetEnd( aSource->GetEnd() ); return cell; }