Skip to content
Permalink
Browse files

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
  • Loading branch information
nyalldawson committed Oct 25, 2017
1 parent 05e97b3 commit a89dfde91b06a6c0fdad87e81dcf0922fc5f0c16
Showing with 40 additions and 8 deletions.
  1. +21 −7 src/app/qgswelcomepage.cpp
  2. +15 −1 src/app/qgswelcomepageitemsmodel.cpp
  3. +4 −0 src/app/qgswelcomepageitemsmodel.h
@@ -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 ) );
}
@@ -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;
}
@@ -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 );
@@ -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;
};

0 comments on commit a89dfde

Please sign in to comment.
You can’t perform that action at this time.