Skip to content

Commit a20da46

Browse files
author
jef
committedJul 24, 2009
[FEATURE] enhance command line arguments
- allow given snapshot sizes - allow suppression of splash screen - capture map decorations from plugins on snapshots git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11172 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed
 

‎src/app/main.cpp

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ void usage( std::string const & appName )
8888
<< "Usage: " << appName << " [options] [FILES]\n"
8989
<< " options:\n"
9090
<< "\t[--snapshot filename]\temit snapshot of loaded datasets to given file\n"
91+
<< "\t[--width width]\twidth of snapshot to emit\n"
92+
<< "\t[--height height]\theight of snapshot to emit\n"
9193
<< "\t[--lang language]\tuse language for interface text\n"
9294
<< "\t[--project projectfile]\tload the given QGIS project\n"
9395
<< "\t[--extent xmin,ymin,xmax,ymax]\tset initial map extent\n"
96+
<< "\t[--nologo]\thide splash screen\n"
9497
<< "\t[--help]\t\tthis text\n\n"
9598
<< " FILES:\n"
9699
<< " Files specified on the command line can include rasters,\n"
@@ -257,6 +260,10 @@ int main( int argc, char *argv[] )
257260
// This behaviour is used to load the app, snapshot the map,
258261
// save the image to disk and then exit
259262
QString mySnapshotFileName = "";
263+
int mySnapshotWidth = 800;
264+
int mySnapshotHeight = 600;
265+
266+
bool myHideSplash = false;
260267

261268
// This behaviour will set initial extent of map canvas, but only if
262269
// there are no command line arguments. This gives a usable map
@@ -284,10 +291,13 @@ int main( int argc, char *argv[] )
284291
static struct option long_options[] =
285292
{
286293
/* These options set a flag. */
287-
{"help", no_argument, 0, 'h'},
294+
{"help", no_argument, 0, '?'},
295+
{"nologo", no_argument, 0, 'n'},
288296
/* These options don't set a flag.
289297
* We distinguish them by their indices. */
290298
{"snapshot", required_argument, 0, 's'},
299+
{"width", required_argument, 0, 'w'},
300+
{"height", required_argument, 0, 'h'},
291301
{"lang", required_argument, 0, 'l'},
292302
{"project", required_argument, 0, 'p'},
293303
{"extent", required_argument, 0, 'e'},
@@ -297,7 +307,7 @@ int main( int argc, char *argv[] )
297307
/* getopt_long stores the option index here. */
298308
int option_index = 0;
299309

300-
optionChar = getopt_long( argc, argv, "slpe",
310+
optionChar = getopt_long( argc, argv, "swhlpe",
301311
long_options, &option_index );
302312

303313
/* Detect the end of the options. */
@@ -320,6 +330,18 @@ int main( int argc, char *argv[] )
320330
mySnapshotFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( optarg ) ).absoluteFilePath() );
321331
break;
322332

333+
case 'w':
334+
mySnapshotWidth = QString( optarg ).toInt();
335+
break;
336+
337+
case 'h':
338+
mySnapshotHeight = QString( optarg ).toInt();
339+
break;
340+
341+
case 'n':
342+
myHideSplash = true;
343+
break;
344+
323345
case 'l':
324346
myTranslationCode = optarg;
325347
break;
@@ -332,7 +354,6 @@ int main( int argc, char *argv[] )
332354
myInitialExtent = optarg;
333355
break;
334356

335-
case 'h':
336357
case '?':
337358
usage( argv[0] );
338359
return 2; // XXX need standard exit codes
@@ -364,15 +385,27 @@ int main( int argc, char *argv[] )
364385
{
365386
QString arg = argv[i];
366387

367-
if ( arg == "--help" || arg == "-h" || arg == "-?" )
388+
if ( arg == "--help" || arg == "-?" )
368389
{
369390
usage( argv[0] );
370391
return 2;
371392
}
393+
else if ( arg == "-nologo" || arg == "-n" )
394+
{
395+
myHideSplash = true;
396+
}
372397
else if ( i + 1 < argc && ( arg == "--snapshot" || arg == "-s" ) )
373398
{
374399
mySnapshotFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() );
375400
}
401+
else if ( i + 1 < argc && ( arg == "-width" || arg == "-w" ) )
402+
{
403+
mySnapshotWidth = QString( argv[++i] ).toInt();
404+
}
405+
else if ( i + 1 < argc && ( arg == "-height" || arg == "-h" ) )
406+
{
407+
mySnapshotHeight = QString( argv[++i] ).toInt();
408+
}
376409
else if ( i + 1 < argc && ( arg == "--lang" || arg == "-l" ) )
377410
{
378411
myTranslationCode = argv[++i];
@@ -518,7 +551,7 @@ int main( int argc, char *argv[] )
518551
QString mySplashPath( QgsApplication::splashPath() );
519552
QPixmap myPixmap( mySplashPath + QString( "splash.png" ) );
520553
QSplashScreen *mypSplash = new QSplashScreen( myPixmap );
521-
if ( mySettings.value( "/qgis/hideSplash" ).toBool() )
554+
if ( mySettings.value( "/qgis/hideSplash" ).toBool() || myHideSplash )
522555
{
523556
//splash screen hidden
524557
}
@@ -701,7 +734,7 @@ int main( int argc, char *argv[] )
701734
*/
702735
//qgis->show();
703736
myApp.processEvents();
704-
QPixmap * myQPixmap = new QPixmap( 800, 600 );
737+
QPixmap * myQPixmap = new QPixmap( mySnapshotWidth, mySnapshotHeight );
705738
myQPixmap->fill();
706739
qgis->saveMapAsImage( mySnapshotFileName, myQPixmap );
707740
myApp.processEvents();

‎src/gui/qgsmapcanvas.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ void QgsMapCanvas::saveAsImage( QString theFileName, QPixmap * theQPixmap, QStri
407407
QPainter painter;
408408
painter.begin( theQPixmap );
409409
mMapRenderer->render( &painter );
410+
emit renderComplete( &painter );
410411
painter.end();
411412

412413
theQPixmap->save( theFileName, theFormat.toLocal8Bit().data() );

0 commit comments

Comments
 (0)
Please sign in to comment.