Navigation Menu

Skip to content

Commit

Permalink
[FEATURE] enhance command line arguments
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jef committed Jul 24, 2009
1 parent 5c3beca commit a20da46
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
45 changes: 39 additions & 6 deletions src/app/main.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'},
Expand All @@ -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. */
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -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() );
Expand Down

0 comments on commit a20da46

Please sign in to comment.