Skip to content

Commit

Permalink
Remember whether project file exists and don't continually recheck
Browse files Browse the repository at this point in the history
Because that's slow for network paths. Instead only check once,
and add a menu option to refresh and force re-check
  • Loading branch information
nyalldawson committed Oct 25, 2017
1 parent 05e97b3 commit a89dfde
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
28 changes: 21 additions & 7 deletions src/app/qgswelcomepage.cpp
Expand Up @@ -121,16 +121,30 @@ void QgsWelcomePage::showContextMenuForProjects( QPoint point )
if ( path.isEmpty() )
return;

bool enabled = mModel->flags( index ) & Qt::ItemIsEnabled;

QMenu *menu = new QMenu( this );

QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu );
connect( openFolderAction, &QAction::triggered, this, [this, path]
if ( enabled )
{
QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu );
connect( openFolderAction, &QAction::triggered, this, [this, path]
{
QFileInfo fi( path );
QString folder = fi.path();
QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) );
} );
menu->addAction( openFolderAction );
}
else
{
QFileInfo fi( path );
QString folder = fi.path();
QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) );
} );
menu->addAction( openFolderAction );
QAction *rescanAction = new QAction( tr( "Refresh" ), menu );
connect( rescanAction, &QAction::triggered, this, [this, index]
{
mModel->recheckProject( index );
} );
menu->addAction( rescanAction );
}

menu->popup( mapToGlobal( point ) );
}
16 changes: 15 additions & 1 deletion src/app/qgswelcomepageitemsmodel.cpp
Expand Up @@ -201,8 +201,22 @@ Qt::ItemFlags QgsWelcomePageItemsModel::flags( const QModelIndex &index ) const

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

if ( !QFile::exists( ( projectData.path ) ) )
// This check can be slow for network based projects, so only run it the first time
if ( !projectData.checkedExists )
{
projectData.exists = QFile::exists( ( projectData.path ) );
projectData.checkedExists = true;
}

if ( !projectData.exists )
flags &= ~Qt::ItemIsEnabled;

return flags;
}

void QgsWelcomePageItemsModel::recheckProject( const QModelIndex &index )
{
const RecentProjectData &projectData = mRecentProjects.at( index.row() );
projectData.exists = QFile::exists( ( projectData.path ) );
projectData.checkedExists = true;
}
4 changes: 4 additions & 0 deletions src/app/qgswelcomepageitemsmodel.h
Expand Up @@ -50,6 +50,8 @@ class QgsWelcomePageItemsModel : public QAbstractListModel
QString title;
QString previewImagePath;
QString crs;
mutable bool checkedExists = false;
mutable bool exists = false;
};

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

void recheckProject( const QModelIndex &index );

private:
QList<RecentProjectData> mRecentProjects;
};
Expand Down

0 comments on commit a89dfde

Please sign in to comment.