Show more detailed information about selection in the grid sample
Show the selected cells/rows/columns/blocks instead of just showing their number, as we now have an efficient (i.e. taking time proportional to the number of selected blocks and not to the number of the individual cells, rows or columns) way of doing this. See #2576.
This commit is contained in:
@@ -1220,32 +1220,68 @@ void GridFrame::SetCornerLabelValue( wxCommandEvent& WXUNUSED(ev) )
|
|||||||
|
|
||||||
void GridFrame::ShowSelection( wxCommandEvent& WXUNUSED(ev) )
|
void GridFrame::ShowSelection( wxCommandEvent& WXUNUSED(ev) )
|
||||||
{
|
{
|
||||||
switch ( grid->GetSelectionMode() )
|
int count = 0;
|
||||||
|
wxString desc;
|
||||||
|
const wxGridSelectionRange& sel = grid->GetSelectionRange();
|
||||||
|
for ( wxGridSelectionRange::iterator it = sel.begin();
|
||||||
|
it != sel.end();
|
||||||
|
++it, ++count )
|
||||||
{
|
{
|
||||||
case wxGrid::wxGridSelectCells:
|
const wxGridBlockCoords& b = *it;
|
||||||
wxLogMessage("%zu individual cells and "
|
|
||||||
"%zu blocks of contiguous cells selected",
|
|
||||||
grid->GetSelectedCells().size(),
|
|
||||||
grid->GetSelectionBlockTopLeft().size());
|
|
||||||
return;
|
|
||||||
|
|
||||||
case wxGrid::wxGridSelectRows:
|
wxString blockDesc;
|
||||||
case wxGrid::wxGridSelectColumns:
|
if ( b.GetLeftCol() == 0 &&
|
||||||
case wxGrid::wxGridSelectRowsOrColumns:
|
b.GetRightCol() == grid->GetNumberCols() - 1 )
|
||||||
const wxArrayInt& rows = grid->GetSelectedRows();
|
{
|
||||||
if ( !rows.empty() )
|
if ( b.GetTopRow() == b.GetBottomRow() )
|
||||||
wxLogMessage("%zu rows selected", rows.size());
|
blockDesc.Printf("row %d", b.GetTopRow() + 1);
|
||||||
|
else
|
||||||
|
blockDesc.Printf("rows %d..%d",
|
||||||
|
b.GetTopRow() + 1, b.GetBottomRow() + 1);
|
||||||
|
}
|
||||||
|
else if ( b.GetTopRow() == 0 &&
|
||||||
|
b.GetBottomRow() == grid->GetNumberRows() - 1 )
|
||||||
|
{
|
||||||
|
if ( b.GetLeftCol() == b.GetRightCol() )
|
||||||
|
blockDesc.Printf("column %d", b.GetLeftCol() + 1);
|
||||||
|
else
|
||||||
|
blockDesc.Printf("columns %d..%d",
|
||||||
|
b.GetLeftCol() + 1,
|
||||||
|
b.GetRightCol() + 1);
|
||||||
|
}
|
||||||
|
else if ( b.GetTopRow() == b.GetBottomRow() &&
|
||||||
|
b.GetLeftCol() == b.GetRightCol() )
|
||||||
|
{
|
||||||
|
blockDesc.Printf("cell R%dC%d",
|
||||||
|
b.GetTopRow() + 1, b.GetLeftCol() + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
blockDesc.Printf("block R%dC%d - R%dC%d",
|
||||||
|
b.GetTopRow() + 1,
|
||||||
|
b.GetLeftCol() + 1,
|
||||||
|
b.GetBottomRow() + 1,
|
||||||
|
b.GetRightCol() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
const wxArrayInt& cols = grid->GetSelectedCols();
|
if ( count )
|
||||||
if ( !cols.empty() )
|
desc += "\n\t";
|
||||||
wxLogMessage("%zu columns selected", rows.size());
|
desc += blockDesc;
|
||||||
|
|
||||||
if ( rows.empty() && cols.empty() )
|
|
||||||
wxLogMessage("No selection");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxLogError("Unknown grid selection mode.");
|
switch ( count )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
wxLogMessage("No selection");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
wxLogMessage("Selection: %s", desc);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
wxLogMessage("%d selected blocks:\n\t%s", count, desc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridFrame::SelectCells( wxCommandEvent& WXUNUSED(ev) )
|
void GridFrame::SelectCells( wxCommandEvent& WXUNUSED(ev) )
|
||||||
|
Reference in New Issue
Block a user