From 30eaa28de5a0d6a80ad685134cdbf9af8e29e523 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Apr 2020 02:36:52 +0200 Subject: [PATCH] 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. --- include/wx/generic/grid.h | 12 ++++++------ interface/wx/grid.h | 24 ++++++++++++------------ samples/grid/griddemo.cpp | 8 +++----- src/generic/grid.cpp | 6 +++--- tests/controls/gridtest.cpp | 6 +++--- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 946236d23c..cbd76d749c 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -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::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; diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 6122f6b3fa..d05931fe4b 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -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() diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index c115f5c2f1..5e314e21b7 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -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; } diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index e8b0734dfa..6dfd5f9b72 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -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 diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index 67892326eb..5aa431a623 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -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 ) {