Skip to content
Permalink
Browse files

[addlayerbutton] Larry Shaffer's fix to the raster button

Tricky solution, but temporary
  • Loading branch information
elpaso committed Jun 2, 2017
1 parent 8db19b2 commit 018afc78db51b44f1af12869fd5185e9c9d3ac6a
Showing with 16 additions and 10 deletions.
  1. +13 −9 src/app/qgsdatasourcemanagerdialog.cpp
  2. +3 −1 src/app/qgsdatasourcemanagerdialog.h
@@ -31,7 +31,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
QgsOptionsDialogBase( QStringLiteral( "Data Source Manager" ), parent, fl ),
ui( new Ui::QgsDataSourceManagerDialog ),
mMapCanvas( mapCanvas ),
mPreviousCurrentRow( -1 )
mPreviousRow( -1 )
{

ui->setupUi( this );
@@ -57,21 +57,20 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
connect( ovl, &QgsOpenVectorLayerDialog::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );

// RASTER (forward to app)
// Note: the tricky solution here will not last long: the browser button is really the
// first that will disappear because its functionality can be replaced completely
// right now by the browser
ui->mOptionsStackedWidget->addWidget( new QWidget() );
QListWidgetItem *rasterItem = new QListWidgetItem( tr( "Raster" ), ui->mOptionsListWidget );
rasterItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddRasterLayer.svg" ) ) );
rasterItem->setToolTip( tr( "Open a GDAL Supported Raster Data Source" ) );
connect( ui->mOptionsListWidget, &QListWidget::currentRowChanged, this, [ = ]( int idx )
{
Q_UNUSED( idx );
if ( rasterItem->isSelected( ) )
if ( rasterItem->isSelected() )
{
emit addRasterLayer();
int prevPage = mPreviousCurrentRow != -1 ? mPreviousCurrentRow : 0;
ui->mOptionsListWidget->setCurrentRow( prevPage );
ui->mOptionsListWidget->item( prevPage )->setSelected( true );
ui->mOptionsListWidget->setFocus();
setCurrentPage( prevPage );
QTimer::singleShot( 0, this, &QgsDataSourceManagerDialog::setPreviousPage );
}
} );

@@ -135,7 +134,6 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
connect( dlg, SIGNAL( replaceVectorLayer( QString, QString, QString, QString ) ), this, SIGNAL( replaceSelectedVectorLayer( QString, QString, QString, QString ) ) );
}


}

QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
@@ -145,11 +143,17 @@ QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()

void QgsDataSourceManagerDialog::setCurrentPage( int index )
{
mPreviousCurrentRow = ui->mOptionsStackedWidget->currentIndex( );
mPreviousRow = ui->mOptionsStackedWidget->currentIndex( );
ui->mOptionsStackedWidget->setCurrentIndex( index );
setWindowTitle( tr( "Data Source Manager | %1" ).arg( ui->mOptionsListWidget->currentItem()->text( ) ) );
}

void QgsDataSourceManagerDialog::setPreviousPage()
{
int prevPage = mPreviousRow != -1 ? mPreviousRow : 0;
setCurrentPage( prevPage );
}

void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey )
{
emit( addRasterLayer( uri, baseName, providerKey ) );
@@ -50,6 +50,8 @@ class QgsDataSourceManagerDialog : public QgsOptionsDialogBase
void vectorLayerAdded( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
void vectorLayersAdded( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
void on_buttonBox_helpRequested() { QgsHelp::openHelp( QStringLiteral( "TODO_PLACEHOLDER.html" ) ); }
//! Reset current page to previously selected page
void setPreviousPage();

signals:
//! For signal forwarding to QgisApp
@@ -74,7 +76,7 @@ class QgsDataSourceManagerDialog : public QgsOptionsDialogBase
QgsBrowserDockWidget *mBrowserWidget = nullptr;
//! Map canvas
QgsMapCanvas *mMapCanvas = nullptr;
int mPreviousCurrentRow;
int mPreviousRow;
};

#endif // QGSDATASOURCEMANAGERDIALOG_H

0 comments on commit 018afc7

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