Skip to content

Commit

Permalink
Anonymise connection string in welcome page (title and tooltip)
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Sep 19, 2023
1 parent 9b9a702 commit 0d5d80e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app/qgsprojectlistitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void QgsProjectListItemDelegate::paint( QPainter *painter, const QStyleOptionVie
doc.setHtml( QStringLiteral( "<div style='font-size:%1px'><span style='font-size:%2px;font-weight:bold;'>%3%4</span><br>%5<br>%6</div>" ).arg( textSize ).arg( QString::number( titleSize ),
index.data( QgsProjectListItemDelegate::TitleRole ).toString(),
index.data( QgsProjectListItemDelegate::PinRole ).toBool() ? QStringLiteral( "<img src=\":/images/themes/default/pin.svg\">" ) : QString(),
mShowPath ? index.data( QgsProjectListItemDelegate::NativePathRole ).toString() : QString(),
mShowPath ? index.data( QgsProjectListItemDelegate::AnonymisedNativePathRole ).toString() : QString(),
index.data( QgsProjectListItemDelegate::CrsRole ).toString() ) );
doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? iconSize.width() + 4.375 * mRoundedRectSizePixels : 4.375 * mRoundedRectSizePixels ) );

Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsprojectlistitemdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class QgsProjectListItemDelegate : public QStyledItemDelegate
PathRole = Qt::UserRole + 2,
NativePathRole = Qt::UserRole + 3,
CrsRole = Qt::UserRole + 4,
PinRole = Qt::UserRole + 5
PinRole = Qt::UserRole + 5,
AnonymisedNativePathRole = Qt::UserRole + 6
};

explicit QgsProjectListItemDelegate( QObject *parent = nullptr );
Expand Down
12 changes: 11 additions & 1 deletion src/app/qgsrecentprojectsitemsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qgsprojectstorageregistry.h"
#include "qgsprojectlistitemdelegate.h"
#include "qgsprojectstorage.h"
#include "qgsdatasourceuri.h"

#include <QApplication>
#include <QAbstractTextDocumentLayout>
Expand Down Expand Up @@ -88,7 +89,16 @@ QVariant QgsRecentProjectItemsModel::data( const QModelIndex &index, int role )
}

case Qt::ToolTipRole:
return mRecentProjects.at( index.row() ).path;
case QgsProjectListItemDelegate::AnonymisedNativePathRole:
{
QString name = mRecentProjects.at( index.row() ).path;
QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromUri( name );
if ( storage )
{
name = QgsDataSourceUri::removePassword( name, true );
}
return name;
}

default:
return QVariant();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgswelcomepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ QgsRecentProjectItemsModel *QgsWelcomePage::recentProjectsModel()

void QgsWelcomePage::recentProjectItemActivated( const QModelIndex &index )
{
QgisApp::instance()->openProject( mRecentProjectsModel->data( index, Qt::ToolTipRole ).toString() );
QgisApp::instance()->openProject( mRecentProjectsModel->data( index, QgsProjectListItemDelegate::PathRole ).toString() );
}

void QgsWelcomePage::templateProjectItemActivated( const QModelIndex &index )
Expand Down

0 comments on commit 0d5d80e

Please sign in to comment.