diff --git a/ChangeLog b/ChangeLog index c7645c0271b..e531d5e7982 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,11 @@ QGIS Change Log -ChangeLog,v 1.122 2004/06/10 15:38:53 sbr00pwb Exp +ChangeLog,v 1.123 2004/06/10 23:10:16 timlinux Exp ------------------------------------------------------------------------------ Version 0.3 'Madison' .... development version +2004-06-10 [ts] 0.3.0devel27 +** Modified projectio (serialisation and deserialisation of project files) to use maplayerregistry and not mapcanvas. +** Implemented state handling of 'showInOverview' property in project io. 2004-06-10 [petebr] 0.3.0devel26 Tidied up the SPIT gui to match the plugin template. Fixed bug in scale bar which displayed the bar the wrong size! diff --git a/configure.in b/configure.in index f9d19d73e64..9ed131a5eb8 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. -dnl configure.in,v 1.125 2004/06/10 15:38:53 sbr00pwb Exp +dnl configure.in,v 1.126 2004/06/10 23:10:16 timlinux Exp AC_INIT @@ -24,7 +24,7 @@ dnl --------------------------------------------------------------------------- MAJOR_VERSION=0 MINOR_VERSION=3 MICRO_VERSION=0 -EXTRA_VERSION=26 +EXTRA_VERSION=27 if test $EXTRA_VERSION -eq 0; then VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION} else diff --git a/qgis.dtd b/qgis.dtd index ed5135e6dea..bb22034b641 100644 --- a/qgis.dtd +++ b/qgis.dtd @@ -31,7 +31,11 @@ - + + + + diff --git a/qgis.kdevelop b/qgis.kdevelop index 880a124c48e..9abfd529a34 100644 --- a/qgis.kdevelop +++ b/qgis.kdevelop @@ -9,7 +9,7 @@ . false - + @@ -21,7 +21,7 @@ src/qgis executable / - + false true @@ -61,19 +61,19 @@ --prefix=$HOME --enable-debug - - - - + + + + kdevgccoptions kdevgppoptions kdevpgf77options - - - - + + + + -O0 -g3 - + @@ -84,17 +84,17 @@ true 1 false - + libtool - - - - - + + + + + true false false @@ -142,16 +142,24 @@ 400 250 - - Qt - GDAL - + - + + false + false + *.o,*.lo,CVS false + false + + true + true + true + true + -C + diff --git a/src/qgisapp.cpp b/src/qgisapp.cpp index a9a8857068d..e78ae426ebb 100644 --- a/src/qgisapp.cpp +++ b/src/qgisapp.cpp @@ -1612,7 +1612,7 @@ void QgisApp::fileOpen() if (answer != QMessageBox::Cancel) { mMapCanvas->freeze(true); - QgsProjectIo *pio = new QgsProjectIo(mMapCanvas, QgsProjectIo::OPEN, this); + QgsProjectIo *pio = new QgsProjectIo( QgsProjectIo::OPEN, this); if (pio->read()) { @@ -1630,9 +1630,9 @@ void QgisApp::fileOpen() void QgisApp::fileSave() { - QgsProjectIo *pio = new QgsProjectIo(mMapCanvas, QgsProjectIo::SAVE); + QgsProjectIo *pio = new QgsProjectIo( QgsProjectIo::SAVE); pio->setFileName(mFullPathName); - if (pio->write()) + if (pio->write(mMapCanvas->extent())) { setCaption(tr("Quantum GIS --") + " " + pio->baseName()); statusBar()->message(tr("Saved map to:") + " " + pio->fullPathName()); @@ -1644,8 +1644,8 @@ void QgisApp::fileSave() void QgisApp::fileSaveAs() { - QgsProjectIo *pio = new QgsProjectIo(mMapCanvas, QgsProjectIo::SAVEAS); - if (pio->write()) + QgsProjectIo *pio = new QgsProjectIo( QgsProjectIo::SAVEAS); + if (pio->write(mMapCanvas->extent())) { setCaption(tr("Quantum GIS --") + " " + pio->baseName()); statusBar()->message(tr("Saved map to:") + " " + pio->fullPathName()); @@ -1782,7 +1782,7 @@ bool QgisApp::addProject(QString projectFile) // adds a saved project to qgis, usually called on startup by // specifying a project file on the command line bool returnValue = false; - QgsProjectIo *pio = new QgsProjectIo(mMapCanvas, QgsProjectIo::OPEN, this); + QgsProjectIo *pio = new QgsProjectIo(QgsProjectIo::OPEN, this); #ifdef QGISDEBUG std::cout << "Loading Project - about to call ProjectIO->read()" << std::endl; #endif @@ -2086,6 +2086,17 @@ void QgisApp::removeLayer() mMapCanvas->clear(); mMapCanvas->render(); } +void QgisApp::removeAllLayers() +{ + std::map myMapLayers = mMapLayerRegistry->mapLayers(); + std::map::iterator myMapIterator; + for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator ) + { + mMapLayerRegistry->removeMapLayer( myMapIterator->first ); + } + mOverviewCanvas->clear(); + mMapCanvas->clear(); +} //remove all layers void QgisApp::zoomToLayerExtent() { @@ -2789,6 +2800,47 @@ void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString } +void QgisApp::addMapLayer(QgsMapLayer *theMapLayer) +{ + mMapCanvas->freeze(); + QApplication::setOverrideCursor(Qt::WaitCursor); + if(theMapLayer->isValid()) + { + // Register this layer with the layers registry + mMapLayerRegistry->addMapLayer(theMapLayer); + // init the context menu so it can connect to slots in main app + theMapLayer->initContextMenu(this); + // add it to the mapcanvas collection + mMapCanvas->addLayer(theMapLayer); + //connect up a request from the raster layer to show in overview map + QObject::connect(theMapLayer, + SIGNAL(showInOverview(QString,bool)), + this, + SLOT(setLayerOverviewStatus(QString,bool))); + + mProjectIsDirtyFlag = true; + statusBar()->message(mMapCanvas->extent().stringRep(2)); + + }else + { + QMessageBox::critical(this,"Layer is not valid", + "The layer is not a valid layer and can not be added to the map"); + } + qApp->processEvents(); + mMapCanvas->freeze(false); + mMapCanvas->render(); + QApplication::restoreOverrideCursor(); + +} + +void QgisApp::setExtent(QgsRect theRect) +{ + mMapCanvas->setExtent(theRect); +} + + + + int QgisApp::saveDirty() { int answer = 0; diff --git a/src/qgisapp.h b/src/qgisapp.h index 9c93a619bdc..e4558669c0b 100644 --- a/src/qgisapp.h +++ b/src/qgisapp.h @@ -115,6 +115,14 @@ public: */ bool addRasterLayer(QFileInfo const & rasterFile); + /** Add a 'pre-made' map layer to the project */ + void addMapLayer(QgsMapLayer *theMapLayer); + + /** Set the extents of the map canvas */ + void setExtent(QgsRect theRect); + + //! Remove all layers from the map and legend + void removeAllLayers(); /** opens a qgis project file @returns false if unable to open the project diff --git a/src/qgsmaplayerregistry.cpp b/src/qgsmaplayerregistry.cpp index 830854f2089..dd907edb9d8 100644 --- a/src/qgsmaplayerregistry.cpp +++ b/src/qgsmaplayerregistry.cpp @@ -91,3 +91,8 @@ void QgsMapLayerRegistry::removeAllMapLayers() //delete mMapLayers[theLayerId]; //mMapLayers.erase(theLayerId); } + +std::map QgsMapLayerRegistry::mapLayers() +{ + return mMapLayers; +} diff --git a/src/qgsmaplayerregistry.h b/src/qgsmaplayerregistry.h index 64ab904c790..ee2c85b8f4a 100644 --- a/src/qgsmaplayerregistry.h +++ b/src/qgsmaplayerregistry.h @@ -39,6 +39,8 @@ public: QStringList mapLayerList(); //! Retrieve a pointer to a loaded plugin by id QgsMapLayer * mapLayer(QString theLayerId); + //! Retrieve the mapLayers collection (mainly intended for use by projectio) + std::map mapLayers(); //! Add a layer to the map of loaded layers void addMapLayer(QgsMapLayer * theMapLayer); //! Remove a layer from qgis - any canvases using that layer will need to remove it diff --git a/src/qgsprojectio.cpp b/src/qgsprojectio.cpp index 683ca3c065e..5151e478842 100644 --- a/src/qgsprojectio.cpp +++ b/src/qgsprojectio.cpp @@ -1,10 +1,10 @@ /*************************************************************************** - qgsprojectio.cpp - Save/Restore QGIS project - -------------------------------------- - Date : 19-Oct-2003 - Copyright : (C) 2003 by Gary E.Sherman - email : sherman at mrcc.com -/*************************************************************************** + qgsprojectio.cpp - Save/Restore QGIS project + -------------------------------------- +Date : 19-Oct-2003 +Copyright : (C) 2003 by Gary E.Sherman +email : sherman at mrcc.com + *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -12,7 +12,7 @@ * (at your option) any later version. * * * ***************************************************************************/ -/* qgsprojectio.cpp,v 1.38 2004/06/09 15:02:33 timlinux Exp */ +/* qgsprojectio.cpp,v 1.39 2004/06/10 23:07:08 timlinux Exp */ #include #include #include @@ -40,9 +40,11 @@ #include "qgsdlgvectorlayerproperties.h" #include "qgisapp.h" #include "qgsmarkersymbol.h" +#include "qgsmaplayerregistry.h" +#include -QgsProjectIo::QgsProjectIo(QgsMapCanvas * _map, int _action, QgisApp * qgis) - : map(_map), action(_action), qgisApp(qgis) + QgsProjectIo::QgsProjectIo(int _action, QgisApp * qgis) +: action(_action), qgisApp(qgis) {} @@ -56,30 +58,30 @@ QString QgsProjectIo::baseName() return fi.baseName(true); } -bool QgsProjectIo::write() +bool QgsProjectIo::write(QgsRect theRect) { if (fullPath.isEmpty()) - { - selectFileName(); - } + { + selectFileName(); + } //QMessageBox::information(0,"Full Path",fullPath); int okToSave = 0; if (QFile::exists(fullPath) && (action == SAVEAS)) - { - okToSave = + { + okToSave = QMessageBox::warning(0, QObject::tr("Overwrite File?"), - QObject::tr("%1 exists.%2Do you want to overwrite it?").arg(fullPath).arg("\n"), QObject::tr("Yes"), - QObject::tr("No")); - } + QObject::tr("%1 exists.%2Do you want to overwrite it?").arg(fullPath).arg("\n"), QObject::tr("Yes"), + QObject::tr("No")); + } if (okToSave == 0) - { - // write the project information to the selected file - writeXML(); - return true; + { + // write the project information to the selected file + writeXML(theRect); + return true; } else - { - return false; - } + { + return false; + } } bool QgsProjectIo::read(QString path) @@ -92,232 +94,240 @@ bool QgsProjectIo::read(QString path) std::auto_ptr doc; if (!path.isEmpty()) + { + doc = std::auto_ptr(new QDomDocument("qgisdocument")); + QFile file(path); + if (!file.open(IO_ReadOnly)) { - doc = std::auto_ptr(new QDomDocument("qgisdocument")); - QFile file(path); - if (!file.open(IO_ReadOnly)) - { - return false; - } - if (!doc->setContent(&file)) - { - file.close(); - return false; - } - file.close(); - qWarning("opened document" + file.name()); - // clear the map canvas - map->removeAll(); - // get the extent - QDomNodeList extents = doc->elementsByTagName("extent"); - QDomNode extentNode = extents.item(0); - QDomNode xminNode = extentNode.namedItem("xmin"); - QDomNode yminNode = extentNode.namedItem("ymin"); - QDomNode xmaxNode = extentNode.namedItem("xmax"); - QDomNode ymaxNode = extentNode.namedItem("ymax"); - QDomElement exElement = xminNode.toElement(); - double xmin = exElement.text().toDouble(); - exElement = yminNode.toElement(); - double ymin = exElement.text().toDouble(); - exElement = xmaxNode.toElement(); - double xmax = exElement.text().toDouble(); - exElement = ymaxNode.toElement(); - double ymax = exElement.text().toDouble(); - QgsRect savedExtent(xmin, ymin, xmax, ymax); - - - QDomNodeList nl = doc->elementsByTagName("maplayer"); - QString layerCount; - layerCount = layerCount.setNum(nl.count()); - //QMessageBox::information(0, "Number of map layers", layerCount); - QString wk; - // process the map layer nodes - for (int i = 0; i < nl.count(); i++) - { - QDomNode node = nl.item(i); - QDomElement element = node.toElement(); - QString type = element.attribute("type"); - QString visible = element.attribute("visible"); - QString showInOverview = element.attribute("showInOverviewFlag"); - - //QMessageBox::information(0,"Type of map layer", type); - // process layer name - QDomNode mnl = node.namedItem("layername"); - QTextStream ts(&wk, IO_WriteOnly); - ts << mnl.nodeType(); - //QMessageBox::information(0,"Node Type", wk); - QDomElement mne = mnl.toElement(); - //QMessageBox::information(0,"Layer Name", mne.text()); - QString layerName = mne.text(); - - //process data source - mnl = node.namedItem("datasource"); - mne = mnl.toElement(); - //QMessageBox::information(0,"Datasource Name", mne.text()); - QString dataSource = mne.text(); - - //process zorder - mnl = node.namedItem("zorder"); - mne = mnl.toElement(); - //QMessageBox::information(0,"Zorder", mne.text()); - - // XXX I strongly suggest that much of this be pushed into the - // XXX provider objects. There just be just enough here to dispatch the - // XXX read to a provider. --MAC - - // add the layer to the maplayer - - if (type == "vector") - { - QString provider; - // determine type of vector layer - if ((dataSource.find("host=") > -1) && (dataSource.find("dbname=") > -1)) - { - provider = "postgres"; - } else - { - provider = "ogr"; - } - QgsVectorLayer *dbl = new QgsVectorLayer(dataSource, layerName, provider); - - Q_CHECK_PTR( dbl ); - - if ( ! dbl ) - { -#ifdef QGISDEBUG - std::cerr << __FILE__ << ":" << __LINE__ - << " unable to create vector layer for " - << dataSource << "\n"; -#endif - return false; - } - - if ( ! dbl->isValid() ) - { -#ifdef QGISDEBUG - std::cerr << __FILE__ << ":" << __LINE__ - << " created vector layer for " - << dataSource << "is invalid ... skipping\n"; -#endif - delete dbl; // discard bogus layer - - // XXX naturally we could be smart and ask the user for the - // XXX new location of the data, but for now we'll just - // XXX ignore the missing data and move on. Perhaps this - // XXX will be revisited when the architecture is refactored. - - return false; - } - - QDomNode singlenode = node.namedItem("singlesymbol"); - QDomNode graduatednode = node.namedItem("graduatedsymbol"); - QDomNode continuousnode = node.namedItem("continuoussymbol"); - QDomNode singlemarkernode = node.namedItem("singlemarker"); - QDomNode graduatedmarkernode = node.namedItem("graduatedmarker"); - - QgsRenderer* renderer; - - if (!singlenode.isNull()) - { - renderer = new QgsSingleSymRenderer(); - renderer->readXML(singlenode,*dbl); - } - else if (!graduatednode.isNull()) - { - renderer = new QgsGraduatedSymRenderer(); - renderer->readXML(graduatednode,*dbl); - } - else if (!continuousnode.isNull()) - { - renderer = new QgsContinuousColRenderer(); - renderer->readXML(continuousnode,*dbl); - } - else if(!singlemarkernode.isNull()) - { - renderer = new QgsSiMaRenderer(); - renderer->readXML(singlemarkernode,*dbl); - } - else if(!graduatedmarkernode.isNull()) - { - renderer = new QgsGraduatedMaRenderer(); - renderer->readXML(graduatedmarkernode,*dbl); - } - - dbl->setVisible(visible == "1"); - dbl->initContextMenu(qgisApp); - map->addLayer(dbl); - } else if (type == "raster") - { - QgsRasterLayer *myRasterLayer = new QgsRasterLayer(dataSource, layerName); - myRasterLayer->initContextMenu(qgisApp); - map->addLayer(myRasterLayer); - - myRasterLayer->setVisible(visible == "1"); - - mnl = node.namedItem("rasterproperties"); - - QDomNode snode = mnl.namedItem("showDebugOverlayFlag"); - QDomElement myElement = snode.toElement(); - QVariant myQVariant = (QVariant) myElement.attribute("boolean"); - myRasterLayer->setShowDebugOverlayFlag(myQVariant.toBool()); - - snode = mnl.namedItem("drawingStyle"); - myElement = snode.toElement(); - myRasterLayer->setDrawingStyle(myElement.text()); - - snode = mnl.namedItem("invertHistogramFlag"); - myElement = snode.toElement(); - myQVariant = (QVariant) myElement.attribute("boolean"); - myRasterLayer->setInvertHistogramFlag(myQVariant.toBool()); - - snode = mnl.namedItem("stdDevsToPlotDouble"); - myElement = snode.toElement(); - myRasterLayer->setStdDevsToPlot(myElement.text().toDouble()); - - snode = mnl.namedItem("transparencyLevelInt"); - myElement = snode.toElement(); - myRasterLayer->setTransparency(myElement.text().toInt()); - - snode = mnl.namedItem("redBandNameQString"); - myElement = snode.toElement(); - myRasterLayer->setRedBandName(myElement.text()); - snode = mnl.namedItem("greenBandNameQString"); - myElement = snode.toElement(); - myRasterLayer->setGreenBandName(myElement.text()); - - snode = mnl.namedItem("blueBandNameQString"); - myElement = snode.toElement(); - myRasterLayer->setBlueBandName(myElement.text()); - - snode = mnl.namedItem("grayBandNameQString"); - myElement = snode.toElement(); - myRasterLayer->setGrayBandName(myElement.text()); - - } - map->setExtent(savedExtent); - } - return true; + return false; } + if (!doc->setContent(&file)) + { + file.close(); + return false; + } + file.close(); + qWarning("opened document" + file.name()); + // clear the map canvas + qgisApp->removeAllLayers(); + // get the extent + QDomNodeList extents = doc->elementsByTagName("extent"); + QDomNode extentNode = extents.item(0); + QDomNode xminNode = extentNode.namedItem("xmin"); + QDomNode yminNode = extentNode.namedItem("ymin"); + QDomNode xmaxNode = extentNode.namedItem("xmax"); + QDomNode ymaxNode = extentNode.namedItem("ymax"); + QDomElement exElement = xminNode.toElement(); + double xmin = exElement.text().toDouble(); + exElement = yminNode.toElement(); + double ymin = exElement.text().toDouble(); + exElement = xmaxNode.toElement(); + double xmax = exElement.text().toDouble(); + exElement = ymaxNode.toElement(); + double ymax = exElement.text().toDouble(); + QgsRect savedExtent(xmin, ymin, xmax, ymax); + + + QDomNodeList nl = doc->elementsByTagName("maplayer"); + QString layerCount; + layerCount = layerCount.setNum(nl.count()); + //QMessageBox::information(0, "Number of map layers", layerCount); + QString wk; + // process the map layer nodes + for (int i = 0; i < nl.count(); i++) + { + QDomNode node = nl.item(i); + QDomElement element = node.toElement(); + QString type = element.attribute("type"); + QString visible = element.attribute("visible"); + QString showInOverview = element.attribute("showInOverviewFlag"); + + //QMessageBox::information(0,"Type of map layer", type); + // process layer name + QDomNode mnl = node.namedItem("layername"); + QTextStream ts(&wk, IO_WriteOnly); + ts << mnl.nodeType(); + //QMessageBox::information(0,"Node Type", wk); + QDomElement mne = mnl.toElement(); + //QMessageBox::information(0,"Layer Name", mne.text()); + QString layerName = mne.text(); + + //process data source + mnl = node.namedItem("datasource"); + mne = mnl.toElement(); + //QMessageBox::information(0,"Datasource Name", mne.text()); + QString dataSource = mne.text(); + + //process zorder + mnl = node.namedItem("zorder"); + mne = mnl.toElement(); + //QMessageBox::information(0,"Zorder", mne.text()); + + // XXX I strongly suggest that much of this be pushed into the + // XXX provider objects. There just be just enough here to dispatch the + // XXX read to a provider. --MAC + + // add the layer to the maplayer + + if (type == "vector") + { + QString provider; + // determine type of vector layer + if ((dataSource.find("host=") > -1) && (dataSource.find("dbname=") > -1)) + { + provider = "postgres"; + } else + { + provider = "ogr"; + } + QgsVectorLayer *dbl = new QgsVectorLayer(dataSource, layerName, provider); + + Q_CHECK_PTR( dbl ); + + if ( ! dbl ) + { +#ifdef QGISDEBUG + std::cerr << __FILE__ << ":" << __LINE__ + << " unable to create vector layer for " + << dataSource << "\n"; +#endif + return false; + } + + if ( ! dbl->isValid() ) + { +#ifdef QGISDEBUG + std::cerr << __FILE__ << ":" << __LINE__ + << " created vector layer for " + << dataSource << "is invalid ... skipping\n"; +#endif + delete dbl; // discard bogus layer + + // XXX naturally we could be smart and ask the user for the + // XXX new location of the data, but for now we'll just + // XXX ignore the missing data and move on. Perhaps this + // XXX will be revisited when the architecture is refactored. + + return false; + } + + QDomNode singlenode = node.namedItem("singlesymbol"); + QDomNode graduatednode = node.namedItem("graduatedsymbol"); + QDomNode continuousnode = node.namedItem("continuoussymbol"); + QDomNode singlemarkernode = node.namedItem("singlemarker"); + QDomNode graduatedmarkernode = node.namedItem("graduatedmarker"); + + QgsRenderer* renderer; + + if (!singlenode.isNull()) + { + renderer = new QgsSingleSymRenderer(); + renderer->readXML(singlenode,*dbl); + } + else if (!graduatednode.isNull()) + { + renderer = new QgsGraduatedSymRenderer(); + renderer->readXML(graduatednode,*dbl); + } + else if (!continuousnode.isNull()) + { + renderer = new QgsContinuousColRenderer(); + renderer->readXML(continuousnode,*dbl); + } + else if(!singlemarkernode.isNull()) + { + renderer = new QgsSiMaRenderer(); + renderer->readXML(singlemarkernode,*dbl); + } + else if(!graduatedmarkernode.isNull()) + { + renderer = new QgsGraduatedMaRenderer(); + renderer->readXML(graduatedmarkernode,*dbl); + } + + dbl->setVisible(visible == "1"); + if (showInOverview == "1") + { + dbl->toggleShowInOverview(); + } + dbl->initContextMenu(qgisApp); + qgisApp->addMapLayer(dbl); + } + else if (type == "raster") + { + QgsRasterLayer *myRasterLayer = new QgsRasterLayer(dataSource, layerName); + qgisApp->addMapLayer(myRasterLayer); + + myRasterLayer->setVisible(visible == "1"); + if (showInOverview == "1") + { + myRasterLayer->toggleShowInOverview(); + } + + mnl = node.namedItem("rasterproperties"); + + QDomNode snode = mnl.namedItem("showDebugOverlayFlag"); + QDomElement myElement = snode.toElement(); + QVariant myQVariant = (QVariant) myElement.attribute("boolean"); + myRasterLayer->setShowDebugOverlayFlag(myQVariant.toBool()); + + snode = mnl.namedItem("drawingStyle"); + myElement = snode.toElement(); + myRasterLayer->setDrawingStyle(myElement.text()); + + snode = mnl.namedItem("invertHistogramFlag"); + myElement = snode.toElement(); + myQVariant = (QVariant) myElement.attribute("boolean"); + myRasterLayer->setInvertHistogramFlag(myQVariant.toBool()); + + snode = mnl.namedItem("stdDevsToPlotDouble"); + myElement = snode.toElement(); + myRasterLayer->setStdDevsToPlot(myElement.text().toDouble()); + + snode = mnl.namedItem("transparencyLevelInt"); + myElement = snode.toElement(); + myRasterLayer->setTransparency(myElement.text().toInt()); + + snode = mnl.namedItem("redBandNameQString"); + myElement = snode.toElement(); + myRasterLayer->setRedBandName(myElement.text()); + snode = mnl.namedItem("greenBandNameQString"); + myElement = snode.toElement(); + myRasterLayer->setGreenBandName(myElement.text()); + + snode = mnl.namedItem("blueBandNameQString"); + myElement = snode.toElement(); + myRasterLayer->setBlueBandName(myElement.text()); + + snode = mnl.namedItem("grayBandNameQString"); + myElement = snode.toElement(); + myRasterLayer->setGrayBandName(myElement.text()); + + } + qgisApp->setExtent(savedExtent); + } + return true; + } } QString QgsProjectIo::selectFileName() { if (action == SAVE && fullPath.isEmpty()) - { - action = SAVEAS; - } + { + action = SAVEAS; + } switch (action) - { + { case OPEN: - fullPath = - QFileDialog::getOpenFileName("./", QObject::tr("QGis files (*.qgs)"), 0, 0, - QObject::tr("Choose a QGIS project file to open")); - break; + fullPath = + QFileDialog::getOpenFileName("./", QObject::tr("QGis files (*.qgs)"), 0, 0, + QObject::tr("Choose a QGIS project file to open")); + break; case SAVEAS: - fullPath = - QFileDialog::getSaveFileName("./", QObject::tr("QGis files (*.qgs)"), 0, 0, QObject::tr("Choose a filename to save")); - break; - } + fullPath = + QFileDialog::getSaveFileName("./", QObject::tr("QGis files (*.qgs)"), 0, 0, QObject::tr("Choose a filename to save")); + break; + } return fullPath; } @@ -333,145 +343,149 @@ QString QgsProjectIo::fullPathName() -void QgsProjectIo::writeXML() +void QgsProjectIo::writeXML(QgsRect theExtent) { std::ofstream xml(fullPath); if (!xml.fail()) + { + xml << "" << std::endl; + xml << "" << std::endl; + xml << "\n"; + xml << "QGis Project File\n"; + + xml << "\n"; + + xml << "\t" << theExtent.xMin() << "\n"; + xml << "\t" << theExtent.yMin() << "\n"; + xml << "\t" << theExtent.xMax() << "\n"; + xml << "\t" << theExtent.yMax() << "\n"; + xml << "\n"; + + // get the layer registry so we can write the layer data to disk + // the registry is a singleton so + // it will be the same registry data as used by the map canvas + QgsMapLayerRegistry * myMapLayerRegistry = QgsMapLayerRegistry::instance(); + std::map myMapLayers = myMapLayerRegistry->mapLayers(); + xml << " \n"; + int i=0; + std::map::iterator myMapIterator; + for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator ) { - xml << "" << std::endl; - xml << "" << std::endl; - xml << "\n"; - xml << "QGis Project File\n"; + QgsMapLayer *lyr = myMapIterator->second; + bool isDatabase = false; + xml << "\ttype()) + { + case QgsMapLayer::VECTOR: + xml << "vector"; + break; + case QgsMapLayer::RASTER: + xml << "raster"; + break; + case QgsMapLayer::DATABASE: + xml << "database"; + isDatabase = true; + break; + } + // + // layer visibility + // + xml << "\" visible=\""; + if (lyr->visible()) + { + xml << "1"; + } else + { + xml << "0"; + } + // + // layer is shown in overview? + // + xml << "\" showInOverviewFlag=\""; + if (lyr->showInOverviewStatus()) + { + xml << "1"; + } else + { + xml << "0"; + } + xml << "\">\n"; - xml << "\n"; - QgsRect extent = map->extent(); - - xml << "\t" << extent.xMin() << "\n"; - xml << "\t" << extent.yMin() << "\n"; - xml << "\t" << extent.xMax() << "\n"; - xml << "\t" << extent.yMax() << "\n"; - xml << "\n"; - - xml << "layerCount() << "\"> \n"; - // write the layers - for (int i = 0; i < map->layerCount(); i++) + if (isDatabase) + { + // cast the layer to a qgsdatabaselayer + // TODO fix this so database layers are properly saved/restored + // when name is changed in legend + /* QgsDatabaseLayer *dblyr = (QgsDatabaseLayer *)lyr; + xml << "\t\t" + dblyr->schemaName() << "." << + dblyr->geometryTableName() << "\n"; */ + xml << "\t\t" + lyr->name() + "\n"; + } else + { + xml << "\t\t" + lyr->name() + "\n"; + } + xml << "\t\t" + lyr->source() + "\n"; + xml << "\t\t" << i << "\n"; + if (lyr->type() != QgsMapLayer::RASTER) + { + QgsVectorLayer *layer = dynamic_cast < QgsVectorLayer * >(lyr); + if (!layer) { - QgsMapLayer *lyr = map->getZpos(i); - bool isDatabase = false; - xml << "\ttype()) - { - case QgsMapLayer::VECTOR: - xml << "vector"; - break; - case QgsMapLayer::RASTER: - xml << "raster"; - break; - case QgsMapLayer::DATABASE: - xml << "database"; - isDatabase = true; - break; - } - // - // layer visibility - // - xml << "\" visible=\""; - if (lyr->visible()) - { - xml << "1"; - } else - { - xml << "0"; - } - // - // layer is shown in overview? - // - xml << "\" showInOverviewFlag=\""; - if (lyr->showInOverviewStatus()) - { - xml << "1"; - } else - { - xml << "0"; - } - xml << "\">\n"; - - if (isDatabase) - { - // cast the layer to a qgsdatabaselayer - // TODO fix this so database layers are properly saved/restored - // when name is changed in legend - /* QgsDatabaseLayer *dblyr = (QgsDatabaseLayer *)lyr; - xml << "\t\t" + dblyr->schemaName() << "." << - dblyr->geometryTableName() << "\n"; */ - xml << "\t\t" + lyr->name() + "\n"; - } else - { - xml << "\t\t" + lyr->name() + "\n"; - } - xml << "\t\t" + lyr->source() + "\n"; - xml << "\t\t" << i << "\n"; - if (lyr->type() != QgsMapLayer::RASTER) - { - QgsVectorLayer *layer = dynamic_cast < QgsVectorLayer * >(lyr); - if (!layer) - { - qWarning("Warning, cast failed in QgsProjectIo, line 309"); - } - - QgsRenderer* renderer; - if(renderer=layer->renderer()) - { - renderer->writeXML(xml); - } - - } else //raster layer properties - { - //cast the maplayer to rasterlayer - QgsRasterLayer *myRasterLayer = (QgsRasterLayer *) lyr; - //Raster flag to indicate whether debug infor overlay should be rendered onto the raster - - xml << "\t\t\n"; - xml << "\t\t\tgetShowDebugOverlayFlag()) - { - xml << "true\"/>\n"; - } else - { - xml << "false\"/>\n"; - } - - // The drawing style for the layer - xml << "\t\t\t" << myRasterLayer->getDrawingStyleAsQString() << "\n"; - //Raster : flag indicating whether the histogram should be inverted or not - xml << "\t\t\tgetInvertHistogramFlag()) - { - xml << "true\"/>\n"; - } else - { - xml << "false\"/>\n"; - } - //Raster : Number of stddev to plot (0) to ignore --> - xml << "\t\t\t" << myRasterLayer->getStdDevsToPlot() << "\n"; - //Raster transparency for this layer should be 0-255 --> - xml << "\t\t\t" << myRasterLayer->getTransparency() << "\n"; - //Raster : the band to be associated with the color red - usually red --> - xml << "\t\t\t" << myRasterLayer->getRedBandName() << "\n"; - //Raster : the band to be associated with the color green - usually green --> - xml << "\t\t\t" << myRasterLayer->getGreenBandName() << "\n"; - //Raster : the band to be associated with the color blue - usually blue --> - xml << "\t\t\t" << myRasterLayer->getBlueBandName() << "\n"; - //Raster : the band to be associated with the grayscale only ouput - usually gray --> - xml << "\t\t\t" << myRasterLayer->getGrayBandName() << "\n"; - xml << "\t\t\n"; - } - xml << "\t\n"; + qWarning("Warning, cast failed in QgsProjectIo, line 309"); } - xml << "\n"; - xml << "\n"; - xml.close(); - } else - { + + QgsRenderer* renderer; + if(renderer=layer->renderer()) + { + renderer->writeXML(xml); + } + + } else //raster layer properties + { + //cast the maplayer to rasterlayer + QgsRasterLayer *myRasterLayer = (QgsRasterLayer *) lyr; + //Raster flag to indicate whether debug infor overlay should be rendered onto the raster + + xml << "\t\t\n"; + xml << "\t\t\tgetShowDebugOverlayFlag()) + { + xml << "true\"/>\n"; + } else + { + xml << "false\"/>\n"; + } + + // The drawing style for the layer + xml << "\t\t\t" << myRasterLayer->getDrawingStyleAsQString() << "\n"; + //Raster : flag indicating whether the histogram should be inverted or not + xml << "\t\t\tgetInvertHistogramFlag()) + { + xml << "true\"/>\n"; + } else + { + xml << "false\"/>\n"; + } + //Raster : Number of stddev to plot (0) to ignore --> + xml << "\t\t\t" << myRasterLayer->getStdDevsToPlot() << "\n"; + //Raster transparency for this layer should be 0-255 --> + xml << "\t\t\t" << myRasterLayer->getTransparency() << "\n"; + //Raster : the band to be associated with the color red - usually red --> + xml << "\t\t\t" << myRasterLayer->getRedBandName() << "\n"; + //Raster : the band to be associated with the color green - usually green --> + xml << "\t\t\t" << myRasterLayer->getGreenBandName() << "\n"; + //Raster : the band to be associated with the color blue - usually blue --> + xml << "\t\t\t" << myRasterLayer->getBlueBandName() << "\n"; + //Raster : the band to be associated with the grayscale only ouput - usually gray --> + xml << "\t\t\t" << myRasterLayer->getGrayBandName() << "\n"; + xml << "\t\t\n"; + } + xml << "\t\n"; + i++; } + xml << "\n"; + xml << "\n"; + xml.close(); + } } diff --git a/src/qgsprojectio.h b/src/qgsprojectio.h index b458ba30e07..09c5cacb92e 100644 --- a/src/qgsprojectio.h +++ b/src/qgsprojectio.h @@ -12,13 +12,14 @@ * (at your option) any later version. * * * ***************************************************************************/ -/* qgsprojectio.h,v 1.5 2004/02/21 20:54:26 gsherman Exp */ +/* qgsprojectio.h,v 1.6 2004/06/10 23:07:08 timlinux Exp */ #ifndef _QGSPROJECTIO_H_ #define _QGSPROJECTIO_H_ -class QgsMapCanvas; class QgisApp; +class QgsMapLayerRegistry; +class QgsRect; /*! \class QgsProjectIo * \brief Class to handle reading and writing a Qgis project file */ @@ -26,13 +27,12 @@ class QgsProjectIo { public: - QgsProjectIo(QgsMapCanvas *map=0, int action=SAVE, QgisApp *qgis=0); + QgsProjectIo(int action=SAVE, QgisApp *qgis=0); ~QgsProjectIo(); //! Read the file and create the map bool read(QString path=0); //! Write the contents of the map to a file - bool write(); - void setMapCanvas(QgsMapCanvas *map); + bool write(QgsRect theExtent); //! 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) @@ -47,13 +47,13 @@ public: OPEN }; private: - void writeXML(void); + void writeXML(QgsRect theExtent); QString fileName; QString fullPath; bool neverSaved; - QgsMapCanvas *map; //! pointer to the main app for connecting slots QgisApp *qgisApp; + QgsMapLayerRegistry * mMapLayerRegistry; int action; };