Skip to content

Commit

Permalink
[ui] Improve UX by adding an original source label when changing / up…
Browse files Browse the repository at this point in the history
…dating layer data source
  • Loading branch information
nirvn committed May 20, 2019
1 parent 98845e5 commit 7132cf3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
13 changes: 13 additions & 0 deletions python/gui/auto_generated/qgsdatasourceselectdialog.sip.in
Expand Up @@ -50,6 +50,19 @@ Constructs a QgsDataSourceSelectDialog, optionally filtering by layer type
void setLayerTypeFilter( QgsMapLayerType layerType );
%Docstring
Sets layer type filter to ``layerType`` and activates the filtering
%End

void setDescription( const QString description );
%Docstring
Sets a description label

:param description: a description string

.. note::

the description will be displayed at the bottom of the dialog

.. versionadded:: 3.8
%End

QgsMimeDataUtils::Uri uri() const;
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -7164,6 +7164,7 @@ void QgisApp::changeDataSource( QgsMapLayer *layer )
QgsMapLayerType layerType( layer->type() );

QgsDataSourceSelectDialog dlg( mBrowserModel, true, layerType );
dlg.setDescription( tr( "Original source URI: %1" ).arg( layer->publicSource() ) );

if ( dlg.exec() == QDialog::Accepted )
{
Expand Down
24 changes: 24 additions & 0 deletions src/gui/qgsdatasourceselectdialog.cpp
Expand Up @@ -162,6 +162,30 @@ void QgsDataSourceSelectDialog::showFilterWidget( bool visible )
}
}

void QgsDataSourceSelectDialog::setDescription( const QString description )
{
if ( !description.isEmpty() )
{
if ( !mDescriptionLabel )
{
mDescriptionLabel = new QLabel();
mDescriptionLabel->setWordWrap( true );
mDescriptionLabel->setMargin( 4 );
verticalLayout->insertWidget( 1, mDescriptionLabel );
}
mDescriptionLabel->setText( description );
}
else
{
if ( mDescriptionLabel )
{
verticalLayout->removeWidget( mDescriptionLabel );
delete mDescriptionLabel;
mDescriptionLabel = nullptr;
}
}
}

void QgsDataSourceSelectDialog::setFilter()
{
QString filter = mLeFilter->text();
Expand Down
12 changes: 11 additions & 1 deletion src/gui/qgsdatasourceselectdialog.h
Expand Up @@ -16,7 +16,6 @@
#ifndef QGSDATASOURCESELECTDIALOG_H
#define QGSDATASOURCESELECTDIALOG_H

#include <QObject>
#include "ui_qgsdatasourceselectdialog.h"

#include "qgis_gui.h"
Expand All @@ -25,6 +24,8 @@
#include "qgsbrowsermodel.h"
#include "qgsbrowserproxymodel.h"

#include <QObject>
#include <QLabel>

/**
* \ingroup gui
Expand Down Expand Up @@ -68,6 +69,14 @@ class GUI_EXPORT QgsDataSourceSelectDialog: public QDialog, private Ui::QgsDataS
*/
void setLayerTypeFilter( QgsMapLayerType layerType );

/**
* Sets a description label
* \param description a description string
* \note the description will be displayed at the bottom of the dialog
* \since 3.8
*/
void setDescription( const QString description );

/**
* Returns the (possibly invalid) uri of the selected data source
*/
Expand Down Expand Up @@ -98,6 +107,7 @@ class GUI_EXPORT QgsDataSourceSelectDialog: public QDialog, private Ui::QgsDataS
std::unique_ptr<QgsBrowserModel> mBrowserModel;
bool mOwnModel = true;
QgsMimeDataUtils::Uri mUri;
QLabel *mDescriptionLabel = nullptr;

};

Expand Down

0 comments on commit 7132cf3

Please sign in to comment.