file save/open fixes

git-svn-id: http://svn.osgeo.org/qgis/trunk@183 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2003-01-26 23:45:47 +00:00
parent 016d8f213f
commit 607796f51e
9 changed files with 112 additions and 47 deletions

View File

@ -1,31 +0,0 @@
<!-- DTD for QGIS project file
* This DTD describes the maplayers and their symbology and
* is used when saving/restoring a QGIS project.
-->
<!ELEMENT qgis (title, projectlayers) >
<!ELEMENT projectlayers (maplayer*) >
<!ELEMENT title (#PCDATA) >
<!ELEMENT maplayer (layername, datasource, zorder, symbol) >
<!ELEMENT layername (#PCDATA) >
<!ELEMENT datasource (#PCDATA) >
<!ELEMENT zorder (#PCDATA) >
<!ELEMENT symbol (linewidth, outlinecolor, fillcolor) >
<!ELEMENT linewidth (#PCDATA) >
<!ELEMENT fillcolor EMPTY>
<!ELEMENT outlinecolor EMPTY>
<!ATTLIST qgis projectname CDATA #REQUIRED >
<!ATTLIST maplayer
type (vector|raster|database) "vector"
visible (1|0) "0"
>
<!ATTLIST projectlayers layercount CDATA #REQUIRED >
<!ATTLIST fillcolor
red CDATA #IMPLIED
green CDATA #IMPLIED
blue CDATA #IMPLIED
>
<!ATTLIST outlinecolor
red CDATA #IMPLIED
green CDATA #IMPLIED
blue CDATA #IMPLIED
>

View File

@ -199,9 +199,9 @@ void QgisApp::about()
abt->setURLs(urls);
QString watsNew = "Version ";
watsNew += qgisVersion;
watsNew += "\n*During repaint, the data store is only accessed if map state or extent has changed\n"
"*Changes to layer properites aren't effective until the Layer Properties dialog is closed\n"
"*Cancelling the Layer Propeties dialog cancels changes";
watsNew += "\n*Preliminary project save/open support\n"
"*Streamlined build system\n";
abt->setWhatsNew(watsNew);
abt->exec();
@ -312,11 +312,21 @@ void QgisApp::fileExit()
QApplication::exit();
}
void QgisApp::fileNew(){
mapCanvas->removeAll();
setCaption("Quantum GIS -- Untitled");
mapCanvas->clear();
mapLegend->update();
fullPath = "";
}
void QgisApp::fileOpen(){
mapCanvas->freeze(true);
QgsProjectIo *pio = new QgsProjectIo(mapCanvas, QgsProjectIo::OPEN);
pio->read();
if(pio->read()){
setCaption("Quantum GIS -- " + pio->baseName());
fullPath = pio->fullPathName();
}
delete pio;
mapLegend->update();
@ -324,11 +334,21 @@ void QgisApp::fileOpen(){
}
void QgisApp::fileSave(){
QgsProjectIo *pio = new QgsProjectIo(mapCanvas, QgsProjectIo::SAVE);
pio->write();
pio->setFileName(fullPath);
if(pio->write()){
setCaption("Quantum GIS -- " + pio->baseName());
statusBar()->message("Saved map to: " + pio->fullPathName());
}
delete pio;
}
void QgisApp::fileSaveAs(){
QgsProjectIo *pio = new QgsProjectIo(mapCanvas, QgsProjectIo::SAVEAS);
if(pio->write()){
setCaption("Quantum GIS -- " + pio->baseName());
statusBar()->message("Saved map to: " + pio->fullPathName());
}
delete pio;
}
void QgisApp::zoomIn()

View File

@ -102,6 +102,8 @@ class QgisApp:public QgisAppBase
void fileSaveAs();
//! Open a project
void fileOpen();
//! Create a new project
void fileNew();
private:
//! Popup menu
QPopupMenu * popMenu;
@ -120,6 +122,8 @@ class QgisApp:public QgisAppBase
int mapTool;
QCursor *cursorZoomIn;
QString startupPath;
//! full path name of the current map file (if it has been saved or loaded)
QString fullPath;
};
#endif

View File

@ -89,6 +89,7 @@
<property name="label">
<string>File Management Toolbar</string>
</property>
<action name="actionFileNew"/>
<action name="actionFileOpen"/>
<action name="actionFileSave"/>
<action name="actionFileSaveAs"/>
@ -372,6 +373,17 @@
<string>Save Project As...</string>
</property>
</action>
<action>
<property name="name">
<cstring>actionFileNew</cstring>
</property>
<property name="iconSet">
<iconset>image14</iconset>
</property>
<property name="text">
<string>Action</string>
</property>
</action>
</actions>
<images>
<image name="image0">
@ -416,6 +428,9 @@
<image name="image13">
<data format="XPM.GZ" length="3598">789cb597496fe3461085effe15c2d46d10d488149b2211e430de3df2a6f1ee20871249495e246f5a2c0ff2df53ec7acdb11320c825d343c09febf5ebaa6ab2497ff9dcba3c3e687dfeb2f63293d94dd12ac6f2dcfa5cce2793d5ef7ffcf663ed531cb7f47fe4d256fce997b54ffd59ab681d3e4cab1aa854a0288bdb71ee39ab5929eb189f79ce3b6d27354b1138f566b45f7327ea64a98fd3025c743b35f38371d23696b1e73cc465651ce2948213c4df1a1ef8b8ab3989920cfa5363d7b638b73d4b922596efc0d8b9ccfc5ec1655ef8f9d39a5d9c2449e4e77f3776ceeaa59e711a995e4660077e0c2c899fbfed5952ac475be01cf139b834a64ecd699c64e8ffa6b16b5b3e34073be7fbcd7bc6a9b37ef3109ce7e65f824b70d5b0d57b60dc8d2c4e55c33eceb3c0627adf8f54fbd7b1fe14c68d9ec0e807fb7e773bddd00f01a37e61cf03e7da99f7cf03a3de6fc66969fbc7afc65dd4234fc6593930ffad864bcf7e7ed649da71dbfb25c619facd53e33c323d8dc10ef397810be7f9daf320dc1f42c6c18f6e8c839e5ec139fcf2c0888fc025d8f7536f6fe42b62acf32ddf0c0cbd2c1bb6fcc112c1efbc618b0fc1a19eb461cbcf3f5f9a5c69cf3b3f1aa711f663659cbbcc3f5fb23096a834bf2e187e320f6c7162b060bd045c213fbf9e24b9c379d1371687fbef045ca1be8786cdcf05463ec7c68318fdef04b6b860bede60e6e7f753b43e3bcf6466ac7a7f3e7204869e4fc0028e1bf67a9982910ff9f903ad07e7c58b71a37f0e5ca5deaf07aeb0fe8671817c6418d8f434f15ca6919d1f7c689ce379e22363b5b7f363653c10dc0febc6c19f6fc129f825b0ad2758af08f9df0546fefe79285c60a9c0a8476e03237fdfefa24c1df2bf3016b1f34d4ae332d4db06231ff2fd295d982ff7c64dfc1a8c7ce8d2b36603be6ad8de8747c6556ccce7e074687a7f7f56699ae3bcde0b6ce723ed180f62f01b58c04fc6458ae7eb162ce00be366fd03b0607d7f3e545519e37cbc04a7783f9c1937fa2e18f5c94d608bf37dc343afdf361ec688ef36ece3eccfcb61da49504f6c5c56763ed0a1f110fbc593c098bf03463f79d1b0c54fc102f6e7e570a8eb59bfd78df57eb7f3fd1eecc02f0ddbfdf404c67ef17360bccfbe1a7783feca3877586f602c95f597ee8c0729be0fe037a8c0f02b04df47bbc6658cefa363e3aac2f7cabe7153ff2638d48ff5ea7f35f7674c2c7a0df4222efc5570e9afca5fc3fe4c55231edbfb996ff896eff89e273aeefe31a63a1ef8919ff8d9ded7aa7ed1dfcf78aed7dfd50b5eaafe9557fcc65fe1bfce1b1a99ebac8d0fda4dbfe2166ff30eeff21e7fb3ef03ee79dd0ceb04edbe6a77f9800ff9888fb9cfdffb33fbde50fd89c637df399f6a1e675ad1395ff0255ff135b7eb9a914fc431777424ec38e52e673a72629e1291d0809fa8a032e8a952bdaaeb66d290531ae918d38d57dfd21dddd384a6b53af8d343edad7e5d75f7de3aa6f4484ff44c2f34a3392d7eead53f81ba4b4bcee8557319d38adee82badd3066dd2d67bbdfa6b26bedabae6052f689b27b443bbeabd47df54dda3fd77fe079af35295a7501ff23d1dd1b17af7e93b9dd0a98eb377fe052de99c37e9822ee98aae75b429a258d51d4a74384a3fe82bcd7904efaedfa103ca281716d2cf68a153d157c9077fad50b5f0163d7875a74f746897652823eac9f89dbed46e8c6b775ec84d9dbbdcca9dde193d1db10c553dfad09f42d5cbda5feed57ba2de3d998aee89ee8bd39f1fb53feff5254fe5499ee54587fe7da41ac75d99d3b92c64a9e3957afcf053df9fc94adefefd3275d0fff7f1bfebfffc75ed2f4cf55fda</data>
</image>
<image name="image14">
<data format="XPM.GZ" length="5034">789c85d7d96ee3ca1106e0fb790a63ea6e10f41129912211e4c2922daf92257977908b2a92b2e4458b2d5b4b90774fabeb6f0e9de383a087b63f7417bb7a23397ffcdabbeb77f77efdf1e37dc9cb49b6978df96def57fef1fabaf9e7bffef1ef1f3fc3c6deee5f3ddd0b7ffeedc74f33ddcbf67ab369e1205550155915a30a06cb6a4d5105579157f15ac54b05fce56ecf553c55d1ad6258c5a48ac32a1eab185731ab40dad5742eaba85740ef55bc55eff650ad595431aff6b34b87ea69bd510f5cd841e9d4d5b7e004f5e7a5b57ed727358230a9d59c2fd5bebd9c95d6f6399cc173676ed4d43c84d13f87de0ded3f2ecdaefe1d4e50df8433d477768e425f4f019ca96558dab537913aaa456e6372e15cde8f66eaa8061fc311e24fbc35de0ce034d2fa1b3887939de3304a11ffe18df8169cc39fa5b5fdbd3397f54b751ca0decd4fb31ea7b1d637d4cda0597776ebd79466a0f5e2fa4fea5114e87a8ee0b496383f3b4b54d3f5360b75338d753eb4bd2441535cfbdd79a1b4e1e3f90eceb15f96ea3808d52f708efd41ea04f999b9b7e6cf2d3855cb18ced3866bdf56a7915a8c731647c8a709e718df44ddccb17f9ed509e6533adec8a70763bda850fbfef8054e91cf59e9ccb577fb811b71aaf3c1fb30f2e158dd0ce053ef40f35dc011e247b08f37ea24c0fe9faad31cfd5f3b67f6fe1a9f94d6fb17b0bfffbddac733a9d91e1167777ea4ec9faed449a0fb896e61ccaf1ca939d0fbc93b8cf933fb6a0959f365e79cfd7a5cc0acfdcb275ca849ef9ffb7876f9645182fd486b18fb911bde9aafb954a7b93ecf68e3adeb2d3db5c4b8ff2bcca2f9877021b9f3a93a0bb3c8b577e72dcb539c373e2aadf93dc1297ce9ade7854218f9d2d01be769a0e620d1f3710a47899ecf7d98713e667001f7d5767c3a9f3518e3131d6f9e853a3e6638d6f1992dcc998eff0e2ed49cee6c1f66182f9f7823ff4c2d21f65b00231f3e84b1fe3c28adeddfe042f3e55c6df3d5fc119fc59a3fbdc2acf94b172eb05e67a5753c1b751ee7ae9edc7ae605e3fc9800f6cf9bad77e89e6ff40833d697bcb1be4bb8407bc467858ecf5ca8f310fbffdc5bf3a31c467e6605dbe2ecd6b388b9c079a87b633f9da92544bdf1467e3d38c6fbfa11669c97ae37decf57de78bf7eaab310e789d53e5f398059f3e5295c603cc7a5753cb7de45ecbc5617217c0dc76a72f3551412637e4f60c6784fbdf13c48e142c74b137516e279b685b13fe5a4b43ebf2e60d6f7a56cbcb13f8fe102f5e28dfd8afa1ccf0f59c1386fd48219fb79df1bfbb70d63bee8455d8430fab3f3a3f3d987193e820b35bbf91ed9f5d3f5e61b18fb41a630f2a7b13a0ff579440d38c6fb7bed8de749cd1bf9f7613f9e83d2da7e01fbe7cb85b7ee17eea9ed7875be3aa575fc0f708cfd26deba5fb80bfbfd78ee8dfdd486fdfeabab47e148e3ddf37c34ca433d0fbc29addf1b1338c6f958c3febcac4aebf756d35bbf47680017f0aab4deffda5be79b527511e27e89b7c6f3b8b4c6cfbd319f198cf9a21866ac6fbfb47bdff08337e66fe68df9fb84fdfbfbde1bf577a5b5bf483df2df0787dea83f80639d7f7a8619ce4a8fdc7a75e0917ab03464582ffbb7d82bdb5dd6fa3bb757f1fbb7bb8798918d18b988473336135b9e6c79b6e5c596575ba6b668a49eab69a5ccccdc96852d6fb6bcdbb2b4e5c37cfe6ef3a798898d589975796dccd6ec9b96699b83bf8c39b43dac4da7528eccb13931a7e6cc9cff454cd7f4ccc597988ee99b81bdb636eae0db98a1b93457e6fa7fa26eccadfd7967a3eebf897930351398d0d4bfc4344c6462d3b4e34abe8949c91011935463283375caa9a0919dc13fc5d0238d69424f666bdb55a39ee9855e694a331f43735ad01bbdd3923ee89356b4a60d6d699f5ad446c4011d52878ee85863e8844ee98ccea94b3dbaa03e0dec5f43baa42bbaa61bba357d1b7147f7f440350aca7e42aa538322db3eb611036a5242a9bdc30d1b26fb9d2bbb08fbc56dbfd17e8f8747f4c18f3cde45f0c49627dbcf0d3ff30bbff294673662ce0b7ee3f7ea1cf0923ff893c7bce2356f78cbfbdca2a9eda3ed22321b71c087dcf93a6f7cc4c7da872d277c4a059ff139dd71d746f4f882fb3ce0e1977e2ef98aaf7963473fe41bbee53bbee7361df2832d3ddb4b9f6b1c70f825a6ce0d9ad8c75ccc4d4e38152324ecb2b211b4cf3511c924ff1263ffdf60bff446f2286399c8933ccb8bbcdaf6bb3e6a2e622a33997f898964216ff6f7d0eefb637997a57cc8a7ac78212b59db888d6c655f5ad5186963f7ccc4adb91c4a478ee4b8ece3c4965339fb668f4ee958ce6de9da989e5c889d2be9db71cc6c1fa73290c76f6366b60432e40e7764cea1cc6dc96d69c9a51debb731ffbffcfccfdf7ffc17b9ebca7e</data>
</image>
</images>
<connections>
<connection>
@ -526,6 +541,12 @@
<receiver>QgisAppBase</receiver>
<slot>fileSaveAs()</slot>
</connection>
<connection>
<sender>actionFileNew</sender>
<signal>activated()</signal>
<receiver>QgisAppBase</receiver>
<slot>fileNew()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">qgisappbase.ui.h</include>
@ -551,6 +572,7 @@
<slot>options()</slot>
<slot>fileSave()</slot>
<slot>fileSaveAs()</slot>
<slot>fileNew()</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@ -122,3 +122,9 @@ void QgisAppBase::fileSaveAs()
{
}
void QgisAppBase::fileNew()
{
}

View File

@ -577,3 +577,7 @@ void QgsMapCanvas::remove(QString key)
delete l;
zOrder.remove(key);
}
void QgsMapCanvas::removeAll(){
layers.clear();
zOrder.clear();
}

View File

@ -75,6 +75,8 @@ public:
void freeze(bool frz=true);
//! remove the layer defined by key
void remove(QString key);
//! remove all layers from the map
void removeAll();
void setDirty(bool _dirty);
friend class QgsLegend;
public slots:

View File

@ -14,6 +14,7 @@
#include <iostream>
#include <fstream>
#include <qfiledialog.h>
#include <qfileinfo.h>
#include <qdom.h>
#include <qmessagebox.h>
#include <qcolor.h>
@ -23,6 +24,7 @@
#endif
#include "qgsshapefilelayer.h"
#include "qgsmapcanvas.h"
#include "qgsrect.h"
#include "qgsprojectio.h"
@ -35,32 +37,42 @@ QgsProjectIo::QgsProjectIo(QgsMapCanvas *_map, int _action) : map(_map), action(
QgsProjectIo::~QgsProjectIo()
{
}
void QgsProjectIo::write(){
selectFileName();
QString QgsProjectIo::baseName(){
QFileInfo fi(fullPath);
return fi.baseName(true);
}
bool QgsProjectIo::write(){
if(fullPath.isEmpty()){
selectFileName();
}
//QMessageBox::information(0,"Full Path",fullPath);
int okToSave = 0;
if(QFile::exists(fullPath)){
if(QFile::exists(fullPath) && (action == SAVEAS)){
okToSave = QMessageBox::warning(0,"Overwrite File?",fullPath + " exists. \nDo you want to overwrite it?", "Yes", "No");
}
if(okToSave == 0){
// write the project information to the selected file
writeXML();
}
writeXML();
return true;
}else{
return false;
}
}
void QgsProjectIo::read(){
bool QgsProjectIo::read(){
QString path = selectFileName();
QDomDocument *doc;
if(!path.isEmpty()){
doc = new QDomDocument( "qgisdocument" );
QFile file( path );
if ( !file.open( IO_ReadOnly ) )
return;
return false;
if ( !doc->setContent( &file ) ) {
file.close();
return;
return false;
}
file.close();
// clear the map canvas
map->removeAll();
QDomNodeList nl = doc->elementsByTagName("maplayer");
QString layerCount;
layerCount = layerCount.setNum(nl.count());
@ -149,6 +161,7 @@ void QgsProjectIo::read(){
}
}
return true;
}
QString QgsProjectIo::selectFileName(){
if(action == SAVE && fullPath.isEmpty()){
@ -165,6 +178,12 @@ switch(action){
}
return fullPath;
}
void QgsProjectIo::setFileName(QString fn){
fullPath = fn;
}
QString QgsProjectIo::fullPathName(){
return fullPath;
}
void QgsProjectIo::writeXML(){
std::ofstream xml(fullPath);
if(!xml.fail()){
@ -172,6 +191,16 @@ void QgsProjectIo::writeXML(){
xml << "<!DOCTYPE qgis SYSTEM \"http://mrcc.com/qgis.dtd\">" << std::endl;
xml << "<qgis projectname=\"default project\">\n";
xml << "<title>QGis Project File</title>\n";
xml << "<extent>\n";
QgsRect extent = map->extent();
xml << "\t<xmin>" << extent.xMin() << "</xmin>\n";
xml << "\t<ymin>" << extent.yMin() << "</ymin>\n";
xml << "\t<xmax>" << extent.xMax() << "</xmax>\n";
xml << "\t<ymax>" << extent.yMax() << "</ymax>\n";
xml << "</extent>\n";
xml << "<projectlayers layercount=\"" << map->layerCount() << "\"> \n";
// write the layers
for(int i = 0; i < map->layerCount(); i++){

View File

@ -25,10 +25,19 @@ class QgsProjectIo
public:
QgsProjectIo(QgsMapCanvas *map=0, int action=SAVE);
~QgsProjectIo();
void read();
void write();
//! Read the file and create the map
bool read();
//! Write the contents of the map to a file
bool write();
void setMapCanvas(QgsMapCanvas *map);
//! Open a file dialog, the type determined by action (SAVE AS or OPEN)
QString selectFileName();
//! get the basename of the file (no path, just the file name)
QString baseName();
//! get the full path name of the map file
QString fullPathName();
//! Set the full path to the file
void setFileName(QString filename);
enum ACTION {
SAVE,
SAVEAS,