Created method to find the first column that has a value instead of assuming that the expander column is the first one. Renamed method HasItemMultipleValues with IsItemMultivalued and made it const.

This commit is contained in:
Jorge Moraleda
2020-04-13 21:35:27 -07:00
parent 8a3b0a9fd6
commit a1f90ae0de

View File

@@ -911,11 +911,11 @@ private:
bool DoItemChanged(const wxDataViewItem& item, int view_column); bool DoItemChanged(const wxDataViewItem& item, int view_column);
// Return whether the item has more than one column that have values // Return whether the item has more than one column that have values
bool HasItemMultipleValues(const wxDataViewItem& item) bool IsItemMultivalued(const wxDataViewItem& item) const
{ {
unsigned int numColsWithValue = 0; unsigned int numColsWithValue = 0;
unsigned int cols = GetOwner()->GetColumnCount(); unsigned int cols = GetOwner()->GetColumnCount();
wxDataViewModel* model = GetModel(); const wxDataViewModel* model = GetModel();
for ( unsigned int i = 0; i < cols; i++ ) for ( unsigned int i = 0; i < cols; i++ )
{ {
if ( model->HasValue(item, i) ) if ( model->HasValue(item, i) )
@@ -926,6 +926,17 @@ private:
return false; return false;
} }
// find first column with value
wxDataViewColumn * FindFirstColumnWithValue(const wxDataViewItem& item) const
{
unsigned int cols = GetOwner()->GetColumnCount();
const wxDataViewModel* model = GetModel();
for ( unsigned int i ; i < cols; i++ )
if ( model->HasValue(item, i) )
return GetOwner()->GetColumnAt(i);
return NULL;
}
private: private:
wxDataViewCtrl *m_owner; wxDataViewCtrl *m_owner;
int m_lineHeight; int m_lineHeight;
@@ -2416,7 +2427,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
if ( !IsList() ) if ( !IsList() )
{ {
wxDataViewTreeNode *node = GetTreeNodeByRow(item); wxDataViewTreeNode *node = GetTreeNodeByRow(item);
if ( !HasItemMultipleValues(node->GetItem()) ) if ( !IsItemMultivalued(node->GetItem()) )
renderColumnFocus = false; renderColumnFocus = false;
} }
} }
@@ -4115,14 +4126,9 @@ wxDataViewMainWindow::FindColumnForEditing(const wxDataViewItem& item, wxDataVie
} }
} }
// If on container item without columns, only the expander column // Switch to the first column with value if the current column has no value
// may be directly editable: if ( candidate && !GetModel()->HasValue(item, candidate->GetModelColumn()) )
if ( candidate && candidate = FindFirstColumnWithValue(item);
GetOwner()->GetExpanderColumn() != candidate &&
!GetModel()->HasValue(item, candidate->GetModelColumn()) )
{
candidate = GetOwner()->GetExpanderColumn();
}
if ( !candidate ) if ( !candidate )
return NULL; return NULL;
@@ -4508,24 +4514,16 @@ bool wxDataViewMainWindow::TryAdvanceCurrentColumn(wxDataViewTreeNode *node, wxK
const bool wrapAround = event.GetKeyCode() == WXK_TAB; const bool wrapAround = event.GetKeyCode() == WXK_TAB;
if ( node ) // navigation shouldn't work in nodes with fewer than two columns
{ if ( node && !IsItemMultivalued(node->GetItem()) )
// navigation shouldn't work in nodes with fewer than two columns return false;
if ( !HasItemMultipleValues(node->GetItem()) )
return false;
}
if ( m_currentCol == NULL || !m_currentColSetByKeyboard ) if ( m_currentCol == NULL || !m_currentColSetByKeyboard )
{ {
if ( forward ) if ( forward )
{ {
// find first column with value // find first column with value
unsigned int i = 0; m_currentCol = FindFirstColumnWithValue(node->GetItem());
unsigned int cols = GetOwner()->GetColumnCount();
for ( ; i < cols; i++ )
if ( GetModel()->HasValue(node->GetItem(), i) )
break;
m_currentCol = GetOwner()->GetColumnAt(i);
m_currentColSetByKeyboard = true; m_currentColSetByKeyboard = true;
RefreshRow(m_currentRow); RefreshRow(m_currentRow);
return true; return true;