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:
@@ -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;
|
typedef wxVector<wxGridBlockCoords>::const_iterator iterator_impl;
|
||||||
|
|
||||||
@@ -913,7 +913,7 @@ public:
|
|||||||
|
|
||||||
iterator_impl m_it;
|
iterator_impl m_it;
|
||||||
|
|
||||||
friend class wxGridSelectionRange;
|
friend class wxGridBlocks;
|
||||||
};
|
};
|
||||||
|
|
||||||
iterator begin() const
|
iterator begin() const
|
||||||
@@ -927,13 +927,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxGridSelectionRange() :
|
wxGridBlocks() :
|
||||||
m_begin(),
|
m_begin(),
|
||||||
m_end()
|
m_end()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGridSelectionRange(iterator_impl begin, iterator_impl end) :
|
wxGridBlocks(iterator_impl begin, iterator_impl end) :
|
||||||
m_begin(begin),
|
m_begin(begin),
|
||||||
m_end(end)
|
m_end(end)
|
||||||
{
|
{
|
||||||
@@ -1994,7 +1994,7 @@ public:
|
|||||||
bool IsInSelection( const wxGridCellCoords& coords ) const
|
bool IsInSelection( const wxGridCellCoords& coords ) const
|
||||||
{ return IsInSelection( coords.GetRow(), coords.GetCol() ); }
|
{ return IsInSelection( coords.GetRow(), coords.GetCol() ); }
|
||||||
|
|
||||||
wxGridSelectionRange GetSelectionRange() const;
|
wxGridBlocks GetSelectedBlocks() const;
|
||||||
wxGridCellCoordsArray GetSelectedCells() const;
|
wxGridCellCoordsArray GetSelectedCells() const;
|
||||||
wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
|
wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
|
||||||
wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
|
wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
|
||||||
|
@@ -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
|
This class provides read-only access to the blocks making up the grid
|
||||||
selection in the most general case.
|
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:
|
The preferable way to iterate over it is using C++11 range-for loop:
|
||||||
@code
|
@code
|
||||||
for ( const auto block: grid->GetSelectionRange() ) {
|
for ( const auto& block: grid->GetSelectedBlocks() ) {
|
||||||
... do something with block ...
|
... do something with block ...
|
||||||
}
|
}
|
||||||
@endcode
|
@endcode
|
||||||
When not using C++11, iteration has to be done manually:
|
When not using C++11, iteration has to be done manually:
|
||||||
@code
|
@code
|
||||||
wxGridSelectionRange range = grid->GetSelectionRange();
|
wxGridBlocks range = grid->GetSelectedBlocks();
|
||||||
for ( wxGridSelectionRange::iterator it = range.begin();
|
for ( wxGridBlocks::iterator it = range.begin();
|
||||||
it != range.end();
|
it != range.end();
|
||||||
++it ) {
|
++it ) {
|
||||||
... do something with *it ...
|
... do something with *it ...
|
||||||
@@ -2030,7 +2030,7 @@ struct wxGridBlockDiffResult
|
|||||||
|
|
||||||
@since 3.1.4
|
@since 3.1.4
|
||||||
*/
|
*/
|
||||||
class wxGridSelectionRange
|
class wxGridBlocks
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@@ -4668,7 +4668,7 @@ public:
|
|||||||
|
|
||||||
The returned range can be iterated over, e.g. with C++11 range-for loop:
|
The returned range can be iterated over, e.g. with C++11 range-for loop:
|
||||||
@code
|
@code
|
||||||
for ( const auto block: grid->GetSelectionRange() ) {
|
for ( const auto block: grid->GetSelectedBlocks() ) {
|
||||||
if ( block.Intersects(myBlock) )
|
if ( block.Intersects(myBlock) )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -4676,7 +4676,7 @@ public:
|
|||||||
|
|
||||||
@since 3.1.4
|
@since 3.1.4
|
||||||
*/
|
*/
|
||||||
wxGridSelectionRange GetSelectionRange() const;
|
wxGridBlocks GetSelectedBlocks() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns an array of individually selected cells.
|
Returns an array of individually selected cells.
|
||||||
@@ -4694,7 +4694,7 @@ public:
|
|||||||
a million of entries in this function, instead it returns an empty
|
a million of entries in this function, instead it returns an empty
|
||||||
array and GetSelectedCols() returns an array containing one element).
|
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.
|
in the new code.
|
||||||
*/
|
*/
|
||||||
wxGridCellCoordsArray GetSelectedCells() const;
|
wxGridCellCoordsArray GetSelectedCells() const;
|
||||||
@@ -4708,7 +4708,7 @@ public:
|
|||||||
or being selected in virtue of all of their cells being selected
|
or being selected in virtue of all of their cells being selected
|
||||||
individually, please see GetSelectedCells() for more details.
|
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.
|
in the new code.
|
||||||
*/
|
*/
|
||||||
wxArrayInt GetSelectedCols() const;
|
wxArrayInt GetSelectedCols() const;
|
||||||
@@ -4722,7 +4722,7 @@ public:
|
|||||||
selected in virtue of all of their cells being selected individually,
|
selected in virtue of all of their cells being selected individually,
|
||||||
please see GetSelectedCells() for more details.
|
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.
|
in the new code.
|
||||||
*/
|
*/
|
||||||
wxArrayInt GetSelectedRows() const;
|
wxArrayInt GetSelectedRows() const;
|
||||||
@@ -4739,7 +4739,7 @@ public:
|
|||||||
Please see GetSelectedCells() for more information about the selection
|
Please see GetSelectedCells() for more information about the selection
|
||||||
representation in wxGrid.
|
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.
|
in the new code.
|
||||||
|
|
||||||
@see GetSelectionBlockTopLeft()
|
@see GetSelectionBlockTopLeft()
|
||||||
@@ -4752,7 +4752,7 @@ public:
|
|||||||
Please see GetSelectedCells() for more information about the selection
|
Please see GetSelectedCells() for more information about the selection
|
||||||
representation in wxGrid.
|
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.
|
in the new code.
|
||||||
|
|
||||||
@see GetSelectionBlockBottomRight()
|
@see GetSelectionBlockBottomRight()
|
||||||
|
@@ -1222,10 +1222,8 @@ void GridFrame::ShowSelection( wxCommandEvent& WXUNUSED(ev) )
|
|||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
wxString desc;
|
wxString desc;
|
||||||
const wxGridSelectionRange& sel = grid->GetSelectionRange();
|
const wxGridBlocks& sel = grid->GetSelectedBlocks();
|
||||||
for ( wxGridSelectionRange::iterator it = sel.begin();
|
for ( wxGridBlocks::iterator it = sel.begin(); it != sel.end(); ++it )
|
||||||
it != sel.end();
|
|
||||||
++it, ++count )
|
|
||||||
{
|
{
|
||||||
const wxGridBlockCoords& b = *it;
|
const wxGridBlockCoords& b = *it;
|
||||||
|
|
||||||
@@ -1264,7 +1262,7 @@ void GridFrame::ShowSelection( wxCommandEvent& WXUNUSED(ev) )
|
|||||||
b.GetRightCol() + 1);
|
b.GetRightCol() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( count )
|
if ( count++ )
|
||||||
desc += "\n\t";
|
desc += "\n\t";
|
||||||
desc += blockDesc;
|
desc += blockDesc;
|
||||||
}
|
}
|
||||||
|
@@ -10284,13 +10284,13 @@ bool wxGrid::IsInSelection( int row, int col ) const
|
|||||||
return m_selection && m_selection->IsInSelection(row, col);
|
return m_selection && m_selection->IsInSelection(row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGridSelectionRange wxGrid::GetSelectionRange() const
|
wxGridBlocks wxGrid::GetSelectedBlocks() const
|
||||||
{
|
{
|
||||||
if ( !m_selection )
|
if ( !m_selection )
|
||||||
return wxGridSelectionRange();
|
return wxGridBlocks();
|
||||||
|
|
||||||
const wxVectorGridBlockCoords& blocks = m_selection->GetBlocks();
|
const wxVectorGridBlockCoords& blocks = m_selection->GetBlocks();
|
||||||
return wxGridSelectionRange(blocks.begin(), blocks.end());
|
return wxGridBlocks(blocks.begin(), blocks.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGridCellCoordsArray wxGrid::GetSelectedCells() const
|
wxGridCellCoordsArray wxGrid::GetSelectedCells() const
|
||||||
|
@@ -526,19 +526,19 @@ TEST_CASE_METHOD(GridTestCase, "Grid::Selection", "[grid]")
|
|||||||
|
|
||||||
TEST_CASE_METHOD(GridTestCase, "Grid::SelectionRange", "[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() );
|
CHECK( empty.begin() == empty.end() );
|
||||||
|
|
||||||
m_grid->SelectBlock(1, 0, 3, 1);
|
m_grid->SelectBlock(1, 0, 3, 1);
|
||||||
|
|
||||||
wxGridSelectionRange sel = m_grid->GetSelectionRange();
|
wxGridBlocks sel = m_grid->GetSelectedBlocks();
|
||||||
REQUIRE( sel.begin() != sel.end() );
|
REQUIRE( sel.begin() != sel.end() );
|
||||||
CHECK( *sel.begin() == wxGridBlockCoords(1, 0, 3, 1) );
|
CHECK( *sel.begin() == wxGridBlockCoords(1, 0, 3, 1) );
|
||||||
|
|
||||||
#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(10)
|
#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(10)
|
||||||
m_grid->SelectBlock(4, 0, 7, 1, true);
|
m_grid->SelectBlock(4, 0, 7, 1, true);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for ( const wxGridBlockCoords& block : m_grid->GetSelectionRange() )
|
for ( const wxGridBlockCoords& block : m_grid->GetSelectedBlocks() )
|
||||||
{
|
{
|
||||||
switch ( index )
|
switch ( index )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user