From c3779f2e5dcb6c57762d9347cce3c8e3cd372e19 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 4 Nov 2018 17:29:24 +0100 Subject: [PATCH] Clarify ItemToRowJob in generic wxDataViewCtrl code Rename its m_ret field to a more clear and more consistent with RowToTreeNodeJob::m_current name and also make m_current, unlike m_ret, 0-based from the beginning instead of having to subtract 1 from it in GetResult(). There should be no changes in the class behaviour. --- src/generic/datavgen.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 994a70171e..d82c2f051f 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3860,41 +3860,49 @@ int wxDataViewMainWindow::RecalculateCount() const class ItemToRowJob : public DoJob { public: + // As with RowToTreeNodeJob above, we initialize m_current to -1 because + // the first node passed to our operator() is the root node which is not + // visible on screen and so we should return 0 for its first child node and + // not for the root itself. ItemToRowJob(const wxDataViewItem& item, wxVector::reverse_iterator iter) - : m_item(item), m_iter(iter), m_ret(-1) + : m_item(item), m_iter(iter), m_current(-1) { } // Maybe binary search will help to speed up this process virtual int operator() ( wxDataViewTreeNode * node) wxOVERRIDE { - m_ret ++; if( node->GetItem() == m_item ) { return DoJob::DONE; } + // Is this node the next (grand)parent of the item we're looking for? if( node->GetItem() == *m_iter ) { + // Search for the next (grand)parent now and skip this item itself. ++m_iter; + ++m_current; return DoJob::CONTINUE; } else { - m_ret += node->GetSubTreeCount(); + // Skip this node and all its currently visible children. + m_current += node->GetSubTreeCount() + 1; return DoJob::SKIP_SUBTREE; } } - // the row number is begin from zero int GetResult() const - { return m_ret -1; } + { return m_current; } private: const wxDataViewItem m_item; wxVector::reverse_iterator m_iter; - int m_ret; + + // The row corresponding to the last node seen in our operator(). + int m_current; };