[Marble-commits] KDE/kdeedu/marble/src/lib

Bernhard Beschow bbeschow at cs.tu-berlin.de
Mon Jan 3 15:56:50 CET 2011


SVN commit 1211288 by beschow:

Qt can't write every image file format that it can read. Deal with it in MapWizard:

* always create preview icons in png format (and scale them to 136x136)
* store the raw image data of the base tile as it was retrieved from the server and test it with QImage

 M  +39 -37    MapWizard.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/MapWizard.cpp #1211287:1211288
@@ -372,30 +372,32 @@
         {
             maps.mkdir( QString( "%1/0/" ).arg( head->theme() ) );
             maps.mkdir( QString( "%1/0/0" ).arg( head->theme() ) );
-            QImage baseTile = QImage::fromData( d->levelZero, d->wmsFormat.toAscii().data() );
-            baseTile.save( QString( "%1/%2/0/0/0.%3" ).arg( maps.absolutePath() )
+            const QString path = QString( "%1/%2/0/0/0.%3" ).arg( maps.absolutePath() )
                                                       .arg( head->theme() )
-                                                      .arg( d->wmsFormat ) );
+                                                            .arg( d->wmsFormat );
+            QFile baseTile( path );
+            baseTile.open( QFile::WriteOnly );
+            baseTile.write( d->levelZero );
         }
 
         else if( d->mapProviderType == MapWizardPrivate::StaticUrlMap )
         {
             maps.mkdir( QString( "%1/0/" ).arg( head->theme() ) );
             maps.mkdir( QString( "%1/0/0" ).arg( head->theme() ) );
-            QImage baseTile( 256, 256, QImage::Format_RGB32 );
-            baseTile.save( QString( "%1/%2/0/0/0.%3" ).arg( maps.absolutePath() )
+            const QString path = QString( "%1/%2/0/0/0.%3" ).arg( maps.absolutePath() )
                                                       .arg( head->theme() )
-                                                      .arg( d->uiWidget.comboBoxStaticUrlFormat->currentText() ) );
+                                                            .arg( d->uiWidget.comboBoxStaticUrlFormat->currentText() );
+            QFile baseTile( path );
+            baseTile.open( QFile::WriteOnly );
+            baseTile.write( d->levelZero );
         }
 
         // Preview image
         QString pixmapPath = d->uiWidget.lineEditPreview->text();
-        QString extension = pixmapPath.right( pixmapPath.length() - pixmapPath.lastIndexOf( '.' ) - 1 );
-
-        QFile previewImage( pixmapPath );
-        previewImage.copy( QString( "%1/%2/preview.%3" ).arg( maps.absolutePath() )
+        QImage previewImage = QImage( pixmapPath ).scaled( 136, 136, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
+        previewImage.save( QString( "%1/%2/%3" ).arg( maps.absolutePath() )
                                                         .arg( head->theme() )
-                                                        .arg( extension ) );
+                                                .arg( head->icon()->pixmap() ) );
 
         // DGML
         QFile file( QString( "%1/%2/%2.dgml" ).arg( maps.absolutePath() )
@@ -495,19 +497,14 @@
 
 void MapWizard::createLevelZero( QNetworkReply* reply )
 {
-    if( d->mapProviderType == MapWizardPrivate::WmsMap || d->mapProviderType == MapWizardPrivate::StaticUrlMap )
-    {
-        QByteArray result = reply->readAll();
-        d->levelZero = result;
-    }
+    d->levelZero = reply->readAll();
     
     if( d->mapProviderType == MapWizardPrivate::StaticUrlMap )
     {
-        QPixmap levelZero;
-        levelZero.loadFromData( d->levelZero );
-	if ( !d->levelZero.isNull() ) {
-	    levelZero = levelZero.scaled( d->uiWidget.labelStaticUrlTest->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
-	    d->uiWidget.labelStaticUrlTest->setPixmap( levelZero );
+        QImage testImage = QImage::fromData( d->levelZero );
+        if ( !testImage.isNull() ) {
+            QImage levelZero = testImage.scaled( d->uiWidget.labelStaticUrlTest->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
+            d->uiWidget.labelStaticUrlTest->setPixmap( QPixmap::fromImage( levelZero ) );
 	}
     }
     
@@ -706,22 +703,14 @@
                 d->uiWidget.lineEditPreview->setText( tempFile.fileName() + ".png" );
             }
             
-            else if( d->mapProviderType == MapWizardPrivate::StaticUrlMap )
+            else if( d->mapProviderType == MapWizardPrivate::StaticUrlMap ||
+                     d->mapProviderType == MapWizardPrivate::WmsMap )
             {
-                QImage tempPreview;
-                tempPreview = QImage::fromData( d->levelZero );
-                tempPreview.save( tempFile.fileName() + "."  + d->uiWidget.comboBoxStaticUrlFormat->currentText() );
-                d->uiWidget.lineEditPreview->setText( tempFile.fileName() + "." + d->uiWidget.comboBoxStaticUrlFormat->currentText() );
+                QImage tempPreview = QImage::fromData( d->levelZero );
+                tempPreview.save( tempFile.fileName() + ".png" );
+                d->uiWidget.lineEditPreview->setText( tempFile.fileName() + ".png" );
             }
             
-            else if ( d->mapProviderType == MapWizardPrivate::WmsMap )
-            {
-                QImage tempPreview;
-                tempPreview = QImage::fromData( d->levelZero );
-                tempPreview.save( tempFile.fileName() + "." + d->wmsFormat );
-                d->uiWidget.lineEditPreview->setText( tempFile.fileName() + "." + d->wmsFormat );
-            }
-            
             d->uiWidget.labelThumbnail->setPixmap( pixmap.scaled( 136, 136, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
         }
         delete dialog;
@@ -739,9 +728,7 @@
     head->setVisible( true );
         
     GeoSceneIcon *icon = head->icon();
-    QString pixmapPath = d->uiWidget.lineEditPreview->text();
-    QString pixmapExtension = pixmapPath.right( pixmapPath.length() - pixmapPath.lastIndexOf( '.' ) - 1 );
-    icon->setPixmap( QString( "preview.%1" ).arg( pixmapExtension ) );
+    icon->setPixmap( QString( "preview.png" ) );
     
     GeoSceneZoom *zoom = head->zoom();
     zoom->setMinimum( 900 );
@@ -830,6 +817,21 @@
         return;
     }
 
+    if ( d->mapProviderType != MapWizardPrivate::StaticImageMap )
+    {
+        if( d->levelZero.isNull() )
+        {
+            QMessageBox::information( this, tr( "Cannot create map" ), tr( "The base tile is missing." ) );
+            return;
+        }
+
+        if( QImage::fromData( d->levelZero ).isNull() )
+        {
+            QMessageBox::information( this, tr( "Cannot create map" ), tr( "The base tile is invalid." ) );
+            return;
+        }
+    }
+
     if( !document->head()->name().isEmpty() && 
         !document->head()->description().isEmpty() && 
         !d->uiWidget.lineEditPreview->text().isEmpty() )


More information about the Marble-commits mailing list