Skip to content

Commit

Permalink
[addlayerbutton] Raster support added
Browse files Browse the repository at this point in the history
There is still an issue with the list not being
correclty reset after the raster icon is selected.
  • Loading branch information
elpaso committed Jun 2, 2017
1 parent 811e4df commit 8db19b2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 27 deletions.
7 changes: 4 additions & 3 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ void QgisApp::dataSourceManager()
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::showStatusMessage, this, &QgisApp::showStatusMessage );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::addDatabaseLayers, this, &QgisApp::addDatabaseLayers );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::replaceSelectedVectorLayer, this, &QgisApp::replaceSelectedVectorLayer );
connect( mDataSourceManagerDialog, static_cast<void ( QgsDataSourceManagerDialog::* )()>( &QgsDataSourceManagerDialog::addRasterLayer ), this, static_cast<void ( QgisApp::* )()>( &QgisApp::addRasterLayer ) );
}
mDataSourceManagerDialog->exec();
}
Expand Down Expand Up @@ -11559,8 +11560,8 @@ void QgisApp::renameView()
/////////////////////////////////////////////////////////////////


// this is a slot for action from GUI to add raster layer
void QgisApp::addRasterLayer()
// this is a slot for action from GUI to open and add raster layers
void QgisApp::addRasterLayer( )
{
QStringList selectedFiles;
QString e;//only for parameter correctness
Expand All @@ -11576,7 +11577,7 @@ void QgisApp::addRasterLayer()

addRasterLayers( selectedFiles );

}// QgisApp::addRasterLayer()
}

//
// This is the method that does the actual work of adding a raster layer - the others
Expand Down
21 changes: 12 additions & 9 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgisApp( QgisApp const & ) = delete;
QgisApp &operator=( QgisApp const & ) = delete;

/** Overloaded vesion of the private addRasterLayer()
Method that takes a list of file names instead of prompting
user with a dialog.
\returns true if successfully added layer(s)
*/
bool addRasterLayers( const QStringList &layerQStringList, bool guiWarning = true );

/** Open a raster layer for the given file
\returns false if unable to open a raster layer for rasterFile
\note
Expand Down Expand Up @@ -794,6 +787,18 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
bool addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );

/** Overloaded vesion of the private addRasterLayer()
Method that takes a list of file names instead of prompting
user with a dialog.
\returns true if successfully added layer(s)
*/
bool addRasterLayers( const QStringList &layerQStringList, bool guiWarning = true );

/** \brief Open one or more raster layers and add to the map
* Will prompt user for file names using a file selection dialog
*/
void addRasterLayer();

//! Open a plugin layer using its provider
QgsPluginLayer *addPluginLayer( const QString &uri, const QString &baseName, const QString &providerKey );

Expand Down Expand Up @@ -861,8 +866,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void sponsors();
//! About QGIS
void about();
//! Add a raster layer to the map (will prompt user for file name using dlg )
void addRasterLayer();
//#ifdef HAVE_POSTGRESQL
//! Add a databaselayer to the map
void addDatabaseLayer();
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgisappinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ QgsVectorLayer *QgisAppInterface::addVectorLayer( const QString &vectorLayerPath

QgsRasterLayer *QgisAppInterface::addRasterLayer( const QString &rasterLayerPath, const QString &baseName )
{
QString nonNullBaseBame = baseName;
if ( nonNullBaseBame.isEmpty() )
QString nonNullBaseName = baseName;
if ( nonNullBaseName.isEmpty() )
{
QFileInfo fi( rasterLayerPath );
nonNullBaseBame = fi.completeBaseName();
nonNullBaseName = fi.completeBaseName();
}
return qgis->addRasterLayer( rasterLayerPath, nonNullBaseBame );
return qgis->addRasterLayer( rasterLayerPath, nonNullBaseName );
}

QgsRasterLayer *QgisAppInterface::addRasterLayer( const QString &url, const QString &baseName, const QString &providerKey )
Expand Down
40 changes: 32 additions & 8 deletions src/app/qgsdatasourcemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent, Qt::WindowFlags fl ) :
QgsOptionsDialogBase( QStringLiteral( "Data Source Manager" ), parent, fl ),
ui( new Ui::QgsDataSourceManagerDialog ),
mMapCanvas( mapCanvas )
mMapCanvas( mapCanvas ),
mPreviousCurrentRow( -1 )
{

ui->setupUi( this );
Expand All @@ -40,7 +41,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
initOptionsBase( true );

// Bind list index to the stacked dialogs
connect( ui->mOptionsListWidget, SIGNAL( currentRowChanged( int ) ), this, SLOT( setCurrentPage( int ) ) );
connect( ui->mOptionsListWidget, &QListWidget::currentRowChanged, this, &QgsDataSourceManagerDialog::setCurrentPage );

// BROWSER Add the browser widget to the first stacked widget page
mBrowserWidget = new QgsBrowserDockWidget( QStringLiteral( "Browser" ), this );
Expand All @@ -55,6 +56,26 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
ogrItem->setToolTip( tr( "Add Vector layer" ) );
connect( ovl, &QgsOpenVectorLayerDialog::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );

// RASTER (forward to app)
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( ) )
{
emit addRasterLayer();
int prevPage = mPreviousCurrentRow != -1 ? mPreviousCurrentRow : 0;
ui->mOptionsListWidget->setCurrentRow( prevPage );
ui->mOptionsListWidget->item( prevPage )->setSelected( true );
ui->mOptionsListWidget->setFocus();
setCurrentPage( prevPage );
}
} );


// Add data provider dialogs
QDialog *dlg = nullptr;

Expand Down Expand Up @@ -113,6 +134,8 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
connect( dlg, SIGNAL( addVectorLayer( QString, QString, QString ) ), this, SLOT( vectorLayerAdded( QString, QString, QString ) ) );
connect( dlg, SIGNAL( replaceVectorLayer( QString, QString, QString, QString ) ), this, SIGNAL( replaceSelectedVectorLayer( QString, QString, QString, QString ) ) );
}


}

QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
Expand All @@ -122,6 +145,7 @@ QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()

void QgsDataSourceManagerDialog::setCurrentPage( int index )
{
mPreviousCurrentRow = ui->mOptionsStackedWidget->currentIndex( );
ui->mOptionsStackedWidget->setCurrentIndex( index );
setWindowTitle( tr( "Data Source Manager | %1" ).arg( ui->mOptionsListWidget->currentItem()->text( ) ) );
}
Expand All @@ -142,7 +166,7 @@ void QgsDataSourceManagerDialog::vectorLayersAdded( const QStringList &layerQStr
}


QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey, const QString providerName, const QString icon )
QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
{
QDialog *dlg = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( providerKey, this, Qt::Widget, QgsProviderRegistry::WidgetMode::Embedded ) );
if ( !dlg )
Expand All @@ -154,15 +178,15 @@ QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey,
{
ui->mOptionsStackedWidget->addWidget( dlg );
QListWidgetItem *layerItem = new QListWidgetItem( providerName, ui->mOptionsListWidget );
layerItem->setToolTip( tr( "Add %1 layer" ).arg( providerName ) );
layerItem->setToolTip( title.isEmpty() ? tr( "Add %1 layer" ).arg( providerName ) : title );
layerItem->setIcon( QgsApplication::getThemeIcon( icon ) );
return dlg;
}
}

void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey, const QString providerName, const QString icon )
void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
{
QDialog *dlg = providerDialog( providerKey, providerName, icon );
QDialog *dlg = providerDialog( providerKey, providerName, icon, title );
if ( dlg )
{
connect( dlg, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
Expand All @@ -174,9 +198,9 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey,
}
}

void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString providerKey, const QString providerName, const QString icon )
void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
{
QDialog *dlg = providerDialog( providerKey, providerName, icon );
QDialog *dlg = providerDialog( providerKey, providerName, icon, title );
if ( dlg )
{
// Forward
Expand Down
8 changes: 5 additions & 3 deletions src/app/qgsdatasourcemanagerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class QgsDataSourceManagerDialog : public QgsOptionsDialogBase
signals:
//! For signal forwarding to QgisApp
void addRasterLayer( QString const &uri, QString const &baseName, QString const &providerKey );
void addRasterLayer( );
void addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
//! Replace the selected layer by a vector layer defined by uri, layer name, data source uri
void replaceSelectedVectorLayer( const QString &oldId, const QString &uri, const QString &layerName, const QString &provider );
Expand All @@ -66,13 +67,14 @@ class QgsDataSourceManagerDialog : public QgsOptionsDialogBase

private:
//! Return the dialog from the provider
QDialog *providerDialog( QString const providerKey, QString const providerName, QString const icon );
void addDbProviderDialog( QString const providerKey, QString const providerName, QString const icon );
void addRasterProviderDialog( QString const providerKey, QString const providerName, QString const icon );
QDialog *providerDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString( ) );
void addDbProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString( ) );
void addRasterProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString( ) );
Ui::QgsDataSourceManagerDialog *ui;
QgsBrowserDockWidget *mBrowserWidget = nullptr;
//! Map canvas
QgsMapCanvas *mMapCanvas = nullptr;
int mPreviousCurrentRow;
};

#endif // QGSDATASOURCEMANAGERDIALOG_H

0 comments on commit 8db19b2

Please sign in to comment.