[QGIS Commit] r11172 - in trunk/qgis/src: app gui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Jul 24 09:41:24 EDT 2009


Author: jef
Date: 2009-07-24 09:41:24 -0400 (Fri, 24 Jul 2009)
New Revision: 11172

Modified:
   trunk/qgis/src/app/main.cpp
   trunk/qgis/src/gui/qgsmapcanvas.cpp
Log:
[FEATURE] enhance command line arguments
- allow given snapshot sizes
- allow suppression of splash screen
- capture map decorations from plugins on snapshots



Modified: trunk/qgis/src/app/main.cpp
===================================================================
--- trunk/qgis/src/app/main.cpp	2009-07-24 13:40:15 UTC (rev 11171)
+++ trunk/qgis/src/app/main.cpp	2009-07-24 13:41:24 UTC (rev 11172)
@@ -88,9 +88,12 @@
             << "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,7 +260,11 @@
   // 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
   // extent when qgis starts with no layers loaded. When layers are
@@ -284,10 +291,13 @@
       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 @@
       /* 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 @@
           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 @@
           myInitialExtent = optarg;
           break;
 
-        case 'h':
         case '?':
           usage( argv[0] );
           return 2;   // XXX need standard exit codes
@@ -364,15 +385,27 @@
   {
     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 @@
   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 @@
       */
     //qgis->show();
     myApp.processEvents();
-    QPixmap * myQPixmap = new QPixmap( 800, 600 );
+    QPixmap * myQPixmap = new QPixmap( mySnapshotWidth, mySnapshotHeight );
     myQPixmap->fill();
     qgis->saveMapAsImage( mySnapshotFileName, myQPixmap );
     myApp.processEvents();

Modified: trunk/qgis/src/gui/qgsmapcanvas.cpp
===================================================================
--- trunk/qgis/src/gui/qgsmapcanvas.cpp	2009-07-24 13:40:15 UTC (rev 11171)
+++ trunk/qgis/src/gui/qgsmapcanvas.cpp	2009-07-24 13:41:24 UTC (rev 11172)
@@ -407,6 +407,7 @@
     QPainter painter;
     painter.begin( theQPixmap );
     mMapRenderer->render( &painter );
+    emit renderComplete( &painter );
     painter.end();
 
     theQPixmap->save( theFileName, theFormat.toLocal8Bit().data() );



More information about the QGIS-commit mailing list