Skip to content

Commit

Permalink
Fix clearing groups
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 28, 2020
1 parent 5c842a6 commit 42a1ed1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsruntimeprofiler.sip.in
Expand Up @@ -151,7 +151,7 @@ Python scripts should not use QgsScopedRuntimeProfile directly. Instead, use :py
%End
public:

QgsScopedRuntimeProfile( const QString &name );
QgsScopedRuntimeProfile( const QString &name, const QString &group = "startup" );
%Docstring
Constructor for QgsScopedRuntimeProfile.

Expand Down
23 changes: 15 additions & 8 deletions src/core/qgsruntimeprofiler.cpp
Expand Up @@ -113,6 +113,12 @@ void QgsRuntimeProfilerNode::clear()
mChildren.clear();
}

void QgsRuntimeProfilerNode::removeChildAt( int index )
{
Q_ASSERT( static_cast< std::size_t >( index ) < mChildren.size() );
mChildren.erase( mChildren.begin() + index );
}

void QgsRuntimeProfilerNode::start()
{
mProfileTime.restart();
Expand Down Expand Up @@ -263,13 +269,14 @@ double QgsRuntimeProfiler::profileTime( const QString &name, const QString &grou

void QgsRuntimeProfiler::clear( const QString &group )
{
if ( QgsRuntimeProfilerNode *node = pathToNode( group, QString() ) )
for ( int row = mRootNode->childCount() - 1; row >= 0; row-- )
{
// FIX!!!
const QModelIndex index = node2index( node );
beginRemoveRows( index, 0, node->childCount() - 1 );
node->clear();
endRemoveRows();
if ( mRootNode->childAt( row )->data( QgsRuntimeProfilerNode::Group ).toString() == group )
{
beginRemoveRows( QModelIndex(), row, row );
mRootNode->removeChildAt( row );
endRemoveRows();
}
}
}

Expand Down Expand Up @@ -562,9 +569,9 @@ QgsRuntimeProfilerNode *QgsRuntimeProfiler::index2node( const QModelIndex &index
// QgsScopedRuntimeProfile
//

QgsScopedRuntimeProfile::QgsScopedRuntimeProfile( const QString &name )
QgsScopedRuntimeProfile::QgsScopedRuntimeProfile( const QString &name, const QString &group )
{
QgsApplication::profiler()->start( name );
QgsApplication::profiler()->start( name, group );
}

QgsScopedRuntimeProfile::~QgsScopedRuntimeProfile()
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsruntimeprofiler.h
Expand Up @@ -102,6 +102,11 @@ class CORE_EXPORT QgsRuntimeProfilerNode
*/
void clear();

/**
* Removes and deletes the child at the specified \a index.
*/
void removeChildAt( int index );

/**
* Starts the node timer.
* \see stop()
Expand Down Expand Up @@ -311,7 +316,7 @@ class CORE_EXPORT QgsScopedRuntimeProfile
* Automatically registers the operation in the QgsApplication::profiler() instance
* and starts recording the run time of the operation.
*/
QgsScopedRuntimeProfile( const QString &name );
QgsScopedRuntimeProfile( const QString &name, const QString &group = "startup" );

/**
* Records the final runtime of the operation in the profiler instance.
Expand Down

0 comments on commit 42a1ed1

Please sign in to comment.