Skip to content
Permalink
Browse files

[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@11172 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Jul 24, 2009
1 parent 9c7f809 commit 2d51ee555e2caad4d69a9ae2a17522b1e1f88520
Showing with 40 additions and 6 deletions.
  1. +39 −6 src/app/main.cpp
  2. +1 −0 src/gui/qgsmapcanvas.cpp
@@ -88,9 +88,12 @@ void usage( std::string const & appName )
<< "Usage: " << appName << " [options] [FILES]\n"
<< " options:\n"
<< "\t[--snapshot filename]\temit snapshot of loaded datasets to given file\n"
<< "\t[--width width]\twidth of snapshot to emit\n"
<< "\t[--height height]\theight of snapshot to emit\n"
<< "\t[--lang language]\tuse language for interface text\n"
<< "\t[--project projectfile]\tload the given QGIS project\n"
<< "\t[--extent xmin,ymin,xmax,ymax]\tset initial map extent\n"
<< "\t[--nologo]\thide splash screen\n"
<< "\t[--help]\t\tthis text\n\n"
<< " FILES:\n"
<< " Files specified on the command line can include rasters,\n"
@@ -257,6 +260,10 @@ int main( int argc, char *argv[] )
// This behaviour is used to load the app, snapshot the map,
// save the image to disk and then exit
QString mySnapshotFileName = "";
int mySnapshotWidth = 800;
int mySnapshotHeight = 600;

bool myHideSplash = false;

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

optionChar = getopt_long( argc, argv, "slpe",
optionChar = getopt_long( argc, argv, "swhlpe",
long_options, &option_index );

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

case 'w':
mySnapshotWidth = QString( optarg ).toInt();
break;

case 'h':
mySnapshotHeight = QString( optarg ).toInt();
break;

case 'n':
myHideSplash = true;
break;

case 'l':
myTranslationCode = optarg;
break;
@@ -332,7 +354,6 @@ int main( int argc, char *argv[] )
myInitialExtent = optarg;
break;

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

if ( arg == "--help" || arg == "-h" || arg == "-?" )
if ( arg == "--help" || arg == "-?" )
{
usage( argv[0] );
return 2;
}
else if ( arg == "-nologo" || arg == "-n" )
{
myHideSplash = true;
}
else if ( i + 1 < argc && ( arg == "--snapshot" || arg == "-s" ) )
{
mySnapshotFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() );
}
else if ( i + 1 < argc && ( arg == "-width" || arg == "-w" ) )
{
mySnapshotWidth = QString( argv[++i] ).toInt();
}
else if ( i + 1 < argc && ( arg == "-height" || arg == "-h" ) )
{
mySnapshotHeight = QString( argv[++i] ).toInt();
}
else if ( i + 1 < argc && ( arg == "--lang" || arg == "-l" ) )
{
myTranslationCode = argv[++i];
@@ -518,7 +551,7 @@ int main( int argc, char *argv[] )
QString mySplashPath( QgsApplication::splashPath() );
QPixmap myPixmap( mySplashPath + QString( "splash.png" ) );
QSplashScreen *mypSplash = new QSplashScreen( myPixmap );
if ( mySettings.value( "/qgis/hideSplash" ).toBool() )
if ( mySettings.value( "/qgis/hideSplash" ).toBool() || myHideSplash )
{
//splash screen hidden
}
@@ -701,7 +734,7 @@ int main( int argc, char *argv[] )
*/
//qgis->show();
myApp.processEvents();
QPixmap * myQPixmap = new QPixmap( 800, 600 );
QPixmap * myQPixmap = new QPixmap( mySnapshotWidth, mySnapshotHeight );
myQPixmap->fill();
qgis->saveMapAsImage( mySnapshotFileName, myQPixmap );
myApp.processEvents();
@@ -407,6 +407,7 @@ void QgsMapCanvas::saveAsImage( QString theFileName, QPixmap * theQPixmap, QStri
QPainter painter;
painter.begin( theQPixmap );
mMapRenderer->render( &painter );
emit renderComplete( &painter );
painter.end();

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

0 comments on commit 2d51ee5

Please sign in to comment.
You can’t perform that action at this time.