Skip to content

Commit

Permalink
[addlayerbutton] Larry Shaffer's fix to the raster button
Browse files Browse the repository at this point in the history
Tricky solution, but temporary
  • Loading branch information
elpaso committed Jun 2, 2017
1 parent 8db19b2 commit 018afc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/app/qgsdatasourcemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
}
} );

Expand Down Expand Up @@ -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()
Expand All @@ -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 ) );
Expand Down
4 changes: 3 additions & 1 deletion src/app/qgsdatasourcemanagerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.