Rename wxGrid::GetSelectionRange() to GetSelectedBlocks()

This seems to be more consistent with the existing functions and doesn't
create ambiguity with a grid range.

Also rename wxGridSelectionRange to just wxGridBlocks as, in principle,
this class could be used for iterating over any blocks, not just the
selected ones.

No changes in functionality, this is just a renaming.
This commit is contained in:
Vadim Zeitlin
2020-04-12 02:36:52 +02:00
parent b10755e553
commit 30eaa28de5
5 changed files with 27 additions and 29 deletions

View File

@@ -876,10 +876,10 @@ struct wxGridBlockDiffResult
};
// ----------------------------------------------------------------------------
// wxGridSelectionRange: a range of grid blocks that can be iterated over
// wxGridBlocks: a range of grid blocks that can be iterated over
// ----------------------------------------------------------------------------
class wxGridSelectionRange
class wxGridBlocks
{
typedef wxVector<wxGridBlockCoords>::const_iterator iterator_impl;
@@ -913,7 +913,7 @@ public:
iterator_impl m_it;
friend class wxGridSelectionRange;
friend class wxGridBlocks;
};
iterator begin() const
@@ -927,13 +927,13 @@ public:
}
private:
wxGridSelectionRange() :
wxGridBlocks() :
m_begin(),
m_end()
{
}
wxGridSelectionRange(iterator_impl begin, iterator_impl end) :
wxGridBlocks(iterator_impl begin, iterator_impl end) :
m_begin(begin),
m_end(end)
{
@@ -1994,7 +1994,7 @@ public:
bool IsInSelection( const wxGridCellCoords& coords ) const
{ return IsInSelection( coords.GetRow(), coords.GetCol() ); }
wxGridSelectionRange GetSelectionRange() const;
wxGridBlocks GetSelectedBlocks() const;
wxGridCellCoordsArray GetSelectedCells() const;
wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
wxGridCellCoordsArray GetSelectionBlockBottomRight() const;

View File

@@ -2004,7 +2004,7 @@ struct wxGridBlockDiffResult
};
/**
Represents a range of grid blocks that can be iterated over.
Represents a collection of grid blocks that can be iterated over.
This class provides read-only access to the blocks making up the grid
selection in the most general case.
@@ -2014,14 +2014,14 @@ struct wxGridBlockDiffResult
The preferable way to iterate over it is using C++11 range-for loop:
@code
for ( const auto block: grid->GetSelectionRange() ) {
for ( const auto& block: grid->GetSelectedBlocks() ) {
... do something with block ...
}
@endcode
When not using C++11, iteration has to be done manually:
@code
wxGridSelectionRange range = grid->GetSelectionRange();
for ( wxGridSelectionRange::iterator it = range.begin();
wxGridBlocks range = grid->GetSelectedBlocks();
for ( wxGridBlocks::iterator it = range.begin();
it != range.end();
++it ) {
... do something with *it ...
@@ -2030,7 +2030,7 @@ struct wxGridBlockDiffResult
@since 3.1.4
*/
class wxGridSelectionRange
class wxGridBlocks
{
public:
/**
@@ -4668,7 +4668,7 @@ public:
The returned range can be iterated over, e.g. with C++11 range-for loop:
@code
for ( const auto block: grid->GetSelectionRange() ) {
for ( const auto block: grid->GetSelectedBlocks() ) {
if ( block.Intersects(myBlock) )
break;
}
@@ -4676,7 +4676,7 @@ public:
@since 3.1.4
*/
wxGridSelectionRange GetSelectionRange() const;
wxGridBlocks GetSelectedBlocks() const;
/**
Returns an array of individually selected cells.
@@ -4694,7 +4694,7 @@ public:
a million of entries in this function, instead it returns an empty
array and GetSelectedCols() returns an array containing one element).
The function can be slow for the big grids, use GetSelectionRange()
The function can be slow for the big grids, use GetSelectedBlocks()
in the new code.
*/
wxGridCellCoordsArray GetSelectedCells() const;
@@ -4708,7 +4708,7 @@ public:
or being selected in virtue of all of their cells being selected
individually, please see GetSelectedCells() for more details.
The function can be slow for the big grids, use GetSelectionRange()
The function can be slow for the big grids, use GetSelectedBlocks()
in the new code.
*/
wxArrayInt GetSelectedCols() const;
@@ -4722,7 +4722,7 @@ public:
selected in virtue of all of their cells being selected individually,
please see GetSelectedCells() for more details.
The function can be slow for the big grids, use GetSelectionRange()
The function can be slow for the big grids, use GetSelectedBlocks()
in the new code.
*/
wxArrayInt GetSelectedRows() const;
@@ -4739,7 +4739,7 @@ public:
Please see GetSelectedCells() for more information about the selection
representation in wxGrid.
The function can be slow for the big grids, use GetSelectionRange()
The function can be slow for the big grids, use GetSelectedBlocks()
in the new code.
@see GetSelectionBlockTopLeft()
@@ -4752,7 +4752,7 @@ public:
Please see GetSelectedCells() for more information about the selection
representation in wxGrid.
The function can be slow for the big grids, use GetSelectionRange()
The function can be slow for the big grids, use GetSelectedBlocks()
in the new code.
@see GetSelectionBlockBottomRight()

View File

@@ -1222,10 +1222,8 @@ void GridFrame::ShowSelection( wxCommandEvent& WXUNUSED(ev) )
{
int count = 0;
wxString desc;
const wxGridSelectionRange& sel = grid->GetSelectionRange();
for ( wxGridSelectionRange::iterator it = sel.begin();
it != sel.end();
++it, ++count )
const wxGridBlocks& sel = grid->GetSelectedBlocks();
for ( wxGridBlocks::iterator it = sel.begin(); it != sel.end(); ++it )
{
const wxGridBlockCoords& b = *it;
@@ -1264,7 +1262,7 @@ void GridFrame::ShowSelection( wxCommandEvent& WXUNUSED(ev) )
b.GetRightCol() + 1);
}
if ( count )
if ( count++ )
desc += "\n\t";
desc += blockDesc;
}

View File

@@ -10284,13 +10284,13 @@ bool wxGrid::IsInSelection( int row, int col ) const
return m_selection && m_selection->IsInSelection(row, col);
}
wxGridSelectionRange wxGrid::GetSelectionRange() const
wxGridBlocks wxGrid::GetSelectedBlocks() const
{
if ( !m_selection )
return wxGridSelectionRange();
return wxGridBlocks();
const wxVectorGridBlockCoords& blocks = m_selection->GetBlocks();
return wxGridSelectionRange(blocks.begin(), blocks.end());
return wxGridBlocks(blocks.begin(), blocks.end());
}
wxGridCellCoordsArray wxGrid::GetSelectedCells() const

View File

@@ -526,19 +526,19 @@ TEST_CASE_METHOD(GridTestCase, "Grid::Selection", "[grid]")
TEST_CASE_METHOD(GridTestCase, "Grid::SelectionRange", "[grid]")
{
const wxGridSelectionRange empty = m_grid->GetSelectionRange();
const wxGridBlocks empty = m_grid->GetSelectedBlocks();
CHECK( empty.begin() == empty.end() );
m_grid->SelectBlock(1, 0, 3, 1);
wxGridSelectionRange sel = m_grid->GetSelectionRange();
wxGridBlocks sel = m_grid->GetSelectedBlocks();
REQUIRE( sel.begin() != sel.end() );
CHECK( *sel.begin() == wxGridBlockCoords(1, 0, 3, 1) );
#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(10)
m_grid->SelectBlock(4, 0, 7, 1, true);
int index = 0;
for ( const wxGridBlockCoords& block : m_grid->GetSelectionRange() )
for ( const wxGridBlockCoords& block : m_grid->GetSelectedBlocks() )
{
switch ( index )
{