fixed handling of NULL items

This commit is contained in:
jensgoe
2018-12-10 00:14:15 +01:00
committed by Jens Göpfert
parent 9a91f59399
commit 1f0e32e485

View File

@@ -710,6 +710,7 @@ public:
bool Cleared(); bool Cleared();
void Resort() void Resort()
{ {
m_rowHeightCache->Clear();
if (!IsVirtualList()) if (!IsVirtualList())
{ {
m_root->Resort(this); m_root->Resort(this);
@@ -822,6 +823,7 @@ public:
int GetLineStart( unsigned int row ) const; // row * m_lineHeight in fixed mode int GetLineStart( unsigned int row ) const; // row * m_lineHeight in fixed mode
int GetLineHeight( unsigned int row ) const; // m_lineHeight in fixed mode int GetLineHeight( unsigned int row ) const; // m_lineHeight in fixed mode
int GetLineAt( unsigned int y ) const; // y / m_lineHeight in fixed mode int GetLineAt( unsigned int y ) const; // y / m_lineHeight in fixed mode
int QueryAndCacheLineHeight(unsigned int row, wxDataViewItem item) const;
void SetRowHeight( int lineHeight ) { m_lineHeight = lineHeight; } void SetRowHeight( int lineHeight ) { m_lineHeight = lineHeight; }
int GetRowHeight() const { return m_lineHeight; } int GetRowHeight() const { return m_lineHeight; }
@@ -3344,8 +3346,6 @@ wxRect wxDataViewMainWindow::GetLinesRect( unsigned int rowFrom, unsigned int ro
int wxDataViewMainWindow::GetLineStart( unsigned int row ) const int wxDataViewMainWindow::GetLineStart( unsigned int row ) const
{ {
const wxDataViewModel *model = GetModel();
if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT)
{ {
int start = 0; int start = 0;
@@ -3362,42 +3362,13 @@ int wxDataViewMainWindow::GetLineStart( unsigned int row ) const
continue; continue;
} }
wxDataViewItem item; wxDataViewItem item = GetItemByRow(r);
if (IsList()) if ( !item )
{ break;
item = GetItemByRow(r);
}
else
{
const wxDataViewTreeNode* node = GetTreeNodeByRow(r);
if (!node) return start;
item = node->GetItem();
}
unsigned int cols = GetOwner()->GetColumnCount(); height = QueryAndCacheLineHeight(r, item);
unsigned int col;
height = m_lineHeight;
for (col = 0; col < cols; col++)
{
const wxDataViewColumn *column = GetOwner()->GetColumn(col);
if (column->IsHidden())
continue; // skip it!
if ((col != 0) &&
model->IsContainer(item) &&
!model->HasContainerColumns(item))
continue; // skip it!
wxDataViewRenderer *renderer =
const_cast<wxDataViewRenderer*>(column->GetRenderer());
renderer->PrepareForItem(model, item, column->GetModelColumn());
height = wxMax( height, renderer->GetSize().y );
}
start += height; start += height;
m_rowHeightCache->Put(r, height);
} }
return start; return start;
@@ -3410,8 +3381,6 @@ int wxDataViewMainWindow::GetLineStart( unsigned int row ) const
int wxDataViewMainWindow::GetLineAt( unsigned int y ) const int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
{ {
const wxDataViewModel *model = GetModel();
// check for the easy case first // check for the easy case first
if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT) ) if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT) )
return y / m_lineHeight; return y / m_lineHeight;
@@ -3429,25 +3398,49 @@ int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
{ {
// row height not in cache -> get it from the renderer... // row height not in cache -> get it from the renderer...
wxDataViewItem item; wxDataViewItem item = GetItemByRow(row);
if (IsList()) if ( !item )
return row; // should be the last row
height = QueryAndCacheLineHeight(row, item);
}
yy += height;
if (y < yy)
return row;
row++;
}
}
int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const
{ {
item = GetItemByRow(row); if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT)
{
int height = 0;
if ( m_rowHeightCache->GetLineHeight(row, height) )
return height;
wxDataViewItem item = GetItemByRow(row);
if ( !item )
return m_lineHeight;
height = QueryAndCacheLineHeight(row, item);
return height;
} }
else else
{ {
const wxDataViewTreeNode* node = GetTreeNodeByRow(row); return m_lineHeight;
if (!node)
{
// not really correct...
return row + ((y-yy) / m_lineHeight);
} }
item = node->GetItem();
} }
int wxDataViewMainWindow::QueryAndCacheLineHeight(unsigned int row, wxDataViewItem item) const
{
const wxDataViewModel *model = GetModel();
int height = m_lineHeight;
unsigned int cols = GetOwner()->GetColumnCount(); unsigned int cols = GetOwner()->GetColumnCount();
unsigned int col; unsigned int col;
height = m_lineHeight;
for (col = 0; col < cols; col++) for (col = 0; col < cols; col++)
{ {
const wxDataViewColumn *column = GetOwner()->GetColumn(col); const wxDataViewColumn *column = GetOwner()->GetColumn(col);
@@ -3468,69 +3461,9 @@ int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
// ... and store the height in the cache // ... and store the height in the cache
m_rowHeightCache->Put(row, height); m_rowHeightCache->Put(row, height);
}
yy += height;
if (y < yy)
return row;
row++;
}
}
int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const
{
const wxDataViewModel *model = GetModel();
if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT)
{
int height = 0;
if (m_rowHeightCache->GetLineHeight(row, height))
return height;
wxDataViewItem item;
if (IsList())
{
item = GetItemByRow(row);
}
else
{
const wxDataViewTreeNode* node = GetTreeNodeByRow(row);
// wxASSERT( node );
if (!node) return m_lineHeight;
item = node->GetItem();
}
height = m_lineHeight;
unsigned int cols = GetOwner()->GetColumnCount();
unsigned int col;
for (col = 0; col < cols; col++)
{
const wxDataViewColumn *column = GetOwner()->GetColumn(col);
if (column->IsHidden())
continue; // skip it!
if ((col != 0) &&
model->IsContainer(item) &&
!model->HasContainerColumns(item))
continue; // skip it!
wxDataViewRenderer *renderer =
const_cast<wxDataViewRenderer*>(column->GetRenderer());
renderer->PrepareForItem(model, item, column->GetModelColumn());
height = wxMax( height, renderer->GetSize().y );
}
m_rowHeightCache->Put(row, height);
return height; return height;
} }
else
{
return m_lineHeight;
}
}
class RowToTreeNodeJob: public DoJob class RowToTreeNodeJob: public DoJob