Skip to content

Commit d40447e

Browse files
authoredOct 26, 2017
[FEATURE][welcome page] remove from list action (fixes #13722)
1 parent 2383edb commit d40447e

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,12 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
744744

745745
startProfile( QStringLiteral( "Welcome page" ) );
746746
mWelcomePage = new QgsWelcomePage( skipVersionCheck );
747+
connect( mWelcomePage, &QgsWelcomePage::projectRemoved, this, [ this ]( int row )
748+
{
749+
mRecentProjects.removeAt( row );
750+
saveRecentProjects();
751+
} );
752+
747753
endProfile();
748754

749755
mCentralContainer = new QStackedWidget;
@@ -3830,8 +3836,6 @@ void QgisApp::saveRecentProjectPath( const QString &projectPath, bool savePrevie
38303836
// projects when multiple QGIS sessions are open
38313837
readRecentProjects();
38323838

3833-
QgsSettings settings;
3834-
38353839
// Get canonical absolute path
38363840
QFileInfo myFileInfo( projectPath );
38373841
QgsWelcomePageItemsModel::RecentProjectData projectData;
@@ -3883,10 +3887,22 @@ void QgisApp::saveRecentProjectPath( const QString &projectPath, bool savePrevie
38833887
QFile( mRecentProjects.takeLast().previewImagePath ).remove();
38843888
}
38853889

3890+
// Persist the list
3891+
saveRecentProjects();
3892+
3893+
// Update menu list of paths
3894+
updateRecentProjectPaths();
3895+
3896+
} // QgisApp::saveRecentProjectPath
3897+
3898+
// Save recent projects list to settings
3899+
void QgisApp::saveRecentProjects()
3900+
{
3901+
QgsSettings settings;
3902+
38863903
settings.remove( QStringLiteral( "/UI/recentProjects" ) );
38873904
int idx = 0;
38883905

3889-
// Persist the list
38903906
Q_FOREACH ( const QgsWelcomePageItemsModel::RecentProjectData &recentProject, mRecentProjects )
38913907
{
38923908
++idx;
@@ -3897,11 +3913,7 @@ void QgisApp::saveRecentProjectPath( const QString &projectPath, bool savePrevie
38973913
settings.setValue( QStringLiteral( "crs" ), recentProject.crs );
38983914
settings.endGroup();
38993915
}
3900-
3901-
// Update menu list of paths
3902-
updateRecentProjectPaths();
3903-
3904-
} // QgisApp::saveRecentProjectPath
3916+
}
39053917

39063918
// Update project menu with the project templates
39073919
void QgisApp::updateProjectFromTemplates()

‎src/app/qgisapp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
16911691
* \param savePreviewImage Set to false when the preview image should not be saved. E.g. project load.
16921692
*/
16931693
void saveRecentProjectPath( const QString &projectPath, bool savePreviewImage = true );
1694+
//! Save recent projects list to settings
1695+
void saveRecentProjects();
16941696
//! Update project menu with the current list of recently accessed projects
16951697
void updateRecentProjectPaths();
16961698
//! Read Well Known Binary stream from PostGIS

‎src/app/qgswelcomepage.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ void QgsWelcomePage::showContextMenuForProjects( QPoint point )
145145
} );
146146
menu->addAction( rescanAction );
147147
}
148+
QAction *removeProjectAction = new QAction( tr( "Remove from List" ), menu );
149+
connect( removeProjectAction, &QAction::triggered, this, [this, index]
150+
{
151+
mModel->removeProject( index );
152+
emit projectRemoved( index.row() );
153+
} );
154+
menu->addAction( removeProjectAction );
148155

149156
menu->popup( mapToGlobal( point ) );
150157
}

‎src/app/qgswelcomepage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class QgsWelcomePage : public QWidget
3535

3636
void setRecentProjects( const QList<QgsWelcomePageItemsModel::RecentProjectData> &recentProjects );
3737

38+
signals:
39+
void projectRemoved( int row );
40+
3841
private slots:
3942
void itemActivated( const QModelIndex &index );
4043
void versionInfoReceived();

‎src/app/qgswelcomepageitemsmodel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ Qt::ItemFlags QgsWelcomePageItemsModel::flags( const QModelIndex &index ) const
214214
return flags;
215215
}
216216

217+
void QgsWelcomePageItemsModel::removeProject( const QModelIndex &index )
218+
{
219+
mRecentProjects.removeAt( index.row() );
220+
}
221+
217222
void QgsWelcomePageItemsModel::recheckProject( const QModelIndex &index )
218223
{
219224
const RecentProjectData &projectData = mRecentProjects.at( index.row() );

‎src/app/qgswelcomepageitemsmodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class QgsWelcomePageItemsModel : public QAbstractListModel
6262
QVariant data( const QModelIndex &index, int role ) const override;
6363
Qt::ItemFlags flags( const QModelIndex &index ) const override;
6464

65+
void removeProject( const QModelIndex &index );
6566
void recheckProject( const QModelIndex &index );
6667

6768
private:

0 commit comments

Comments
 (0)
Please sign in to comment.