void TestQgsProject::testProjectUnits() { //test setting and retrieving project units // DISTANCE //first set a default QGIS distance unit QSettings s; s.setValue( "/qgis/measure/displayunits", QgsUnitTypes::encodeUnit( QGis::Feet ) ); QgsProject* prj = QgsProject::instance(); // new project should inherit QGIS default distance unit prj->clear(); QCOMPARE( prj->distanceUnits(), QGis::Feet ); //changing default QGIS unit should not affect existing project s.setValue( "/qgis/measure/displayunits", QgsUnitTypes::encodeUnit( QGis::NauticalMiles ) ); QCOMPARE( prj->distanceUnits(), QGis::Feet ); //test setting new units for project prj->writeEntry( "Measurement", "/DistanceUnits", QgsUnitTypes::encodeUnit( QGis::NauticalMiles ) ); QCOMPARE( prj->distanceUnits(), QGis::NauticalMiles ); // AREA //first set a default QGIS area unit s.setValue( "/qgis/measure/areaunits", QgsUnitTypes::encodeUnit( QgsUnitTypes::SquareYards ) ); // new project should inherit QGIS default area unit prj->clear(); QCOMPARE( prj->areaUnits(), QgsUnitTypes::SquareYards ); //changing default QGIS unit should not affect existing project s.setValue( "/qgis/measure/areaunits", QgsUnitTypes::encodeUnit( QgsUnitTypes::Acres ) ); QCOMPARE( prj->areaUnits(), QgsUnitTypes::SquareYards ); //test setting new units for project prj->writeEntry( "Measurement", "/AreaUnits", QgsUnitTypes::encodeUnit( QgsUnitTypes::Acres ) ); QCOMPARE( prj->areaUnits(), QgsUnitTypes::Acres ); }
QString QgsServerProjectUtils::wcsServiceUrl( const QgsProject &project ) { return project.readEntry( QStringLiteral( "WCSUrl" ), QStringLiteral( "/" ), "" ); }
QString QgsServerProjectUtils::owsServiceOnlineResource( const QgsProject &project ) { return project.readEntry( QStringLiteral( "WMSOnlineResource" ), QStringLiteral( "/" ) ); }
QStringList QgsServerProjectUtils::wmsRestrictedLayers( const QgsProject &project ) { return project.readListEntry( QStringLiteral( "WMSRestrictedLayers" ), QStringLiteral( "/" ), QStringList() ); }
int QgsServerProjectUtils::wfsLayerPrecision( const QgsProject &project, const QString &layerId ) { return project.readNumEntry( QStringLiteral( "WFSLayersPrecision" ), "/" + layerId, 6 ); }
QString QgsServerProjectUtils::wmsInspireLanguage( const QgsProject &project ) { return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/language" ) ); }
QString QgsServerProjectUtils::wmsInspireMetadataDate( const QgsProject &project ) { return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/metadataDate" ) ); }
void GeolFile::on_pushButtonRun_clicked() { QgsProject *p = QgsProject::instance(); QString projDir = p->readPath(p->readEntry("pihm", "projDir")); p->writeEntry("pihm", "geol", p->writePath(ui->lineEditGeolTexture->text())); // 89 p->writeEntry("pihm", "/model/geol", p->writePath(ui->lineEditGeolFile->text())); // 90 int RunFlag=1; ifstream inFile; ofstream outFile; inFile.open((ui->lineEditGeolTexture->text()).toAscii()); outFile.open((ui->lineEditGeolFile->text()).toAscii()); ofstream logFile; QDir dir = QDir::home(); QString home = dir.homePath(); QString logFileName(home+"/log.html"); logFile.open(qPrintable(logFileName)); logFile<<"<html><body><font size=3 color=black> Verifying Files...<br>"; logFile.close(); ui->textBrowser->setSource(logFileName); ui->textBrowser->setFocus(); ui->textBrowser->setModified(TRUE); logFile.open(qPrintable(logFileName), ios::app); logFile<<"Checking Geol Texture File... "; if (inFile == NULL) { logFile<<"could NOT open file. ERROR<br>"; RunFlag = 0; } else logFile<<"Done!<br>"; logFile<<"Checking .Geol File... "; if (outFile == NULL) { logFile<<"could NOT open file to write. ERROR<br>"; RunFlag = 0; } else logFile<<"Done!<br>"; logFile.close(); ui->textBrowser->reload(); if(RunFlag == 1) { logFile.open(qPrintable(logFileName), ios::app); logFile<<"Generating .GEOL file... "; char tempS[500]; int count=0; double data[1000][6]; // (1) MUKEY (2) SILT (3) CLAY (4) ORGANIC_MATTER (5) BULK_DENSITY //<(6) TOPSOIL> //inFile>>tempS; inFile>>tempS; inFile>>tempS; inFile>>tempS; inFile>>tempS; //<inFile>>tempS;> inFile.getline(tempS, 500); while(inFile) { inFile>>data[count][0]; //MUKEY inFile>>data[count][1]; //SILT inFile>>data[count][2]; //CLAY inFile>>data[count][3]; if(data[count][3]<0) data[count][3]=2.5; //ORGANIC MATTER inFile>>data[count][4]; if(data[count][4]<0) data[count][4]=1.3; // BULK DENSITY (g/cm3) //inFile>>data[count][5]; // TOP SOIL data[count][5] = 0; // Forced for GEOL i.e. TOPSOIL = 0 //? outFile<<"-$ "<<data[count][0]<<"\t"<<data[count][1]<<"\t"<<data[count][2]<<"\t"<<data[count][3]<<"\t"<<data[count][4]<<"\t"<<data[count][5]<<" $- \n"; count++; } count--; outFile<<count<<"\n"; double S, C, OM, D; //S=SILT, C=CLAY, OM=ORGANIC MATTER, D=BULK DENSITY, int topsoil; //TOPSOIL double **outData; outData = (double **)malloc(count*sizeof(double *)); for(int i=0; i<count; i++) { outData[i] = (double *)malloc(10*sizeof(double)); for(int j=0; j<10; j++) outData[i][j]=0.0; S = data[i][1]; C = data[i][2]; OM = data[i][3]; D = data[i][4]; topsoil = (int) data[i][5]; //Index outData[i][0]=i+1; outFile<<outData[i][0]<<"\t"; //Ksat //outData[i][1]= (7.755+0.03252*S+0.93*topsoil-0.967*D*D-0.000484*C*C-0.000322*S*S+0.001/S-0.0748/OM-0.643*log(S)-0.01398*D*C-0.1673*D*OM+0.02986*topsoil*C-0.03305*topsoil*S); outData[i][1]=exp(7.755+0.03252*S+0.93*topsoil-0.967*D*D-0.000484*C*C-0.000322*S*S+0.001/S-0.0748/OM-0.643*log(S)-0.01398*D*C-0.1673*D*OM+0.02986*topsoil*C-0.03305*topsoil*S); outData[i][1]=outData[i][1]/100; //[cm per d] to [m per d] outFile<<outData[i][1]*10<<"\t"; //KsatH = KsatV * 10 //Ksat outFile<<outData[i][1]<<"\t"; //KsatV //ThetaS //outData[i][2]=(0.7919+0.001691*C-0.29619*D-0.000001491*S*S+0.0000821*OM*OM+0.02427/C+0.01113/S+0.01472*log(S)-0.0000733*OM*C-0.000619*D*C-0.001183*D*OM-0.0001664*topsoil*S); outData[i][2]= (0.7919+0.001691*C-0.29619*D-0.000001491*S*S+0.0000821*OM*OM+0.02427/C+0.01113/S+0.01472*log(S)-0.0000733*OM*C-0.000619*D*C-0.001183*D*OM-0.0001664*topsoil*S); outFile<<outData[i][2]<<"\t"; //ThetaR outData[i][3]=0.01; outFile<<outData[i][3]<<"\t"; //InfD //outData[i][4]=0.10; //outFile<<outData[i][4]<<"\t"; //Alpha //outData[i][5]=log(-14.96+0.03135*C+0.0351*S+0.646*OM+15.29*D-0.192*topsoil-4.671*D*D-0.000781*C*C-0.00687*OM*OM+0.0449/OM+0.0663*log(S)+0.1482*log(OM)-0.04546*D*S-0.4852*D*OM+0.00673*topsoil*C); outData[i][5]= exp(-14.96+0.03135*C+0.0351*S+0.646*OM+15.29*D-0.192*topsoil-4.671*D*D-0.000781*C*C-0.00687*OM*OM+0.0449/OM+0.0663*log(S)+0.1482*log(OM)-0.04546*D*S-0.4852*D*OM+0.00673*topsoil*C); outData[i][5]= 100*outData[i][5]; //UNIT CONVERSION 1/cm TO 1/m outFile<<outData[i][5]<<"\t"; //Beta outData[i][6]=1+exp(-25.23-0.02195*C+0.0074*S-0.1940*OM+45.5*D-7.24*D*D+0.0003658*C*C+0.002885*OM*OM-12.81/D-0.1524/S-0.01958/OM-0.2876*log(S)-0.0709*log(OM)-44.6*log(D)-0.02264*D*C+0.0896*D*OM+0.00718*topsoil*C); outFile<<outData[i][6]<<"\t"; //hAreaF outData[i][7]=0.01; outFile<<outData[i][7]<<"\t"; //macKsatV outData[i][8]=100000*outData[i][1]; outFile<<outData[i][8]<<"\t"; //macD outData[i][9]=1.0; outFile<<outData[i][9]<<"\n"; } logFile<<"Done!<br>"; logFile<<"GeolFile Module - COMPLETE"; logFile.close(); ui->textBrowser->reload(); QApplication::processEvents(); }
void TestQgsProject::testPathResolverSvg() { QString dataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt QString layerPath = dataDir + "/points.shp"; QVERIFY( QgsSymbolLayerUtils::svgSymbolNameToPath( QString(), QgsPathResolver() ).isEmpty() ); QVERIFY( QgsSymbolLayerUtils::svgSymbolPathToName( QString(), QgsPathResolver() ).isEmpty() ); // build a project with 3 layers, each having a simple renderer with SVG marker // - existing SVG file in project dir // - existing SVG file in QGIS dir // - non-exsiting SVG file QTemporaryDir dir; QVERIFY( dir.isValid() ); // on mac the returned path was not canonical and the resolver failed to convert paths properly QString dirPath = QFileInfo( dir.path() ).canonicalFilePath(); QString projectFilename = dirPath + "/project.qgs"; QString ourSvgPath = dirPath + "/valid.svg"; QString invalidSvgPath = dirPath + "/invalid.svg"; QFile svgFile( ourSvgPath ); QVERIFY( svgFile.open( QIODevice::WriteOnly ) ); svgFile.write( "<svg/>" ); // not a proper SVG, but good enough for this case svgFile.close(); QVERIFY( QFileInfo::exists( ourSvgPath ) ); // should exist now QString librarySvgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( QStringLiteral( "transport/transport_airport.svg" ), QgsPathResolver() ); QCOMPARE( QgsSymbolLayerUtils::svgSymbolPathToName( librarySvgPath, QgsPathResolver() ), QStringLiteral( "transport/transport_airport.svg" ) ); QgsVectorLayer *layer1 = new QgsVectorLayer( layerPath, QStringLiteral( "points 1" ), QStringLiteral( "ogr" ) ); _useRendererWithSvgSymbol( layer1, ourSvgPath ); QgsVectorLayer *layer2 = new QgsVectorLayer( layerPath, QStringLiteral( "points 2" ), QStringLiteral( "ogr" ) ); _useRendererWithSvgSymbol( layer2, invalidSvgPath ); QgsVectorLayer *layer3 = new QgsVectorLayer( layerPath, QStringLiteral( "points 3" ), QStringLiteral( "ogr" ) ); _useRendererWithSvgSymbol( layer3, librarySvgPath ); QVERIFY( layer1->isValid() ); QgsProject project; project.addMapLayers( QList<QgsMapLayer *>() << layer1 << layer2 << layer3 ); project.write( projectFilename ); // make sure the path resolver works with relative paths (enabled by default) QCOMPARE( project.pathResolver().readPath( "./a.txt" ), dirPath + "/a.txt" ); QCOMPARE( project.pathResolver().writePath( dirPath + "/a.txt" ), QString( "./a.txt" ) ); // check that the saved paths are relative // key = layer name, value = svg path QHash<QString, QString> projectFileSvgPaths = _parseSvgPathsForLayers( projectFilename ); QCOMPARE( projectFileSvgPaths.count(), 3 ); QCOMPARE( projectFileSvgPaths["points 1"], QString( "./valid.svg" ) ); // relative path to project QCOMPARE( projectFileSvgPaths["points 2"], invalidSvgPath ); // full path to non-existent file (not sure why - but that's how it works now) QCOMPARE( projectFileSvgPaths["points 3"], QString( "transport/transport_airport.svg" ) ); // relative path to library // load project again, check that the paths are absolute QgsProject projectLoaded; projectLoaded.read( projectFilename ); QString svg1 = _getLayerSvgMarkerPath( projectLoaded, QStringLiteral( "points 1" ) ); QString svg2 = _getLayerSvgMarkerPath( projectLoaded, QStringLiteral( "points 2" ) ); QString svg3 = _getLayerSvgMarkerPath( projectLoaded, QStringLiteral( "points 3" ) ); QCOMPARE( svg1, ourSvgPath ); QCOMPARE( svg2, invalidSvgPath ); QCOMPARE( svg3, librarySvgPath ); // // now let's use these layers in embedded in another project... // QList<QDomNode> brokenNodes; QgsProject projectMaster; QVERIFY( projectMaster.createEmbeddedLayer( layer1->id(), projectFilename, brokenNodes ) ); QVERIFY( projectMaster.createEmbeddedLayer( layer2->id(), projectFilename, brokenNodes ) ); QVERIFY( projectMaster.createEmbeddedLayer( layer3->id(), projectFilename, brokenNodes ) ); QString svg1x = _getLayerSvgMarkerPath( projectMaster, QStringLiteral( "points 1" ) ); QString svg2x = _getLayerSvgMarkerPath( projectLoaded, QStringLiteral( "points 2" ) ); QString svg3x = _getLayerSvgMarkerPath( projectLoaded, QStringLiteral( "points 3" ) ); QCOMPARE( svg1x, ourSvgPath ); QCOMPARE( svg2x, invalidSvgPath ); QCOMPARE( svg3x, librarySvgPath ); }
spatialPlotDlg::spatialPlotDlg(QDialog *parent) { setupUi(this); connect( pushButtonEleShape, SIGNAL( clicked() ), this, SLOT( browseEleShapeFile() ) ); connect( pushButtonRivShape, SIGNAL( clicked() ), this, SLOT( browseRivShapeFile() ) ); connect( pushButtonFileName, SIGNAL( clicked() ), this, SLOT( browseModelFile() ) ); connect( pushButtonGenerate, SIGNAL( clicked() ), this, SLOT( generate() ) ); connect( pushButtonHelp, SIGNAL( clicked() ), this, SLOT( help() ) ); QgsProject *p = QgsProject::instance(); QString projDir = p->readPath(p->readEntry("pihm", "projDir")); int scale = p->readNumEntry("pihm", "scale"); // 110 int step = p->readNumEntry("pihm", "step5"); // 106 comboBoxEle->setCurrentIndex(scale); comboBoxRiv->setCurrentIndex(scale); step= scale==0 ? step : scale==1 ? step/60 : step/1440; //lineEditEleTime->setText(QString::number(step, 10)); step=p->readNumEntry("pihm", "step8"); // 109 step= scale==0 ? step : scale==1 ? step/60 : step/1440; //lineEditRivTime->setText(QString::number(step,10)); lineEditEleShape->setText(p->readPath(p->readEntry("pihm", "TIN"))); // 48 lineEditRivShape->setText(p->readPath(p->readEntry("pihm", "rivdec"))); // 81 int start, finish; start = p->readNumEntry("pihm", "start"); // 111 finish= p->readNumEntry("pihm", "finish"); // 112 start = scale==0 ? start : scale==1 ? start/60 : start/1440; start = start +1; finish= scale==0 ? finish : scale==1 ? finish/60 : finish/1440; lineEditEleStart->setText(QString::number(start,10)); lineEditEleFinish->setText(QString::number(finish,10)); lineEditRivStart->setText(QString::number(start,10)); lineEditRivFinish->setText(QString::number(finish,10)); }
void spatialPlotDlg::generate() { QDir dir = QDir::home(); QString home = dir.homePath(); QString logFileName(home+"/log.html"); ofstream log; log.open(qPrintable(logFileName), ios::out); log<<"<html><body><br><font size=3 color=black><p> Running... "; //</p></font></body></html>"; log.close(); textBrowser->setSource(logFileName); textBrowser->setFocus(); textBrowser->setModified(TRUE); QApplication::processEvents(); QgsProject *p = QgsProject::instance(); QString projDir = p->readPath(p->readEntry("pihm", "projDir")); int bins; double **avgVal; int tabIndex; int variableIndex; int startTime, finishTime; int NUM_STEPS; int dataCount = 0; char fStr[100]; int runFlag = 1; QString shapeFileName, outputFileName; ifstream inStream, inStream2; int NUM_ELE = 0; int NUM_RIV = 0; tabIndex = tabWidget->currentIndex(); if(tabIndex == ELEMENT_FEATURE) { variableIndex = comboBoxEleVariable->currentIndex(); startTime = ( lineEditEleStart->text() ).toInt(); finishTime = ( lineEditEleFinish->text() ).toInt(); bins = lineEditBinsEle->text().toInt(); int units = comboBoxEle->currentIndex(); units = units==0 ? 1 : units==1 ? 60 : 1440; // how many minutes // intercep, sat, unsat, surf, evap, trans, evap gw/sw, prep ??, nprep ??, infil ??, rech // 106, 101, 107, 102, 108, 108, 108, 101, 101, 101, 105 const int index[] = {5, 0, 6, 1, 7, 7, 7, 0, 0, 0, 4}; QString var("step%1"); int steps = p->readNumEntry("pihm", var.arg(index[comboBoxEleVariable->currentIndex()])); startTime = startTime*units / steps; cout << "Start Row= "<<startTime<<"\n"; finishTime= finishTime*units/ steps; cout << "FinishRow= "<<finishTime<<"\n"; shapeFileName = lineEditEleShape->text(); outputFileName = lineEditFileName->text(); NUM_STEPS = finishTime - startTime + 1; cout<<"NUM_STEPS= "<<NUM_STEPS<<"\n"; //getchar(); getchar(); if( outputFileName.endsWith("txt", Qt::CaseInsensitive) ) { inStream.open( qPrintable(outputFileName) ); if(inStream == NULL) { QMessageBox::critical(this, "Couldn't Open File", outputFileName); return; //exit(1); } string str; getline(inStream, str); int pos = 0; while( (pos = str.find('\t', pos+1) ) != -1 ) { NUM_ELE++; } cout << "NUM_ELE= "<<NUM_ELE<<"\n"; inStream.close(); inStream.open(qPrintable(outputFileName)); avgVal = (double **)malloc(bins * sizeof(double *)); for(int i=0; i<bins; i++) { avgVal[i] = (double *)malloc(NUM_ELE * sizeof(double)); for(int j=0; j<NUM_ELE; j++) avgVal[i][j] = 0.0; } for(int i=1; i<startTime; i++) getline(inStream, str); if(inStream == NULL) { qWarning("Error: File ended Prematurely!\n Cannot parse \"Start Time\" provided.\n"); runFlag = 0; } if(runFlag != 0) { double temp; for(int b=0; b<bins; b++) { for(int i=0; i<NUM_STEPS/bins; i++) { if(inStream) { for(int j=0; j<NUM_ELE; j++) { inStream >> temp; avgVal[b][j]+=temp; } dataCount++; } else{ dataCount--; break; } } }
void PIHMgis::runImportProject(){ QString projFile = QFileDialog::getOpenFileName(NULL, "Choose pihmgis project file to import", QString::null, "PIHM GIS project (*.pihmgis)"); if (!projFile.isEmpty()) { typedef enum {Skip, Vector, Raster, Path, String, Int, Double} What; typedef struct { What what; const char* prop; } Action; Action lines[] = { //{Skip, "/model/mesh" }; // Excel semi-generated {Skip, NULL}, // date { Skip, "projDir"}, // line 2, { Raster, "dem" }, // line 3, source DEM { Raster, "fill" }, // line 4, sink filled DEM { Skip, "fill" }, // line 5, { Raster, "fdr" }, // line 6, { Raster, "fac" }, // line 7, { Skip, "fac" }, // line 8, See 7 { Raster, "strgrid" }, // line 9, Streams raster { Int, "facThreshold" }, // line 10, Threshold for stream acc { Skip, "strgrid" }, // line 11, See 9 { Skip, "fdr" }, // line 12, See 6 { Raster, "lnk" }, // line 13, { Skip, "strgrid" }, // line 14, See 11 { Skip, "fdr" }, // line 15, See 6 { Vector, "strline" }, // line 16, Streams shapefile { Skip, "lnk" }, // line 17, { Skip, "fdr" }, // line 18, { Raster, "catgrid" }, // line 19, { Skip, "catgrid" }, // line 20, { Vector, "catpoly" }, // line 21, { Skip, "catpoly" }, // line 22, See 21 { Vector, "catdiss" }, // line 23, { Skip, "catdiss" }, // line 24, See 23 { Vector, "catline" }, // line 25, { Skip, "catline" }, // line 26, { Vector, "catsimple" }, // line 27, { Double, "cattol" }, // line 28, line simplification tolerance for diss polylines? { Vector, "strline" }, // line 29, { Vector, "strsimple" }, // line 30, { Double, "strtol" }, // line 31, line simplification tolerance for streams? { Skip, "catsimple" }, // line 32, { Vector, "catsplit" }, // line 33, { Skip, "strsimple" }, // line 34, { Vector, "strsplit" }, // line 35, { Skip, "catsplit" }, // line 36, See 33 { Skip, "strsplit" }, // line 37, See 35 { Vector, "merge" }, // line 38, { Skip, "merge" }, // line 39, { Skip, "merge" }, // line 40, { Path, "pslg" }, // line 41, Planar Straight Line Graph { Skip, "pslg" }, // line 42, { Double, "triangle/angle" }, // line 43, triangulation parameter { Double, "triangle/area" }, // line 44, triangulation parameter { String, "triangle/other" }, // line 45, triangulation parameter { Path, "ele" }, // line 46, { Path, "node" }, // line 47, { Vector, "TIN" }, // line 48, TIN/ele shp file { Path, "/model/mesh" }, // line 49, { String, "ID" }, // line 50, file ID { Skip, NULL }, // line 51, { Skip, NULL }, // line 52, { Skip, NULL }, // line 53, { Path, "Precip" }, // line 54, { Path, "Temp" }, // line 55, { Path, "Humid" }, // line 56, { Path, "Wind" }, // line 57, { Path, "G" }, // line 58, { Path, "Rn" }, // line 59, { Path, "P" }, // line 60, { Path, "Soil" }, // line 61, { Path, "Geol" }, // line 62, { Path, "LC" }, // line 63, { Path, "MF" }, // line 64, { Path, "MP" }, // line 65, { Path, "ISIC" }, // line 66, { Path, "SnowIC" }, // line 67, { Path, "OverlandIC" }, // line 68, { Path, "UnSatIC" }, // line 69, { Path, "SatIC" }, // line 70, { Path, "BC" }, // line 71, { Path, "Source" }, // line 72, { Skip, NULL }, // line 73, { Path, "/model/att" }, // line 74, { Skip, "strsplit" }, // line 75, input stream { Skip, "ele" }, // line 76, { Skip, "node" }, // line 77, { Path, "neigh" }, // line 78, { Skip, NULL }, // line 79, { Path, "/model/riv" }, // line 80, .riv file { Path, "rivdec" }, // line 81, For spatial plots { Path, "/model/para" }, // line 82, { Skip, NULL }, // line 83, { Skip, NULL }, // line 84, { Skip, NULL }, // line 85, { Skip, NULL }, // line 86, { Path, "soil" }, // line 87, in { Path, "/model/soil" }, // line 88, out { Path, "geol" }, // line 89, in { Path, "/model/geol" }, // line 90, out { Path, "nlcd" }, // line 91, NLCD source? { Path, "/model/lc" }, // line 92, { Path, "/model/calib" }, // line 93, { Path, "/model/init" }, // line 94, { Skip, NULL }, // line 95, { Skip, NULL }, // line 96, { Skip, NULL }, // line 97, { Skip, NULL }, // line 98, { Skip, NULL }, // line 99, { Double, "res" }, // line 100, DEM resolution { Double, "step0" }, // line 101, prep steps, adjustments { Double, "step1" }, // line 102, { Double, "step2" }, // line 103, { Double, "step3" }, // line 104, { Double, "step4" }, // line 105, { Double, "step5" }, // line 106, { Double, "step6" }, // line 107, { Double, "step7" }, // line 108, { Double, "step8" }, // line 109, adjustments { Double, "scale" }, // line 110, { Double, "start" }, // line 111, from .para file { Double, "finish" }, // line 112, from .para file { Skip, NULL }, // line 113, { Skip, NULL }, // line 114, { Skip, NULL }, // line 115, { Skip, NULL }, // line 116, { Skip, NULL }, // line 117, { Skip, NULL }, // line 118, { Skip, NULL }, // line 119, { Skip, NULL }, // line 120, { Skip, NULL }, // line 121, }; int lines_size = sizeof(lines)/sizeof(lines[0]); QFile file(projFile); if (file.open(QFile::ReadOnly)) { QTextStream in(&file); in.readLine(); // date QString oldDir = in.readLine(); QRegExp rx("[\\/]"); // file could have been created on other platform, can't rely on QFileInfo qDebug("oldDir = %s", qPrintable(oldDir)); oldDir = oldDir.left(oldDir.lastIndexOf(rx)); int oldDirLength = oldDir.length(); qDebug("oldDir = %s, oldDirLength = %d", qPrintable(oldDir), oldDirLength); QFileInfo fi(projFile); QString projDir = fi.absoluteDir().absPath(); qDebug("new projDir is %s", qPrintable(projDir)); QgsProject *p = QgsProject::instance(); QString s = projFile.left(projFile.length() - 7) + "qgs"; p->setFileName(s); // instead of pihmgis p->writeEntry("Paths", "/Absolute", false); p->writeEntry("pihm", "projDir", QString(".")); bool ok; double d; int i; for( int idx=2; idx<lines_size && !in.atEnd(); ++idx) { s = in.readLine(); switch (lines[idx].what) { case Int: i = s.toInt(&ok); if (ok) p->writeEntry("pihm", lines[idx].prop, i); break; case Double: d = s.toDouble(&ok); if (ok) p->writeEntry("pihm", lines[idx].prop, d); break; case Path: { qDebug("Path Was %s", qPrintable(s)); s = ".." + s.mid(oldDirLength); qDebug("Truncated version is %s", qPrintable(s)); QFileInfo fi(projDir, s); s = p->writePath(fi.canonicalFilePath()); qDebug("Became %s", qPrintable(s)); } // no break!! Don't move case String: p->writeEntry("pihm", lines[idx].prop, s); break; case Raster: { qDebug("Raster Was %s", qPrintable(s)); s = ".." + s.mid(oldDirLength); qDebug("Truncated version is %s", qPrintable(s)); QFileInfo fi(projDir, s); s = fi.canonicalFilePath(); qDebug("Became %s", qPrintable(s)); } p->writeEntry("pihm", lines[idx].prop, p->writePath(s)); mQGisIface->addRasterLayer(s); break; case Vector: { qDebug("Vector Was %s", qPrintable(s)); QFileInfo fi(projDir, ".." + s.mid(oldDirLength)); s = fi.canonicalFilePath(); qDebug("Became %s", qPrintable(s)); } p->writeEntry("pihm", lines[idx].prop, p->writePath(s)); mQGisIface->addVectorLayer(s, QString::null, "ogr"); break; } } } } }
void InitFile::on_pushButton_Run_clicked() { QgsProject *p = QgsProject::instance(); QString projDir = p->readPath(p->readEntry("pihm", "projDir")); p->writeEntry("pihm", "/model/init", p->writePath(ui->lineEditInitFile->text())); // 94 int RunFlag=1; ifstream inFileMesh, inFileRiv; ofstream outFile; inFileMesh.open((ui->lineEditMeshFile->text()).toAscii()); inFileRiv.open((ui->lineEditRivFile->text()).toAscii()); outFile.open((ui->lineEditInitFile->text()).toAscii()); ofstream logFile; QDir dir = QDir::home(); QString home = dir.homePath(); QString logFileName(home+"/log.html"); logFile.open(qPrintable(logFileName)); logFile<<"<html><body><font size=3 color=black> Verifying Files...<br>"; logFile.close(); ui->textBrowser->setSource(logFileName); ui->textBrowser->setFocus(); ui->textBrowser->setModified(TRUE); logFile.open(qPrintable(logFileName), ios::app); logFile<<"Checking Mesh File... "; if (inFileMesh == NULL) { logFile<<"could NOT open file. ERROR<br>"; RunFlag = 0; } else logFile<<"Done!<br>"; logFile<<"Checking Riv File... "; if (inFileRiv == NULL) { logFile<<"could NOT open file. ERROR<br>"; RunFlag = 0; } else logFile<<"Done!<br>"; logFile<<"Checking Init File... "; if (outFile == NULL) { logFile<<"could NOT open file to write. ERROR<br>"; RunFlag = 0; } else logFile<<"Done!<br>"; logFile.close(); ui->textBrowser->reload(); if(RunFlag == 1) { logFile.open(qPrintable(logFileName), ios::app); logFile<<"Generating INIT file... "; int NumEle, NumRiv; inFileMesh >> NumEle; inFileRiv >> NumRiv; for(int i=0; i<NumEle; i++) { outFile<<ui->interception->text().toFloat()<<"\t"; outFile<<ui->snow->text().toFloat()<<"\t"; outFile<<ui->surface->text().toFloat()<<"\t"; outFile<<ui->unsaturated->text().toFloat()<<"\t"; outFile<<ui->saturated->text().toFloat()<<"\n"; } for(int i=0; i<NumRiv; i++) { outFile<<ui->river->text().toFloat()<<"\t"; outFile<<ui->riverBed->text().toFloat()<<"\n"; } logFile<<"Done!<br>"; logFile<<"InitFile Module - COMPLETE"; logFile.close(); ui->textBrowser->reload(); QApplication::processEvents(); }
QString QgsAuxiliaryStorage::filenameForProject( const QgsProject &project ) { const QFileInfo info = project.fileInfo(); const QString path = info.path() + QDir::separator() + info.baseName(); return path + '.' + QgsAuxiliaryStorage::extension(); }
bool QgsServerProjectUtils::owsServiceCapabilities( const QgsProject &project ) { return project.readBoolEntry( QStringLiteral( "WMSServiceCapabilities" ), QStringLiteral( "/" ), false ); }
void TestQgsProject::testProjectUnits() { //test setting and retrieving project units // DISTANCE //first set a default QGIS distance unit QgsSettings s; s.setValue( QStringLiteral( "/qgis/measure/displayunits" ), QgsUnitTypes::encodeUnit( QgsUnitTypes::DistanceFeet ) ); QgsProject *prj = new QgsProject; // new project should inherit QGIS default distance unit prj->clear(); QCOMPARE( prj->distanceUnits(), QgsUnitTypes::DistanceFeet ); //changing default QGIS unit should not affect existing project s.setValue( QStringLiteral( "/qgis/measure/displayunits" ), QgsUnitTypes::encodeUnit( QgsUnitTypes::DistanceNauticalMiles ) ); QCOMPARE( prj->distanceUnits(), QgsUnitTypes::DistanceFeet ); //test setting new units for project prj->setDistanceUnits( QgsUnitTypes::DistanceNauticalMiles ); QCOMPARE( prj->distanceUnits(), QgsUnitTypes::DistanceNauticalMiles ); // AREA //first set a default QGIS area unit s.setValue( QStringLiteral( "/qgis/measure/areaunits" ), QgsUnitTypes::encodeUnit( QgsUnitTypes::AreaSquareYards ) ); // new project should inherit QGIS default area unit prj->clear(); QCOMPARE( prj->areaUnits(), QgsUnitTypes::AreaSquareYards ); //changing default QGIS unit should not affect existing project s.setValue( QStringLiteral( "/qgis/measure/areaunits" ), QgsUnitTypes::encodeUnit( QgsUnitTypes::AreaAcres ) ); QCOMPARE( prj->areaUnits(), QgsUnitTypes::AreaSquareYards ); //test setting new units for project prj->setAreaUnits( QgsUnitTypes::AreaAcres ); QCOMPARE( prj->areaUnits(), QgsUnitTypes::AreaAcres ); delete prj; }
bool QgsServerProjectUtils::wmsInspireActivate( const QgsProject &project ) { return project.readBoolEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/activated" ) ); }
void rulesDialog::addRule() { //sanity checks QString test = mRuleBox->currentText(); QString layer1 = mLayer1Box->currentText(); if ( layer1 == "No layer" ) return; QString layer2 = mLayer2Box->currentText(); if ( layer2 == "No layer" && mTestConfMap[test].useSecondLayer ) return; for ( int i = 0; i < mRulesTable->rowCount(); ++i ) { if ( mRulesTable->item( i, 0 )->text() == test && mRulesTable->item( i, 1 )->text() == layer1 && mRulesTable->item( i, 2 )->text() == layer2 ) { return; } } int row = mRulesTable->rowCount(); mRulesTable->insertRow( row ); QTableWidgetItem* newItem; newItem = new QTableWidgetItem( test ); mRulesTable->setItem( row, 0, newItem ); newItem = new QTableWidgetItem( layer1 ); mRulesTable->setItem( row, 1, newItem ); if ( mTestConfMap[test].useSecondLayer ) newItem = new QTableWidgetItem( layer2 ); else newItem = new QTableWidgetItem( "No layer" ); mRulesTable->setItem( row, 2, newItem ); if ( mTestConfMap[test].useTolerance ) newItem = new QTableWidgetItem( QString( "%1" ).arg( mToleranceBox->value() ) ); else newItem = new QTableWidgetItem( QString( "No tolerance" ) ); mRulesTable->setItem( row, 3, newItem ); QString layer1ID, layer2ID; // add layer ids to hidden columns // -1 for "No layer" string if ( mTestConfMap[test].useSecondLayer ) layer2ID = mLayer2Box->itemData( mLayer2Box->currentIndex() ).toString(); else layer2ID = "No layer"; layer1ID = mLayer1Box->itemData( mLayer1Box->currentIndex() ).toString(); //TODO: use setItemData (or something like that) instead of hidden columns newItem = new QTableWidgetItem( layer1ID ); mRulesTable->setItem( row, 4, newItem ); newItem = new QTableWidgetItem( layer2ID ); mRulesTable->setItem( row, 5, newItem ); // save state to the project file..... QString postfix = QString( "%1" ).arg( row ); QgsProject* project = QgsProject::instance(); project->writeEntry( "Topol", "/testCount", row + 1 ); project->writeEntry( "Topol", "/testname_" + postfix, test ); project->writeEntry( "Topol", "/tolerance_" + postfix, QString( "%1" ).arg( mToleranceBox->value() ) ); project->writeEntry( "Topol", "/layer1_" + postfix, layer1ID ); project->writeEntry( "Topol", "/layer2_" + postfix, layer2ID ); // reset controls to default mRuleBox->setCurrentIndex( 0 ); mLayer1Box->setCurrentIndex( 0 ); mLayer2Box->setCurrentIndex( 0 ); mToleranceBox->setValue( 0 ); }
QString QgsServerProjectUtils::wmsInspireTemporalReference( const QgsProject &project ) { return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/temporalReference" ) ); }
void rulesDialog::readTest( int index, QgsMapLayerRegistry* layerRegistry ) { QString testName; QString layer1Id; QString layer2Id; QString tolerance; QgsProject* project = QgsProject::instance(); QString postfix = QString( "%1" ).arg( index ); testName = project->readEntry( "Topol", "/testname_" + postfix, "" ); tolerance = project->readEntry( "Topol", "/tolerance_" + postfix, "" ); layer1Id = project->readEntry( "Topol", "/layer1_" + postfix, "" ); layer2Id = project->readEntry( "Topol", "/layer2_" + postfix, "" ); QgsVectorLayer* l1; if ( !( QgsVectorLayer* )layerRegistry->mapLayers().contains( layer1Id ) ) return; l1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layer1Id]; if ( !l1 ) return; QString layer1Name = l1->name(); QString layer2Name; QgsVectorLayer* l2; if ( mTestConfMap[testName].useSecondLayer ) { if ( !( QgsVectorLayer* )layerRegistry->mapLayers().contains( layer2Id ) ) return; else { l2 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layer2Id]; layer2Name = l2->name(); } } else layer2Name = "No layer"; int row = index; mRulesTable->insertRow( row ); QTableWidgetItem* newItem; newItem = new QTableWidgetItem( testName ); newItem->setFlags( newItem->flags() & ~Qt::ItemIsEditable ); mRulesTable->setItem( row, 0, newItem ); newItem = new QTableWidgetItem( layer1Name ); newItem->setFlags( newItem->flags() & ~Qt::ItemIsEditable ); mRulesTable->setItem( row, 1, newItem ); newItem = new QTableWidgetItem( layer2Name ); newItem->setFlags( newItem->flags() & ~Qt::ItemIsEditable ); mRulesTable->setItem( row, 2, newItem ); if ( mTestConfMap[testName].useTolerance ) newItem = new QTableWidgetItem( tolerance ); else newItem = new QTableWidgetItem( QString( "No tolerance" ) ); newItem->setFlags( newItem->flags() & ~Qt::ItemIsEditable ); mRulesTable->setItem( row, 3, newItem ); // add layer ids to hidden columns newItem = new QTableWidgetItem( layer1Id ); mRulesTable->setItem( row, 4, newItem ); newItem = new QTableWidgetItem( layer2Id ); mRulesTable->setItem( row, 5, newItem ); }
QString QgsServerProjectUtils::wmsRootName( const QgsProject &project ) { return project.readEntry( QStringLiteral( "WMSRootName" ), QStringLiteral( "/" ), "" ); }
bool QgsServerProjectUtils::wmsUseLayerIds( const QgsProject &project ) { return project.readBoolEntry( QStringLiteral( "WMSUseLayerIDs" ), QStringLiteral( "/" ), false ); }
QString QgsServerProjectUtils::owsServiceAbstract( const QgsProject &project ) { return project.readEntry( QStringLiteral( "WMSServiceAbstract" ), QStringLiteral( "/" ) ); }
int QgsServerProjectUtils::wmsFeatureInfoPrecision( const QgsProject &project ) { return project.readNumEntry( QStringLiteral( "WMSPrecision" ), QStringLiteral( "/" ), 6 ); }
QStringList QgsServerProjectUtils::wfstDeleteLayerIds( const QgsProject &project ) { return project.readListEntry( QStringLiteral( "WFSTLayers" ), QStringLiteral( "Delete" ) ); }
QString QgsServerProjectUtils::wmsFeatureInfoDocumentElementNs( const QgsProject &project ) { return project.readEntry( QStringLiteral( "WMSFeatureInfoDocumentElementNS" ), QStringLiteral( "/" ), "" ); }
QStringList QgsServerProjectUtils::wcsLayerIds( const QgsProject &project ) { return project.readListEntry( QStringLiteral( "WCSLayers" ), QStringLiteral( "/" ) ); }
QString QgsServerProjectUtils::wmsFeatureInfoSchema( const QgsProject &project ) { return project.readEntry( QStringLiteral( "WMSFeatureInfoSchema" ), QStringLiteral( "/" ), "" ); }
QString QgsServerProjectUtils::owsServiceContactPosition( const QgsProject &project ) { return project.readEntry( QStringLiteral( "WMSContactPosition" ), QStringLiteral( "/" ) ); }
void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale ) { //Lock render method for concurrent threads (e.g. from globe) QMutexLocker renderLock( &mRenderMutex ); QgsDebugMsg( "========== Rendering ==========" ); if ( mExtent.isEmpty() ) { QgsDebugMsg( "empty extent... not rendering" ); return; } if ( mSize.width() == 1 && mSize.height() == 1 ) { QgsDebugMsg( "size 1x1... not rendering" ); return; } QPaintDevice* thePaintDevice = painter->device(); if ( !thePaintDevice ) { return; } // wait if ( mDrawing ) { QgsDebugMsg( "already rendering" ); QCoreApplication::processEvents(); } if ( mDrawing ) { QgsDebugMsg( "still rendering - skipping" ); return; } mDrawing = true; const QgsCoordinateTransform *ct; #ifdef QGISDEBUG QgsDebugMsg( "Starting to render layer stack." ); QTime renderTime; renderTime.start(); #endif if ( mOverview ) mRenderContext.setDrawEditingInformation( !mOverview ); mRenderContext.setPainter( painter ); mRenderContext.setCoordinateTransform( 0 ); //this flag is only for stopping during the current rendering progress, //so must be false at every new render operation mRenderContext.setRenderingStopped( false ); // set selection color QgsProject* prj = QgsProject::instance(); int myRed = prj->readNumEntry( "Gui", "/SelectionColorRedPart", 255 ); int myGreen = prj->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 ); int myBlue = prj->readNumEntry( "Gui", "/SelectionColorBluePart", 0 ); int myAlpha = prj->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 ); mRenderContext.setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) ); //calculate scale factor //use the specified dpi and not those from the paint device //because sometimes QPainter units are in a local coord sys (e.g. in case of QGraphicsScene) double sceneDpi = mScaleCalculator->dpi(); double scaleFactor = 1.0; if ( mOutputUnits == QgsMapRenderer::Millimeters ) { if ( forceWidthScale ) { scaleFactor = *forceWidthScale; } else { scaleFactor = sceneDpi / 25.4; } } double rasterScaleFactor = ( thePaintDevice->logicalDpiX() + thePaintDevice->logicalDpiY() ) / 2.0 / sceneDpi; if ( mRenderContext.rasterScaleFactor() != rasterScaleFactor ) { mRenderContext.setRasterScaleFactor( rasterScaleFactor ); } if ( mRenderContext.scaleFactor() != scaleFactor ) { mRenderContext.setScaleFactor( scaleFactor ); } if ( mRenderContext.rendererScale() != mScale ) { //add map scale to render context mRenderContext.setRendererScale( mScale ); } if ( mLastExtent != mExtent ) { mLastExtent = mExtent; } mRenderContext.setLabelingEngine( mLabelingEngine ); if ( mLabelingEngine ) mLabelingEngine->init( mapSettings() ); // render all layers in the stack, starting at the base QListIterator<QString> li( mLayerSet ); li.toBack(); QgsRectangle r1, r2; while ( li.hasPrevious() ) { if ( mRenderContext.renderingStopped() ) { break; } // Store the painter in case we need to swap it out for the // cache painter QPainter * mypContextPainter = mRenderContext.painter(); // Flattened image for drawing when a blending mode is set QImage * mypFlattenedImage = 0; QString layerId = li.previous(); QgsDebugMsg( "Rendering at layer item " + layerId ); // This call is supposed to cause the progress bar to // advance. However, it seems that updating the progress bar is // incompatible with having a QPainter active (the one that is // passed into this function), as Qt produces a number of errors // when try to do so. I'm (Gavin) not sure how to fix this, but // added these comments and debug statement to help others... QgsDebugMsg( "If there is a QPaintEngine error here, it is caused by an emit call" ); //emit drawingProgress(myRenderCounter++, mLayerSet.size()); QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId ); if ( !ml ) { QgsDebugMsg( "Layer not found in registry!" ); continue; } QgsDebugMsg( QString( "layer %1: minscale:%2 maxscale:%3 scaledepvis:%4 extent:%5 blendmode:%6" ) .arg( ml->name() ) .arg( ml->minimumScale() ) .arg( ml->maximumScale() ) .arg( ml->hasScaleBasedVisibility() ) .arg( ml->extent().toString() ) .arg( ml->blendMode() ) ); if ( mRenderContext.useAdvancedEffects() ) { // Set the QPainter composition mode so that this layer is rendered using // the desired blending mode mypContextPainter->setCompositionMode( ml->blendMode() ); } if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mScale && mScale < ml->maximumScale() ) || mOverview ) { connect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) ); // // Now do the call to the layer that actually does // the rendering work! // bool split = false; if ( hasCrsTransformEnabled() ) { r1 = mExtent; split = splitLayersExtent( ml, r1, r2 ); ct = transformation( ml ); mRenderContext.setExtent( r1 ); QgsDebugMsg( " extent 1: " + r1.toString() ); QgsDebugMsg( " extent 2: " + r2.toString() ); if ( !r1.isFinite() || !r2.isFinite() ) //there was a problem transforming the extent. Skip the layer { continue; } } else { ct = NULL; } mRenderContext.setCoordinateTransform( ct ); //decide if we have to scale the raster //this is necessary in case QGraphicsScene is used bool scaleRaster = false; QgsMapToPixel rasterMapToPixel; QgsMapToPixel bk_mapToPixel; if ( ml->type() == QgsMapLayer::RasterLayer && qAbs( rasterScaleFactor - 1.0 ) > 0.000001 ) { scaleRaster = true; } QSettings mySettings; // If we are drawing with an alternative blending mode then we need to render to a separate image // before compositing this on the map. This effectively flattens the layer and prevents // blending occuring between objects on the layer // (this is not required for raster layers or when layer caching is enabled, since that has the same effect) bool flattenedLayer = false; if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) ) { QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml ); if ((( vl->blendMode() != QPainter::CompositionMode_SourceOver ) || ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver ) || ( vl->layerTransparency() != 0 ) ) ) { flattenedLayer = true; mypFlattenedImage = new QImage( mRenderContext.painter()->device()->width(), mRenderContext.painter()->device()->height(), QImage::Format_ARGB32 ); if ( mypFlattenedImage->isNull() ) { QgsDebugMsg( "insufficient memory for image " + QString::number( mRenderContext.painter()->device()->width() ) + "x" + QString::number( mRenderContext.painter()->device()->height() ) ); emit drawError( ml ); painter->end(); // drawError is not caught by anyone, so we end painting to notify caller return; } mypFlattenedImage->fill( 0 ); QPainter * mypPainter = new QPainter( mypFlattenedImage ); if ( mySettings.value( "/qgis/enable_anti_aliasing", true ).toBool() ) { mypPainter->setRenderHint( QPainter::Antialiasing ); } mypPainter->scale( rasterScaleFactor, rasterScaleFactor ); mRenderContext.setPainter( mypPainter ); } } // Per feature blending mode if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) ) { QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml ); if ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver ) { // set the painter to the feature blend mode, so that features drawn // on this layer will interact and blend with each other mRenderContext.painter()->setCompositionMode( vl->featureBlendMode() ); } } if ( scaleRaster ) { bk_mapToPixel = mRenderContext.mapToPixel(); rasterMapToPixel = mRenderContext.mapToPixel(); rasterMapToPixel.setMapUnitsPerPixel( mRenderContext.mapToPixel().mapUnitsPerPixel() / rasterScaleFactor ); rasterMapToPixel.setYMaximum( mSize.height() * rasterScaleFactor ); mRenderContext.setMapToPixel( rasterMapToPixel ); mRenderContext.painter()->save(); mRenderContext.painter()->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor ); } if ( !ml->draw( mRenderContext ) ) { emit drawError( ml ); } else { QgsDebugMsg( "Layer rendered without issues" ); } if ( split ) { mRenderContext.setExtent( r2 ); if ( !ml->draw( mRenderContext ) ) { emit drawError( ml ); } } if ( scaleRaster ) { mRenderContext.setMapToPixel( bk_mapToPixel ); mRenderContext.painter()->restore(); } //apply layer transparency for vector layers if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) ) { QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml ); if ( vl->layerTransparency() != 0 ) { // a layer transparency has been set, so update the alpha for the flattened layer // by combining it with the layer transparency QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * vl->layerTransparency() / 100 ) ); // use destination in composition mode to merge source's alpha with destination mRenderContext.painter()->setCompositionMode( QPainter::CompositionMode_DestinationIn ); mRenderContext.painter()->fillRect( 0, 0, mRenderContext.painter()->device()->width(), mRenderContext.painter()->device()->height(), transparentFillColor ); } } if ( flattenedLayer ) { // If we flattened this layer for alternate blend modes, composite it now delete mRenderContext.painter(); mRenderContext.setPainter( mypContextPainter ); mypContextPainter->save(); mypContextPainter->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor ); mypContextPainter->drawImage( 0, 0, *( mypFlattenedImage ) ); mypContextPainter->restore(); delete mypFlattenedImage; mypFlattenedImage = 0; } disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) ); } else // layer not visible due to scale {