Minor style and formatting clean up of the new code
Fix typos in comments and indent them. Wrap over-long lines. Remove useless top-level const.
This commit is contained in:
@@ -21,39 +21,40 @@ struct RowRange
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class RowRanges
|
A helper class that manages a set of RowRange objects.
|
||||||
A helper class that manages a set of RowRange objects.
|
|
||||||
It stores the indices that are members of a group in a memory
|
It stores the indices that are members of a group in a memory
|
||||||
efficiant way.
|
efficient way.
|
||||||
*/
|
*/
|
||||||
class WXDLLIMPEXP_CORE RowRanges
|
class WXDLLIMPEXP_CORE RowRanges
|
||||||
//class RowRanges
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
Adds a row index to this group by adding it to an existing RowRange
|
Adds a row index to this group by adding it to an existing RowRange
|
||||||
or by creating a new one.
|
or by creating a new one.
|
||||||
*/
|
*/
|
||||||
void Add(unsigned int row);
|
void Add(unsigned int row);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Removes a row index and all indices after idx from this group.
|
Removes a row index and all indices after idx from this group.
|
||||||
*/
|
*/
|
||||||
void Remove(unsigned int row);
|
void Remove(unsigned int row);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Checks whether a row index is contained in this group.
|
Checks whether a row index is contained in this group.
|
||||||
*/
|
*/
|
||||||
bool Has(unsigned int row) const;
|
bool Has(unsigned int row) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the number of row indices that are contained in this group.
|
Returns the number of row indices that are contained in this group.
|
||||||
*/
|
*/
|
||||||
unsigned int CountAll() const;
|
unsigned int CountAll() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the number of rows that are in this group before the given row index.
|
Returns the number of rows that are in this group before the given row
|
||||||
not including given row.
|
index.
|
||||||
|
|
||||||
|
Not that this doesn't include the given row.
|
||||||
*/
|
*/
|
||||||
unsigned int CountTo(unsigned int row) const;
|
unsigned int CountTo(unsigned int row) const;
|
||||||
|
|
||||||
@@ -66,10 +67,11 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
wxVector<RowRange> m_ranges;
|
wxVector<RowRange> m_ranges;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
If a new row index was inserted Cleanup checks if the neighbour ranges
|
If a new row index was inserted, Cleanup() checks if the neighbour
|
||||||
of idx can includes the same row indices and discards
|
ranges of idx can includes the same row indices and discards
|
||||||
unnecessary RowRange objects.
|
unnecessary RowRange objects.
|
||||||
*/
|
*/
|
||||||
void CleanUp(unsigned int idx);
|
void CleanUp(unsigned int idx);
|
||||||
};
|
};
|
||||||
@@ -78,70 +80,75 @@ WX_DECLARE_HASH_MAP(unsigned int, RowRanges*, wxIntegerHash, wxIntegerEqual,
|
|||||||
HeightToRowRangesMap);
|
HeightToRowRangesMap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class HeightCache
|
HeightCache implements a cache mechanism for wxDataViewCtrl.
|
||||||
|
|
||||||
HeightCache implements a cache mechanism for the DataViewCtrl to give
|
It gives fast access to:
|
||||||
fast access to:
|
* the height of one line (GetLineHeight)
|
||||||
* the height of one line (GetLineHeight)
|
* the y-coordinate where a row starts (GetLineStart)
|
||||||
* the y-coordinate where a row starts (GetLineStart)
|
* and vice versa (GetLineAt)
|
||||||
* and vice versa (GetLineAt)
|
|
||||||
|
|
||||||
The layout of the cache is a hashmap where the keys are all exisiting
|
The layout of the cache is a hashmap where the keys are all existing row
|
||||||
row heights in pixels. The values are RowRange objects that represents
|
heights in pixels. The values are RowRange objects that represent all rows
|
||||||
all having the specified height.
|
having the specified height.
|
||||||
|
|
||||||
{
|
An example:
|
||||||
22: RowRange([0..10], [15..17], [20..2000]),
|
@code
|
||||||
42: RowRange([11..12], [18..18]),
|
{
|
||||||
62: RowRange([13..14], [19..19])
|
22: RowRange([0..10], [15..17], [20..2000]),
|
||||||
}
|
42: RowRange([11..12], [18..18]),
|
||||||
|
62: RowRange([13..14], [19..19])
|
||||||
|
}
|
||||||
|
@endcode
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
========
|
========
|
||||||
|
|
||||||
GetLineStart
|
GetLineStart
|
||||||
------------
|
------------
|
||||||
To retrieve the y-coordinate of item 1000 it is neccessary to look into
|
To retrieve the y-coordinate of item 1000 it is necessary to look into
|
||||||
each key of the hashmap *m_heightToRowRange*. Get the row count of
|
each key of the hashmap *m_heightToRowRange*. Get the row count of
|
||||||
indices lower than 1000 (RowRange::CountTo) and multiplies it wich the
|
indices lower than 1000 (RowRange::CountTo) and multiplies it which the
|
||||||
according height.
|
according height.
|
||||||
|
|
||||||
RowRange([0..10], [15..17], [20..2000]).CountTo(1000)
|
RowRange([0..10], [15..17], [20..2000]).CountTo(1000)
|
||||||
--> 0..10 are 11 items, 15..17 are 3 items and 20..1000 are 980 items (1000-20)
|
--> 0..10 are 11 items, 15..17 are 3 items and 20..1000 are 980 items (1000-20)
|
||||||
= 11 + 3 + 980 = 994 items
|
= 11 + 3 + 980 = 994 items
|
||||||
|
|
||||||
GetLineStart(1000) --> (22 * 994) + (42 * 3) + (62 * 3) = 22180
|
GetLineStart(1000) --> (22 * 994) + (42 * 3) + (62 * 3) = 22180
|
||||||
|
|
||||||
GetLineHeight
|
GetLineHeight
|
||||||
-------------
|
-------------
|
||||||
To retrieve the line height look into each key and check if row is
|
To retrieve the line height look into each key and check if row is
|
||||||
contained in RowRange (RowRange::Has)
|
contained in RowRange (RowRange::Has)
|
||||||
|
|
||||||
GetLineAt
|
GetLineAt
|
||||||
---------
|
---------
|
||||||
To retrieve the row that starts at a specific y-coordinate.
|
To retrieve the row that starts at a specific y-coordinate.
|
||||||
Look into each key and count all rows.
|
Look into each key and count all rows.
|
||||||
Use bisect algorithm in combination with GetLineStart() to
|
Use bisect algorithm in combination with GetLineStart() to
|
||||||
find the appropriate item
|
find the appropriate item
|
||||||
*/
|
*/
|
||||||
class WXDLLIMPEXP_ADV HeightCache
|
class WXDLLIMPEXP_ADV HeightCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool GetLineStart(unsigned int row, int &start);
|
bool GetLineStart(unsigned int row, int& start);
|
||||||
bool GetLineHeight(unsigned int row, int &height);
|
bool GetLineHeight(unsigned int row, int& height);
|
||||||
bool GetLineAt(int y, unsigned int &row);
|
bool GetLineAt(int y, unsigned int& row);
|
||||||
|
|
||||||
|
void Put(unsigned int row, int height);
|
||||||
|
|
||||||
void Put(const unsigned int row, const int height);
|
|
||||||
/**
|
/**
|
||||||
removes the stored height of the given row from the cache
|
Removes the stored height of the given row from the cache and
|
||||||
and invalidates all cached rows (including row)
|
invalidates all cached rows (including the given one).
|
||||||
*/
|
*/
|
||||||
void Remove(const unsigned int row);
|
void Remove(unsigned int row);
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool GetLineInfo(unsigned int row, int &start, int &height);
|
bool GetLineInfo(unsigned int row, int &start, int &height);
|
||||||
HeightToRowRangesMap m_heightToRowRange;
|
|
||||||
|
HeightToRowRangesMap m_heightToRowRange;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3447,7 +3447,7 @@ int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
|
|||||||
if (!node)
|
if (!node)
|
||||||
{
|
{
|
||||||
// not really correct...
|
// not really correct...
|
||||||
return row + ((y - yy) / m_lineHeight);
|
return row + ((y-yy) / m_lineHeight);
|
||||||
}
|
}
|
||||||
item = node->GetItem();
|
item = node->GetItem();
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: wx/private/rowheightcache.h
|
// Name: generic/rowheightcache.cpp
|
||||||
// Purpose: height cache of rows in a dataview
|
// Purpose: height cache of rows in a dataview
|
||||||
// Author: Jens Goepfert (mail@jensgoepfert.de)
|
// Author: Jens Goepfert (mail@jensgoepfert.de)
|
||||||
// Created: 2018-03-06
|
// Created: 2018-03-06
|
||||||
@@ -27,20 +27,15 @@
|
|||||||
|
|
||||||
#include "wx/generic/private/rowheightcache.h"
|
#include "wx/generic/private/rowheightcache.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// private structs
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// implementation
|
// implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// RowRanges
|
// RowRanges
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void RowRanges::Add(const unsigned int row)
|
void RowRanges::Add(unsigned int row)
|
||||||
{
|
{
|
||||||
size_t count = m_ranges.size();
|
size_t count = m_ranges.size();
|
||||||
size_t rngIdx = 0;
|
size_t rngIdx = 0;
|
||||||
@@ -63,7 +58,8 @@ void RowRanges::Add(const unsigned int row)
|
|||||||
}
|
}
|
||||||
if (row == rng.to)
|
if (row == rng.to)
|
||||||
{
|
{
|
||||||
// extend range at the end (set to row+1 because 'to' is not including)
|
// extend range at the end (set to row+1 because 'to' is not
|
||||||
|
// including)
|
||||||
rng.to = row + 1;
|
rng.to = row + 1;
|
||||||
CleanUp(rngIdx);
|
CleanUp(rngIdx);
|
||||||
return;
|
return;
|
||||||
@@ -71,7 +67,8 @@ void RowRanges::Add(const unsigned int row)
|
|||||||
|
|
||||||
if (rng.from > row + 1)
|
if (rng.from > row + 1)
|
||||||
{
|
{
|
||||||
// this range is already behind row index, so break here and insert a new range before
|
// this range is already behind row index, so break here and insert
|
||||||
|
// a new range before
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +79,7 @@ void RowRanges::Add(const unsigned int row)
|
|||||||
m_ranges.insert(m_ranges.begin() + rngIdx, newRange);
|
m_ranges.insert(m_ranges.begin() + rngIdx, newRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RowRanges::Remove(const unsigned int row)
|
void RowRanges::Remove(unsigned int row)
|
||||||
{
|
{
|
||||||
size_t count = m_ranges.size();
|
size_t count = m_ranges.size();
|
||||||
size_t rngIdx = 0;
|
size_t rngIdx = 0;
|
||||||
@@ -129,7 +126,8 @@ void RowRanges::CleanUp(unsigned int idx)
|
|||||||
if (prevRng->to == rng.from)
|
if (prevRng->to == rng.from)
|
||||||
{
|
{
|
||||||
// this range starts where the previous range began, so remove this
|
// this range starts where the previous range began, so remove this
|
||||||
// and set the to-value of the previous range to the to-value of this range
|
// and set the to-value of the previous range to the to-value of
|
||||||
|
// this range
|
||||||
prevRng->to = rng.to;
|
prevRng->to = rng.to;
|
||||||
m_ranges.erase(m_ranges.begin() + rngIdx);
|
m_ranges.erase(m_ranges.begin() + rngIdx);
|
||||||
count--;
|
count--;
|
||||||
@@ -274,7 +272,8 @@ bool HeightCache::GetLineAt(int y, unsigned int &row)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// should never happen, except the HeightCache has gaps which is an invalid state
|
// should never happen, except the HeightCache has gaps which is an
|
||||||
|
// invalid state
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,7 +294,7 @@ bool HeightCache::GetLineAt(int y, unsigned int &row)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeightCache::Put(const unsigned int row, const int height)
|
void HeightCache::Put(unsigned int row, int height)
|
||||||
{
|
{
|
||||||
RowRanges *rowRanges = m_heightToRowRange[height];
|
RowRanges *rowRanges = m_heightToRowRange[height];
|
||||||
if (rowRanges == NULL)
|
if (rowRanges == NULL)
|
||||||
@@ -306,7 +305,7 @@ void HeightCache::Put(const unsigned int row, const int height)
|
|||||||
rowRanges->Add(row);
|
rowRanges->Add(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeightCache::Remove(const unsigned int row)
|
void HeightCache::Remove(unsigned int row)
|
||||||
{
|
{
|
||||||
HeightToRowRangesMap::iterator it;
|
HeightToRowRangesMap::iterator it;
|
||||||
for (it = m_heightToRowRange.begin(); it != m_heightToRowRange.end(); ++it)
|
for (it = m_heightToRowRange.begin(); it != m_heightToRowRange.end(); ++it)
|
||||||
|
@@ -22,11 +22,6 @@
|
|||||||
|
|
||||||
#include "wx/generic/private/rowheightcache.h"
|
#include "wx/generic/private/rowheightcache.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// local functions
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// TestRowRangesAdd
|
// TestRowRangesAdd
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user