Fix returning duplicates from Get{Row,Col}Selection()
The "unique" rows/columns arrays used in the implementation of these functions were not unique at all, as we happily added duplicates of the existing items into them. Fix this by checking that a row/column is not already present before adding it. Add a (previously failing) unit test checking that this works correctly with overlapping selected blocks.
This commit is contained in:
@@ -749,7 +749,8 @@ wxArrayInt wxGridSelection::GetRowSelection() const
|
||||
{
|
||||
for ( int r = block.GetTopRow(); r <= block.GetBottomRow(); ++r )
|
||||
{
|
||||
uniqueRows.Add(r);
|
||||
if ( uniqueRows.Index(r) == wxNOT_FOUND )
|
||||
uniqueRows.Add(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -779,7 +780,8 @@ wxArrayInt wxGridSelection::GetColSelection() const
|
||||
{
|
||||
for ( int c = block.GetLeftCol(); c <= block.GetRightCol(); ++c )
|
||||
{
|
||||
uniqueCols.Add(c);
|
||||
if ( uniqueCols.Index(c) == wxNOT_FOUND )
|
||||
uniqueCols.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -901,6 +901,12 @@ TEST_CASE_METHOD(GridTestCase, "Grid::SelectionMode", "[grid]")
|
||||
CHECK(selectedRows.Count() == 1);
|
||||
CHECK(selectedRows[0] == 3);
|
||||
|
||||
// Check that overlapping selection blocks are handled correctly.
|
||||
m_grid->ClearSelection();
|
||||
m_grid->SelectBlock(0, 0, 4, 1);
|
||||
m_grid->SelectBlock(2, 0, 6, 1, true /* add to selection */);
|
||||
CHECK( m_grid->GetSelectedRows().size() == 7 );
|
||||
|
||||
CHECK(m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user