889452 Fixed. Bug was caused by incorrect checking of feature type before trying to access fill color. Added a bunch of debug statements when debug mode is on.

git-svn-id: http://svn.osgeo.org/qgis/trunk@722 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
timlinux 2004-02-06 22:08:37 +00:00
parent 7891a6dad6
commit 2c3abab958

View File

@ -1,9 +1,9 @@
/*************************************************************************** /***************************************************************************
qgsmapserverexport.cpp - Export QGIS MapCanvas to MapServer qgsmapserverexport.cpp - Export QGIS MapCanvas to MapServer
-------------------------------------- --------------------------------------
Date : 8-Nov-2003 Date : 8-Nov-2003
Copyright : (C) 2003 by Gary E.Sherman Copyright : (C) 2003 by Gary E.Sherman
email : sherman at mrcc.com email : sherman at mrcc.com
*************************************************************************** ***************************************************************************
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
@ -35,9 +35,9 @@
// constructor // constructor
QgsMapserverExport::QgsMapserverExport(QgsMapCanvas *_map, QgsMapserverExport::QgsMapserverExport(QgsMapCanvas *_map,
QWidget* parent, const char* name, bool modal, WFlags fl ) QWidget* parent, const char* name, bool modal, WFlags fl )
: QgsMapserverExportBase(parent, name, modal, fl), : QgsMapserverExportBase(parent, name, modal, fl),
map(_map) map(_map)
{ {
} }
@ -48,197 +48,230 @@ QgsMapserverExport::~QgsMapserverExport()
} }
// Get the base name for the map file // Get the base name for the map file
QString QgsMapserverExport::baseName(){ QString QgsMapserverExport::baseName(){
QFileInfo fi(txtMapFilePath->text()); QFileInfo fi(txtMapFilePath->text());
return fi.baseName(true); return fi.baseName(true);
} }
// Write the map file // Write the map file
bool QgsMapserverExport::write(){ bool QgsMapserverExport::write(){
//QMessageBox::information(0,"Full Path",fullPath); //QMessageBox::information(0,"Full Path",fullPath);
int okToSave = 0; int okToSave = 0;
// Check for file and prompt for overwrite if it exists // Check for file and prompt for overwrite if it exists
if(QFile::exists(txtMapFilePath->text())){ if(QFile::exists(txtMapFilePath->text())){
okToSave = QMessageBox::warning(0,"Overwrite File?",txtMapFilePath->text() + okToSave = QMessageBox::warning(0,"Overwrite File?",txtMapFilePath->text() +
" exists. \nDo you want to overwrite it?", "Yes", "No"); " exists. \nDo you want to overwrite it?", "Yes", "No");
} }
if(okToSave == 0){ if(okToSave == 0){
// write the project information to the selected file // write the project information to the selected file
writeMapFile(); writeMapFile();
return true; return true;
}else{ }else{
return false; return false;
} }
} }
void QgsMapserverExport::setFileName(QString fn){ void QgsMapserverExport::setFileName(QString fn){
fullPath = fn; fullPath = fn;
} }
QString QgsMapserverExport::fullPathName(){ QString QgsMapserverExport::fullPathName(){
return fullPath; return fullPath;
} }
void QgsMapserverExport::writeMapFile(){ void QgsMapserverExport::writeMapFile(){
// write the map file, making massive assumptions about default values // write the map file, making massive assumptions about default values
std::cout << "Opening map file " << txtMapFilePath->text() << std::endl; #ifdef DEBUG
std::ofstream mapFile(txtMapFilePath->text()); std::cout << "Opening map file " << txtMapFilePath->text() << std::endl;
if(!mapFile.fail()){ #endif
mapFile << "# Map file generated by QGIS version " << QGis::qgisVersion << std::endl; std::ofstream mapFile(txtMapFilePath->text());
mapFile << "# Edit this file to customize for your interface" << std::endl; if(!mapFile.fail()){
mapFile << "# Not all sections are complete. See comments for details." << std::endl; mapFile << "# Map file generated by QGIS version " << QGis::qgisVersion << std::endl;
if(!chkExpLayersOnly->isChecked()){ mapFile << "# Edit this file to customize for your interface" << std::endl;
// header mapFile << "# Not all sections are complete. See comments for details." << std::endl;
mapFile << "NAME " << txtMapName->text() << std::endl; if(!chkExpLayersOnly->isChecked()){
mapFile << "STATUS ON" << std::endl; // header
mapFile << "\n# Map image size. Change size as desired" << std::endl; mapFile << "NAME " << txtMapName->text() << std::endl;
mapFile << "SIZE " << txtMapWidth->text() << " " << txtMapHeight->text() << std::endl; mapFile << "STATUS ON" << std::endl;
// web interface definition - this is minimal! mapFile << "\n# Map image size. Change size as desired" << std::endl;
mapFile << "#" << std::endl; mapFile << "SIZE " << txtMapWidth->text() << " " << txtMapHeight->text() << std::endl;
mapFile << "# Start of web interface definition. Only the TEMPLATE parameter" << std::endl; // web interface definition - this is minimal!
mapFile << "# must be specified to display a map. See Mapserver documentation" << std::endl; mapFile << "#" << std::endl;
mapFile << "#" << std::endl; mapFile << "# Start of web interface definition. Only the TEMPLATE parameter" << std::endl;
mapFile << "WEB" << std::endl; mapFile << "# must be specified to display a map. See Mapserver documentation" << std::endl;
// if no header is supplied, write the header line but comment it out mapFile << "#" << std::endl;
if(txtWebHeader->text().isEmpty()){ mapFile << "WEB" << std::endl;
mapFile << " # HEADER" << std::endl; // if no header is supplied, write the header line but comment it out
}else{ if(txtWebHeader->text().isEmpty()){
// header provided - write it mapFile << " # HEADER" << std::endl;
mapFile << " HEADER " << txtWebHeader->text() << std::endl; }else{
} // header provided - write it
// if no template provided, write the template line but comment it out mapFile << " HEADER " << txtWebHeader->text() << std::endl;
if(txtWebTemplate->text().isEmpty()){ }
mapFile << " # TEMPLATE" << std::endl; // if no template provided, write the template line but comment it out
}else{ if(txtWebTemplate->text().isEmpty()){
// template provided - write it mapFile << " # TEMPLATE" << std::endl;
mapFile << " TEMPLATE " << txtWebTemplate->text() << std::endl; }else{
} // template provided - write it
// if no footer provided, write the footer line but comment it out mapFile << " TEMPLATE " << txtWebTemplate->text() << std::endl;
if(txtWebFooter->text().isEmpty()){ }
mapFile << " # FOOTER" << std::endl; // if no footer provided, write the footer line but comment it out
}else{ if(txtWebFooter->text().isEmpty()){
mapFile << " FOOTER " << txtWebFooter->text() << std::endl; mapFile << " # FOOTER" << std::endl;
} }else{
// write min and maxscale mapFile << " FOOTER " << txtWebFooter->text() << std::endl;
mapFile << " MINSCALE " << txtMinScale->text() << std::endl; }
mapFile << " MAXSCALE " << txtMaxScale->text() << std::endl; // write min and maxscale
// end of web section mapFile << " MINSCALE " << txtMinScale->text() << std::endl;
mapFile << "END" << std::endl; mapFile << " MAXSCALE " << txtMaxScale->text() << std::endl;
// end of web section
// extent mapFile << "END" << std::endl;
mapFile << "\n# Extent based on full extent of QGIS view" << std::endl;
mapFile << "EXTENT "; // extent
QgsRect extent = map->extent(); mapFile << "\n# Extent based on full extent of QGIS view" << std::endl;
mapFile << extent.xMin() << " " << extent.yMin() << " "; mapFile << "EXTENT ";
mapFile << extent.xMax() << " " << extent.yMax() << std::endl; QgsRect extent = map->extent();
// units mapFile << extent.xMin() << " " << extent.yMin() << " ";
mapFile << "UNITS " << cmbMapUnits->currentText() << std::endl; mapFile << extent.xMax() << " " << extent.yMax() << std::endl;
// image info // units
mapFile << "IMAGECOLOR 255 255 255" << std::endl; mapFile << "UNITS " << cmbMapUnits->currentText() << std::endl;
mapFile << "IMAGETYPE " << cmbMapImageType->currentText() << std::endl; // image info
// projection information TODO: support projections :) mapFile << "IMAGECOLOR 255 255 255" << std::endl;
mapFile << "# Projection definition" << std::endl; mapFile << "IMAGETYPE " << cmbMapImageType->currentText() << std::endl;
mapFile << "# Projections are not currenlty supported. If desired, add your own" << std::endl; // projection information TODO: support projections :)
mapFile << "# projection information based on Mapserver documentation." << std::endl; mapFile << "# Projection definition" << std::endl;
mapFile << "#" << std::endl; mapFile << "# Projections are not currenlty supported. If desired, add your own" << std::endl;
mapFile << "# projection information based on Mapserver documentation." << std::endl;
}else{ mapFile << "#" << std::endl;
mapFile << " # This file contains layer definitions only and is not a complete" << std::endl;
mapFile << " # Mapserver map file." << std::endl; }
} else
{
// write layer definitions mapFile << " # This file contains layer definitions only and is not a complete" << std::endl;
for(int i = 0; i < map->layerCount(); i++){ mapFile << " # Mapserver map file." << std::endl;
bool isPolygon =false; }
bool isLine = false;
QgsMapLayer *lyr = map->getZpos(i); // write layer definitions
mapFile << "LAYER" << std::endl; for(int i = 0; i < map->layerCount(); i++)
QString name = lyr->name().lower(); {
// MapServer NAME must be < 20 char and unique bool isPolygon =false;
name.replace(QRegExp(" "),"_"); bool isLine = false;
name.replace(QRegExp("\\."),"_"); QgsMapLayer *lyr = map->getZpos(i);
name.replace(QRegExp("\\("), "_"); #ifdef DEBUG
name.replace(QRegExp("\\)"), "_"); std::cout << "Mapsrver Export Processing Layer" << std::endl;
mapFile << " NAME " << name << std::endl; #endif
// feature type mapFile << "LAYER" << std::endl;
mapFile << " TYPE "; QString name = lyr->name().lower();
switch (lyr->featureType()) { // MapServer NAME must be < 20 char and unique
case QGis::WKBPoint: name.replace(QRegExp(" "),"_");
case QGis::WKBMultiPoint: name.replace(QRegExp("\\."),"_");
mapFile << "POINT"; name.replace(QRegExp("\\("), "_");
break; name.replace(QRegExp("\\)"), "_");
case QGis::WKBLineString: mapFile << " NAME " << name << std::endl;
case QGis::WKBMultiLineString: // feature type
mapFile << "LINE"; #ifdef DEBUG
isLine = true; std::cout << "\tMapsrver Export checking feature type" << std::endl;
break; #endif
case QGis::WKBPolygon: mapFile << " TYPE ";
case QGis::WKBMultiPolygon: switch (lyr->featureType()) {
mapFile << "POLYGON"; case QGis::WKBPoint:
isPolygon = true; case QGis::WKBMultiPoint:
break; mapFile << "POINT";
} break;
mapFile << std::endl; case QGis::WKBLineString:
case QGis::WKBMultiLineString:
// set visibility (STATUS) mapFile << "LINE";
mapFile << " STATUS "; isLine = true;
if(lyr->visible()){ break;
mapFile << "ON"; case QGis::WKBPolygon:
}else{ case QGis::WKBMultiPolygon:
mapFile << "OFF"; mapFile << "POLYGON";
} isPolygon = true;
mapFile << std::endl; break;
}
// data source (DATA) mapFile << std::endl;
// Data source spec depends on layer type
switch(lyr->type()){ #ifdef DEBUG
case QgsMapLayer::VECTOR: std::cout << "\tMapsrver Export checking visibility" << std::endl;
mapFile << " DATA " << lyr->source() << std::endl; #endif
break; // set visibility (STATUS)
//TODO FIX THIS TO DEAL WITH EXPORT USING QgsVectorLayer objects mapFile << " STATUS ";
/* #ifdef POSTGRESQL if(lyr->visible()){
case QgsMapLayer::DATABASE: mapFile << "ON";
QgsDatabaseLayer *dblyr = (QgsDatabaseLayer *)lyr; }else{
mapFile << " CONNECTION \"" << lyr->source() << "\"" mapFile << "OFF";
<< std::endl; }
mapFile << " CONNECTIONTYPE postgis" << std::endl; mapFile << std::endl;
mapFile << " DATA \"" << dblyr->geometryColumnName() <<
" from " << dblyr->geometryTableName() << "\"" // data source (DATA)
<< std::endl; // Data source spec depends on layer type
break; #ifdef DEBUG
std::cout << "\tMapsrver Export checking layer type" << std::endl;
#endif
switch(lyr->type()){
case QgsMapLayer::VECTOR:
mapFile << " DATA " << lyr->source() << std::endl;
break;
//TODO FIX THIS TO DEAL WITH EXPORT USING QgsVectorLayer objects
/* #ifdef POSTGRESQL
case QgsMapLayer::DATABASE:
QgsDatabaseLayer *dblyr = (QgsDatabaseLayer *)lyr;
mapFile << " CONNECTION \"" << lyr->source() << "\""
<< std::endl;
mapFile << " CONNECTIONTYPE postgis" << std::endl;
mapFile << " DATA \"" << dblyr->geometryColumnName() <<
" from " << dblyr->geometryTableName() << "\""
<< std::endl;
break;
#endif */ #endif */
} }
// create a simple class entry based on layer color #ifdef DEBUG
QgsSymbol *sym = lyr->symbol(); std::cout << "\tMapsrver Export creating symbol entries" << std::endl;
mapFile << " CLASS" << std::endl; #endif
QgsLegend *lgd = map->getLegend(); // create a simple class entry based on layer color
//QListViewItem *li = lgd->currentItem(); QgsSymbol *sym = lyr->symbol();
// return li->text(0); mapFile << " CLASS" << std::endl;
mapFile << " NAME \"" << lyr->name() << "\"" << std::endl; QgsLegend *lgd = map->getLegend();
mapFile << " # TEMPLATE" << std::endl; //QListViewItem *li = lgd->currentItem();
QColor fillColor = sym->fillColor(); // return li->text(0);
if(!isLine){ #ifdef DEBUG
mapFile << " COLOR " << fillColor.red() << " " << std::cout << "\tMapsrver Export symbol name" << std::endl;
fillColor.green() << " " << fillColor.blue() << std::endl; #endif
} mapFile << " NAME \"" << lyr->name() << "\"" << std::endl;
if(isPolygon || isLine){ mapFile << " # TEMPLATE" << std::endl;
QColor outlineColor = sym->color(); if(isPolygon)
mapFile << " OUTLINECOLOR " << outlineColor.red() << " " {
<< outlineColor.green() << " " << outlineColor.blue() #ifdef DEBUG
<< std::endl; std::cout << "\tMapsrver Export symbol fill color" << std::endl;
} #endif
mapFile << " END" << std::endl; QColor fillColor = sym->fillColor();
mapFile << "END" << std::endl; mapFile << " COLOR " << fillColor.red() << " " <<
} fillColor.green() << " " << fillColor.blue() << std::endl;
if(!chkExpLayersOnly->isChecked()){ }
mapFile << "END # Map File"; #ifdef DEBUG
} std::cout << "\tMapsrver Export checking for line symbol " << std::endl;
mapFile.close(); #endif
}else{ if(isPolygon || isLine){
} QColor outlineColor = sym->color();
mapFile << " OUTLINECOLOR " << outlineColor.red() << " "
<< outlineColor.green() << " " << outlineColor.blue()
<< std::endl;
}
mapFile << " END" << std::endl;
mapFile << "END" << std::endl;
#ifdef DEBUG
std::cout << "\tMapsrver Export layer definition done..." << std::endl;
#endif
}
if(!chkExpLayersOnly->isChecked()){
mapFile << "END # Map File";
}
mapFile.close();
}else{
}
} }
void QgsMapserverExport::showHelp(){ void QgsMapserverExport::showHelp(){
//QMessageBox::information(this, "Help","Help"); //QMessageBox::information(this, "Help","Help");
QgsHelpViewer *hv = new QgsHelpViewer(this); QgsHelpViewer *hv = new QgsHelpViewer(this);
// causes problems in qt3.1.x: hv->setModal(false); // causes problems in qt3.1.x: hv->setModal(false);
hv->setCaption("QGIS Help - Mapserver Export"); hv->setCaption("QGIS Help - Mapserver Export");
hv->show(); hv->show();
} }