Skip to content

Commit 7132cf3

Browse files
committedMay 20, 2019
[ui] Improve UX by adding an original source label when changing / updating layer data source
1 parent 98845e5 commit 7132cf3

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed
 

‎python/gui/auto_generated/qgsdatasourceselectdialog.sip.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ Constructs a QgsDataSourceSelectDialog, optionally filtering by layer type
5050
void setLayerTypeFilter( QgsMapLayerType layerType );
5151
%Docstring
5252
Sets layer type filter to ``layerType`` and activates the filtering
53+
%End
54+
55+
void setDescription( const QString description );
56+
%Docstring
57+
Sets a description label
58+
59+
:param description: a description string
60+
61+
.. note::
62+
63+
the description will be displayed at the bottom of the dialog
64+
65+
.. versionadded:: 3.8
5366
%End
5467

5568
QgsMimeDataUtils::Uri uri() const;

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7164,6 +7164,7 @@ void QgisApp::changeDataSource( QgsMapLayer *layer )
71647164
QgsMapLayerType layerType( layer->type() );
71657165

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

71687169
if ( dlg.exec() == QDialog::Accepted )
71697170
{

‎src/gui/qgsdatasourceselectdialog.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,30 @@ void QgsDataSourceSelectDialog::showFilterWidget( bool visible )
162162
}
163163
}
164164

165+
void QgsDataSourceSelectDialog::setDescription( const QString description )
166+
{
167+
if ( !description.isEmpty() )
168+
{
169+
if ( !mDescriptionLabel )
170+
{
171+
mDescriptionLabel = new QLabel();
172+
mDescriptionLabel->setWordWrap( true );
173+
mDescriptionLabel->setMargin( 4 );
174+
verticalLayout->insertWidget( 1, mDescriptionLabel );
175+
}
176+
mDescriptionLabel->setText( description );
177+
}
178+
else
179+
{
180+
if ( mDescriptionLabel )
181+
{
182+
verticalLayout->removeWidget( mDescriptionLabel );
183+
delete mDescriptionLabel;
184+
mDescriptionLabel = nullptr;
185+
}
186+
}
187+
}
188+
165189
void QgsDataSourceSelectDialog::setFilter()
166190
{
167191
QString filter = mLeFilter->text();

‎src/gui/qgsdatasourceselectdialog.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#ifndef QGSDATASOURCESELECTDIALOG_H
1717
#define QGSDATASOURCESELECTDIALOG_H
1818

19-
#include <QObject>
2019
#include "ui_qgsdatasourceselectdialog.h"
2120

2221
#include "qgis_gui.h"
@@ -25,6 +24,8 @@
2524
#include "qgsbrowsermodel.h"
2625
#include "qgsbrowserproxymodel.h"
2726

27+
#include <QObject>
28+
#include <QLabel>
2829

2930
/**
3031
* \ingroup gui
@@ -68,6 +69,14 @@ class GUI_EXPORT QgsDataSourceSelectDialog: public QDialog, private Ui::QgsDataS
6869
*/
6970
void setLayerTypeFilter( QgsMapLayerType layerType );
7071

72+
/**
73+
* Sets a description label
74+
* \param description a description string
75+
* \note the description will be displayed at the bottom of the dialog
76+
* \since 3.8
77+
*/
78+
void setDescription( const QString description );
79+
7180
/**
7281
* Returns the (possibly invalid) uri of the selected data source
7382
*/
@@ -98,6 +107,7 @@ class GUI_EXPORT QgsDataSourceSelectDialog: public QDialog, private Ui::QgsDataS
98107
std::unique_ptr<QgsBrowserModel> mBrowserModel;
99108
bool mOwnModel = true;
100109
QgsMimeDataUtils::Uri mUri;
110+
QLabel *mDescriptionLabel = nullptr;
101111

102112
};
103113

0 commit comments

Comments
 (0)
Please sign in to comment.