mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Show the 8 most recently used projects in the File menu
git-svn-id: http://svn.osgeo.org/qgis/trunk@2582 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
81bc4c63d8
commit
96e80889b3
106
src/qgisapp.cpp
106
src/qgisapp.cpp
@ -32,6 +32,7 @@
|
||||
#include <qdir.h>
|
||||
#include <qerrormessage.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <qfile.h>
|
||||
#include <qfileinfo.h>
|
||||
#include <qinputdialog.h>
|
||||
#include <qlabel.h>
|
||||
@ -404,7 +405,37 @@ QgisApp::QgisApp(QWidget * parent, const char *name, WFlags fl)
|
||||
// Add the whats this toolbar button
|
||||
//TODO Fix this ToolBar pointer to be named consistently
|
||||
QWhatsThis::whatsThisButton(helpToolbar);
|
||||
|
||||
|
||||
// Add the recently accessed project file paths to the File menu
|
||||
mRecentProjectPaths = settings.readListEntry("/qgis/UI/recentProjectsList");
|
||||
// Exit is the last item. Find it and insert these just before it
|
||||
uint count = popupMenuFile->count();
|
||||
// Remember the items before and after the paths so we can manipulate them later
|
||||
popupMenuFile->setId(count - 2, 123); // item before paths
|
||||
popupMenuFile->setId(count - 1, 321); // Exit - comes after paths
|
||||
uint currentIndex = count - 1;
|
||||
popupMenuFile->insertSeparator(currentIndex++);
|
||||
if (mRecentProjectPaths.size() > 0)
|
||||
{
|
||||
uint IdCounter = 1;
|
||||
for ( QStringList::Iterator it = mRecentProjectPaths.begin();
|
||||
it != mRecentProjectPaths.end();
|
||||
++it )
|
||||
{
|
||||
int myId = IdCounter++;
|
||||
popupMenuFile->insertItem((*it), this, SLOT(openProject(int)), 0, myId, currentIndex++);
|
||||
// This parameter corresponds to this path's index
|
||||
// in mRecentProjectPaths
|
||||
popupMenuFile->setItemParameter(myId, myId - 1);
|
||||
// Disable this menu item if the file has been removed
|
||||
if (!QFile::exists((*it)))
|
||||
{
|
||||
popupMenuFile->setItemEnabled(myId, FALSE);
|
||||
}
|
||||
}
|
||||
popupMenuFile->insertSeparator(currentIndex);
|
||||
}
|
||||
|
||||
// Add the empty plugin menu
|
||||
mPluginMenu = new QPopupMenu(this);
|
||||
// Add the plugin manager action to it
|
||||
@ -1633,6 +1664,9 @@ void QgisApp::fileOpen()
|
||||
emit projectRead(); // let plug-ins know that we've read in a new
|
||||
// project so that they can check any project
|
||||
// specific plug-in state
|
||||
|
||||
// add this to the list of recently used project files
|
||||
saveRecentProjectPath(fullPath, settings);
|
||||
}
|
||||
}
|
||||
catch ( std::exception & e )
|
||||
@ -1775,6 +1809,8 @@ void QgisApp::fileSaveAs()
|
||||
if ( QgsProject::instance()->write() )
|
||||
{
|
||||
statusBar()->message(tr("Saved map to:") + " " + QgsProject::instance()->filename() );
|
||||
// add this to the list of recently used project files
|
||||
saveRecentProjectPath(fullPath, settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4131,3 +4167,71 @@ void QgisApp::keyPressEvent ( QKeyEvent * e )
|
||||
std::cout << e->ascii() << " (keypress recevied)" << std::endl;
|
||||
emit keyPressed (e);
|
||||
}
|
||||
|
||||
|
||||
// add this file to the recently opened/saved projects list
|
||||
void QgisApp::saveRecentProjectPath(QString projectPath, QSettings & settings)
|
||||
{
|
||||
// If this file is already in the list, remove it
|
||||
mRecentProjectPaths.remove(projectPath);
|
||||
|
||||
// Prepend this file to the list
|
||||
mRecentProjectPaths.prepend(projectPath);
|
||||
|
||||
// Keep the list to 8 items by trimming excess off the bottom
|
||||
while (mRecentProjectPaths.count() > 8)
|
||||
{
|
||||
mRecentProjectPaths.pop_back();
|
||||
}
|
||||
|
||||
// Persist the list
|
||||
settings.writeEntry("/qgis/UI/recentProjectsList", mRecentProjectPaths);
|
||||
|
||||
// Update the file menu with the changed list
|
||||
// Find the item before the paths in the menu
|
||||
uint currentIndex = popupMenuFile->indexOf(123);
|
||||
currentIndex++;
|
||||
// Remove existing paths from the file menu
|
||||
while (currentIndex != popupMenuFile->indexOf(321))
|
||||
{
|
||||
popupMenuFile->removeItemAt(currentIndex);
|
||||
}
|
||||
// Add back in the updated list of paths
|
||||
uint IdCounter = 1;
|
||||
popupMenuFile->insertSeparator(currentIndex++);
|
||||
for ( QStringList::Iterator it = mRecentProjectPaths.begin();
|
||||
it != mRecentProjectPaths.end();
|
||||
++it )
|
||||
{
|
||||
int myId = IdCounter++;
|
||||
popupMenuFile->insertItem((*it), this, SLOT(openProject(int)), 0, myId, currentIndex++);
|
||||
// This parameter corresponds to this path's index
|
||||
// in mRecentProjectPaths
|
||||
popupMenuFile->setItemParameter(myId, myId - 1);
|
||||
// Disable this menu item if the file has been removed
|
||||
if (!QFile::exists((*it)))
|
||||
{
|
||||
popupMenuFile->setItemEnabled(myId, FALSE);
|
||||
}
|
||||
}
|
||||
popupMenuFile->insertSeparator(currentIndex);
|
||||
}
|
||||
|
||||
|
||||
// Open the project file corresponding to the
|
||||
// path at the given index in mRecentProjectPaths
|
||||
void QgisApp::openProject(int pathIndex)
|
||||
{
|
||||
// possibly save any pending work before opening a different project
|
||||
int answer = saveDirty();
|
||||
|
||||
if (answer != QMessageBox::Cancel)
|
||||
{
|
||||
QStringList::Iterator it = mRecentProjectPaths.at(pathIndex);
|
||||
addProject((*it));
|
||||
|
||||
// move to the top of the list of recently used project files
|
||||
QSettings settings;
|
||||
saveRecentProjectPath((*it), settings);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ class QListViewItem;
|
||||
class QProgressBar;
|
||||
class QFileInfo;
|
||||
class QgsMapLayer;
|
||||
class QSettings;
|
||||
class QSocket;
|
||||
class QgsProviderRegistry;
|
||||
class QgsHelpViewer;
|
||||
@ -222,6 +223,10 @@ private:
|
||||
void select();
|
||||
//! check to see if file is dirty and if so, prompt the user th save it
|
||||
int saveDirty();
|
||||
//! add this file to the recently opened/saved projects list
|
||||
// pass settings by reference since creating more than one
|
||||
//! instance simultaneously results in data loss.
|
||||
void saveRecentProjectPath(QString projectPath, QSettings & settings);
|
||||
|
||||
private slots:
|
||||
|
||||
@ -298,6 +303,9 @@ private slots:
|
||||
void hideAllLayers();
|
||||
//reimplements method from base (gui) class
|
||||
void showAllLayers();
|
||||
//! Open the project file corresponding to the
|
||||
//! path at the given index in mRecentProjectPaths
|
||||
void openProject(int pathIndex);
|
||||
|
||||
|
||||
|
||||
@ -445,6 +453,8 @@ private:
|
||||
std::map<QString, int>mMenuMapByName;
|
||||
//! menu map (key is menu id, value is name)
|
||||
std::map<int, QString>mMenuMapById;
|
||||
//! list of recently opened/saved project files
|
||||
QStringList mRecentProjectPaths;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because one or more lines are too long
133
src/src.pro
133
src/src.pro
@ -1,3 +1,120 @@
|
||||
TEMPLATE = app
|
||||
LANGUAGE = C++
|
||||
|
||||
CONFIG += qt thread rtti debug console
|
||||
|
||||
LIBS += $(GDAL)\lib\gdal_i.lib $(POSTGRESQL)\src\interfaces\libpq\Release\libpq.lib $(GEOS)\lib\geos.lib
|
||||
|
||||
DEFINES += QGISDEBUG
|
||||
|
||||
INCLUDEPATH += . $(GDAL)\include $(POSTGRESQL)\src\interfaces\libpq $(POSTGRESQL)\src\include $(GEOS)\include
|
||||
|
||||
HEADERS += qgscolortable.h
|
||||
|
||||
SOURCES += main.cpp \
|
||||
qgisapp.cpp \
|
||||
qgisiface.cpp \
|
||||
qgisinterface.cpp \
|
||||
qgsattributeaction.cpp \
|
||||
qgsattributeactiondialog.cpp \
|
||||
qgsattributedialog.cpp \
|
||||
qgsattributetable.cpp \
|
||||
qgsattributetabledisplay.cpp \
|
||||
qgscontcoldialog.cpp \
|
||||
qgscontinuouscolrenderer.cpp \
|
||||
qgscoordinatetransform.cpp \
|
||||
qgscustomsymbol.cpp \
|
||||
qgsdatasource.cpp \
|
||||
qgsdbsourceselect.cpp \
|
||||
qgsdlgvectorlayerproperties.cpp \
|
||||
qgsfeature.cpp \
|
||||
qgsfeatureattribute.cpp \
|
||||
qgsfield.cpp \
|
||||
qgsgraduatedmarenderer.cpp \
|
||||
qgsgraduatedsymrenderer.cpp \
|
||||
qgsgramadialog.cpp \
|
||||
qgsgramaextensionwidget.cpp \
|
||||
qgsgrasydialog.cpp \
|
||||
qgshelpviewer.cpp \
|
||||
qgsidentifyresults.cpp \
|
||||
qgslegend.cpp \
|
||||
qgslegenditem.cpp \
|
||||
qgslinestyledialog.cpp \
|
||||
qgslinesymbol.cpp \
|
||||
qgsmapcanvas.cpp \
|
||||
qgsmaplayer.cpp \
|
||||
qgsmaplayerregistry.cpp \
|
||||
qgsmapserverexport.cpp \
|
||||
qgsmarkerdialog.cpp \
|
||||
qgsmarkersymbol.cpp \
|
||||
qgsnewconnection.cpp \
|
||||
qgsoptions.cpp \
|
||||
qgspatterndialog.cpp \
|
||||
qgspgquerybuilder.cpp \
|
||||
qgspluginitem.cpp \
|
||||
qgspluginmanager.cpp \
|
||||
qgspluginmetadata.cpp \
|
||||
qgspluginregistry.cpp \
|
||||
qgspoint.cpp \
|
||||
qgspolygonsymbol.cpp \
|
||||
qgsproject.cpp \
|
||||
qgsprojectproperties.cpp \
|
||||
qgsprovidermetadata.cpp \
|
||||
qgsproviderregistry.cpp \
|
||||
qgsrangerenderitem.cpp \
|
||||
qgsrasterlayer.cpp \
|
||||
qgsrasterlayerproperties.cpp \
|
||||
qgsrect.cpp \
|
||||
qgsrenderitem.cpp \
|
||||
qgsscalecalculator.cpp \
|
||||
qgssimadialog.cpp \
|
||||
qgssimarenderer.cpp \
|
||||
qgssinglesymrenderer.cpp \
|
||||
qgssisydialog.cpp \
|
||||
qgssymbol.cpp \
|
||||
qgssymbologyutils.cpp \
|
||||
qgsvectorlayer.cpp \
|
||||
qgssvgcache.cpp \
|
||||
splashscreen.cpp \
|
||||
qgsacetateobject.cpp \
|
||||
qgslabeldialog.cpp \
|
||||
qgslabel.cpp \
|
||||
qgslabelattributes.cpp \
|
||||
qgsacetaterectangle.cpp \
|
||||
qgsuvaldialog.cpp \
|
||||
qgsludialog.cpp \
|
||||
qgsuniquevalrenderer.cpp \
|
||||
qgsuvalmadialog.cpp \
|
||||
qgsuvalmarenderer.cpp \
|
||||
qgsvectorfilewriter.cpp \
|
||||
qgsgeomtypedialog.cpp
|
||||
|
||||
FORMS = qgisappbase.ui \
|
||||
qgsabout.ui \
|
||||
qgsattributetablebase.ui \
|
||||
qgsattributeactiondialogbase.ui \
|
||||
qgsattributedialogbase.ui \
|
||||
qgscontcoldialogbase.ui \
|
||||
qgsdbsourceselectbase.ui \
|
||||
qgsdlgvectorlayerpropertiesbase.ui \
|
||||
qgsgramadialogbase.ui \
|
||||
qgsgrasydialogbase.ui \
|
||||
qgshelpviewerbase.ui \
|
||||
qgsidentifyresultsbase.ui \
|
||||
qgslegenditembase.ui \
|
||||
qgslinestyledialogbase.ui \
|
||||
qgsmapserverexportbase.ui \
|
||||
qgsmarkerdialogbase.ui \
|
||||
qgsmessageviewer.ui \
|
||||
qgsnewconnectionbase.ui \
|
||||
qgsoptionsbase.ui \
|
||||
qgspatterndialogbase.ui \
|
||||
qgspgquerybuilderbase.ui \
|
||||
qgspluginmanagerbase.ui \
|
||||
qgsprojectpropertiesbase.ui \
|
||||
qgsrasterlayerpropertiesbase.ui \
|
||||
qgslabeldialogbase.ui
|
||||
|
||||
######################################################################
|
||||
# Qmake project file for QGIS src directory
|
||||
# This file is used by qmake to generate the Makefile for building
|
||||
@ -27,19 +144,9 @@
|
||||
# The headers/lib can be downloaded from http://qgis.org/win32_geos.zip #
|
||||
###########################################################################
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = qgis
|
||||
INCLUDEPATH += . $(GDAL)\include \
|
||||
$(POSTGRESQL)\src\interfaces\libpq \
|
||||
$(POSTGRESQL)\src\include \
|
||||
$(GEOS)\include
|
||||
LIBS += $(GDAL)\lib\gdal_i.lib \
|
||||
$(POSTGRESQL)\src\interfaces\libpq\Release\libpq.lib \
|
||||
$(GEOS)\lib\geos.lib
|
||||
|
||||
DEFINES+= QGISDEBUG
|
||||
DESTDIR = ../win_build
|
||||
CONFIG += qt thread rtti debug console
|
||||
#CONFIG += qt thread rtti console
|
||||
RC_FILE = qgis_win32.rc
|
||||
# Input
|
||||
@ -136,8 +243,7 @@ HEADERS += qgis.h \
|
||||
qgsuvalmarenderer.h \
|
||||
qgscolortable.h \
|
||||
qgsvectorfilewriter.h \
|
||||
qgsgeomtypedialog.h
|
||||
INTERFACES += qgisappbase.ui \
|
||||
qgsgeomtINTERFACES += qgisappbase.ui \
|
||||
qgsabout.ui \
|
||||
qgsattributetablebase.ui \
|
||||
qgsattributeactiondialogbase.ui \
|
||||
@ -167,8 +273,7 @@ INTERFACES += qgisappbase.ui \
|
||||
qgsludialogbase.ui \
|
||||
qgsuvaldialogbase.ui \
|
||||
qgsuvalmadialogbase.ui \
|
||||
qgsgeomtypedialogbase.ui
|
||||
SOURCES += main.cpp \
|
||||
qgsgeomtypediSOURCES += main.cpp \
|
||||
qgisapp.cpp \
|
||||
qgisiface.cpp \
|
||||
qgisinterface.cpp \
|
||||
|
Loading…
x
Reference in New Issue
Block a user