Skip to content
Permalink
Browse files

[addlayerbutton] Add method to open a given page in the layer dlg

This is preliminary to change all dialogs slots to
open the unified dialog with the righ page open.
  • Loading branch information
elpaso committed Jun 2, 2017
1 parent e43dfa2 commit 463fd0362b0a9a3e5ba006efc4ae426131651cb0
Showing with 21 additions and 0 deletions.
  1. +13 −0 src/app/qgsdatasourcemanagerdialog.cpp
  2. +8 −0 src/app/qgsdatasourcemanagerdialog.h
@@ -47,6 +47,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
mBrowserWidget = new QgsBrowserDockWidget( QStringLiteral( "Browser" ), this );
mBrowserWidget->setFeatures( QDockWidget::NoDockWidgetFeatures );
ui->mOptionsStackedWidget->addWidget( mBrowserWidget );
mPageNames.append( QStringLiteral( "browser" ) );

// VECTOR Layers (completely different interface: it's not a provider)
QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this, Qt::Widget, QgsProviderRegistry::WidgetMode::Embedded );
@@ -55,6 +56,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
ogrItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddOgrLayer.svg" ) ) );
ogrItem->setToolTip( tr( "Add Vector layer" ) );
connect( ovl, &QgsOpenVectorLayerDialog::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );
mPageNames.append( QStringLiteral( "ogr" ) );

// RASTER (forward to app)
// Note: the tricky solution here will not last long: the browser button is really the
@@ -73,6 +75,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
QTimer::singleShot( 0, this, &QgsDataSourceManagerDialog::setPreviousPage );
}
} );
mPageNames.append( QStringLiteral( "raster" ) );


// Add data provider dialogs
@@ -141,6 +144,15 @@ QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
delete ui;
}

void QgsDataSourceManagerDialog::openPage( QString pageName )
{
int pageIdx = mPageNames.indexOf( pageName );
if ( pageIdx != -1 )
{
QTimer::singleShot( 0, this, [ = ] { setCurrentPage( pageIdx ); } );
}
}

void QgsDataSourceManagerDialog::setCurrentPage( int index )
{
mPreviousRow = ui->mOptionsStackedWidget->currentIndex( );
@@ -180,6 +192,7 @@ QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey,
}
else
{
mPageNames.append( providerKey );
ui->mOptionsStackedWidget->addWidget( dlg );
QListWidgetItem *layerItem = new QListWidgetItem( providerName, ui->mOptionsListWidget );
layerItem->setToolTip( title.isEmpty() ? tr( "Add %1 layer" ).arg( providerName ) : title );
@@ -40,6 +40,13 @@ class QgsDataSourceManagerDialog : public QgsOptionsDialogBase
explicit QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
~QgsDataSourceManagerDialog();

/**
* @brief openPage open a given page in the dialog
* @param pageName the page name, usually the provider name or "browser" (for the browser panel)
* or "ogr" (vector layers) or "raster" (raster layers)
*/
void openPage( QString pageName );

public slots:

//! Sync current page with the leftbar list
@@ -76,6 +83,7 @@ class QgsDataSourceManagerDialog : public QgsOptionsDialogBase
//! Map canvas
QgsMapCanvas *mMapCanvas = nullptr;
int mPreviousRow;
QStringList mPageNames;
};

#endif // QGSDATASOURCEMANAGERDIALOG_H

0 comments on commit 463fd03

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