Skip to content

Commit f8b2b13

Browse files
committed
Added optional argument to keep legacy API and behavior
1 parent ccdda89 commit f8b2b13

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

python/core/qgsbrowsermodel.sip

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class QgsBrowserModel : QAbstractItemModel
55
%End
66

77
public:
8-
explicit QgsBrowserModel( QObject *parent = 0 );
8+
explicit QgsBrowserModel( QObject *parent = 0, bool initialize = true );
99
~QgsBrowserModel();
1010

1111
enum ItemDataRole
@@ -81,6 +81,12 @@ class QgsBrowserModel : QAbstractItemModel
8181
bool canFetchMore( const QModelIndex & parent ) const;
8282
void fetchMore( const QModelIndex & parent );
8383

84+
//! Returns true if the model has been initialized
85+
bool initialized( );
86+
87+
//! Delayed initialization
88+
void init();
89+
8490
signals:
8591
/** Emitted when item children fetch was finished */
8692
void stateChanged( const QModelIndex & index, QgsDataItem::State oldState );

src/app/qgisapp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
804804
mSnappingDialog->setObjectName( "SnappingOption" );
805805
endProfile();
806806

807-
mBrowserModel = new QgsBrowserModel( this );
807+
// Create the (shared) model with delayed initialization
808+
mBrowserModel = new QgsBrowserModel( this, false );
808809
mBrowserWidget = new QgsBrowserDockWidget( tr( "Browser Panel" ), mBrowserModel, this );
809810
mBrowserWidget->setObjectName( "Browser" );
810811
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget );

src/core/qgsbrowsermodel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ static bool cmpByDataItemName_( QgsDataItem* a, QgsDataItem* b )
4747
return QString::localeAwareCompare( a->name(), b->name() ) < 0;
4848
}
4949

50-
QgsBrowserModel::QgsBrowserModel( QObject *parent )
50+
QgsBrowserModel::QgsBrowserModel( QObject *parent, bool initialize )
5151
: QAbstractItemModel( parent )
5252
, mFavourites( nullptr )
5353
, mProjectHome( nullptr )
5454
, mInitialized( false )
5555
{
56+
if ( initialize )
57+
init();
5658
}
5759

5860
QgsBrowserModel::~QgsBrowserModel()

src/core/qgsbrowsermodel.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
5353
Q_OBJECT
5454

5555
public:
56-
explicit QgsBrowserModel( QObject *parent = nullptr );
56+
57+
/**
58+
* @brief QgsBrowserModel
59+
* @param parent
60+
* @param initialize immediately called init, default to true
61+
*/
62+
explicit QgsBrowserModel( QObject *parent = nullptr , bool initialize = true );
5763
~QgsBrowserModel();
5864

5965
enum ItemDataRole

0 commit comments

Comments
 (0)