mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-22 00:14:55 -05:00
Modified projectio (serialisation and deserialisation of project files) to use maplayerregistry and not mapcanvas.
Implemented state handling of 'showInOverview' property in project io. git-svn-id: http://svn.osgeo.org/qgis/trunk@1554 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
077dcef119
commit
3fb49d8efd
@ -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!
|
||||
|
||||
@ -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
|
||||
|
||||
4
qgis.dtd
4
qgis.dtd
@ -31,6 +31,10 @@
|
||||
<!ELEMENT datasource (#PCDATA) >
|
||||
<!ELEMENT zorder (#PCDATA) >
|
||||
<!-- Attribute Lists -->
|
||||
<!--Raster : flag indicating whether the layer should be represented in overview or not -->
|
||||
<!ELEMENT showInOverviewFlag>
|
||||
<!-- Attribute lists -->
|
||||
<!ATTLIST showInOverViewFlag boolean (1|0|true|false) "false">
|
||||
<!ATTLIST maplayer
|
||||
type (vector|raster|database) "vector"
|
||||
visible (1|0) "0"
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
<ignoreparts/>
|
||||
<projectdirectory>.</projectdirectory>
|
||||
<absoluteprojectpath>false</absoluteprojectpath>
|
||||
<description></description>
|
||||
<description/>
|
||||
<secondaryLanguages/>
|
||||
</general>
|
||||
<kdevautoproject>
|
||||
@ -21,7 +21,7 @@
|
||||
<mainprogram>src/qgis</mainprogram>
|
||||
<directoryradio>executable</directoryradio>
|
||||
<customdirectory>/</customdirectory>
|
||||
<programargs></programargs>
|
||||
<programargs/>
|
||||
<terminal>false</terminal>
|
||||
<autocompile>true</autocompile>
|
||||
<envvars/>
|
||||
@ -61,19 +61,19 @@
|
||||
</debug>
|
||||
<default>
|
||||
<configargs>--prefix=$HOME --enable-debug</configargs>
|
||||
<builddir></builddir>
|
||||
<topsourcedir></topsourcedir>
|
||||
<cppflags></cppflags>
|
||||
<ldflags></ldflags>
|
||||
<builddir/>
|
||||
<topsourcedir/>
|
||||
<cppflags/>
|
||||
<ldflags/>
|
||||
<ccompiler>kdevgccoptions</ccompiler>
|
||||
<cxxcompiler>kdevgppoptions</cxxcompiler>
|
||||
<f77compiler>kdevpgf77options</f77compiler>
|
||||
<ccompilerbinary></ccompilerbinary>
|
||||
<cxxcompilerbinary></cxxcompilerbinary>
|
||||
<f77compilerbinary></f77compilerbinary>
|
||||
<cflags></cflags>
|
||||
<ccompilerbinary/>
|
||||
<cxxcompilerbinary/>
|
||||
<f77compilerbinary/>
|
||||
<cflags/>
|
||||
<cxxflags>-O0 -g3</cxxflags>
|
||||
<f77flags></f77flags>
|
||||
<f77flags/>
|
||||
</default>
|
||||
</configurations>
|
||||
<make>
|
||||
@ -84,17 +84,17 @@
|
||||
<abortonerror>true</abortonerror>
|
||||
<numberofjobs>1</numberofjobs>
|
||||
<dontact>false</dontact>
|
||||
<makebin></makebin>
|
||||
<makebin/>
|
||||
</make>
|
||||
</kdevautoproject>
|
||||
<kdevdebugger>
|
||||
<general>
|
||||
<dbgshell>libtool</dbgshell>
|
||||
<programargs></programargs>
|
||||
<gdbpath></gdbpath>
|
||||
<configGdbScript></configGdbScript>
|
||||
<runShellScript></runShellScript>
|
||||
<runGdbScript></runGdbScript>
|
||||
<programargs/>
|
||||
<gdbpath/>
|
||||
<configGdbScript/>
|
||||
<runShellScript/>
|
||||
<runGdbScript/>
|
||||
<breakonloadinglibs>true</breakonloadinglibs>
|
||||
<separatetty>false</separatetty>
|
||||
<floatingtoolbar>false</floatingtoolbar>
|
||||
@ -142,16 +142,24 @@
|
||||
<argumentsHintDelay>400</argumentsHintDelay>
|
||||
<headerCompletionDelay>250</headerCompletionDelay>
|
||||
</codecompletion>
|
||||
<references>
|
||||
<pcs>Qt</pcs>
|
||||
<pcs>GDAL</pcs>
|
||||
</references>
|
||||
<references/>
|
||||
</kdevcppsupport>
|
||||
<kdevfileview>
|
||||
<groups/>
|
||||
<groups>
|
||||
<hidenonprojectfiles>false</hidenonprojectfiles>
|
||||
<hidenonlocation>false</hidenonlocation>
|
||||
</groups>
|
||||
<tree>
|
||||
<hidepatterns>*.o,*.lo,CVS</hidepatterns>
|
||||
<hidenonprojectfiles>false</hidenonprojectfiles>
|
||||
<showvcsfields>false</showvcsfields>
|
||||
</tree>
|
||||
</kdevfileview>
|
||||
<kdevcvsservice>
|
||||
<recursivewhenupdate>true</recursivewhenupdate>
|
||||
<prunedirswhenupdate>true</prunedirswhenupdate>
|
||||
<createdirswhenupdate>true</createdirswhenupdate>
|
||||
<recursivewhencommitremove>true</recursivewhencommitremove>
|
||||
<revertoptions>-C</revertoptions>
|
||||
</kdevcvsservice>
|
||||
</kdevelop>
|
||||
|
||||
@ -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<QString, QgsMapLayer *> myMapLayers = mMapLayerRegistry->mapLayers();
|
||||
std::map<QString, QgsMapLayer *>::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;
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -91,3 +91,8 @@ void QgsMapLayerRegistry::removeAllMapLayers()
|
||||
//delete mMapLayers[theLayerId];
|
||||
//mMapLayers.erase(theLayerId);
|
||||
}
|
||||
|
||||
std::map<QString,QgsMapLayer*> QgsMapLayerRegistry::mapLayers()
|
||||
{
|
||||
return mMapLayers;
|
||||
}
|
||||
|
||||
@ -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<QString,QgsMapLayer*> 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
|
||||
|
||||
@ -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
|
||||
/***************************************************************************
|
||||
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 <iostream>
|
||||
#include <fstream>
|
||||
#include <qfiledialog.h>
|
||||
@ -40,9 +40,11 @@
|
||||
#include "qgsdlgvectorlayerproperties.h"
|
||||
#include "qgisapp.h"
|
||||
#include "qgsmarkersymbol.h"
|
||||
#include "qgsmaplayerregistry.h"
|
||||
#include <map>
|
||||
|
||||
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,7 +58,7 @@ QString QgsProjectIo::baseName()
|
||||
return fi.baseName(true);
|
||||
}
|
||||
|
||||
bool QgsProjectIo::write()
|
||||
bool QgsProjectIo::write(QgsRect theRect)
|
||||
{
|
||||
if (fullPath.isEmpty())
|
||||
{
|
||||
@ -74,7 +76,7 @@ bool QgsProjectIo::write()
|
||||
if (okToSave == 0)
|
||||
{
|
||||
// write the project information to the selected file
|
||||
writeXML();
|
||||
writeXML(theRect);
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
@ -107,7 +109,7 @@ bool QgsProjectIo::read(QString path)
|
||||
file.close();
|
||||
qWarning("opened document" + file.name());
|
||||
// clear the map canvas
|
||||
map->removeAll();
|
||||
qgisApp->removeAllLayers();
|
||||
// get the extent
|
||||
QDomNodeList extents = doc->elementsByTagName("extent");
|
||||
QDomNode extentNode = extents.item(0);
|
||||
@ -244,15 +246,23 @@ bool QgsProjectIo::read(QString path)
|
||||
}
|
||||
|
||||
dbl->setVisible(visible == "1");
|
||||
if (showInOverview == "1")
|
||||
{
|
||||
dbl->toggleShowInOverview();
|
||||
}
|
||||
dbl->initContextMenu(qgisApp);
|
||||
map->addLayer(dbl);
|
||||
} else if (type == "raster")
|
||||
qgisApp->addMapLayer(dbl);
|
||||
}
|
||||
else if (type == "raster")
|
||||
{
|
||||
QgsRasterLayer *myRasterLayer = new QgsRasterLayer(dataSource, layerName);
|
||||
myRasterLayer->initContextMenu(qgisApp);
|
||||
map->addLayer(myRasterLayer);
|
||||
qgisApp->addMapLayer(myRasterLayer);
|
||||
|
||||
myRasterLayer->setVisible(visible == "1");
|
||||
if (showInOverview == "1")
|
||||
{
|
||||
myRasterLayer->toggleShowInOverview();
|
||||
}
|
||||
|
||||
mnl = node.namedItem("rasterproperties");
|
||||
|
||||
@ -294,7 +304,7 @@ bool QgsProjectIo::read(QString path)
|
||||
myRasterLayer->setGrayBandName(myElement.text());
|
||||
|
||||
}
|
||||
map->setExtent(savedExtent);
|
||||
qgisApp->setExtent(savedExtent);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -333,7 +343,7 @@ QString QgsProjectIo::fullPathName()
|
||||
|
||||
|
||||
|
||||
void QgsProjectIo::writeXML()
|
||||
void QgsProjectIo::writeXML(QgsRect theExtent)
|
||||
{
|
||||
std::ofstream xml(fullPath);
|
||||
if (!xml.fail())
|
||||
@ -344,19 +354,24 @@ void QgsProjectIo::writeXML()
|
||||
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 << "\t<xmin>" << theExtent.xMin() << "</xmin>\n";
|
||||
xml << "\t<ymin>" << theExtent.yMin() << "</ymin>\n";
|
||||
xml << "\t<xmax>" << theExtent.xMax() << "</xmax>\n";
|
||||
xml << "\t<ymax>" << theExtent.yMax() << "</ymax>\n";
|
||||
xml << "</extent>\n";
|
||||
|
||||
xml << "<projectlayers layercount=\"" << map->layerCount() << "\"> \n";
|
||||
// write the layers
|
||||
for (int i = 0; i < map->layerCount(); i++)
|
||||
// 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<QString, QgsMapLayer *> myMapLayers = myMapLayerRegistry->mapLayers();
|
||||
xml << "<projectlayers layercount=\"" << myMapLayers.size() << "\"> \n";
|
||||
int i=0;
|
||||
std::map<QString, QgsMapLayer *>::iterator myMapIterator;
|
||||
for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator )
|
||||
{
|
||||
QgsMapLayer *lyr = map->getZpos(i);
|
||||
QgsMapLayer *lyr = myMapIterator->second;
|
||||
bool isDatabase = false;
|
||||
xml << "\t<maplayer type=\"";
|
||||
switch (lyr->type())
|
||||
@ -467,11 +482,10 @@ void QgsProjectIo::writeXML()
|
||||
xml << "\t\t</rasterproperties>\n";
|
||||
}
|
||||
xml << "\t</maplayer>\n";
|
||||
i++;
|
||||
}
|
||||
xml << "</projectlayers>\n";
|
||||
xml << "</qgis>\n";
|
||||
xml.close();
|
||||
} else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user