Clarify RowToTreeNodeJob in generic wxDataViewCtrl code

Get rid of hardcoded, without any explanation, "-2" value passed to this
class ctor and instead initialize its m_current member to -1 and explain
why do we do it and increment it after processing the current item, not
before, in operator().

No changes in behaviour.
This commit is contained in:
Vadim Zeitlin
2018-11-04 17:16:31 +01:00
parent ada5de3d0d
commit ed20421181

View File

@@ -3468,14 +3468,16 @@ int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const
class RowToTreeNodeJob: public DoJob class RowToTreeNodeJob: public DoJob
{ {
public: public:
RowToTreeNodeJob(int row, int current) // Note that we initialize m_current to -1 because the first node passed to
: m_row(row), m_current(current), m_ret(NULL) // our operator() will be the root node, which doesn't appear in the window
// and so doesn't count as a real row.
explicit RowToTreeNodeJob(int row)
: m_row(row), m_current(-1), m_ret(NULL)
{ {
} }
virtual int operator() ( wxDataViewTreeNode * node ) wxOVERRIDE virtual int operator() ( wxDataViewTreeNode * node ) wxOVERRIDE
{ {
m_current ++;
if( m_current == m_row) if( m_current == m_row)
{ {
m_ret = node; m_ret = node;
@@ -3484,7 +3486,7 @@ public:
if( node->GetSubTreeCount() + m_current < m_row ) if( node->GetSubTreeCount() + m_current < m_row )
{ {
m_current += node->GetSubTreeCount(); m_current += node->GetSubTreeCount() + 1;
return DoJob::SKIP_SUBTREE; return DoJob::SKIP_SUBTREE;
} }
else else
@@ -3500,6 +3502,8 @@ public:
return DoJob::DONE; return DoJob::DONE;
} }
m_current++;
return DoJob::CONTINUE; return DoJob::CONTINUE;
} }
} }
@@ -3520,7 +3524,7 @@ wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row) co
if ( row == (unsigned)-1 ) if ( row == (unsigned)-1 )
return NULL; return NULL;
RowToTreeNodeJob job( static_cast<int>(row) , -2 ); RowToTreeNodeJob job(static_cast<int>(row));
Walker( m_root , job ); Walker( m_root , job );
return job.GetResult(); return job.GetResult();
} }