Skip to content
Permalink
Browse files

[bugfix][backport] Browser shared model

Backport of master PR 5164
  • Loading branch information
elpaso committed Sep 19, 2017
1 parent c81adf8 commit ccdda891ab6622e99ca60d42c30f92b53ea38847
@@ -116,6 +116,7 @@
#include "qgsauthsslerrorsdialog.h"
#endif
#include "qgsbookmarks.h"
#include "qgsbrowsermodel.h"
#include "qgsbrowserdockwidget.h"
#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsclipboard.h"
@@ -803,12 +804,13 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mSnappingDialog->setObjectName( "SnappingOption" );
endProfile();

mBrowserWidget = new QgsBrowserDockWidget( tr( "Browser Panel" ), this );
mBrowserModel = new QgsBrowserModel( this );
mBrowserWidget = new QgsBrowserDockWidget( tr( "Browser Panel" ), mBrowserModel, this );
mBrowserWidget->setObjectName( "Browser" );
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget );
mBrowserWidget->hide();

mBrowserWidget2 = new QgsBrowserDockWidget( tr( "Browser Panel (2)" ), this );
mBrowserWidget2 = new QgsBrowserDockWidget( tr( "Browser Panel (2)" ), mBrowserModel, this );
mBrowserWidget2->setObjectName( "Browser2" );
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget2 );
mBrowserWidget2->hide();
@@ -1147,6 +1149,7 @@ QgisApp::QgisApp()
, mPythonUtils( nullptr )
, mUndoWidget( nullptr )
, mUndoDock( nullptr )
, mBrowserModel( nullptr )
, mBrowserWidget( nullptr )
, mBrowserWidget2( nullptr )
, mAdvancedDigitizingDockWidget( nullptr )
@@ -82,6 +82,7 @@ class QNetworkProxy;
class QAuthenticator;

class QgsBrowserDockWidget;
class QgsBrowserModel;
class QgsAdvancedDigitizingDockWidget;
class QgsSnappingDialog;
class QgsGPSInformationWidget;
@@ -1724,6 +1725,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsUndoWidget *mUndoWidget;
QgsDockWidget *mUndoDock;

QgsBrowserModel *mBrowserModel;
QgsBrowserDockWidget *mBrowserWidget;
QgsBrowserDockWidget *mBrowserWidget2;

@@ -261,12 +261,30 @@ void QgsBrowserPropertiesDialog::setItem( QgsDataItem* item )
setWindowTitle( item->type() == QgsDataItem::Layer ? tr( "Layer Properties" ) : tr( "Directory Properties" ) );
}


QgsBrowserDockWidget::QgsBrowserDockWidget( const QString& name, QgsBrowserModel *model, QWidget * parent )
: QgsDockWidget( parent )
, mModel( model )
, mProxyModel( nullptr )
, mPropertiesWidgetEnabled( false )
, mPropertiesWidgetHeight( 0 )
{
init( name );
}


QgsBrowserDockWidget::QgsBrowserDockWidget( const QString& name, QWidget * parent )
: QgsDockWidget( parent )
, mModel( nullptr )
, mProxyModel( nullptr )
, mPropertiesWidgetEnabled( false )
, mPropertiesWidgetHeight( 0 )
{
init( name );
}


void QgsBrowserDockWidget::init( const QString& name )
{
setupUi( this );

@@ -324,6 +342,7 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( const QString& name, QWidget * paren
connect( mSplitter, SIGNAL( splitterMoved( int, int ) ), this, SLOT( splitterMoved() ) );
}


QgsBrowserDockWidget::~QgsBrowserDockWidget()
{
QSettings settings;
@@ -334,11 +353,20 @@ QgsBrowserDockWidget::~QgsBrowserDockWidget()

void QgsBrowserDockWidget::showEvent( QShowEvent * e )
{
// delayed initialization of the model

if ( !mModel )
{
mModel = new QgsBrowserModel( mBrowserView );
}

// delayed initialization of the model
if ( !mModel->initialized( ) )
{
mModel->init();
}

if ( ! mProxyModel )
{
connect( QgisApp::instance(), SIGNAL( newProject() ), mModel, SLOT( updateProjectHome() ) );

mProxyModel = new QgsBrowserTreeFilterProxyModel( this );
@@ -105,6 +105,7 @@ class APP_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
Q_OBJECT
public:
explicit QgsBrowserDockWidget( const QString& name, QWidget *parent = nullptr );
explicit QgsBrowserDockWidget( const QString& name, QgsBrowserModel *model, QWidget *parent = nullptr );
~QgsBrowserDockWidget();
void addFavouriteDirectory( const QString& favDir );

@@ -153,6 +154,7 @@ class APP_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
float mPropertiesWidgetHeight;

private:
void init( const QString& name );
};


@@ -51,10 +51,8 @@ QgsBrowserModel::QgsBrowserModel( QObject *parent )
: QAbstractItemModel( parent )
, mFavourites( nullptr )
, mProjectHome( nullptr )
, mInitialized( false )
{
connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), this, SLOT( updateProjectHome() ) );
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), this, SLOT( updateProjectHome() ) );
addRootItems();
}

QgsBrowserModel::~QgsBrowserModel()
@@ -574,3 +572,14 @@ void QgsBrowserModel::hidePath( QgsDataItem *item )
emit endRemoveRows();
}
}

void QgsBrowserModel::init()
{
if ( ! mInitialized )
{
connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), this, SLOT( updateProjectHome() ) );
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), this, SLOT( updateProjectHome() ) );
addRootItems();
mInitialized = true;
}
}
@@ -129,6 +129,12 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
bool canFetchMore( const QModelIndex & parent ) const override;
void fetchMore( const QModelIndex & parent ) override;

//! Returns true if the model has been initialized
bool initialized( ) const { return mInitialized; }

//! Delayed initialization
void init();

signals:
/** Emitted when item children fetch was finished */
void stateChanged( const QModelIndex & index, QgsDataItem::State oldState );
@@ -158,6 +164,9 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
QVector<QgsDataItem*> mRootItems;
QgsFavouritesItem *mFavourites;
QgsDirectoryItem *mProjectHome;

private:
bool mInitialized;
};

#endif // QGSBROWSERMODEL_H

0 comments on commit ccdda89

Please sign in to comment.
You can’t perform that action at this time.