Skip to content

Commit a89dfde

Browse files
committedOct 25, 2017
Remember whether project file exists and don't continually recheck
Because that's slow for network paths. Instead only check once, and add a menu option to refresh and force re-check
1 parent 05e97b3 commit a89dfde

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed
 

‎src/app/qgswelcomepage.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,30 @@ void QgsWelcomePage::showContextMenuForProjects( QPoint point )
121121
if ( path.isEmpty() )
122122
return;
123123

124+
bool enabled = mModel->flags( index ) & Qt::ItemIsEnabled;
125+
124126
QMenu *menu = new QMenu( this );
125127

126-
QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu );
127-
connect( openFolderAction, &QAction::triggered, this, [this, path]
128+
if ( enabled )
129+
{
130+
QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu );
131+
connect( openFolderAction, &QAction::triggered, this, [this, path]
132+
{
133+
QFileInfo fi( path );
134+
QString folder = fi.path();
135+
QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) );
136+
} );
137+
menu->addAction( openFolderAction );
138+
}
139+
else
128140
{
129-
QFileInfo fi( path );
130-
QString folder = fi.path();
131-
QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) );
132-
} );
133-
menu->addAction( openFolderAction );
141+
QAction *rescanAction = new QAction( tr( "Refresh" ), menu );
142+
connect( rescanAction, &QAction::triggered, this, [this, index]
143+
{
144+
mModel->recheckProject( index );
145+
} );
146+
menu->addAction( rescanAction );
147+
}
134148

135149
menu->popup( mapToGlobal( point ) );
136150
}

‎src/app/qgswelcomepageitemsmodel.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,22 @@ Qt::ItemFlags QgsWelcomePageItemsModel::flags( const QModelIndex &index ) const
201201

202202
const RecentProjectData &projectData = mRecentProjects.at( index.row() );
203203

204-
if ( !QFile::exists( ( projectData.path ) ) )
204+
// This check can be slow for network based projects, so only run it the first time
205+
if ( !projectData.checkedExists )
206+
{
207+
projectData.exists = QFile::exists( ( projectData.path ) );
208+
projectData.checkedExists = true;
209+
}
210+
211+
if ( !projectData.exists )
205212
flags &= ~Qt::ItemIsEnabled;
206213

207214
return flags;
208215
}
216+
217+
void QgsWelcomePageItemsModel::recheckProject( const QModelIndex &index )
218+
{
219+
const RecentProjectData &projectData = mRecentProjects.at( index.row() );
220+
projectData.exists = QFile::exists( ( projectData.path ) );
221+
projectData.checkedExists = true;
222+
}

‎src/app/qgswelcomepageitemsmodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class QgsWelcomePageItemsModel : public QAbstractListModel
5050
QString title;
5151
QString previewImagePath;
5252
QString crs;
53+
mutable bool checkedExists = false;
54+
mutable bool exists = false;
5355
};
5456

5557
explicit QgsWelcomePageItemsModel( QObject *parent = nullptr );
@@ -60,6 +62,8 @@ class QgsWelcomePageItemsModel : public QAbstractListModel
6062
QVariant data( const QModelIndex &index, int role ) const override;
6163
Qt::ItemFlags flags( const QModelIndex &index ) const override;
6264

65+
void recheckProject( const QModelIndex &index );
66+
6367
private:
6468
QList<RecentProjectData> mRecentProjects;
6569
};

0 commit comments

Comments
 (0)
Please sign in to comment.