Skip to content

Commit

Permalink
Added optional argument to keep legacy API and behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Sep 20, 2017
1 parent ccdda89 commit f8b2b13
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
8 changes: 7 additions & 1 deletion python/core/qgsbrowsermodel.sip
Expand Up @@ -5,7 +5,7 @@ class QgsBrowserModel : QAbstractItemModel
%End

public:
explicit QgsBrowserModel( QObject *parent = 0 );
explicit QgsBrowserModel( QObject *parent = 0, bool initialize = true );
~QgsBrowserModel();

enum ItemDataRole
Expand Down Expand Up @@ -81,6 +81,12 @@ class QgsBrowserModel : QAbstractItemModel
bool canFetchMore( const QModelIndex & parent ) const;
void fetchMore( const QModelIndex & parent );

//! Returns true if the model has been initialized
bool initialized( );

//! Delayed initialization
void init();

signals:
/** Emitted when item children fetch was finished */
void stateChanged( const QModelIndex & index, QgsDataItem::State oldState );
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -804,7 +804,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mSnappingDialog->setObjectName( "SnappingOption" );
endProfile();

mBrowserModel = new QgsBrowserModel( this );
// Create the (shared) model with delayed initialization
mBrowserModel = new QgsBrowserModel( this, false );
mBrowserWidget = new QgsBrowserDockWidget( tr( "Browser Panel" ), mBrowserModel, this );
mBrowserWidget->setObjectName( "Browser" );
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget );
Expand Down
4 changes: 3 additions & 1 deletion src/core/qgsbrowsermodel.cpp
Expand Up @@ -47,12 +47,14 @@ static bool cmpByDataItemName_( QgsDataItem* a, QgsDataItem* b )
return QString::localeAwareCompare( a->name(), b->name() ) < 0;
}

QgsBrowserModel::QgsBrowserModel( QObject *parent )
QgsBrowserModel::QgsBrowserModel( QObject *parent, bool initialize )
: QAbstractItemModel( parent )
, mFavourites( nullptr )
, mProjectHome( nullptr )
, mInitialized( false )
{
if ( initialize )
init();
}

QgsBrowserModel::~QgsBrowserModel()
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsbrowsermodel.h
Expand Up @@ -53,7 +53,13 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
Q_OBJECT

public:
explicit QgsBrowserModel( QObject *parent = nullptr );

/**
* @brief QgsBrowserModel
* @param parent
* @param initialize immediately called init, default to true
*/
explicit QgsBrowserModel( QObject *parent = nullptr , bool initialize = true );
~QgsBrowserModel();

enum ItemDataRole
Expand Down

0 comments on commit f8b2b13

Please sign in to comment.