mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Revert "Merge pull request #245 from Oslandia/atlas_integration"
This reverts commit fe8385e7f5735507adf1acfcce81a399fa6bc6f5, reversing changes made to 23352ce0d66855a4a9c403a81feaa1884415e45c.
This commit is contained in:
parent
a654e274a3
commit
8a1953b9e7
@ -43,13 +43,6 @@ class QgsExpression
|
||||
//! Return the number used for $rownum special column
|
||||
int currentRowNumber();
|
||||
|
||||
//! Assign a special column
|
||||
static void setSpecialColumn( const QString& name, QVariant value );
|
||||
//! Unset a special column
|
||||
static void unsetSpecialColumn( const QString& name );
|
||||
//! Return the value of the given special column or a null QVariant if undefined
|
||||
static QVariant specialColumn( const QString& name );
|
||||
|
||||
void setScale( double scale );
|
||||
|
||||
int scale();
|
||||
@ -71,6 +64,7 @@ class QgsExpression
|
||||
static QString replaceExpressionText( QString action, QgsFeature &feat,
|
||||
QgsVectorLayer* layer,
|
||||
const QMap<QString, QVariant> *substitutionMap = 0 );
|
||||
|
||||
//
|
||||
|
||||
enum UnaryOperator
|
||||
@ -147,11 +141,6 @@ class QgsExpression
|
||||
*/
|
||||
static int functionCount();
|
||||
|
||||
/**
|
||||
* Returns a list of special Column definitions
|
||||
*/
|
||||
static QList<QgsExpression::FunctionDef> specialColumns();
|
||||
|
||||
//! return quoted column reference (in double quotes)
|
||||
static QString quotedColumnRef( QString name );
|
||||
//! return quoted string (in single quotes)
|
||||
|
@ -16,8 +16,6 @@
|
||||
***************************************************************************/
|
||||
#include "qgscomposer.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "qgisapp.h"
|
||||
#include "qgsapplication.h"
|
||||
#include "qgscomposerview.h"
|
||||
@ -72,7 +70,6 @@
|
||||
#include <QToolButton>
|
||||
#include <QUndoView>
|
||||
#include <QPaintEngine>
|
||||
#include <QProgressDialog>
|
||||
|
||||
|
||||
QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
|
||||
@ -565,147 +562,30 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
|
||||
showWMSPrintingWarning();
|
||||
}
|
||||
|
||||
bool hasAnAtlas = mComposition->atlasMap() != 0;
|
||||
bool atlasOnASingleFile = hasAnAtlas && mComposition->atlasMap()->atlasSingleFile();
|
||||
QgsComposerMap* atlasMap = mComposition->atlasMap();
|
||||
QSettings myQSettings; // where we keep last used filter in persistent state
|
||||
QString lastUsedFile = myQSettings.value( "/UI/lastSaveAsPdfFile", "qgis.pdf" ).toString();
|
||||
QFileInfo file( lastUsedFile );
|
||||
|
||||
QString outputFileName;
|
||||
QString outputDir;
|
||||
|
||||
if ( !hasAnAtlas || atlasOnASingleFile )
|
||||
QString outputFileName = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
tr( "Choose a file name to save the map as" ),
|
||||
file.path(),
|
||||
tr( "PDF Format" ) + " (*.pdf *.PDF)" );
|
||||
if ( outputFileName.isEmpty() )
|
||||
{
|
||||
QSettings myQSettings; // where we keep last used filter in persistent state
|
||||
QString lastUsedFile = myQSettings.value( "/UI/lastSaveAsPdfFile", "qgis.pdf" ).toString();
|
||||
QFileInfo file( lastUsedFile );
|
||||
|
||||
outputFileName = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
tr( "Choose a file name to save the map as" ),
|
||||
file.path(),
|
||||
tr( "PDF Format" ) + " (*.pdf *.PDF)" );
|
||||
if ( outputFileName.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !outputFileName.endsWith( ".pdf", Qt::CaseInsensitive ) )
|
||||
{
|
||||
outputFileName += ".pdf";
|
||||
}
|
||||
|
||||
myQSettings.setValue( "/UI/lastSaveAsPdfFile", outputFileName );
|
||||
}
|
||||
// else, we need to choose a directory
|
||||
else
|
||||
{
|
||||
if ( atlasMap->atlasFilenamePattern().size() == 0 )
|
||||
{
|
||||
int res = QMessageBox::warning( 0, tr( "Empty filename pattern" ),
|
||||
tr( "The filename pattern is empty. A default one will be used." ),
|
||||
QMessageBox::Ok | QMessageBox::Cancel,
|
||||
QMessageBox::Ok );
|
||||
if ( res == QMessageBox::Cancel )
|
||||
{
|
||||
return;
|
||||
}
|
||||
atlasMap->setAtlasFilenamePattern( "'output_'||$feature" );
|
||||
}
|
||||
|
||||
QSettings myQSettings;
|
||||
QString lastUsedDir = myQSettings.value( "/UI/lastSaveAtlasAsPdfDir", "." ).toString();
|
||||
outputDir = QFileDialog::getExistingDirectory(this,
|
||||
tr("Directory where to save PDF files"),
|
||||
lastUsedDir,
|
||||
QFileDialog::ShowDirsOnly);
|
||||
if ( outputDir.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
// test directory (if it exists and is writeable)
|
||||
if ( !QDir(outputDir).exists() || !QFileInfo(outputDir).isWritable() )
|
||||
{
|
||||
QMessageBox::warning( 0, tr( "Unable to write into the directory" ),
|
||||
tr( "The given output directory is not writeable. Cancelling." ),
|
||||
QMessageBox::Ok,
|
||||
QMessageBox::Ok );
|
||||
return;
|
||||
}
|
||||
|
||||
myQSettings.setValue( "/UI/lastSaveAtlasAsPdfDir", outputDir );
|
||||
return;
|
||||
}
|
||||
|
||||
size_t featureI = 0;
|
||||
QgsAtlasRendering atlasRender( mComposition );
|
||||
QPrinter printer;
|
||||
if ( hasAnAtlas )
|
||||
if ( !outputFileName.endsWith( ".pdf", Qt::CaseInsensitive ) )
|
||||
{
|
||||
atlasRender.begin( atlasMap->atlasFilenamePattern() );
|
||||
if ( atlasOnASingleFile )
|
||||
{
|
||||
mComposition->beginPrintAsPDF( printer, outputFileName );
|
||||
}
|
||||
outputFileName += ".pdf";
|
||||
}
|
||||
QPainter painter( &printer );
|
||||
|
||||
QProgressDialog progress( tr("Rendering maps..."), tr("Abort"), 0, atlasRender.numFeatures(), this );
|
||||
myQSettings.setValue( "/UI/lastSaveAsPdfFile", outputFileName );
|
||||
|
||||
QApplication::setOverrideCursor( Qt::BusyCursor );
|
||||
mView->setPaintingEnabled( false );
|
||||
|
||||
do
|
||||
{
|
||||
if ( hasAnAtlas )
|
||||
{
|
||||
if ( 0 == atlasRender.numFeatures() )
|
||||
break;
|
||||
|
||||
progress.setValue( featureI );
|
||||
// process input events in order to allow aborting
|
||||
QCoreApplication::processEvents();
|
||||
if ( progress.wasCanceled() )
|
||||
{
|
||||
atlasRender.end();
|
||||
break;
|
||||
}
|
||||
try
|
||||
{
|
||||
atlasRender.prepareForFeature( featureI );
|
||||
}
|
||||
catch ( std::runtime_error& e )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Atlas processing error" ),
|
||||
e.what(),
|
||||
QMessageBox::Ok,
|
||||
QMessageBox::Ok);
|
||||
break;
|
||||
}
|
||||
if ( !atlasOnASingleFile )
|
||||
{
|
||||
outputFileName = QDir(outputDir).filePath( atlasRender.currentFilename() ) + ".pdf";
|
||||
}
|
||||
}
|
||||
|
||||
if ( !atlasOnASingleFile )
|
||||
{
|
||||
mComposition->exportAsPDF( outputFileName );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( featureI > 0 )
|
||||
{
|
||||
printer.newPage();
|
||||
}
|
||||
mComposition->doPrint( printer, painter );
|
||||
}
|
||||
|
||||
featureI++;
|
||||
} while ( hasAnAtlas && featureI < atlasRender.numFeatures() );
|
||||
|
||||
if ( hasAnAtlas )
|
||||
{
|
||||
atlasRender.end();
|
||||
}
|
||||
painter.end();
|
||||
|
||||
mComposition->exportAsPDF( outputFileName );
|
||||
mView->setPaintingEnabled( true );
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
@ -731,56 +611,7 @@ void QgsComposer::on_mActionPrint_triggered()
|
||||
|
||||
QApplication::setOverrideCursor( Qt::BusyCursor );
|
||||
mView->setPaintingEnabled( false );
|
||||
|
||||
if ( mComposition->atlasMap() == 0 )
|
||||
{
|
||||
mComposition->print( mPrinter );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
QgsAtlasRendering atlasRender( mComposition );
|
||||
|
||||
mComposition->beginPrint( mPrinter );
|
||||
QPainter painter( &mPrinter );
|
||||
atlasRender.begin();
|
||||
QProgressDialog progress( tr("Rendering maps..."), tr("Abort"), 0, atlasRender.numFeatures(), this );
|
||||
|
||||
for ( size_t i = 0; i < atlasRender.numFeatures(); ++i )
|
||||
{
|
||||
progress.setValue( i );
|
||||
// process input events in order to allow cancelling
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
if ( progress.wasCanceled() )
|
||||
{
|
||||
atlasRender.end();
|
||||
break;
|
||||
}
|
||||
try
|
||||
{
|
||||
atlasRender.prepareForFeature( i );
|
||||
}
|
||||
catch ( std::runtime_error& e )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Atlas processing error" ),
|
||||
e.what(),
|
||||
QMessageBox::Ok,
|
||||
QMessageBox::Ok);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ( i > 0 )
|
||||
{
|
||||
mPrinter.newPage();
|
||||
}
|
||||
mComposition->doPrint( mPrinter, painter );
|
||||
}
|
||||
atlasRender.end();
|
||||
painter.end();
|
||||
}
|
||||
|
||||
mComposition->print( mPrinter );
|
||||
mView->setPaintingEnabled( true );
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
@ -817,168 +648,30 @@ void QgsComposer::on_mActionExportAsImage_triggered()
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 0 == mComposition->atlasMap() )
|
||||
QPair<QString, QString> fileNExt = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ) );
|
||||
|
||||
if ( fileNExt.first.isEmpty() )
|
||||
{
|
||||
QPair<QString, QString> fileNExt = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ) );
|
||||
|
||||
if ( fileNExt.first.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mView->setPaintingEnabled( false );
|
||||
|
||||
for ( int i = 0; i < mComposition->numPages(); ++i )
|
||||
{
|
||||
QImage image = mComposition->printPageAsRaster( i );
|
||||
if ( i == 0 )
|
||||
{
|
||||
image.save( fileNExt.first, fileNExt.second.toLocal8Bit().constData() );
|
||||
}
|
||||
else
|
||||
{
|
||||
QFileInfo fi( fileNExt.first );
|
||||
QString outputFilePath = fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
|
||||
image.save( outputFilePath, fileNExt.second.toLocal8Bit().constData() );
|
||||
}
|
||||
}
|
||||
mView->setPaintingEnabled( true );
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
mView->setPaintingEnabled( false );
|
||||
|
||||
for ( int i = 0; i < mComposition->numPages(); ++i )
|
||||
{
|
||||
// else, it has an atlas to render, so a directory must first be selected
|
||||
QgsComposerMap* atlasMap = mComposition->atlasMap();
|
||||
if ( atlasMap->atlasFilenamePattern().size() == 0 )
|
||||
QImage image = mComposition->printPageAsRaster( i );
|
||||
if ( i == 0 )
|
||||
{
|
||||
int res = QMessageBox::warning( 0, tr( "Empty filename pattern" ),
|
||||
tr( "The filename pattern is empty. A default one will be used." ),
|
||||
QMessageBox::Ok | QMessageBox::Cancel,
|
||||
QMessageBox::Ok );
|
||||
if ( res == QMessageBox::Cancel )
|
||||
{
|
||||
return;
|
||||
}
|
||||
atlasMap->setAtlasFilenamePattern( "'output_'||$feature" );
|
||||
image.save( fileNExt.first, fileNExt.second.toLocal8Bit().constData() );
|
||||
}
|
||||
|
||||
QSettings myQSettings;
|
||||
QString lastUsedDir = myQSettings.value( "/UI/lastSaveAtlasAsImagesDir", "." ).toString();
|
||||
QString lastUsedFormat = myQSettings.value( "/UI/lastSaveAtlasAsImagesFormat", "jpg" ).toString();
|
||||
|
||||
QFileDialog dlg( this, tr("Directory where to save image files") );
|
||||
dlg.setFileMode( QFileDialog::Directory );
|
||||
dlg.setOption( QFileDialog::ShowDirsOnly, true );
|
||||
|
||||
//
|
||||
// Build an augmented FialeDialog with a combo box to select the output format
|
||||
QComboBox *box = new QComboBox();
|
||||
QHBoxLayout* hlayout = new QHBoxLayout();
|
||||
QWidget* widget = new QWidget();
|
||||
|
||||
QList<QByteArray> formats = QImageWriter::supportedImageFormats();
|
||||
int selectedFormat = 0;
|
||||
for ( int i = 0; i < formats.size(); ++i )
|
||||
else
|
||||
{
|
||||
QString format = QString( formats.at(i) );
|
||||
if ( format == lastUsedFormat )
|
||||
{
|
||||
selectedFormat = i;
|
||||
}
|
||||
box->addItem( format );
|
||||
QFileInfo fi( fileNExt.first );
|
||||
QString outputFilePath = fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
|
||||
image.save( outputFilePath, fileNExt.second.toLocal8Bit().constData() );
|
||||
}
|
||||
box->setCurrentIndex( selectedFormat );
|
||||
|
||||
hlayout->setMargin( 0 );
|
||||
hlayout->addWidget( new QLabel( tr("Image format: ")) );
|
||||
hlayout->addWidget( box );
|
||||
widget->setLayout( hlayout );
|
||||
dlg.layout()->addWidget( widget );
|
||||
|
||||
if ( !dlg.exec() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
QStringList s = dlg.selectedFiles();
|
||||
if ( s.size() < 1 || s.at(0).isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
QString dir = s.at(0);
|
||||
QString format = box->currentText();
|
||||
QString fileExt = "." + format;
|
||||
|
||||
if ( dir.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
// test directory (if it exists and is writeable)
|
||||
if ( !QDir(dir).exists() || !QFileInfo(dir).isWritable() )
|
||||
{
|
||||
QMessageBox::warning( 0, tr( "Unable to write into the directory" ),
|
||||
tr( "The given output directory is not writeable. Cancelling." ),
|
||||
QMessageBox::Ok,
|
||||
QMessageBox::Ok );
|
||||
return;
|
||||
}
|
||||
|
||||
myQSettings.setValue( "/UI/lastSaveAtlasAsImagesDir", dir );
|
||||
|
||||
// So, now we can render the atlas
|
||||
QgsAtlasRendering atlasRender( mComposition );
|
||||
|
||||
mView->setPaintingEnabled( false );
|
||||
QApplication::setOverrideCursor( Qt::BusyCursor );
|
||||
|
||||
atlasRender.begin( atlasMap->atlasFilenamePattern() );
|
||||
|
||||
QProgressDialog progress( tr("Rendering maps..."), tr("Abort"), 0, atlasRender.numFeatures(), this );
|
||||
|
||||
for ( size_t feature = 0; feature < atlasRender.numFeatures(); ++feature )
|
||||
{
|
||||
progress.setValue( feature );
|
||||
// process input events in order to allow cancelling
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
if ( progress.wasCanceled() )
|
||||
{
|
||||
atlasRender.end();
|
||||
break;
|
||||
}
|
||||
try
|
||||
{
|
||||
atlasRender.prepareForFeature( feature );
|
||||
}
|
||||
catch ( std::runtime_error& e )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Atlas processing error" ),
|
||||
e.what(),
|
||||
QMessageBox::Ok,
|
||||
QMessageBox::Ok);
|
||||
break;
|
||||
}
|
||||
|
||||
QString filename = QDir(dir).filePath(atlasRender.currentFilename()) + fileExt;
|
||||
|
||||
for ( int i = 0; i < mComposition->numPages(); ++i )
|
||||
{
|
||||
QImage image = mComposition->printPageAsRaster( i );
|
||||
|
||||
if ( i == 0 )
|
||||
{
|
||||
image.save( filename, format.toLocal8Bit().constData() );
|
||||
}
|
||||
else
|
||||
{
|
||||
QFileInfo fi( filename );
|
||||
QString outputFilePath = fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
|
||||
image.save( outputFilePath, format.toLocal8Bit().constData() );
|
||||
}
|
||||
}
|
||||
}
|
||||
atlasRender.end();
|
||||
mView->setPaintingEnabled( true );
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
mView->setPaintingEnabled( true );
|
||||
}
|
||||
|
||||
|
||||
@ -1015,149 +708,56 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
|
||||
m->exec();
|
||||
}
|
||||
|
||||
bool hasAnAtlas = mComposition->atlasMap() != 0;
|
||||
QString lastUsedFile = settings.value( "/UI/lastSaveAsSvgFile", "qgis.svg" ).toString();
|
||||
QFileInfo file( lastUsedFile );
|
||||
|
||||
QString outputFileName;
|
||||
QString outputDir;
|
||||
QString outputFileName = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
tr( "Choose a file name to save the map as" ),
|
||||
file.path(),
|
||||
tr( "SVG Format" ) + " (*.svg *.SVG)" );
|
||||
if ( outputFileName.isEmpty() )
|
||||
return;
|
||||
|
||||
if ( !hasAnAtlas )
|
||||
if ( !outputFileName.endsWith( ".svg", Qt::CaseInsensitive ) )
|
||||
{
|
||||
QString lastUsedFile = settings.value( "/UI/lastSaveAsSvgFile", "qgis.svg" ).toString();
|
||||
QFileInfo file( lastUsedFile );
|
||||
|
||||
outputFileName = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
tr( "Choose a file name to save the map as" ),
|
||||
file.path(),
|
||||
tr( "SVG Format" ) + " (*.svg *.SVG)" );
|
||||
if ( outputFileName.isEmpty() )
|
||||
return;
|
||||
|
||||
if ( !outputFileName.endsWith( ".svg", Qt::CaseInsensitive ) )
|
||||
{
|
||||
outputFileName += ".svg";
|
||||
}
|
||||
|
||||
settings.setValue( "/UI/lastSaveAsSvgFile", outputFileName );
|
||||
outputFileName += ".svg";
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we have an Atlas
|
||||
QgsComposerMap* atlasMap = mComposition->atlasMap();
|
||||
if ( atlasMap->atlasFilenamePattern().size() == 0 )
|
||||
{
|
||||
int res = QMessageBox::warning( 0, tr( "Empty filename pattern" ),
|
||||
tr( "The filename pattern is empty. A default one will be used." ),
|
||||
QMessageBox::Ok | QMessageBox::Cancel,
|
||||
QMessageBox::Ok );
|
||||
if ( res == QMessageBox::Cancel )
|
||||
{
|
||||
return;
|
||||
}
|
||||
atlasMap->setAtlasFilenamePattern( "'output_'||$feature" );
|
||||
}
|
||||
|
||||
QSettings myQSettings;
|
||||
QString lastUsedDir = myQSettings.value( "/UI/lastSaveAtlasAsSvgDir", "." ).toString();
|
||||
settings.setValue( "/UI/lastSaveAsSvgFile", outputFileName );
|
||||
|
||||
outputDir = QFileDialog::getExistingDirectory(this,
|
||||
tr("Directory where to save SVG files"),
|
||||
lastUsedDir,
|
||||
QFileDialog::ShowDirsOnly);
|
||||
if ( outputDir.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
// test directory (if it exists and is writeable)
|
||||
if ( !QDir(outputDir).exists() || !QFileInfo(outputDir).isWritable() )
|
||||
{
|
||||
QMessageBox::warning( 0, tr( "Unable to write into the directory" ),
|
||||
tr( "The given output directory is not writeable. Cancelling." ),
|
||||
QMessageBox::Ok,
|
||||
QMessageBox::Ok );
|
||||
return;
|
||||
}
|
||||
|
||||
myQSettings.setValue( "/UI/lastSaveAtlasAsSvgDir", outputDir );
|
||||
}
|
||||
|
||||
mView->setPaintingEnabled( false );
|
||||
|
||||
QgsAtlasRendering atlasRender( mComposition );
|
||||
size_t featureI = 0;
|
||||
if ( hasAnAtlas )
|
||||
for ( int i = 0; i < mComposition->numPages(); ++i )
|
||||
{
|
||||
atlasRender.begin( mComposition->atlasMap()->atlasFilenamePattern() );
|
||||
QSvgGenerator generator;
|
||||
#if QT_VERSION >= 0x040500
|
||||
generator.setTitle( QgsProject::instance()->title() );
|
||||
#endif
|
||||
if ( i == 0 )
|
||||
{
|
||||
generator.setFileName( outputFileName );
|
||||
}
|
||||
else
|
||||
{
|
||||
QFileInfo fi( outputFileName );
|
||||
generator.setFileName( fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix() );
|
||||
}
|
||||
|
||||
//width in pixel
|
||||
int width = ( int )( mComposition->paperWidth() * mComposition->printResolution() / 25.4 );
|
||||
//height in pixel
|
||||
int height = ( int )( mComposition->paperHeight() * mComposition->printResolution() / 25.4 );
|
||||
generator.setSize( QSize( width, height ) );
|
||||
#if QT_VERSION >= 0x040500
|
||||
generator.setViewBox( QRect( 0, 0, width, height ) );
|
||||
#endif
|
||||
generator.setResolution( mComposition->printResolution() ); //because the rendering is done in mm, convert the dpi
|
||||
|
||||
QPainter p( &generator );
|
||||
|
||||
mComposition->renderPage( &p, i );
|
||||
p.end();
|
||||
}
|
||||
QProgressDialog progress( tr("Rendering maps..."), tr("Abort"), 0, atlasRender.numFeatures(), this );
|
||||
|
||||
do
|
||||
{
|
||||
if ( hasAnAtlas )
|
||||
{
|
||||
if ( atlasRender.numFeatures() == 0 )
|
||||
break;
|
||||
|
||||
progress.setValue( featureI );
|
||||
// process input events in order to allow aborting
|
||||
QCoreApplication::processEvents();
|
||||
if ( progress.wasCanceled() )
|
||||
{
|
||||
atlasRender.end();
|
||||
break;
|
||||
}
|
||||
try
|
||||
{
|
||||
atlasRender.prepareForFeature( featureI );
|
||||
}
|
||||
catch ( std::runtime_error& e )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Atlas processing error" ),
|
||||
e.what(),
|
||||
QMessageBox::Ok,
|
||||
QMessageBox::Ok);
|
||||
break;
|
||||
}
|
||||
outputFileName = QDir(outputDir).filePath( atlasRender.currentFilename() ) + ".svg";
|
||||
}
|
||||
|
||||
for ( int i = 0; i < mComposition->numPages(); ++i )
|
||||
{
|
||||
QSvgGenerator generator;
|
||||
#if QT_VERSION >= 0x040500
|
||||
generator.setTitle( QgsProject::instance()->title() );
|
||||
#endif
|
||||
if ( i == 0 )
|
||||
{
|
||||
generator.setFileName( outputFileName );
|
||||
}
|
||||
else
|
||||
{
|
||||
QFileInfo fi( outputFileName );
|
||||
generator.setFileName( fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix() );
|
||||
}
|
||||
|
||||
//width in pixel
|
||||
int width = ( int )( mComposition->paperWidth() * mComposition->printResolution() / 25.4 );
|
||||
//height in pixel
|
||||
int height = ( int )( mComposition->paperHeight() * mComposition->printResolution() / 25.4 );
|
||||
generator.setSize( QSize( width, height ) );
|
||||
#if QT_VERSION >= 0x040500
|
||||
generator.setViewBox( QRect( 0, 0, width, height ) );
|
||||
#endif
|
||||
generator.setResolution( mComposition->printResolution() ); //because the rendering is done in mm, convert the dpi
|
||||
|
||||
QPainter p( &generator );
|
||||
|
||||
mComposition->renderPage( &p, i );
|
||||
p.end();
|
||||
}
|
||||
featureI++;
|
||||
} while ( hasAnAtlas && featureI < atlasRender.numFeatures() );
|
||||
|
||||
if ( hasAnAtlas )
|
||||
atlasRender.end();
|
||||
|
||||
mView->setPaintingEnabled( true );
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "qgscomposerlabelwidget.h"
|
||||
#include "qgscomposerlabel.h"
|
||||
#include "qgscomposeritemwidget.h"
|
||||
#include "qgsexpressionbuilderdialog.h"
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QFontDialog>
|
||||
#include <QWidget>
|
||||
@ -100,33 +98,6 @@ void QgsComposerLabelWidget::on_mFontColorButton_clicked()
|
||||
mComposerLabel->endCommand();
|
||||
}
|
||||
|
||||
void QgsComposerLabelWidget::on_mInsertExpressionButton_clicked()
|
||||
{
|
||||
if ( !mComposerLabel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QString selText = mTextEdit->textCursor().selectedText();
|
||||
|
||||
// edit the selected expression if there's one
|
||||
if ( selText.startsWith( "[%" ) && selText.endsWith( "%]" ) )
|
||||
selText = selText.mid( 2, selText.size() - 4 );
|
||||
|
||||
QgsExpressionBuilderDialog exprDlg( /* layer = */ 0, selText, this );
|
||||
exprDlg.setWindowTitle( tr( "Insert expression" ) );
|
||||
if ( exprDlg.exec() == QDialog::Accepted )
|
||||
{
|
||||
QString expression = exprDlg.expressionText();
|
||||
if ( !expression.isEmpty() )
|
||||
{
|
||||
mComposerLabel->beginCommand( tr( "Insert expression" ) );
|
||||
mTextEdit->insertPlainText( "[%" + expression + "%]" );
|
||||
mComposerLabel->endCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerLabelWidget::on_mCenterRadioButton_clicked()
|
||||
{
|
||||
if ( mComposerLabel )
|
||||
|
@ -34,7 +34,6 @@ class QgsComposerLabelWidget: public QWidget, private Ui::QgsComposerLabelWidget
|
||||
public slots:
|
||||
void on_mTextEdit_textChanged();
|
||||
void on_mFontButton_clicked();
|
||||
void on_mInsertExpressionButton_clicked();
|
||||
void on_mMarginDoubleSpinBox_valueChanged( double d );
|
||||
void on_mFontColorButton_clicked();
|
||||
void on_mCenterRadioButton_clicked();
|
||||
|
@ -23,15 +23,8 @@
|
||||
//#include "qgssymbolv2propertiesdialog.h"
|
||||
#include "qgssymbolv2selectordialog.h"
|
||||
#include "qgssymbollayerv2utils.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectordataprovider.h"
|
||||
#include "qgsmaplayerregistry.h"
|
||||
#include "qgscomposershape.h"
|
||||
#include "qgspaperitem.h"
|
||||
#include "qgsexpressionbuilderdialog.h"
|
||||
#include <QColorDialog>
|
||||
#include <QFontDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidget(), mComposerMap( composerMap )
|
||||
{
|
||||
@ -416,29 +409,6 @@ void QgsComposerMapWidget::updateGuiElements()
|
||||
mLineWidthSpinBox->setValue( gridPen.widthF() );
|
||||
mLineColorButton->setColor( gridPen.color() );
|
||||
|
||||
// special processing for atlas
|
||||
QgsComposition* composition = mComposerMap->composition();
|
||||
if ( composition->atlasMap() && composition->atlasMap() == mComposerMap )
|
||||
{
|
||||
mIsAtlasCheckBox->setCheckState( Qt::Checked );
|
||||
|
||||
int idx = mAtlasCoverageLayerComboBox->findData( qVariantFromValue( (void*)mComposerMap->atlasCoverageLayer() ));
|
||||
if ( idx != -1 )
|
||||
{
|
||||
mAtlasCoverageLayerComboBox->setCurrentIndex( idx );
|
||||
}
|
||||
|
||||
mAtlasMarginSpinBox->setValue( static_cast<int>(mComposerMap->atlasMargin() * 100) );
|
||||
mAtlasFilenamePatternEdit->setText( mComposerMap->atlasFilenamePattern() );
|
||||
mAtlasFixedScaleCheckBox->setCheckState( mComposerMap->atlasFixedScale() ? Qt::Checked : Qt::Unchecked );
|
||||
mAtlasHideCoverageCheckBox->setCheckState( mComposerMap->atlasHideCoverage() ? Qt::Checked : Qt::Unchecked );
|
||||
mAtlasSingleFileCheckBox->setCheckState( mComposerMap->atlasSingleFile() ? Qt::Checked : Qt::Unchecked );
|
||||
}
|
||||
else
|
||||
{
|
||||
mIsAtlasCheckBox->setCheckState( Qt::Unchecked );
|
||||
}
|
||||
|
||||
blockAllSignals( false );
|
||||
}
|
||||
}
|
||||
@ -927,151 +897,12 @@ void QgsComposerMapWidget::on_mFrameWidthSpinBox_valueChanged( double d )
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::on_mIsAtlasCheckBox_stateChanged( int state )
|
||||
{
|
||||
if ( !mComposerMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsComposition* composition = mComposerMap->composition();
|
||||
if ( state == Qt::Checked )
|
||||
{
|
||||
if ( composition->atlasMap() != 0 && composition->atlasMap() != mComposerMap )
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(tr("An atlas map already exists."));
|
||||
msgBox.setInformativeText("Are you sure to define this map as the new atlas map ?");
|
||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No );
|
||||
msgBox.setDefaultButton(QMessageBox::No);
|
||||
if ( msgBox.exec() != QMessageBox::Yes )
|
||||
{
|
||||
mIsAtlasCheckBox->setCheckState( Qt::Unchecked );
|
||||
return;
|
||||
}
|
||||
}
|
||||
composition->setAtlasMap( mComposerMap );
|
||||
|
||||
// repopulate the layer list
|
||||
mAtlasCoverageLayerComboBox->clear();
|
||||
QMap< QString, QgsMapLayer * >& layers = QgsMapLayerRegistry::instance()->mapLayers();
|
||||
int idx = 0;
|
||||
for ( QMap<QString, QgsMapLayer*>::const_iterator it = layers.begin(); it != layers.end(); ++it )
|
||||
{
|
||||
// Only consider vector layers
|
||||
if ( dynamic_cast<QgsVectorLayer*>(it.value()) )
|
||||
{
|
||||
mAtlasCoverageLayerComboBox->insertItem( idx++, it.key(), /* userdata */ qVariantFromValue( (void*)it.value() ) );
|
||||
}
|
||||
}
|
||||
|
||||
mAtlasFrame->setEnabled( true );
|
||||
updateGuiElements();
|
||||
}
|
||||
else
|
||||
{
|
||||
mAtlasFrame->setEnabled( false );
|
||||
|
||||
// If the current atlas map was this one and a uncheck is requested, set the atlas map to null
|
||||
if ( composition->atlasMap() == mComposerMap )
|
||||
{
|
||||
composition->setAtlasMap( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index )
|
||||
{
|
||||
if ( !mComposerMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsVectorLayer* layer = reinterpret_cast<QgsVectorLayer*>(mAtlasCoverageLayerComboBox->itemData( index ).value<void*>());
|
||||
mComposerMap->setAtlasCoverageLayer( layer );
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::on_mAtlasFilenamePatternEdit_textChanged( const QString& text )
|
||||
{
|
||||
if ( !mComposerMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mComposerMap->setAtlasFilenamePattern( text );
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::on_mAtlasFilenameExpressionButton_clicked()
|
||||
{
|
||||
if ( !mComposerMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ( !mComposerMap->atlasCoverageLayer() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
QgsExpressionBuilderDialog exprDlg( mComposerMap->atlasCoverageLayer(), mAtlasFilenamePatternEdit->text(), this );
|
||||
exprDlg.setWindowTitle( tr( "Expression based filename" ) );
|
||||
if ( exprDlg.exec() == QDialog::Accepted )
|
||||
{
|
||||
QString expression = exprDlg.expressionText();
|
||||
if ( !expression.isEmpty() )
|
||||
{
|
||||
// will emit a textChanged signal
|
||||
mAtlasFilenamePatternEdit->setText( expression );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::on_mAtlasHideCoverageCheckBox_stateChanged( int state )
|
||||
{
|
||||
if (!mComposerMap)
|
||||
{
|
||||
return;
|
||||
}
|
||||
mComposerMap->setAtlasHideCoverage( state == Qt::Checked );
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::on_mAtlasFixedScaleCheckBox_stateChanged( int state )
|
||||
{
|
||||
if (!mComposerMap)
|
||||
{
|
||||
return;
|
||||
}
|
||||
mComposerMap->setAtlasFixedScale( state == Qt::Checked );
|
||||
|
||||
// in fixed scale mode, the margin is meaningless
|
||||
if ( state == Qt::Checked )
|
||||
{
|
||||
mAtlasMarginSpinBox->setEnabled( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
mAtlasMarginSpinBox->setEnabled( true );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::on_mAtlasSingleFileCheckBox_stateChanged( int state )
|
||||
{
|
||||
if (!mComposerMap)
|
||||
{
|
||||
return;
|
||||
}
|
||||
mComposerMap->setAtlasSingleFile( state == Qt::Checked );
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::showEvent( QShowEvent * event )
|
||||
{
|
||||
refreshMapComboBox();
|
||||
QWidget::showEvent( event );
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::addPageToToolbox( QWidget* widget, const QString& name )
|
||||
{
|
||||
toolBox->addItem( widget, name );
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::insertAnnotationPositionEntries( QComboBox* c )
|
||||
{
|
||||
c->insertItem( 0, tr( "Inside frame" ) );
|
||||
|
@ -31,7 +31,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
|
||||
public:
|
||||
|
||||
QgsComposerMapWidget( QgsComposerMap* composerMap );
|
||||
virtual ~QgsComposerMapWidget();
|
||||
~QgsComposerMapWidget();
|
||||
|
||||
public slots:
|
||||
void on_mWidthLineEdit_editingFinished();
|
||||
@ -83,22 +83,9 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
|
||||
void on_mFrameStyleComboBox_currentIndexChanged( const QString& text );
|
||||
void on_mFrameWidthSpinBox_valueChanged( double d );
|
||||
|
||||
void on_mIsAtlasCheckBox_stateChanged( int state );
|
||||
void on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index );
|
||||
void on_mAtlasFilenamePatternEdit_textChanged( const QString& );
|
||||
void on_mAtlasFilenameExpressionButton_clicked();
|
||||
void on_mAtlasHideCoverageCheckBox_stateChanged( int state );
|
||||
void on_mAtlasFixedScaleCheckBox_stateChanged( int state );
|
||||
void on_mAtlasSingleFileCheckBox_stateChanged( int state );
|
||||
|
||||
protected:
|
||||
void showEvent( QShowEvent * event );
|
||||
|
||||
void addPageToToolbox( QWidget * widget, const QString& name );
|
||||
|
||||
/**Sets the current composer map values to the GUI elements*/
|
||||
virtual void updateGuiElements();
|
||||
|
||||
private slots:
|
||||
|
||||
/**Sets the GUI elements to the values of mPicture*/
|
||||
@ -107,6 +94,9 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
|
||||
private:
|
||||
QgsComposerMap* mComposerMap;
|
||||
|
||||
/**Sets the current composer map values to the GUI elements*/
|
||||
void updateGuiElements();
|
||||
|
||||
/**Sets extent of composer map from line edits*/
|
||||
void updateComposerExtentFromGui();
|
||||
|
||||
|
@ -190,7 +190,6 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
|
||||
virtual void removeItems() {}
|
||||
|
||||
const QgsComposition* composition() const {return mComposition;}
|
||||
QgsComposition* composition() {return mComposition;}
|
||||
|
||||
virtual void beginItemCommand( const QString& text ) { beginCommand( text ); }
|
||||
|
||||
|
@ -16,15 +16,12 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgscomposerlabel.h"
|
||||
#include "qgsexpression.h"
|
||||
#include <QDate>
|
||||
#include <QDomElement>
|
||||
#include <QPainter>
|
||||
|
||||
QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ):
|
||||
QgsComposerItem( composition ), mMargin( 1.0 ), mFontColor( QColor( 0, 0, 0 ) ),
|
||||
mHAlignment( Qt::AlignLeft ), mVAlignment( Qt::AlignTop ),
|
||||
mExpressionFeature( 0 ), mExpressionLayer( 0 )
|
||||
QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ): QgsComposerItem( composition ), mMargin( 1.0 ), mFontColor( QColor( 0, 0, 0 ) ),
|
||||
mHAlignment( Qt::AlignLeft ), mVAlignment( Qt::AlignTop )
|
||||
{
|
||||
//default font size is 10 point
|
||||
mFont.setPointSizeF( 10 );
|
||||
@ -78,36 +75,23 @@ void QgsComposerLabel::setText( const QString& text )
|
||||
emit itemChanged();
|
||||
}
|
||||
|
||||
void QgsComposerLabel::setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, QMap<QString, QVariant> substitutions )
|
||||
{
|
||||
mExpressionFeature = feature;
|
||||
mExpressionLayer = layer;
|
||||
mSubstitutions = substitutions;
|
||||
}
|
||||
|
||||
QString QgsComposerLabel::displayText() const
|
||||
{
|
||||
QString displayText = mText;
|
||||
replaceDateText( displayText );
|
||||
QMap<QString, QVariant> subs = mSubstitutions;
|
||||
subs[ "$page" ] = QVariant((int)mComposition->itemPageNumber( this ) + 1);
|
||||
return QgsExpression::replaceExpressionText( displayText, mExpressionFeature, mExpressionLayer, &subs );
|
||||
return displayText;
|
||||
}
|
||||
|
||||
void QgsComposerLabel::replaceDateText( QString& text ) const
|
||||
{
|
||||
QString constant = "$CURRENT_DATE";
|
||||
int currentDatePos = text.indexOf( constant );
|
||||
int currentDatePos = text.indexOf( "$CURRENT_DATE" );
|
||||
if ( currentDatePos != -1 )
|
||||
{
|
||||
//check if there is a bracket just after $CURRENT_DATE
|
||||
QString formatText;
|
||||
int openingBracketPos = text.indexOf( "(", currentDatePos );
|
||||
int closingBracketPos = text.indexOf( ")", openingBracketPos + 1 );
|
||||
if ( openingBracketPos != -1 &&
|
||||
closingBracketPos != -1 &&
|
||||
( closingBracketPos - openingBracketPos ) > 1 &&
|
||||
openingBracketPos == currentDatePos + constant.size() )
|
||||
if ( openingBracketPos != -1 && closingBracketPos != -1 && ( closingBracketPos - openingBracketPos ) > 1 )
|
||||
{
|
||||
formatText = text.mid( openingBracketPos + 1, closingBracketPos - openingBracketPos - 1 );
|
||||
text.replace( currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString( formatText ) );
|
||||
|
@ -19,9 +19,6 @@
|
||||
|
||||
#include "qgscomposeritem.h"
|
||||
|
||||
class QgsVectorLayer;
|
||||
class QgsFeature;
|
||||
|
||||
/** \ingroup MapComposer
|
||||
* A label that can be placed onto a map composition.
|
||||
*/
|
||||
@ -48,9 +45,6 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
|
||||
@note this function was added in version 1.2*/
|
||||
QString displayText() const;
|
||||
|
||||
/** Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions */
|
||||
void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, QMap<QString, QVariant> substitutions = QMap<QString, QVariant>() );
|
||||
|
||||
QFont font() const;
|
||||
void setFont( const QFont& f );
|
||||
/** Accessor for the vertical alignment of the label
|
||||
@ -126,10 +120,6 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
|
||||
double mTextBoxWidth;
|
||||
/**Height of the text box. This is different to rectangle().height() in case there is rotation*/
|
||||
double mTextBoxHeight;
|
||||
|
||||
QgsFeature* mExpressionFeature;
|
||||
QgsVectorLayer* mExpressionLayer;
|
||||
QMap<QString, QVariant> mSubstitutions;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -38,14 +38,12 @@
|
||||
#include <cmath>
|
||||
|
||||
QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
|
||||
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ),
|
||||
mOverviewFrameMapId( -1 ), mGridEnabled( false ), mGridStyle( Solid ),
|
||||
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 ), mGridEnabled( false ), mGridStyle( Solid ),
|
||||
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
|
||||
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
|
||||
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
|
||||
mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
|
||||
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true ),
|
||||
mAtlasHideCoverage( false ), mAtlasFixedScale( false ), mAtlasMargin( 0.10 ), mAtlasFilenamePattern("'output_'||$feature"), mAtlasCoverageLayer(0), mAtlasSingleFile( false )
|
||||
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
|
||||
{
|
||||
mComposition = composition;
|
||||
mOverviewFrameMapSymbol = 0;
|
||||
@ -86,8 +84,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
|
||||
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
|
||||
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
|
||||
mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
|
||||
mMapCanvas( 0 ), mDrawCanvasItems( true ),
|
||||
mAtlasHideCoverage( false ), mAtlasFixedScale( false ), mAtlasMargin( 0.10 ), mAtlasFilenamePattern("'output_'||$feature"), mAtlasCoverageLayer(0), mAtlasSingleFile( false )
|
||||
mMapCanvas( 0 ), mDrawCanvasItems( true )
|
||||
{
|
||||
mOverviewFrameMapSymbol = 0;
|
||||
createDefaultOverviewFrameSymbol();
|
||||
@ -620,26 +617,10 @@ void QgsComposerMap::connectUpdateSlot()
|
||||
if ( layerRegistry )
|
||||
{
|
||||
connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( updateCachedImage() ) );
|
||||
connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( syncAtlasCoverageLayer( QString ) ) );
|
||||
connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( updateCachedImage() ) );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerMap::syncAtlasCoverageLayer( QString lname )
|
||||
{
|
||||
if ( mAtlasCoverageLayer && mAtlasCoverageLayer->id() == lname )
|
||||
{
|
||||
mAtlasCoverageLayer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerMap::setAtlasCoverageLayer( QgsVectorLayer* map )
|
||||
{
|
||||
mAtlasCoverageLayer = map;
|
||||
|
||||
emit atlasCoverageLayerChanged( map );
|
||||
}
|
||||
|
||||
bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
|
||||
{
|
||||
if ( elem.isNull() )
|
||||
@ -747,27 +728,6 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
|
||||
gridElem.appendChild( annotationElem );
|
||||
composerMapElem.appendChild( gridElem );
|
||||
|
||||
// atlas
|
||||
if ( mComposition->atlasMap() == this )
|
||||
{
|
||||
QDomElement atlasElem = doc.createElement( "Atlas" );
|
||||
if ( mAtlasCoverageLayer )
|
||||
{
|
||||
atlasElem.setAttribute( "coverageLayer", mAtlasCoverageLayer->id() );
|
||||
}
|
||||
else
|
||||
{
|
||||
atlasElem.setAttribute( "coverageLayer", "" );
|
||||
}
|
||||
atlasElem.setAttribute( "hideCoverage", mAtlasHideCoverage ? "true" : "false" );
|
||||
atlasElem.setAttribute( "fixedScale", mAtlasFixedScale ? "true" : "false" );
|
||||
atlasElem.setAttribute( "singleFile", mAtlasSingleFile ? "true" : "false" );
|
||||
atlasElem.setAttribute( "margin", QString::number(mAtlasMargin) );
|
||||
atlasElem.setAttribute( "filenamePattern", mAtlasFilenamePattern );
|
||||
|
||||
composerMapElem.appendChild( atlasElem );
|
||||
}
|
||||
|
||||
elem.appendChild( composerMapElem );
|
||||
return _writeXML( composerMapElem, doc );
|
||||
}
|
||||
@ -905,32 +865,6 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
|
||||
}
|
||||
}
|
||||
|
||||
// atlas
|
||||
QDomNodeList atlasNodeList = itemElem.elementsByTagName( "Atlas" );
|
||||
if ( atlasNodeList.size() > 0 )
|
||||
{
|
||||
mComposition->setAtlasMap( this );
|
||||
|
||||
QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
|
||||
|
||||
// look for stored layer name
|
||||
mAtlasCoverageLayer = 0;
|
||||
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
|
||||
for ( QMap<QString, QgsMapLayer*>::const_iterator it = layers.begin(); it != layers.end(); ++it )
|
||||
{
|
||||
if ( it.key() == atlasElem.attribute("coverageLayer") )
|
||||
{
|
||||
mAtlasCoverageLayer = dynamic_cast<QgsVectorLayer*>(it.value());
|
||||
break;
|
||||
}
|
||||
}
|
||||
mAtlasMargin = atlasElem.attribute( "margin", "0.0" ).toDouble();
|
||||
mAtlasHideCoverage = atlasElem.attribute( "hideCoverage", "false" ) == "true" ? true : false;
|
||||
mAtlasFixedScale = atlasElem.attribute( "fixedScale", "false" ) == "true" ? true : false;
|
||||
mAtlasSingleFile = atlasElem.attribute( "singleFile", "false" ) == "true" ? true : false;
|
||||
mAtlasFilenamePattern = atlasElem.attribute( "filenamePattern", "" );
|
||||
}
|
||||
|
||||
//restore general composer item properties
|
||||
QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
|
||||
if ( composerItemList.size() > 0 )
|
||||
|
@ -30,7 +30,6 @@ class QDomDocument;
|
||||
class QGraphicsView;
|
||||
class QPainter;
|
||||
class QgsFillSymbolV2;
|
||||
class QgsVectorLayer;
|
||||
|
||||
/** \ingroup MapComposer
|
||||
* \class QgsComposerMap
|
||||
@ -46,7 +45,7 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
|
||||
QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height );
|
||||
/** Constructor. Settings are read from project. */
|
||||
QgsComposerMap( QgsComposition *composition );
|
||||
virtual ~QgsComposerMap();
|
||||
~QgsComposerMap();
|
||||
|
||||
/** return correct graphics item type. Added in v1.7 */
|
||||
virtual int type() const { return ComposerMap; }
|
||||
@ -317,29 +316,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
|
||||
Usually, this function is called before adding the composer map to the composition*/
|
||||
void assignFreeId();
|
||||
|
||||
bool atlasHideCoverage() const { return mAtlasHideCoverage; }
|
||||
void setAtlasHideCoverage( bool hide ) { mAtlasHideCoverage = hide; }
|
||||
|
||||
bool atlasFixedScale() const { return mAtlasFixedScale; }
|
||||
void setAtlasFixedScale( bool fixed ) { mAtlasFixedScale = fixed; }
|
||||
|
||||
float atlasMargin() const { return mAtlasMargin; }
|
||||
void setAtlasMargin( float margin ) { mAtlasMargin = margin; }
|
||||
|
||||
QString atlasFilenamePattern() const { return mAtlasFilenamePattern; }
|
||||
void setAtlasFilenamePattern( const QString& pattern ) { mAtlasFilenamePattern = pattern; }
|
||||
|
||||
QgsVectorLayer* atlasCoverageLayer() const { return mAtlasCoverageLayer; }
|
||||
void setAtlasCoverageLayer( QgsVectorLayer* lmap );
|
||||
|
||||
bool atlasSingleFile() const { return mAtlasSingleFile; }
|
||||
void setAtlasSingleFile( bool single ) { mAtlasSingleFile = single; }
|
||||
|
||||
signals:
|
||||
void extentChanged();
|
||||
|
||||
void atlasCoverageLayerChanged( QgsVectorLayer* );
|
||||
|
||||
public slots:
|
||||
|
||||
/**Called if map canvas has changed*/
|
||||
@ -347,9 +326,6 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
|
||||
/**Call updateCachedImage if item is in render mode*/
|
||||
void renderModeUpdateCachedImage();
|
||||
|
||||
private slots:
|
||||
void syncAtlasCoverageLayer( QString );
|
||||
|
||||
private:
|
||||
|
||||
enum AnnotationCoordinate
|
||||
@ -462,13 +438,6 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
|
||||
/**True if annotation items, rubber band, etc. from the main canvas should be displayed*/
|
||||
bool mDrawCanvasItems;
|
||||
|
||||
bool mAtlasHideCoverage;
|
||||
bool mAtlasFixedScale;
|
||||
double mAtlasMargin;
|
||||
QString mAtlasFilenamePattern;
|
||||
QgsVectorLayer* mAtlasCoverageLayer;
|
||||
bool mAtlasSingleFile;
|
||||
|
||||
/**Draws the map grid*/
|
||||
void drawGrid( QPainter* p );
|
||||
void drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines );
|
||||
|
@ -14,8 +14,6 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "qgscomposition.h"
|
||||
#include "qgscomposeritem.h"
|
||||
#include "qgscomposerarrow.h"
|
||||
@ -28,275 +26,35 @@
|
||||
#include "qgscomposerpicture.h"
|
||||
#include "qgscomposerscalebar.h"
|
||||
#include "qgscomposershape.h"
|
||||
#include "qgscomposerlabel.h"
|
||||
#include "qgscomposerattributetable.h"
|
||||
#include "qgsaddremovemultiframecommand.h"
|
||||
#include "qgscomposermultiframecommand.h"
|
||||
#include "qgslogger.h"
|
||||
#include "qgspaintenginehack.h"
|
||||
#include "qgspaperitem.h"
|
||||
#include "qgsgeometry.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectordataprovider.h"
|
||||
#include "qgsexpression.h"
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QPainter>
|
||||
#include <QPrinter>
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
|
||||
/**
|
||||
* Private members of the QgsAtlasRendering class
|
||||
*/
|
||||
struct QgsAtlasRendering::QgsAtlasRenderingImpl
|
||||
{
|
||||
QgsComposition* composition;
|
||||
QgsCoordinateTransform transform;
|
||||
QString filenamePattern;
|
||||
QString currentFilename;
|
||||
int nFeatures;
|
||||
std::vector<QgsFeature> features;
|
||||
QgsRectangle origExtent;
|
||||
bool restoreLayer;
|
||||
std::auto_ptr<QgsExpression> filenameExpr;
|
||||
size_t pageNumber;
|
||||
size_t numberOfPages;
|
||||
};
|
||||
|
||||
QgsAtlasRendering::QgsAtlasRendering( QgsComposition* composition )
|
||||
{
|
||||
impl = std::auto_ptr<QgsAtlasRendering::QgsAtlasRenderingImpl>( new QgsAtlasRendering::QgsAtlasRenderingImpl() );
|
||||
impl->composition = composition;
|
||||
impl->nFeatures = 0;
|
||||
}
|
||||
|
||||
void QgsAtlasRendering::begin( const QString& filenamePattern )
|
||||
{
|
||||
if ( !impl->composition || !impl->composition->atlasMap() || !impl->composition->atlasMap()->atlasCoverageLayer() )
|
||||
return;
|
||||
|
||||
impl->filenamePattern = filenamePattern;
|
||||
|
||||
QgsVectorLayer* coverage = impl->composition->atlasMap()->atlasCoverageLayer();
|
||||
const QgsCoordinateReferenceSystem& coverage_crs = coverage->crs();
|
||||
const QgsCoordinateReferenceSystem& destination_crs = impl->composition->atlasMap()->mapRenderer()->destinationCrs();
|
||||
// transformation needed for feature geometries
|
||||
impl->transform.setSourceCrs( coverage_crs );
|
||||
impl->transform.setDestCRS( destination_crs );
|
||||
|
||||
QgsVectorDataProvider* provider = coverage->dataProvider();
|
||||
impl->nFeatures = provider->featureCount();
|
||||
|
||||
QgsFieldMap fieldmap = provider->fields();
|
||||
|
||||
if ( filenamePattern.size() > 0 )
|
||||
{
|
||||
impl->filenameExpr = std::auto_ptr<QgsExpression>( new QgsExpression( filenamePattern ) );
|
||||
// expression used to evaluate each filename
|
||||
// test for evaluation errors
|
||||
if ( impl->filenameExpr->hasParserError() )
|
||||
{
|
||||
throw std::runtime_error( "Filename parsing error: " + impl->filenameExpr->parserErrorString().toStdString() );
|
||||
}
|
||||
|
||||
// prepare the filename expression
|
||||
impl->filenameExpr->prepare( fieldmap );
|
||||
}
|
||||
|
||||
// select all features with all attributes
|
||||
provider->select( provider->attributeIndexes() );
|
||||
|
||||
// features must be stored in a list, since modifying the layer's extent rewinds nextFeature()
|
||||
QgsFeature feature;
|
||||
while ( provider->nextFeature( feature ) )
|
||||
{
|
||||
impl->features.push_back( feature );
|
||||
}
|
||||
|
||||
impl->origExtent = impl->composition->atlasMap()->extent();
|
||||
|
||||
impl->restoreLayer = false;
|
||||
QStringList& layerSet = impl->composition->mapRenderer()->layerSet();
|
||||
if ( impl->composition->atlasMap()->atlasHideCoverage() )
|
||||
{
|
||||
// look for the layer in the renderer's set
|
||||
int removeAt = layerSet.indexOf( coverage->id() );
|
||||
if ( removeAt != -1 )
|
||||
{
|
||||
impl->restoreLayer = true;
|
||||
layerSet.removeAt( removeAt );
|
||||
}
|
||||
}
|
||||
|
||||
// special columns for expressions
|
||||
QgsExpression::setSpecialColumn( "$numfeatures", QVariant( (int)impl->nFeatures ) );
|
||||
}
|
||||
|
||||
void QgsAtlasRendering::prepareForFeature( size_t featureI )
|
||||
{
|
||||
if ( !impl->composition || !impl->composition->atlasMap() || !impl->composition->atlasMap()->atlasCoverageLayer() )
|
||||
return;
|
||||
|
||||
QgsFeature* fit = &impl->features[featureI];
|
||||
|
||||
if ( impl->filenamePattern.size() > 0 )
|
||||
{
|
||||
QgsExpression::setSpecialColumn( "$feature", QVariant( (int)featureI + 1 ) );
|
||||
QVariant filenameRes = impl->filenameExpr->evaluate( &*fit );
|
||||
if ( impl->filenameExpr->hasEvalError() )
|
||||
{
|
||||
throw std::runtime_error( "Filename eval error: " + impl->filenameExpr->evalErrorString().toStdString() );
|
||||
}
|
||||
|
||||
impl->currentFilename = filenameRes.toString();
|
||||
}
|
||||
|
||||
//
|
||||
// compute the new extent
|
||||
// keep the original aspect ratio
|
||||
// and apply a margin
|
||||
|
||||
// QgsGeometry::boundingBox is expressed in the geometry"s native CRS
|
||||
// We have to transform the grometry to the destination CRS and ask for the bounding box
|
||||
// Note: we cannot directly take the transformation of the bounding box, since transformations are not linear
|
||||
|
||||
QgsGeometry tgeom( *fit->geometry() );
|
||||
tgeom.transform( impl->transform );
|
||||
QgsRectangle geom_rect = tgeom.boundingBox();
|
||||
|
||||
double xa1 = geom_rect.xMinimum();
|
||||
double xa2 = geom_rect.xMaximum();
|
||||
double ya1 = geom_rect.yMinimum();
|
||||
double ya2 = geom_rect.yMaximum();
|
||||
QgsRectangle new_extent = geom_rect;
|
||||
|
||||
// restore the original extent
|
||||
// (successive calls to setNewExtent tend to deform the original rectangle)
|
||||
impl->composition->atlasMap()->setNewExtent( impl->origExtent );
|
||||
|
||||
if ( impl->composition->atlasMap()->atlasFixedScale() )
|
||||
{
|
||||
// only translate, keep the original scale (i.e. width x height)
|
||||
|
||||
double geom_center_x = (xa1 + xa2) / 2.0;
|
||||
double geom_center_y = (ya1 + ya2) / 2.0;
|
||||
double xx = geom_center_x - impl->origExtent.width() / 2.0;
|
||||
double yy = geom_center_y - impl->origExtent.height() / 2.0;
|
||||
new_extent = QgsRectangle( xx,
|
||||
yy,
|
||||
xx + impl->origExtent.width(),
|
||||
yy + impl->origExtent.height() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// auto scale
|
||||
|
||||
double geom_ratio = geom_rect.width() / geom_rect.height();
|
||||
double map_ratio = impl->origExtent.width() / impl->origExtent.height();
|
||||
|
||||
// geometry height is too big
|
||||
if ( geom_ratio < map_ratio )
|
||||
{
|
||||
new_extent = QgsRectangle( (xa1 + xa2 + map_ratio * (ya1 - ya2)) / 2.0,
|
||||
ya1,
|
||||
xa1 + map_ratio * (ya2 - ya1),
|
||||
ya2);
|
||||
}
|
||||
// geometry width is too big
|
||||
else if ( geom_ratio > map_ratio )
|
||||
{
|
||||
new_extent = QgsRectangle( xa1,
|
||||
(ya1 + ya2 + (xa1 - xa2) / map_ratio) / 2.0,
|
||||
xa2,
|
||||
ya1 + (xa2 - xa1) / map_ratio);
|
||||
}
|
||||
if ( impl->composition->atlasMap()->atlasMargin() > 0.0 )
|
||||
{
|
||||
new_extent.scale( 1 + impl->composition->atlasMap()->atlasMargin() );
|
||||
}
|
||||
}
|
||||
|
||||
// evaluate label expressions
|
||||
QList<QgsComposerLabel*> labels;
|
||||
impl->composition->composerItems( labels );
|
||||
QgsExpression::setSpecialColumn( "$feature", QVariant( (int)featureI + 1 ) );
|
||||
|
||||
for ( QList<QgsComposerLabel*>::iterator lit = labels.begin(); lit != labels.end(); ++lit )
|
||||
{
|
||||
(*lit)->setExpressionContext( fit, impl->composition->atlasMap()->atlasCoverageLayer() );
|
||||
}
|
||||
|
||||
// set the new extent (and render)
|
||||
impl->composition->atlasMap()->setNewExtent( new_extent );
|
||||
}
|
||||
|
||||
size_t QgsAtlasRendering::numFeatures() const
|
||||
{
|
||||
return impl->nFeatures;
|
||||
}
|
||||
|
||||
const QString& QgsAtlasRendering::currentFilename() const
|
||||
{
|
||||
return impl->currentFilename;
|
||||
}
|
||||
|
||||
void QgsAtlasRendering::end()
|
||||
{
|
||||
if ( !impl->composition || !impl->composition->atlasMap() || !impl->composition->atlasMap()->atlasCoverageLayer() )
|
||||
return;
|
||||
|
||||
// reset label expression contexts
|
||||
QList<QgsComposerLabel*> labels;
|
||||
impl->composition->composerItems( labels );
|
||||
for ( QList<QgsComposerLabel*>::iterator lit = labels.begin(); lit != labels.end(); ++lit )
|
||||
{
|
||||
(*lit)->setExpressionContext( 0, 0 );
|
||||
}
|
||||
|
||||
// restore the coverage visibility
|
||||
if ( impl->restoreLayer )
|
||||
{
|
||||
QStringList& layerSet = impl->composition->mapRenderer()->layerSet();
|
||||
QgsVectorLayer* coverage = impl->composition->atlasMap()->atlasCoverageLayer();
|
||||
|
||||
layerSet.push_back( coverage->id() );
|
||||
impl->composition->atlasMap()->cache();
|
||||
impl->composition->atlasMap()->update();
|
||||
}
|
||||
impl->composition->atlasMap()->setNewExtent( impl->origExtent );
|
||||
}
|
||||
|
||||
QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ) :
|
||||
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
|
||||
mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 ),
|
||||
mAtlasMap( 0 )
|
||||
QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ):
|
||||
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
|
||||
mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 )
|
||||
{
|
||||
setBackgroundBrush( Qt::gray );
|
||||
addPaperItem();
|
||||
|
||||
mPrintResolution = 300; //hardcoded default
|
||||
loadSettings();
|
||||
|
||||
// declare special columns with a default value
|
||||
QgsExpression::setSpecialColumn( "$page", QVariant((int)0) );
|
||||
QgsExpression::setSpecialColumn( "$feature", QVariant((int)0) );
|
||||
QgsExpression::setSpecialColumn( "$numpages", QVariant((int)0) );
|
||||
QgsExpression::setSpecialColumn( "$numfeatures", QVariant((int)0) );
|
||||
}
|
||||
|
||||
QgsComposition::QgsComposition():
|
||||
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ),
|
||||
mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 ),
|
||||
mAtlasMap( 0 )
|
||||
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ),
|
||||
mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 )
|
||||
{
|
||||
loadSettings();
|
||||
|
||||
QgsExpression::setSpecialColumn( "$page", QVariant((int)0) );
|
||||
QgsExpression::setSpecialColumn( "$feature", QVariant((int)0) );
|
||||
QgsExpression::setSpecialColumn( "$numpages", QVariant((int)0) );
|
||||
QgsExpression::setSpecialColumn( "$numfeatures", QVariant((int)0) );
|
||||
}
|
||||
|
||||
QgsComposition::~QgsComposition()
|
||||
@ -354,10 +112,6 @@ void QgsComposition::setNumPages( int pages )
|
||||
mPages.removeLast();
|
||||
}
|
||||
}
|
||||
|
||||
// update the corresponding variable
|
||||
QgsExpression::setSpecialColumn( "$numpages", QVariant((int)numPages()) );
|
||||
|
||||
emit nPagesChanged();
|
||||
}
|
||||
|
||||
@ -392,16 +146,6 @@ QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position )
|
||||
return 0;
|
||||
}
|
||||
|
||||
int QgsComposition::pageNumberAt( const QPointF& position ) const
|
||||
{
|
||||
return position.y() / (paperHeight() + spaceBetweenPages() );
|
||||
}
|
||||
|
||||
int QgsComposition::itemPageNumber( const QgsComposerItem* item ) const
|
||||
{
|
||||
return pageNumberAt( QPointF( item->transform().dx(), item->transform().dy()) );
|
||||
}
|
||||
|
||||
QList<QgsComposerItem*> QgsComposition::selectedComposerItems()
|
||||
{
|
||||
QList<QgsComposerItem*> composerItemList;
|
||||
@ -1529,11 +1273,6 @@ void QgsComposition::addComposerHtmlFrame( QgsComposerHtml* html, QgsComposerFra
|
||||
void QgsComposition::removeComposerItem( QgsComposerItem* item, bool createCommand )
|
||||
{
|
||||
QgsComposerMap* map = dynamic_cast<QgsComposerMap *>( item );
|
||||
if ( map && mAtlasMap == map )
|
||||
{
|
||||
mAtlasMap = 0;
|
||||
}
|
||||
|
||||
if ( !map || !map->isDrawing() ) //don't delete a composer map while it draws
|
||||
{
|
||||
removeItem( item );
|
||||
@ -1714,8 +1453,6 @@ void QgsComposition::addPaperItem()
|
||||
addItem( paperItem );
|
||||
paperItem->setZValue( 0 );
|
||||
mPages.push_back( paperItem );
|
||||
|
||||
QgsExpression::setSpecialColumn( "$numpages", QVariant((int)mPages.size()) );
|
||||
}
|
||||
|
||||
void QgsComposition::removePaperItems()
|
||||
@ -1725,7 +1462,6 @@ void QgsComposition::removePaperItems()
|
||||
delete mPages.at( i );
|
||||
}
|
||||
mPages.clear();
|
||||
QgsExpression::setSpecialColumn( "$numpages", QVariant((int)0) );
|
||||
}
|
||||
|
||||
void QgsComposition::deleteAndRemoveMultiFrames()
|
||||
@ -1738,25 +1474,29 @@ void QgsComposition::deleteAndRemoveMultiFrames()
|
||||
mMultiFrames.clear();
|
||||
}
|
||||
|
||||
void QgsComposition::beginPrintAsPDF( QPrinter& printer, const QString& file )
|
||||
void QgsComposition::exportAsPDF( const QString& file )
|
||||
{
|
||||
QPrinter printer;
|
||||
printer.setOutputFormat( QPrinter::PdfFormat );
|
||||
printer.setOutputFileName( file );
|
||||
printer.setPaperSize( QSizeF( paperWidth(), paperHeight() ), QPrinter::Millimeter );
|
||||
|
||||
QgsPaintEngineHack::fixEngineFlags( printer.paintEngine() );
|
||||
}
|
||||
|
||||
void QgsComposition::exportAsPDF( const QString& file )
|
||||
{
|
||||
QPrinter printer;
|
||||
beginPrintAsPDF( printer, file );
|
||||
print( printer );
|
||||
}
|
||||
|
||||
void QgsComposition::doPrint( QPrinter& printer, QPainter& p )
|
||||
void QgsComposition::print( QPrinter &printer )
|
||||
{
|
||||
//QgsComposition starts page numbering at 0
|
||||
//set resolution based on composer setting
|
||||
printer.setFullPage( true );
|
||||
printer.setColorMode( QPrinter::Color );
|
||||
|
||||
//set user-defined resolution
|
||||
printer.setResolution( printResolution() );
|
||||
|
||||
QPainter p( &printer );
|
||||
|
||||
//QgsComposition starts page numbering at 0
|
||||
int fromPage = ( printer.fromPage() < 1 ) ? 0 : printer.fromPage() - 1 ;
|
||||
int toPage = ( printer.toPage() < 1 ) ? numPages() - 1 : printer.toPage() - 1;
|
||||
|
||||
@ -1791,23 +1531,6 @@ void QgsComposition::doPrint( QPrinter& printer, QPainter& p )
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposition::beginPrint( QPrinter &printer )
|
||||
{
|
||||
//set resolution based on composer setting
|
||||
printer.setFullPage( true );
|
||||
printer.setColorMode( QPrinter::Color );
|
||||
|
||||
//set user-defined resolution
|
||||
printer.setResolution( printResolution() );
|
||||
}
|
||||
|
||||
void QgsComposition::print( QPrinter &printer )
|
||||
{
|
||||
beginPrint( printer );
|
||||
QPainter p( &printer );
|
||||
doPrint( printer, p );
|
||||
}
|
||||
|
||||
QImage QgsComposition::printPageAsRaster( int page )
|
||||
{
|
||||
//print out via QImage, code copied from on_mActionExportAsImage_activated
|
||||
@ -1854,35 +1577,6 @@ void QgsComposition::renderPage( QPainter* p, int page )
|
||||
mPlotStyle = savedPlotStyle;
|
||||
}
|
||||
|
||||
void QgsComposition::setAtlasMap( QgsComposerMap* map )
|
||||
{
|
||||
mAtlasMap = map;
|
||||
if ( map != 0 )
|
||||
{
|
||||
QObject::connect( map, SIGNAL( atlasCoverageLayerChanged( QgsVectorLayer* )), this, SLOT( onAtlasCoverageChanged( QgsVectorLayer* ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
QObject::disconnect( map, SIGNAL( atlasCoverageLayerChanged( QgsVectorLayer* )), this, SLOT( onAtlasCoverageChanged( QgsVectorLayer* ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposition::onAtlasCoverageChanged( QgsVectorLayer* )
|
||||
{
|
||||
// update variables
|
||||
if ( mAtlasMap != 0 && mAtlasMap->atlasCoverageLayer() != 0 )
|
||||
{
|
||||
QgsVectorDataProvider* provider = mAtlasMap->atlasCoverageLayer()->dataProvider();
|
||||
QgsExpression::setSpecialColumn( "$numfeatures", QVariant( (int)provider->featureCount() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
QgsExpression::setSpecialColumn( "$numfeatures", QVariant( (int)0 ) );
|
||||
}
|
||||
//
|
||||
QgsExpression::setSpecialColumn( "$numpages", QVariant( (int)numPages() ) );
|
||||
}
|
||||
|
||||
QString QgsComposition::encodeStringForXML( const QString& str )
|
||||
{
|
||||
QString modifiedStr( str );
|
||||
|
@ -16,15 +16,11 @@
|
||||
#ifndef QGSCOMPOSITION_H
|
||||
#define QGSCOMPOSITION_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QGraphicsScene>
|
||||
#include <QLinkedList>
|
||||
#include <QSet>
|
||||
#include <QUndoStack>
|
||||
#include <QPrinter>
|
||||
#include <QPainter>
|
||||
|
||||
#include "qgsaddremoveitemcommand.h"
|
||||
#include "qgscomposeritemcommand.h"
|
||||
@ -48,37 +44,6 @@ class QgsComposerShape;
|
||||
class QgsComposerAttributeTable;
|
||||
class QgsComposerMultiFrame;
|
||||
class QgsComposerMultiFrameCommand;
|
||||
class QgsVectorLayer;
|
||||
|
||||
/** \ingroup MapComposer
|
||||
* Class used to render an Atlas, iterating over geometry features.
|
||||
* prepareForFeature() modifies the atlas map's extent to zoom on the given feature.
|
||||
* This class is used for printing, exporting to PDF and images.
|
||||
* */
|
||||
class QgsAtlasRendering
|
||||
{
|
||||
public:
|
||||
QgsAtlasRendering( QgsComposition* composition );
|
||||
|
||||
/** Begins the rendering. Sets an optional output filename pattern */
|
||||
void begin( const QString& filenamePattern = "" );
|
||||
/** Ends the rendering. Restores original extent*/
|
||||
void end();
|
||||
|
||||
/** Returns the number of features in the coverage layer */
|
||||
size_t numFeatures() const;
|
||||
|
||||
/** Prepare the atlas map for the given feature. Sets the extent and context variables */
|
||||
void prepareForFeature( size_t i );
|
||||
|
||||
/** Returns the current filename. Must be called after prepareForFeature( i ) */
|
||||
const QString& currentFilename() const;
|
||||
|
||||
private:
|
||||
// Use the PImpl idiom for private members.
|
||||
struct QgsAtlasRenderingImpl;
|
||||
std::auto_ptr<QgsAtlasRenderingImpl> impl;
|
||||
};
|
||||
|
||||
/** \ingroup MapComposer
|
||||
* Graphics scene for map printing. The class manages the paper item which always
|
||||
@ -150,12 +115,6 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
|
||||
/**Returns the topmost composer item. Ignores mPaperItem*/
|
||||
QgsComposerItem* composerItemAt( const QPointF & position );
|
||||
|
||||
/** Returns the page number (0-bsaed) given a coordinate */
|
||||
int pageNumberAt( const QPointF& position ) const;
|
||||
|
||||
/** Returns on which page number (0-based) is displayed an item */
|
||||
int itemPageNumber( const QgsComposerItem* ) const;
|
||||
|
||||
QList<QgsComposerItem*> selectedComposerItems();
|
||||
|
||||
/**Returns pointers to all composer maps in the scene
|
||||
@ -200,9 +159,6 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
|
||||
/**Returns pointer to map renderer of qgis map canvas*/
|
||||
QgsMapRenderer* mapRenderer() {return mMapRenderer;}
|
||||
|
||||
QgsComposerMap* atlasMap() { return mAtlasMap; }
|
||||
void setAtlasMap( QgsComposerMap* map );
|
||||
|
||||
QgsComposition::PlotStyle plotStyle() const {return mPlotStyle;}
|
||||
void setPlotStyle( QgsComposition::PlotStyle style ) {mPlotStyle = style;}
|
||||
|
||||
@ -315,19 +271,10 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
|
||||
|
||||
//printing
|
||||
|
||||
/** Prepare the printer for printing */
|
||||
void beginPrint( QPrinter& printer );
|
||||
/** Prepare the printer for printing in a PDF */
|
||||
void beginPrintAsPDF( QPrinter& printer, const QString& file );
|
||||
/** Print on a preconfigured printer */
|
||||
void doPrint( QPrinter& printer, QPainter& painter );
|
||||
|
||||
/** Convenience function that prepares the printer and prints */
|
||||
void print( QPrinter &printer );
|
||||
|
||||
/** Convenience function that prepares the printer for printing in PDF and prints */
|
||||
void exportAsPDF( const QString& file );
|
||||
|
||||
void print( QPrinter &printer );
|
||||
|
||||
//! print composer page to image
|
||||
//! If the image does not fit into memory, a null image is returned
|
||||
QImage printPageAsRaster( int page );
|
||||
@ -340,9 +287,6 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
|
||||
/**Casts object to the proper subclass type and calls corresponding itemAdded signal*/
|
||||
void sendItemAddedSignal( QgsComposerItem* item );
|
||||
|
||||
private slots:
|
||||
void onAtlasCoverageChanged( QgsVectorLayer* );
|
||||
|
||||
private:
|
||||
/**Pointer to map renderer of QGIS main map*/
|
||||
QgsMapRenderer* mMapRenderer;
|
||||
@ -380,8 +324,6 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
|
||||
QgsComposerItemCommand* mActiveItemCommand;
|
||||
QgsComposerMultiFrameCommand* mActiveMultiFrameCommand;
|
||||
|
||||
QgsComposerMap* mAtlasMap;
|
||||
|
||||
QgsComposition(); //default constructor is forbidden
|
||||
|
||||
/**Reset z-values of items based on position in z list*/
|
||||
|
@ -799,19 +799,6 @@ static QVariant fcnFormatNumber( const QVariantList& values, QgsFeature*, QgsExp
|
||||
return QString( "%L1" ).arg( value, 0, 'f', places );
|
||||
}
|
||||
|
||||
static QVariant fcnFormatDate( const QVariantList& values, QgsFeature*, QgsExpression* parent )
|
||||
{
|
||||
QDateTime dt = getDateTimeValue( values.at( 0 ), parent );
|
||||
QString format = getStringValue( values.at( 1 ), parent );
|
||||
return dt.toString( format );
|
||||
}
|
||||
|
||||
static QVariant fcnSpecialColumn( const QVariantList& values, QgsFeature* /*f*/, QgsExpression* parent )
|
||||
{
|
||||
QString varName = getStringValue( values.at( 0 ), parent );
|
||||
return QgsExpression::specialColumn( varName );
|
||||
}
|
||||
|
||||
QList<QgsExpression::FunctionDef> QgsExpression::gmBuiltinFunctions;
|
||||
|
||||
const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
|
||||
@ -868,7 +855,6 @@ const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
|
||||
<< FunctionDef( "rpad", 3, fcnRPad, QObject::tr( "String" ) )
|
||||
<< FunctionDef( "lpad", 3, fcnLPad, QObject::tr( "String" ) )
|
||||
<< FunctionDef( "format_number", 2, fcnFormatNumber, QObject::tr( "String" ) )
|
||||
<< FunctionDef( "format_date", 2, fcnFormatDate, QObject::tr( "String" ) )
|
||||
|
||||
// geometry accessors
|
||||
<< FunctionDef( "xat", 1, fcnXat, QObject::tr( "Geometry" ), "", true )
|
||||
@ -882,61 +868,12 @@ const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
|
||||
<< FunctionDef( "$rownum", 0, fcnRowNumber, QObject::tr( "Record" ) )
|
||||
<< FunctionDef( "$id", 0, fcnFeatureId, QObject::tr( "Record" ) )
|
||||
<< FunctionDef( "$scale", 0, fcnScale, QObject::tr( "Record" ) )
|
||||
// private functions
|
||||
<< FunctionDef( "_specialcol_", 1, fcnSpecialColumn, QObject::tr( "Special" ) )
|
||||
;
|
||||
}
|
||||
|
||||
return gmBuiltinFunctions;
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> QgsExpression::gmSpecialColumns;
|
||||
|
||||
void QgsExpression::setSpecialColumn( const QString& name, QVariant variant )
|
||||
{
|
||||
int fnIdx = functionIndex( name );
|
||||
if ( fnIdx != -1 )
|
||||
{
|
||||
// function of the same name already exists
|
||||
return;
|
||||
}
|
||||
gmSpecialColumns[ name ] = variant;
|
||||
}
|
||||
|
||||
void QgsExpression::unsetSpecialColumn( const QString& name )
|
||||
{
|
||||
QMap<QString, QVariant>::iterator fit = gmSpecialColumns.find( name );
|
||||
if ( fit != gmSpecialColumns.end() )
|
||||
{
|
||||
gmSpecialColumns.erase( fit );
|
||||
}
|
||||
}
|
||||
|
||||
QVariant QgsExpression::specialColumn( const QString& name )
|
||||
{
|
||||
int fnIdx = functionIndex( name );
|
||||
if ( fnIdx != -1 )
|
||||
{
|
||||
// function of the same name already exists
|
||||
return QVariant();
|
||||
}
|
||||
QMap<QString, QVariant>::iterator it = gmSpecialColumns.find( name );
|
||||
if ( it == gmSpecialColumns.end() )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
return it.value();
|
||||
}
|
||||
|
||||
QList<QgsExpression::FunctionDef> QgsExpression::specialColumns()
|
||||
{
|
||||
QList<FunctionDef> defs;
|
||||
for ( QMap<QString, QVariant>::const_iterator it = gmSpecialColumns.begin(); it != gmSpecialColumns.end(); ++it )
|
||||
{
|
||||
defs << FunctionDef( it.key(), 0, 0, QObject::tr( "Record" ));
|
||||
}
|
||||
return defs;
|
||||
}
|
||||
|
||||
bool QgsExpression::isFunctionName( QString name )
|
||||
{
|
||||
@ -1112,27 +1049,12 @@ void QgsExpression::acceptVisitor( QgsExpression::Visitor& v )
|
||||
mRootNode->accept( v );
|
||||
}
|
||||
|
||||
QString QgsExpression::replaceExpressionText( QString action, QgsFeature* feat,
|
||||
QString QgsExpression::replaceExpressionText( QString action, QgsFeature &feat,
|
||||
QgsVectorLayer* layer,
|
||||
const QMap<QString, QVariant> *substitutionMap )
|
||||
{
|
||||
QString expr_action;
|
||||
|
||||
QMap<QString, QVariant> savedValues;
|
||||
if ( substitutionMap )
|
||||
{
|
||||
// variables with a local scope (must be restored after evaluation)
|
||||
for ( QMap<QString, QVariant>::const_iterator sit = substitutionMap->begin(); sit != substitutionMap->end(); ++sit )
|
||||
{
|
||||
QVariant oldValue = QgsExpression::specialColumn( sit.key() );
|
||||
if ( !oldValue.isNull() )
|
||||
savedValues.insert( sit.key(), oldValue );
|
||||
|
||||
// set the new value
|
||||
QgsExpression::setSpecialColumn( sit.key(), sit.value() );
|
||||
}
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
while ( index < action.size() )
|
||||
{
|
||||
@ -1148,6 +1070,12 @@ QString QgsExpression::replaceExpressionText( QString action, QgsFeature* feat,
|
||||
QString to_replace = rx.cap( 1 ).trimmed();
|
||||
QgsDebugMsg( "Found expression: " + to_replace );
|
||||
|
||||
if ( substitutionMap && substitutionMap->contains( to_replace ) )
|
||||
{
|
||||
expr_action += action.mid( start, pos - start ) + substitutionMap->value( to_replace ).toString();
|
||||
continue;
|
||||
}
|
||||
|
||||
QgsExpression exp( to_replace );
|
||||
if ( exp.hasParserError() )
|
||||
{
|
||||
@ -1156,15 +1084,7 @@ QString QgsExpression::replaceExpressionText( QString action, QgsFeature* feat,
|
||||
continue;
|
||||
}
|
||||
|
||||
QVariant result;
|
||||
if ( layer )
|
||||
{
|
||||
result = exp.evaluate( feat, layer->pendingFields() );
|
||||
}
|
||||
else
|
||||
{
|
||||
result = exp.evaluate( feat );
|
||||
}
|
||||
QVariant result = exp.evaluate( &feat, layer->pendingFields() );
|
||||
if ( exp.hasEvalError() )
|
||||
{
|
||||
QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() );
|
||||
@ -1177,24 +1097,10 @@ QString QgsExpression::replaceExpressionText( QString action, QgsFeature* feat,
|
||||
}
|
||||
|
||||
expr_action += action.mid( index );
|
||||
|
||||
// restore overwritten local values
|
||||
for ( QMap<QString, QVariant>::const_iterator sit = savedValues.begin(); sit != savedValues.end(); ++sit )
|
||||
{
|
||||
QgsExpression::setSpecialColumn( sit.key(), sit.value() );
|
||||
}
|
||||
|
||||
return expr_action;
|
||||
}
|
||||
|
||||
|
||||
QString QgsExpression::replaceExpressionText( QString action, QgsFeature& feat,
|
||||
QgsVectorLayer* layer,
|
||||
const QMap<QString, QVariant> *substitutionMap )
|
||||
{
|
||||
return replaceExpressionText( action, &feat, layer, substitutionMap );
|
||||
}
|
||||
|
||||
QgsExpression::Node* QgsExpression::Node::createFromOgcFilter( QDomElement &element, QString &errorMessage )
|
||||
{
|
||||
if ( element.isNull() )
|
||||
@ -2142,11 +2048,7 @@ QgsExpression::Node* QgsExpression::NodeLiteral::createFromOgcFilter( QDomElemen
|
||||
|
||||
QVariant QgsExpression::NodeColumnRef::eval( QgsExpression* /*parent*/, QgsFeature* f )
|
||||
{
|
||||
if ( f )
|
||||
{
|
||||
return f->attributeMap()[mIndex];
|
||||
}
|
||||
return QVariant("[" + mName + "]");
|
||||
return f->attributeMap()[mIndex];
|
||||
}
|
||||
|
||||
bool QgsExpression::NodeColumnRef::prepare( QgsExpression* parent, const QgsFieldMap& fields )
|
||||
|
@ -122,13 +122,6 @@ class CORE_EXPORT QgsExpression
|
||||
//! Return the number used for $rownum special column
|
||||
int currentRowNumber() { return mRowNumber; }
|
||||
|
||||
//! Assign a special column
|
||||
static void setSpecialColumn( const QString& name, QVariant value );
|
||||
//! Unset a special column
|
||||
static void unsetSpecialColumn( const QString& name );
|
||||
//! Return the value of the given special column or a null QVariant if undefined
|
||||
static QVariant specialColumn( const QString& name );
|
||||
|
||||
void setScale( double scale ) { mScale = scale; }
|
||||
|
||||
int scale() {return mScale; }
|
||||
@ -147,14 +140,10 @@ class CORE_EXPORT QgsExpression
|
||||
Additional substitutions can be passed through the substitutionMap
|
||||
parameter
|
||||
*/
|
||||
static QString replaceExpressionText( QString action, QgsFeature* feat,
|
||||
static QString replaceExpressionText( QString action, QgsFeature &feat,
|
||||
QgsVectorLayer* layer,
|
||||
const QMap<QString, QVariant> *substitutionMap = 0 );
|
||||
|
||||
|
||||
static QString replaceExpressionText( QString action, QgsFeature& feat,
|
||||
QgsVectorLayer* layer,
|
||||
const QMap<QString, QVariant> *substitutionMap = 0 );
|
||||
//
|
||||
|
||||
enum UnaryOperator
|
||||
@ -237,11 +226,6 @@ class CORE_EXPORT QgsExpression
|
||||
*/
|
||||
static int functionCount();
|
||||
|
||||
/**
|
||||
* Returns a list of special Column definitions
|
||||
*/
|
||||
static QList<FunctionDef> specialColumns();
|
||||
|
||||
//! return quoted column reference (in double quotes)
|
||||
static QString quotedColumnRef( QString name ) { return QString( "\"%1\"" ).arg( name.replace( "\"", "\"\"" ) ); }
|
||||
//! return quoted string (in single quotes)
|
||||
@ -548,8 +532,6 @@ class CORE_EXPORT QgsExpression
|
||||
int mRowNumber;
|
||||
double mScale;
|
||||
|
||||
static QMap<QString, QVariant> gmSpecialColumns;
|
||||
|
||||
QgsDistanceArea* mCalc;
|
||||
};
|
||||
|
||||
|
@ -193,23 +193,11 @@ expression:
|
||||
int fnIndex = QgsExpression::functionIndex(*$1);
|
||||
if (fnIndex == -1)
|
||||
{
|
||||
QVariant userVar = QgsExpression::specialColumn( *$1 );
|
||||
if ( userVar.isNull() )
|
||||
{
|
||||
exp_error("Special column is not known");
|
||||
YYERROR;
|
||||
}
|
||||
// $var is equivalent to _specialcol_( "$var" )
|
||||
QgsExpression::NodeList* args = new QgsExpression::NodeList();
|
||||
QgsExpression::NodeLiteral* literal = new QgsExpression::NodeLiteral( *$1 );
|
||||
args->append( literal );
|
||||
$$ = new QgsExpression::NodeFunction( QgsExpression::functionIndex( "_specialcol_" ), args );
|
||||
exp_error("Special column is not known");
|
||||
YYERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
$$ = new QgsExpression::NodeFunction( fnIndex, NULL );
|
||||
delete $1;
|
||||
}
|
||||
$$ = new QgsExpression::NodeFunction( fnIndex, NULL );
|
||||
delete $1;
|
||||
}
|
||||
|
||||
// literals
|
||||
|
@ -311,13 +311,13 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
|
||||
}
|
||||
if ( composition() )
|
||||
{
|
||||
QgsComposerMap* composerMap = new QgsComposerMap( composition(), mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height() );
|
||||
composition()->addComposerMap( composerMap );
|
||||
scene()->removeItem( mRubberBandItem );
|
||||
delete mRubberBandItem;
|
||||
mRubberBandItem = 0;
|
||||
emit actionFinished();
|
||||
composition()->pushAddRemoveCommand( composerMap, tr( "Map added" ) );
|
||||
QgsComposerMap* composerMap = new QgsComposerMap( composition(), mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height() );
|
||||
composition()->addComposerMap( composerMap );
|
||||
scene()->removeItem( mRubberBandItem );
|
||||
delete mRubberBandItem;
|
||||
mRubberBandItem = 0;
|
||||
emit actionFinished();
|
||||
composition()->pushAddRemoveCommand( composerMap, tr( "Map added" ) );
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -90,20 +90,11 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
|
||||
{
|
||||
QgsExpression::FunctionDef func = QgsExpression::BuiltinFunctions()[i];
|
||||
QString name = func.mName;
|
||||
if ( name.startsWith( "_" ) ) // do not display private functions
|
||||
continue;
|
||||
if ( func.mParams >= 1 )
|
||||
name += "(";
|
||||
registerItem( func.mGroup, func.mName, " " + name + " " );
|
||||
}
|
||||
|
||||
QList<QgsExpression::FunctionDef> specials = QgsExpression::specialColumns();
|
||||
for ( int i = 0; i < specials.size(); ++i )
|
||||
{
|
||||
QString name = specials[i].mName;
|
||||
registerItem( specials[i].mGroup, name, " " + name + " " );
|
||||
}
|
||||
|
||||
#if QT_VERSION >= 0x040700
|
||||
txtSearchEdit->setPlaceholderText( tr( "Search" ) );
|
||||
#endif
|
||||
@ -268,6 +259,8 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
|
||||
|
||||
QgsExpression exp( text );
|
||||
|
||||
// TODO We could do this without a layer.
|
||||
// Maybe just calling exp.evaluate()?
|
||||
if ( mLayer )
|
||||
{
|
||||
if ( !mFeature.isValid() )
|
||||
@ -289,15 +282,6 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
|
||||
lblPreview->setText( "" );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No layer defined
|
||||
QVariant value = exp.evaluate();
|
||||
if ( !exp.hasEvalError() )
|
||||
{
|
||||
lblPreview->setText( value.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( exp.hasParserError() || exp.hasEvalError() )
|
||||
{
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>307</width>
|
||||
<height>525</height>
|
||||
<width>274</width>
|
||||
<height>488</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -30,8 +30,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>276</width>
|
||||
<height>503</height>
|
||||
<width>271</width>
|
||||
<height>470</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@ -45,14 +45,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="mFontColorButton">
|
||||
<property name="text">
|
||||
<string>Font color...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="buttonGroup1">
|
||||
<property name="title">
|
||||
<string>Horizontal Alignment:</string>
|
||||
@ -98,7 +98,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="buttonGroup2">
|
||||
<property name="title">
|
||||
<string>Vertical Alignment:</string>
|
||||
@ -141,7 +141,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QDoubleSpinBox" name="mMarginDoubleSpinBox">
|
||||
<property name="prefix">
|
||||
<string>Margin </string>
|
||||
@ -151,7 +151,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="mRotationLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
@ -170,14 +170,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<item row="6" column="1">
|
||||
<widget class="QDoubleSpinBox" name="mRotationSpinBox">
|
||||
<property name="maximum">
|
||||
<double>360.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="mFontButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
@ -190,13 +190,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="mInsertExpressionButton">
|
||||
<property name="text">
|
||||
<string>Insert an expression</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
@ -50,9 +50,9 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>374</width>
|
||||
<height>549</height>
|
||||
<y>-109</y>
|
||||
<width>370</width>
|
||||
<height>523</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@ -220,8 +220,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>393</width>
|
||||
<height>162</height>
|
||||
<width>367</width>
|
||||
<height>170</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>450</width>
|
||||
<height>501</height>
|
||||
<width>265</width>
|
||||
<height>483</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -25,55 +25,23 @@
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QToolBox" name="toolBox">
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>3</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>437</width>
|
||||
<height>408</height>
|
||||
<width>255</width>
|
||||
<height>392</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
<string>Map</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="7" column="1">
|
||||
<widget class="QComboBox" name="mOverviewFrameMapComboBox"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QComboBox" name="mPreviewModeComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="9" column="0" colspan="2">
|
||||
<item row="7" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -89,35 +57,24 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<item row="2" column="0">
|
||||
<widget class="QComboBox" name="mPreviewModeComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="mUpdatePreviewButton">
|
||||
<property name="text">
|
||||
<string>Update preview</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="mOverviewFrameStyleLabel">
|
||||
<property name="text">
|
||||
<string>Overview style</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QPushButton" name="mOverviewFrameStyleButton">
|
||||
<property name="text">
|
||||
<string>Change...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="mOverviewFrameMapLabel">
|
||||
<property name="text">
|
||||
<string>Overview frame</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<item row="4" column="0" colspan="2">
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
@ -231,7 +188,23 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -247,6 +220,30 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QComboBox" name="mOverviewFrameMapComboBox"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="mOverviewFrameMapLabel">
|
||||
<property name="text">
|
||||
<string>Overview frame</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="mOverviewFrameStyleLabel">
|
||||
<property name="text">
|
||||
<string>Overview style</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QPushButton" name="mOverviewFrameStyleButton">
|
||||
<property name="text">
|
||||
<string>Change...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2">
|
||||
@ -254,8 +251,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>450</width>
|
||||
<height>377</height>
|
||||
<width>255</width>
|
||||
<height>392</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@ -362,8 +359,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>437</width>
|
||||
<height>893</height>
|
||||
<width>238</width>
|
||||
<height>770</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@ -790,153 +787,6 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>450</width>
|
||||
<height>377</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
<string>Atlas</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_9">
|
||||
<item row="4" column="0">
|
||||
<spacer name="verticalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>76</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="mIsAtlasCheckBox">
|
||||
<property name="text">
|
||||
<string>Make it the atlas map</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QFrame" name="mAtlasFrame">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_7" rowstretch="0,0,0,0,0,0,0,0,0" columnstretch="0,0,0">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="mAtlasHideCoverageCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>Hide the coverage layer when generating the output</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Hidden coverage layer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Margin around coverage</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Output filename expression</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="mAtlasMarginSpinBox">
|
||||
<property name="suffix">
|
||||
<string> %</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<widget class="QToolButton" name="mAtlasFilenameExpressionButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLineEdit" name="mAtlasFilenamePatternEdit"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Coverage layer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="mAtlasCoverageLayerComboBox">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::NoContextMenu</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="mAtlasFixedScaleCheckBox">
|
||||
<property name="text">
|
||||
<string>Fixed scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="mAtlasSingleFileCheckBox">
|
||||
<property name="text">
|
||||
<string>Single file export when possible</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -101,8 +101,6 @@ ADD_QGIS_TEST(rulebasedrenderertest testqgsrulebasedrenderer.cpp)
|
||||
ADD_QGIS_TEST(ziplayertest testziplayer.cpp)
|
||||
ADD_QGIS_TEST(dataitemtest testqgsdataitem.cpp)
|
||||
ADD_QGIS_TEST(composermaptest testqgscomposermap.cpp)
|
||||
ADD_QGIS_TEST(composermapatlastest testqgscomposermapatlas.cpp)
|
||||
ADD_QGIS_TEST(composerlabeltest testqgscomposerlabel.cpp)
|
||||
ADD_QGIS_TEST(stylev2test testqgsstylev2.cpp)
|
||||
#ADD_QGIS_TEST(composerhtmltest testqgscomposerhtml.cpp )
|
||||
ADD_QGIS_TEST(rectangletest testqgsrectangle.cpp)
|
||||
|
@ -1,181 +0,0 @@
|
||||
/***************************************************************************
|
||||
testqgscomposerlabel.cpp
|
||||
----------------------
|
||||
begin : Sept 2012
|
||||
copyright : (C) 2012 by Hugo Mercier
|
||||
email : hugo dot mercier at oslandia dot 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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgsapplication.h"
|
||||
#include "qgscomposition.h"
|
||||
#include "qgscomposerlabel.h"
|
||||
#include "qgsmaplayerregistry.h"
|
||||
#include "qgsmaprenderer.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectordataprovider.h"
|
||||
#include <QObject>
|
||||
#include <QtTest>
|
||||
|
||||
class TestQgsComposerLabel: public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
private slots:
|
||||
void initTestCase();// will be called before the first testfunction is executed.
|
||||
void cleanupTestCase();// will be called after the last testfunction was executed.
|
||||
void init();// will be called before each testfunction is executed.
|
||||
void cleanup();// will be called after every testfunction.
|
||||
|
||||
// test simple expression evaluation
|
||||
void evaluation();
|
||||
// test expression evaluation when a feature is set
|
||||
void feature_evaluation();
|
||||
// test "$page" expressions
|
||||
void page_evaluation();
|
||||
private:
|
||||
QgsComposition* mComposition;
|
||||
QgsComposerLabel* mComposerLabel;
|
||||
QgsMapRenderer* mMapRenderer;
|
||||
QgsVectorLayer* mVectorLayer;
|
||||
};
|
||||
|
||||
void TestQgsComposerLabel::initTestCase()
|
||||
{
|
||||
QgsApplication::init();
|
||||
QgsApplication::initQgis();
|
||||
|
||||
//create maplayers from testdata and add to layer registry
|
||||
QFileInfo vectorFileInfo( QString( TEST_DATA_DIR ) + QDir::separator() + "france_parts.shp" );
|
||||
mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(),
|
||||
vectorFileInfo.completeBaseName(),
|
||||
"ogr" );
|
||||
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << mVectorLayer );
|
||||
|
||||
//create composition with composer map
|
||||
mMapRenderer = new QgsMapRenderer();
|
||||
mMapRenderer->setLayerSet( QStringList() << mVectorLayer->id() );
|
||||
mMapRenderer->setProjectionsEnabled( false );
|
||||
mComposition = new QgsComposition( mMapRenderer );
|
||||
mComposition->setPaperSize( 297, 210 ); //A4 landscape
|
||||
|
||||
mComposerLabel = new QgsComposerLabel( mComposition );
|
||||
mComposition->addComposerLabel( mComposerLabel );
|
||||
}
|
||||
|
||||
void TestQgsComposerLabel::cleanupTestCase()
|
||||
{
|
||||
delete mComposition;
|
||||
delete mMapRenderer;
|
||||
delete mVectorLayer;
|
||||
}
|
||||
|
||||
void TestQgsComposerLabel::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsComposerLabel::cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsComposerLabel::evaluation()
|
||||
{
|
||||
{
|
||||
// $CURRENT_DATE evaluation
|
||||
QString expected = "__" + QDate::currentDate().toString() + "__";
|
||||
mComposerLabel->setText( "__$CURRENT_DATE__" );
|
||||
QString evaluated = mComposerLabel->displayText();
|
||||
QCOMPARE( evaluated, expected );
|
||||
}
|
||||
{
|
||||
// $CURRENT_DATE() evaluation
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QString expected = "__" + now.toString( "dd" ) + "(ok)__";
|
||||
mComposerLabel->setText( "__$CURRENT_DATE(dd)(ok)__" );
|
||||
QString evaluated = mComposerLabel->displayText();
|
||||
QCOMPARE( evaluated, expected );
|
||||
}
|
||||
{
|
||||
// $CURRENT_DATE() evaluation (inside an expression)
|
||||
QDate now = QDate::currentDate();
|
||||
int dd = now.day();
|
||||
|
||||
QString expected = "__" + QString("%1").arg(dd+1, 2, 10, QChar('0')) + "(ok)__";
|
||||
mComposerLabel->setText( "__[%$CURRENT_DATE(dd) + 1%](ok)__" );
|
||||
QString evaluated = mComposerLabel->displayText();
|
||||
QCOMPARE( evaluated, expected );
|
||||
}
|
||||
{
|
||||
// expression evaluation (without feature)
|
||||
QString expected = "__[NAME_1]42__";
|
||||
mComposerLabel->setText( "__[%\"NAME_1\"%][%21*2%]__" );
|
||||
QString evaluated = mComposerLabel->displayText();
|
||||
QCOMPARE( evaluated, expected );
|
||||
}
|
||||
}
|
||||
|
||||
void TestQgsComposerLabel::feature_evaluation()
|
||||
{
|
||||
QgsVectorDataProvider* provider = mVectorLayer->dataProvider();
|
||||
|
||||
QgsAttributeList allAttrs = provider->attributeIndexes();
|
||||
provider->select( allAttrs );
|
||||
QgsFeature feat;
|
||||
|
||||
provider->nextFeature( feat );
|
||||
{
|
||||
// evaluation with a feature
|
||||
mComposerLabel->setExpressionContext( &feat, mVectorLayer );
|
||||
mComposerLabel->setText( "[%\"NAME_1\"||'_ok'%]" );
|
||||
QString evaluated = mComposerLabel->displayText();
|
||||
QString expected = "Basse-Normandie_ok";
|
||||
QCOMPARE( evaluated, expected );
|
||||
}
|
||||
provider->nextFeature( feat );
|
||||
{
|
||||
// evaluation with a feature
|
||||
mComposerLabel->setExpressionContext( &feat, mVectorLayer );
|
||||
mComposerLabel->setText( "[%\"NAME_1\"||'_ok'%]" );
|
||||
QString evaluated = mComposerLabel->displayText();
|
||||
QString expected = "Bretagne_ok";
|
||||
QCOMPARE( evaluated, expected );
|
||||
}
|
||||
{
|
||||
// evaluation with a feature and local variables
|
||||
QMap<QString, QVariant> locals;
|
||||
locals.insert( "$test", "OK" );
|
||||
|
||||
mComposerLabel->setExpressionContext( &feat, mVectorLayer, locals );
|
||||
mComposerLabel->setText( "[%\"NAME_1\"||$test%]" );
|
||||
QString evaluated = mComposerLabel->displayText();
|
||||
QString expected = "BretagneOK";
|
||||
QCOMPARE( evaluated, expected );
|
||||
}
|
||||
}
|
||||
|
||||
void TestQgsComposerLabel::page_evaluation()
|
||||
{
|
||||
mComposition->setNumPages( 2 );
|
||||
{
|
||||
mComposerLabel->setText( "[%$page||'/'||$numpages%]" );
|
||||
QString evaluated = mComposerLabel->displayText();
|
||||
QString expected = "1/2";
|
||||
QCOMPARE( evaluated, expected );
|
||||
|
||||
// move to the second page and re-evaluate
|
||||
mComposerLabel->setItemPosition( 0, 320 );
|
||||
QCOMPARE( mComposerLabel->displayText(), QString("2/2") );
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN( TestQgsComposerLabel )
|
||||
#include "moc_testqgscomposerlabel.cxx"
|
@ -1,224 +0,0 @@
|
||||
/***************************************************************************
|
||||
testqgscomposermapatlas.cpp
|
||||
---------------------------
|
||||
begin : Sept 2012
|
||||
copyright : (C) 2012 by Hugo Mercier
|
||||
email : hugo dot mercier at oslandia dot 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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgsapplication.h"
|
||||
#include "qgscomposition.h"
|
||||
#include "qgscompositionchecker.h"
|
||||
#include "qgscomposermap.h"
|
||||
#include "qgscomposerlabel.h"
|
||||
#include "qgsmaplayerregistry.h"
|
||||
#include "qgsmaprenderer.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectordataprovider.h"
|
||||
#include "qgssymbolv2.h"
|
||||
#include "qgssinglesymbolrendererv2.h"
|
||||
#include <QObject>
|
||||
#include <QtTest>
|
||||
|
||||
class TestQgsComposerMapAtlas: public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
private slots:
|
||||
void initTestCase();// will be called before the first testfunction is executed.
|
||||
void cleanupTestCase();// will be called after the last testfunction was executed.
|
||||
void init();// will be called before each testfunction is executed.
|
||||
void cleanup();// will be called after every testfunction.
|
||||
|
||||
// test filename pattern evaluation
|
||||
void filename();
|
||||
// test rendering with an autoscale atlas
|
||||
void autoscale_render();
|
||||
// test rendering with a fixed scale atlas
|
||||
void fixedscale_render();
|
||||
// test rendering with a hidden coverage
|
||||
void hiding_render();
|
||||
private:
|
||||
QgsComposition* mComposition;
|
||||
QgsComposerLabel* mLabel1;
|
||||
QgsComposerLabel* mLabel2;
|
||||
QgsComposerMap* mAtlasMap;
|
||||
QgsComposerMap* mOverview;
|
||||
QgsMapRenderer* mMapRenderer;
|
||||
QgsVectorLayer* mVectorLayer;
|
||||
};
|
||||
|
||||
void TestQgsComposerMapAtlas::initTestCase()
|
||||
{
|
||||
QgsApplication::init();
|
||||
QgsApplication::initQgis();
|
||||
|
||||
//create maplayers from testdata and add to layer registry
|
||||
QFileInfo vectorFileInfo( QString( TEST_DATA_DIR ) + QDir::separator() + "france_parts.shp" );
|
||||
mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(),
|
||||
vectorFileInfo.completeBaseName(),
|
||||
"ogr" );
|
||||
|
||||
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << mVectorLayer );
|
||||
|
||||
//create composition with composer map
|
||||
mMapRenderer = new QgsMapRenderer();
|
||||
mMapRenderer->setLayerSet( QStringList() << mVectorLayer->id() );
|
||||
mMapRenderer->setProjectionsEnabled( true );
|
||||
|
||||
// select epsg:2154
|
||||
QgsCoordinateReferenceSystem crs;
|
||||
crs.createFromSrid( 2154 );
|
||||
mMapRenderer->setDestinationCrs( crs );
|
||||
mComposition = new QgsComposition( mMapRenderer );
|
||||
mComposition->setPaperSize( 297, 210 ); //A4 landscape
|
||||
|
||||
// fix the renderer, fill with green
|
||||
QgsStringMap props;
|
||||
props.insert( "color", "0,127,0" );
|
||||
QgsFillSymbolV2* fillSymbol = QgsFillSymbolV2::createSimple( props );
|
||||
QgsSingleSymbolRendererV2* renderer = new QgsSingleSymbolRendererV2( fillSymbol );
|
||||
mVectorLayer->setRendererV2( renderer );
|
||||
|
||||
// the atlas map
|
||||
mAtlasMap = new QgsComposerMap( mComposition, 20, 20, 130, 130 );
|
||||
mAtlasMap->setFrameEnabled( true );
|
||||
mAtlasMap->setAtlasCoverageLayer( mVectorLayer );
|
||||
mComposition->addComposerMap( mAtlasMap );
|
||||
mComposition->setAtlasMap( mAtlasMap );
|
||||
|
||||
// an overview
|
||||
mOverview = new QgsComposerMap( mComposition, 180, 20, 50, 50 );
|
||||
mOverview->setFrameEnabled( true );
|
||||
mOverview->setOverviewFrameMap( mAtlasMap->id() );
|
||||
mComposition->addComposerMap( mOverview );
|
||||
mOverview->setNewExtent( QgsRectangle( 49670.718, 6415139.086, 699672.519, 7065140.887 ) );
|
||||
|
||||
// header label
|
||||
mLabel1 = new QgsComposerLabel( mComposition );
|
||||
mComposition->addComposerLabel( mLabel1 );
|
||||
mLabel1->setText( "[% \"NAME_1\" %] area" );
|
||||
mLabel1->adjustSizeToText();
|
||||
mLabel1->setItemPosition( 150, 5 );
|
||||
|
||||
// feature number label
|
||||
mLabel2 = new QgsComposerLabel( mComposition );
|
||||
mComposition->addComposerLabel( mLabel2 );
|
||||
mLabel2->setText( "# [%$feature || ' / ' || $numfeatures%]" );
|
||||
mLabel2->adjustSizeToText();
|
||||
mLabel2->setItemPosition( 150, 200 );
|
||||
}
|
||||
|
||||
void TestQgsComposerMapAtlas::cleanupTestCase()
|
||||
{
|
||||
delete mComposition;
|
||||
delete mMapRenderer;
|
||||
delete mVectorLayer;
|
||||
}
|
||||
|
||||
void TestQgsComposerMapAtlas::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsComposerMapAtlas::cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsComposerMapAtlas::filename()
|
||||
{
|
||||
QgsAtlasRendering atlasRender( mComposition );
|
||||
atlasRender.begin( "'output_' || $feature" );
|
||||
for ( size_t fi = 0; fi < atlasRender.numFeatures(); ++fi )
|
||||
{
|
||||
atlasRender.prepareForFeature( fi );
|
||||
QString expected = QString( "output_%1" ).arg( (int)(fi+1) );
|
||||
QCOMPARE( atlasRender.currentFilename(), expected );
|
||||
}
|
||||
atlasRender.end();
|
||||
}
|
||||
|
||||
|
||||
void TestQgsComposerMapAtlas::autoscale_render()
|
||||
{
|
||||
mAtlasMap->setAtlasFixedScale( false );
|
||||
mAtlasMap->setAtlasMargin( 0.10 );
|
||||
|
||||
QgsAtlasRendering atlasRender( mComposition );
|
||||
|
||||
atlasRender.begin();
|
||||
|
||||
for ( size_t fit = 0; fit < 2; ++fit )
|
||||
{
|
||||
atlasRender.prepareForFeature( fit );
|
||||
mLabel1->adjustSizeToText();
|
||||
|
||||
QgsCompositionChecker checker( "Atlas autoscale test", mComposition,
|
||||
QString( TEST_DATA_DIR ) + QDir::separator() + "control_images" + QDir::separator() +
|
||||
"expected_composermapatlas" + QDir::separator() +
|
||||
QString( "autoscale_%1.png" ).arg((int)fit) );
|
||||
QVERIFY( checker.testComposition( 0 ) );
|
||||
}
|
||||
atlasRender.end();
|
||||
}
|
||||
|
||||
void TestQgsComposerMapAtlas::fixedscale_render()
|
||||
{
|
||||
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
|
||||
mAtlasMap->setAtlasFixedScale( true );
|
||||
|
||||
QgsAtlasRendering atlasRender( mComposition );
|
||||
|
||||
atlasRender.begin();
|
||||
|
||||
for ( size_t fit = 0; fit < 2; ++fit )
|
||||
{
|
||||
atlasRender.prepareForFeature( fit );
|
||||
mLabel1->adjustSizeToText();
|
||||
|
||||
QgsCompositionChecker checker( "Atlas fixedscale test", mComposition,
|
||||
QString( TEST_DATA_DIR ) + QDir::separator() + "control_images" + QDir::separator() +
|
||||
"expected_composermapatlas" + QDir::separator() +
|
||||
QString( "fixedscale_%1.png" ).arg((int)fit) );
|
||||
QVERIFY( checker.testComposition( 0 ) );
|
||||
}
|
||||
atlasRender.end();
|
||||
|
||||
}
|
||||
|
||||
void TestQgsComposerMapAtlas::hiding_render()
|
||||
{
|
||||
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
|
||||
mAtlasMap->setAtlasFixedScale( true );
|
||||
mAtlasMap->setAtlasHideCoverage( true );
|
||||
|
||||
QgsAtlasRendering atlasRender( mComposition );
|
||||
|
||||
atlasRender.begin();
|
||||
|
||||
for ( size_t fit = 0; fit < 2; ++fit )
|
||||
{
|
||||
atlasRender.prepareForFeature( fit );
|
||||
mLabel1->adjustSizeToText();
|
||||
|
||||
QgsCompositionChecker checker( "Atlas hidden test", mComposition,
|
||||
QString( TEST_DATA_DIR ) + QDir::separator() + "control_images" + QDir::separator() +
|
||||
"expected_composermapatlas" + QDir::separator() +
|
||||
QString( "hiding_%1.png" ).arg((int)fit) );
|
||||
QVERIFY( checker.testComposition( 0 ) );
|
||||
}
|
||||
atlasRender.end();
|
||||
|
||||
}
|
||||
|
||||
QTEST_MAIN( TestQgsComposerMapAtlas )
|
||||
#include "moc_testqgscomposermapatlas.cxx"
|
@ -544,33 +544,6 @@ class TestQgsExpression: public QObject
|
||||
QVariant vPerimeter = exp3.evaluate( &fPolygon );
|
||||
QCOMPARE( vPerimeter.toDouble(), 20. );
|
||||
}
|
||||
|
||||
void eval_special_columns()
|
||||
{
|
||||
QTest::addColumn<QString>( "string" );
|
||||
QTest::addColumn<QVariant>( "result" );
|
||||
|
||||
QgsExpression::setSpecialColumn( "$var1", QVariant((int)42) );
|
||||
|
||||
QgsExpression exp( "$var1 + 1" );
|
||||
QVariant v1 = exp.evaluate();
|
||||
QCOMPARE( v1.toInt(), 43 );
|
||||
|
||||
QgsExpression::setSpecialColumn( "$var1", QVariant((int)100) );
|
||||
QVariant v2 = exp.evaluate();
|
||||
QCOMPARE( v2.toInt(), 101 );
|
||||
|
||||
QgsExpression exp2( "_specialcol_('$var1')+1" );
|
||||
QVariant v3 = exp2.evaluate();
|
||||
QCOMPARE( v3.toInt(), 101 );
|
||||
|
||||
QgsExpression exp3( "_specialcol_('undefined')");
|
||||
QVariant v4 = exp3.evaluate();
|
||||
QCOMPARE( v4, QVariant() );
|
||||
|
||||
QgsExpression::unsetSpecialColumn( "$var1" );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
QTEST_MAIN( TestQgsExpression )
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 157 KiB |
Binary file not shown.
Before Width: | Height: | Size: 170 KiB |
Binary file not shown.
Before Width: | Height: | Size: 169 KiB |
Binary file not shown.
Before Width: | Height: | Size: 187 KiB |
Binary file not shown.
Before Width: | Height: | Size: 51 KiB |
Binary file not shown.
Before Width: | Height: | Size: 48 KiB |
BIN
tests/testdata/france_parts.dbf
vendored
BIN
tests/testdata/france_parts.dbf
vendored
Binary file not shown.
1
tests/testdata/france_parts.prj
vendored
1
tests/testdata/france_parts.prj
vendored
@ -1 +0,0 @@
|
||||
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
|
1
tests/testdata/france_parts.qpj
vendored
1
tests/testdata/france_parts.qpj
vendored
@ -1 +0,0 @@
|
||||
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]
|
BIN
tests/testdata/france_parts.shp
vendored
BIN
tests/testdata/france_parts.shp
vendored
Binary file not shown.
BIN
tests/testdata/france_parts.shx
vendored
BIN
tests/testdata/france_parts.shx
vendored
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user