|
211 | 211 | #include "qgsmessagelogviewer.h"
|
212 | 212 | #include "qgsdataitem.h"
|
213 | 213 | #include "qgsmaplayeractionregistry.h"
|
| 214 | +#include "qgswelcomedialog.h" |
| 215 | +#include "qgsmaprendererparalleljob.h" |
214 | 216 |
|
215 | 217 | #include "qgssublayersdialog.h"
|
216 | 218 | #include "ogr/qgsopenvectorlayerdialog.h"
|
@@ -869,6 +871,10 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
|
869 | 871 | #ifdef ANDROID
|
870 | 872 | toggleFullScreen();
|
871 | 873 | #endif
|
| 874 | + |
| 875 | + QgsWelcomeDialog dlg; |
| 876 | + dlg.setRecentProjects( mRecentProjects ); |
| 877 | + dlg.exec(); |
872 | 878 | } // QgisApp ctor
|
873 | 879 |
|
874 | 880 | QgisApp::QgisApp()
|
@@ -1123,8 +1129,22 @@ void QgisApp::readSettings()
|
1123 | 1129 | // 'gis' theme is new /themes/default directory (2013-04-15)
|
1124 | 1130 | setTheme( settings.value( "/Themes", "default" ).toString() );
|
1125 | 1131 |
|
1126 |
| - // Add the recently accessed project file paths to the Project menu |
1127 |
| - mRecentProjectPaths = settings.value( "/UI/recentProjectsList" ).toStringList(); |
| 1132 | + settings.beginGroup( "/UI/recentProjects" ); |
| 1133 | + QStringList projectKeys = settings.childGroups(); |
| 1134 | + |
| 1135 | + mRecentProjects.clear(); |
| 1136 | + |
| 1137 | + Q_FOREACH( const QString& key, projectKeys ) |
| 1138 | + { |
| 1139 | + QgsWelcomePageItemsModel::RecentProjectData data; |
| 1140 | + settings.beginGroup( key ); |
| 1141 | + data.title = settings.value( "title" ).toString(); |
| 1142 | + data.path = settings.value( "path" ).toString(); |
| 1143 | + data.previewImagePath = settings.value( "previewImage" ).toString(); |
| 1144 | + settings.endGroup(); |
| 1145 | + mRecentProjects.prepend( data ); |
| 1146 | + } |
| 1147 | + settings.endGroup(); |
1128 | 1148 |
|
1129 | 1149 | // this is a new session! reset enable macros value to "ask"
|
1130 | 1150 | // whether set to "just for this session"
|
@@ -2673,52 +2693,74 @@ void QgisApp::projectReadDecorationItems()
|
2673 | 2693 | // Update project menu with the current list of recently accessed projects
|
2674 | 2694 | void QgisApp::updateRecentProjectPaths()
|
2675 | 2695 | {
|
2676 |
| - // Remove existing paths from the recent projects menu |
2677 |
| - int i; |
2678 |
| - |
2679 |
| - int menusize = mRecentProjectsMenu->actions().size(); |
| 2696 | + mRecentProjectsMenu->clear(); |
2680 | 2697 |
|
2681 |
| - for ( i = menusize; i < mRecentProjectPaths.size(); i++ ) |
| 2698 | + Q_FOREACH( const QgsWelcomePageItemsModel::RecentProjectData& recentProject, mRecentProjects ) |
2682 | 2699 | {
|
2683 |
| - mRecentProjectsMenu->addAction( "Dummy text" ); |
2684 |
| - } |
2685 |
| - |
2686 |
| - QList<QAction *> menulist = mRecentProjectsMenu->actions(); |
2687 |
| - |
2688 |
| - assert( menulist.size() == mRecentProjectPaths.size() ); |
2689 |
| - |
2690 |
| - for ( i = 0; i < mRecentProjectPaths.size(); i++ ) |
2691 |
| - { |
2692 |
| - menulist.at( i )->setText( mRecentProjectPaths.at( i ) ); |
2693 |
| - |
2694 |
| - // Disable this menu item if the file has been removed, if not enable it |
2695 |
| - menulist.at( i )->setEnabled( QFile::exists(( mRecentProjectPaths.at( i ) ) ) ); |
2696 |
| - |
| 2700 | + QAction* action = mRecentProjectsMenu->addAction( QString( "%1 (%2)" ).arg( recentProject.title ).arg( recentProject.path ) ); |
| 2701 | + action->setEnabled( QFile::exists(( recentProject.path ) ) ); |
| 2702 | + action->setData( recentProject.path ); |
2697 | 2703 | }
|
2698 | 2704 | } // QgisApp::updateRecentProjectPaths
|
2699 | 2705 |
|
2700 | 2706 | // add this file to the recently opened/saved projects list
|
2701 |
| -void QgisApp::saveRecentProjectPath( QString projectPath, QSettings & settings ) |
| 2707 | +void QgisApp::saveRecentProjectPath( QString projectPath, bool savePreviewImage ) |
2702 | 2708 | {
|
| 2709 | + QSettings settings; |
| 2710 | + |
2703 | 2711 | // Get canonical absolute path
|
2704 | 2712 | QFileInfo myFileInfo( projectPath );
|
2705 |
| - projectPath = myFileInfo.absoluteFilePath(); |
| 2713 | + QgsWelcomePageItemsModel::RecentProjectData projectData; |
| 2714 | + projectData.path = myFileInfo.absoluteFilePath(); |
| 2715 | + projectData.title = QgsProject::instance()->title(); |
| 2716 | + if ( projectData.title.isEmpty() ) |
| 2717 | + projectData.title = projectData.path; |
| 2718 | + |
| 2719 | + if ( savePreviewImage ) |
| 2720 | + { |
| 2721 | + QgsMapSettings mapSettings = mMapCanvas->mapSettings(); |
| 2722 | + mapSettings.setOutputSize( QSize( 200, 70 ) ); |
| 2723 | + QgsMapRendererParallelJob job( mapSettings ); |
| 2724 | + job.start(); |
| 2725 | + job.waitForFinished(); |
| 2726 | + QString fileName( QCryptographicHash::hash( ( projectData.path.toUtf8() ), QCryptographicHash::Md5 ).toHex() ); |
| 2727 | + QString previewDir = QString( "%1/previewImages" ).arg( QgsApplication::qgisSettingsDirPath() ); |
| 2728 | + projectData.previewImagePath = QString( "%1/%2.png" ).arg( previewDir ).arg( fileName ); |
| 2729 | + QDir().mkdir( previewDir ); |
| 2730 | + job.renderedImage().save( projectData.previewImagePath ); |
| 2731 | + } |
| 2732 | + else |
| 2733 | + { |
| 2734 | + int idx = mRecentProjects.indexOf( projectData ); |
| 2735 | + if ( idx != -1 ) |
| 2736 | + projectData.previewImagePath = mRecentProjects.at( idx ).previewImagePath; |
| 2737 | + } |
2706 | 2738 |
|
2707 | 2739 | // If this file is already in the list, remove it
|
2708 |
| - mRecentProjectPaths.removeAll( projectPath ); |
| 2740 | + mRecentProjects.removeAll( projectData ); |
2709 | 2741 |
|
2710 | 2742 | // Prepend this file to the list
|
2711 |
| - mRecentProjectPaths.prepend( projectPath ); |
| 2743 | + mRecentProjects.prepend( projectData ); |
2712 | 2744 |
|
2713 | 2745 | // Keep the list to 8 items by trimming excess off the bottom
|
2714 |
| - while ( mRecentProjectPaths.count() > 8 ) |
| 2746 | + while ( mRecentProjects.count() > 8 ) |
2715 | 2747 | {
|
2716 |
| - mRecentProjectPaths.pop_back(); |
| 2748 | + mRecentProjects.pop_back(); |
2717 | 2749 | }
|
2718 | 2750 |
|
2719 |
| - // Persist the list |
2720 |
| - settings.setValue( "/UI/recentProjectsList", mRecentProjectPaths ); |
| 2751 | + settings.remove( "/UI/recentProjects" ); |
| 2752 | + int idx = 0; |
2721 | 2753 |
|
| 2754 | + // Persist the list |
| 2755 | + Q_FOREACH( const QgsWelcomePageItemsModel::RecentProjectData& recentProject, mRecentProjects ) |
| 2756 | + { |
| 2757 | + ++idx; |
| 2758 | + settings.beginGroup( QString( "/UI/recentProjects/%1" ).arg( idx ) ); |
| 2759 | + settings.setValue( "title", recentProject.title ); |
| 2760 | + settings.setValue( "path", recentProject.path ); |
| 2761 | + settings.setValue( "previewImage", recentProject.previewImagePath ); |
| 2762 | + settings.endGroup(); |
| 2763 | + } |
2722 | 2764 |
|
2723 | 2765 | // Update menu list of paths
|
2724 | 2766 | updateRecentProjectPaths();
|
@@ -3832,9 +3874,9 @@ void QgisApp::fileOpenAfterLaunch()
|
3832 | 3874 |
|
3833 | 3875 | // get path of project file to open, or was attempted
|
3834 | 3876 | QString projPath = QString();
|
3835 |
| - if ( projOpen == 1 && mRecentProjectPaths.size() > 0 ) // most recent project |
| 3877 | + if ( projOpen == 1 && mRecentProjects.size() > 0 ) // most recent project |
3836 | 3878 | {
|
3837 |
| - projPath = mRecentProjectPaths.at( 0 ); |
| 3879 | + projPath = mRecentProjects.at( 0 ).path; |
3838 | 3880 | }
|
3839 | 3881 | if ( projOpen == 2 ) // specific project
|
3840 | 3882 | {
|
@@ -4145,7 +4187,7 @@ bool QgisApp::addProject( QString projectFile )
|
4145 | 4187 | // specific plug-in state
|
4146 | 4188 |
|
4147 | 4189 | // add this to the list of recently used project files
|
4148 |
| - saveRecentProjectPath( projectFile, settings ); |
| 4190 | + saveRecentProjectPath( projectFile, false ); |
4149 | 4191 |
|
4150 | 4192 | QApplication::restoreOverrideCursor();
|
4151 | 4193 |
|
@@ -4199,6 +4241,7 @@ bool QgisApp::fileSave()
|
4199 | 4241 | else
|
4200 | 4242 | {
|
4201 | 4243 | QFileInfo fi( QgsProject::instance()->fileName() );
|
| 4244 | + fullPath = fi.absoluteFilePath(); |
4202 | 4245 | if ( fi.exists() && !mProjectLastModified.isNull() && mProjectLastModified != fi.lastModified() )
|
4203 | 4246 | {
|
4204 | 4247 | if ( QMessageBox::warning( this,
|
@@ -4226,12 +4269,7 @@ bool QgisApp::fileSave()
|
4226 | 4269 | setTitleBarText_( *this ); // update title bar
|
4227 | 4270 | statusBar()->showMessage( tr( "Saved project to: %1" ).arg( QgsProject::instance()->fileName() ), 5000 );
|
4228 | 4271 |
|
4229 |
| - if ( isNewProject ) |
4230 |
| - { |
4231 |
| - // add this to the list of recently used project files |
4232 |
| - QSettings settings; |
4233 |
| - saveRecentProjectPath( fullPath.filePath(), settings ); |
4234 |
| - } |
| 4272 | + saveRecentProjectPath( fullPath.filePath() ); |
4235 | 4273 |
|
4236 | 4274 | QFileInfo fi( QgsProject::instance()->fileName() );
|
4237 | 4275 | mProjectLastModified = fi.lastModified();
|
@@ -4283,7 +4321,7 @@ void QgisApp::fileSaveAs()
|
4283 | 4321 | setTitleBarText_( *this ); // update title bar
|
4284 | 4322 | statusBar()->showMessage( tr( "Saved project to: %1" ).arg( QgsProject::instance()->fileName() ), 5000 );
|
4285 | 4323 | // add this to the list of recently used project files
|
4286 |
| - saveRecentProjectPath( fullPath.filePath(), settings ); |
| 4324 | + saveRecentProjectPath( fullPath.filePath() ); |
4287 | 4325 | }
|
4288 | 4326 | else
|
4289 | 4327 | {
|
@@ -4350,7 +4388,7 @@ void QgisApp::openProject( QAction *action )
|
4350 | 4388 | QString debugme;
|
4351 | 4389 | assert( action != NULL );
|
4352 | 4390 |
|
4353 |
| - debugme = action->text(); |
| 4391 | + debugme = action->data().toString(); |
4354 | 4392 |
|
4355 | 4393 | if ( saveDirty() )
|
4356 | 4394 | {
|
|
0 commit comments