Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 463fd03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/app/qgsdatasourcemanagerdialog.cpp
Expand Up @@ -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 );
Expand All @@ -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
Expand All @@ -73,6 +75,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
QTimer::singleShot( 0, this, &QgsDataSourceManagerDialog::setPreviousPage );
}
} );
mPageNames.append( QStringLiteral( "raster" ) );


// Add data provider dialogs
Expand Down Expand Up @@ -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( );
Expand Down Expand Up @@ -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 );
Expand Down
8 changes: 8 additions & 0 deletions src/app/qgsdatasourcemanagerdialog.h
Expand Up @@ -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
Expand Down Expand Up @@ -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.