From fd1595bae6f5041b46f24b613d35fad471463dca Mon Sep 17 00:00:00 2001 From: gsherman Date: Sat, 25 Jan 2003 04:37:10 +0000 Subject: [PATCH] file save/open git-svn-id: http://svn.osgeo.org/qgis/trunk@176 c8812cc2-4d05-0410-92ff-de0c093fc19c --- qgis/src/qgisapp.cpp | 11 +++- qgis/src/qgisapp.h | 2 + qgis/src/qgsprojectio.cpp | 105 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 114 insertions(+), 4 deletions(-) diff --git a/qgis/src/qgisapp.cpp b/qgis/src/qgisapp.cpp index 66bea9054b2..9d6413e5f42 100644 --- a/qgis/src/qgisapp.cpp +++ b/qgis/src/qgisapp.cpp @@ -312,7 +312,16 @@ void QgisApp::fileExit() QApplication::exit(); } - +void QgisApp::fileOpen(){ + mapCanvas->freeze(true); + QgsProjectIo *pio = new QgsProjectIo(mapCanvas, QgsProjectIo::OPEN); + + pio->read(); + delete pio; + + mapLegend->update(); + mapCanvas->freeze(false); +} void QgisApp::fileSave(){ QgsProjectIo *pio = new QgsProjectIo(mapCanvas, QgsProjectIo::SAVE); pio->write(); diff --git a/qgis/src/qgisapp.h b/qgis/src/qgisapp.h index 2c6f48d6ec1..3d507c4e992 100644 --- a/qgis/src/qgisapp.h +++ b/qgis/src/qgisapp.h @@ -100,6 +100,8 @@ class QgisApp:public QgisAppBase void fileSave(); //! Save project as void fileSaveAs(); + //! Open a project + void fileOpen(); private: //! Popup menu QPopupMenu * popMenu; diff --git a/qgis/src/qgsprojectio.cpp b/qgis/src/qgsprojectio.cpp index 32c0cedeeb4..99ee6429a65 100644 --- a/qgis/src/qgsprojectio.cpp +++ b/qgis/src/qgsprojectio.cpp @@ -14,8 +14,11 @@ #include #include #include + #include #include + #include #include "qgsmaplayer.h" + #include "qgsdatabaselayer.h" #include "qgsmapcanvas.h" #include "qgsprojectio.h" @@ -42,7 +45,101 @@ void QgsProjectIo::write(){ } } void QgsProjectIo::read(){ - selectFileName(); + QString path = selectFileName(); + QDomDocument *doc; + if(!path.isEmpty()){ + doc = new QDomDocument( "qgisdocument" ); + QFile file( path ); + if ( !file.open( IO_ReadOnly ) ) + return; + if ( !doc->setContent( &file ) ) { + file.close(); + return; + } + file.close(); + + 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"); + + //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()); + + //process symbology + mnl = node.namedItem("symbol"); + QDomNode snode = mnl.namedItem("linewidth"); + QDomElement lineElement = snode.toElement(); + int lineWidth = lineElement.text().toInt(); + + + snode = mnl.namedItem("outlinecolor"); + QDomElement colorElement = snode.toElement(); + int olRed = colorElement.attribute("red").toInt(); + int olGreen = colorElement.attribute("green").toInt(); + int olBlue = colorElement.attribute("blue").toInt(); + + snode = mnl.namedItem("fillcolor"); + colorElement = snode.toElement(); + int fillRed = colorElement.attribute("red").toInt(); + int fillGreen = colorElement.attribute("green").toInt(); + int fillBlue = colorElement.attribute("blue").toInt(); + + QgsSymbol *sym = new QgsSymbol(); + sym->setFillColor( QColor(fillRed, fillGreen, fillBlue)); + sym->setColor(QColor(olRed, olGreen, olBlue)); + sym->setLineWidth(lineWidth); + // get the linewidth information + + //QMessageBox::information(0,"Zorder", mne.text()); + + + // add the layer to the maplayer + + if(type = "database"){ + + QgsDatabaseLayer *dbl = new QgsDatabaseLayer(dataSource, layerName); + + map->addLayer(dbl); + dbl->setSymbol(sym); + dbl->setVisible(visible == "1"); + }else{ + if(type == "vector"){ + }else{ + if(type == "raster"){ + } + } + } + + + } + + } } QString QgsProjectIo::selectFileName(){ if(action == SAVE && fullPath.isEmpty()){ @@ -97,9 +194,11 @@ void QgsProjectIo::writeXML(){ QgsSymbol *sym = lyr->symbol(); xml << "\t\t\t" << sym->lineWidth() << "\n"; QColor outlineColor = sym->color(); - xml << "\t\t\t\n"; + xml << "\t\t\t\n"; QColor fillColor = sym->fillColor(); - xml << "\t\t\t\n"; + xml << "\t\t\t\n"; xml << "\t\t\n"; xml << "\t\n";