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

Bernhard Beschow bbeschow at cs.tu-berlin.de
Sun Jan 9 18:39:05 CET 2011


SVN commit 1213220 by beschow:

use Q_ASSERT rather than error dialogs in MapWizard::accept()

The data entered by the user should have been validated in the respective pages. Thus, anything that goes wrong here
is a programming error.

 M  +17 -46    MapWizard.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/MapWizard.cpp #1213219:1213220
@@ -775,63 +775,41 @@
     Q_ASSERT( d->format == d->format.toLower() );
     Q_ASSERT( !d->mapTheme.isEmpty() );
 
-    QSharedPointer<GeoSceneDocument> document( createDocument() );
+    if ( d->mapProviderType == MapWizardPrivate::StaticImageMap )
+    {
     d->sourceImage = d->uiWidget.lineEditSource->text();
-
-    if( d->uiWidget.radioButtonWms->isChecked() )
+        Q_ASSERT( !d->sourceImage.isEmpty() );
+        Q_ASSERT( QFile( d->sourceImage ).exists() );
+    }
+    else if ( d->mapProviderType == MapWizardPrivate::WmsMap )
     {
+        Q_ASSERT( !d->uiWidget.comboBoxWmsMap->currentText().isEmpty() );
+
         QUrl wmsUrl( d->uiWidget.lineEditWmsUrl->text() );
         d->protocol = wmsUrl.toString().left( wmsUrl.toString().indexOf( ':' ) );
         d->host =  QString( wmsUrl.encodedHost() );
         d->path =  QString( wmsUrl.encodedPath() );
         d->query = QString( "layers=%1&%2" ).arg( d->uiWidget.comboBoxWmsMap->itemData( d->uiWidget.comboBoxWmsMap->currentIndex() ).toString() )
                       .arg( QString( wmsUrl.encodedQuery() ) );
-    }
 
-    else if( d->uiWidget.radioButtonStaticUrl->isChecked() )
+        Q_ASSERT( !d->levelZero.isNull() );
+        Q_ASSERT( !QImage::fromData( d->levelZero ).isNull() );
+    }
+    else if ( d->mapProviderType == MapWizardPrivate::StaticImageMap )
     {
         QUrl staticImageUrl( d->uiWidget.comboBoxStaticUrlServer->currentText() );
         d->protocol = staticImageUrl.toString().left( staticImageUrl.toString().indexOf( ':' ) );
         d->host =  QString( staticImageUrl.encodedHost() );
         d->path =  QUrl::fromPercentEncoding( staticImageUrl.encodedPath() );
-    }
 
-    if( d->mapProviderType == MapWizardPrivate::StaticImageMap && d->uiWidget.lineEditSource->text().isEmpty() )
-    {
-        QMessageBox::information( this, tr( "Problem with map information" ), tr( "Please specify a source image." ) );
-        return;
+        Q_ASSERT( !d->levelZero.isNull() );
+        Q_ASSERT( !QImage::fromData( d->levelZero ).isNull() );
     }
 
-    if( d->mapProviderType == MapWizardPrivate::WmsMap && d->uiWidget.comboBoxWmsMap->currentText().isEmpty() )
-    {
-        QMessageBox::information( this, tr( "Problem with map information" ), tr( "Please choose a map." ) );
-        return;
-    }
+    QSharedPointer<GeoSceneDocument> document( createDocument() );
+    Q_ASSERT( !document->head()->description().isEmpty() );
+    Q_ASSERT( !document->head()->name().isEmpty() );
 
-    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() )
-    {
-        if( d->mapProviderType == MapWizardPrivate::StaticImageMap && !QFile( d->sourceImage ).exists() )
-        {
-            QMessageBox::critical( this, tr( "File not found" ), tr( "Source image is not found." ) );
-            return;
-        }
-
         if( createFiles( document.data() ) )
         {
             if( d->mapProviderType == MapWizardPrivate::WmsMap )
@@ -859,13 +837,6 @@
         }
     }
 
-    else
-    {
-        QMessageBox::information( this, tr( "Empty fields" ), tr( "Sorry, some required information is missing. Please fill in all fields." ) );
-        return;
     }
-}
 
-}
-
 #include "MapWizard.moc"


More information about the Marble-commits mailing list