[browser] Don't try to open links within the browser properties widget

Instead open them externally. Fixes clicking on the path link
within metadata tries to open layer files instead the text
widget instead of showing them in the desktop file browser.
This commit is contained in:
Nyall Dawson 2018-10-31 15:24:29 +10:00
parent 3f72e0cd41
commit ab4601820c
2 changed files with 20 additions and 0 deletions

View File

@ -38,6 +38,9 @@
#include "qgsproject.h"
#include "qgssettings.h"
#include "qgsmeshlayer.h"
#include "qgsgui.h"
#include "qgsnative.h"
#include <QDesktopServices>
#include <QDragEnterEvent>
@ -115,6 +118,10 @@ QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
mUriLabel = new QgsBrowserPropertiesWrapLabel( QString(), this );
mHeaderGridLayout->addItem( new QWidgetItem( mUriLabel ), 1, 1 );
// we don't want links to open in the little widget, open them externally instead
mMetadataTextBrowser->setOpenLinks( false );
connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked, this, &QgsBrowserLayerProperties::urlClicked );
}
class ProjectionSettingRestorer
@ -249,6 +256,15 @@ void QgsBrowserLayerProperties::setCondensedMode( bool condensedMode )
}
}
void QgsBrowserLayerProperties::urlClicked( const QUrl &url )
{
QFileInfo file( url.toLocalFile() );
if ( file.exists() && !file.isDir() )
QgsGui::instance()->nativePlatformInterface()->openFileExplorerAndSelectFile( url.toLocalFile() );
else
QDesktopServices::openUrl( url );
}
QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
: QgsBrowserPropertiesWidget( parent )

View File

@ -123,6 +123,10 @@ class QgsBrowserLayerProperties : public QgsBrowserPropertiesWidget, private Ui:
*/
void setCondensedMode( bool condensedMode ) override;
private slots:
void urlClicked( const QUrl &url );
private:
QgsBrowserPropertiesWrapLabel *mUriLabel = nullptr;
};