[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeedu/marble/src/lib/geodata
From:       Patrick Spendrin <ps_ml () gmx ! de>
Date:       2008-12-29 1:27:41
Message-ID: 1230514061.999541.17235.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 902733 by sengels:

do not use QPixmap in another thread than the GUI thread.
This fixes a warning and makes it easier to use the icon given by the kml-IconStyle \
tag

 M  +30 -12    data/GeoDataIconStyle.cpp  
 M  +2 -0      data/GeoDataIconStyle.h  
 M  +1 -2      handlers/kml/KmlHrefTagHandler.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/geodata/data/GeoDataIconStyle.cpp #902732:902733
@@ -21,14 +21,14 @@
   public:
     GeoDataIconStylePrivate() 
         : m_scale( 1.0 ),
-          m_icon( QPixmap() ),
+          m_icon( 0 ),
           m_hotSpot( new GeoDataHotSpot() )
     {
     }
 
     GeoDataIconStylePrivate( const QPixmap& icon, const QPointF &hotSpot )
         : m_scale( 1.0 ),
-          m_icon( icon ),
+          m_icon( new QPixmap( icon ) ),
           m_hotSpot( new GeoDataHotSpot( hotSpot ) )
     {
     }
@@ -36,12 +36,14 @@
     ~GeoDataIconStylePrivate()
     {
         delete m_hotSpot;
+        delete m_icon;
     }
 
     float            m_scale;
 
-    QPixmap          m_icon;    // To save memory we use a pointer
-    GeoDataHotSpot  *m_hotSpot; // default unit is "fraction"
+    QPixmap         *m_icon;
+    QString          m_iconPath;
+    GeoDataHotSpot  *m_hotSpot;
     mutable QPointF  m_pixelHotSpot;
 };
 
@@ -62,12 +64,23 @@
 
 void GeoDataIconStyle::setIcon( const QPixmap &icon )
 {
-    d->m_icon = icon;
+    delete d->m_icon;
+    d->m_icon = new QPixmap( icon );
 }
 
+void GeoDataIconStyle::setIconPath( const QString& filename )
+{
+    d->m_iconPath = filename;
+}
+
 QPixmap GeoDataIconStyle::icon() const
 {
-    return d->m_icon;
+    if(d->m_icon && !d->m_icon->isNull())
+        return *(d->m_icon);
+    else if(!d->m_iconPath.isEmpty())
+        return QPixmap(d->m_iconPath);
+    else
+        return QPixmap();
 }
 
 void GeoDataIconStyle::setHotSpot( const QPointF& hotSpot, 
@@ -85,17 +98,17 @@
     d->m_pixelHotSpot = d->m_hotSpot->hotSpot( xunits, yunits );
 
     if ( xunits == GeoDataHotSpot::Fraction )
-        d->m_pixelHotSpot.setX( d->m_icon.width()  * d->m_pixelHotSpot.x() );
+        d->m_pixelHotSpot.setX( d->m_icon->width()  * d->m_pixelHotSpot.x() );
     else {
         if ( xunits == GeoDataHotSpot::InsetPixels )
-            d->m_pixelHotSpot.setX( d->m_icon.width()  - d->m_pixelHotSpot.x() );
+            d->m_pixelHotSpot.setX( d->m_icon->width()  - d->m_pixelHotSpot.x() );
     }
 
     if ( yunits == GeoDataHotSpot::Fraction )
-        d->m_pixelHotSpot.setY( d->m_icon.height() * ( 1.0 - d->m_pixelHotSpot.y() ) \
); +        d->m_pixelHotSpot.setY( d->m_icon->height() * ( 1.0 - \
d->m_pixelHotSpot.y() ) );  else {
         if ( yunits == GeoDataHotSpot::Pixels )
-            d->m_pixelHotSpot.setY( d->m_icon.height() - d->m_pixelHotSpot.y() );
+            d->m_pixelHotSpot.setY( d->m_icon->height() - d->m_pixelHotSpot.y() );
     }
 
     return d->m_pixelHotSpot;
@@ -116,7 +129,10 @@
     GeoDataColorStyle::pack( stream );
 
     stream << d->m_scale;
-    stream << d->m_icon;
+    if(d->m_icon)
+        stream << *(d->m_icon);
+    else
+        stream << QPixmap();
     d->m_hotSpot->pack( stream );
 }
 
@@ -125,7 +141,9 @@
     GeoDataColorStyle::unpack( stream );
 
     stream >> d->m_scale;
-    stream >> d->m_icon;
+    if(!d->m_icon)
+        d->m_icon = new QPixmap;
+    stream >> *(d->m_icon);
     d->m_hotSpot->unpack( stream );
 }
 
--- trunk/KDE/kdeedu/marble/src/lib/geodata/data/GeoDataIconStyle.h #902732:902733
@@ -36,6 +36,8 @@
 
     void setIcon( const QPixmap& icon );
     QPixmap icon() const;
+    
+    void setIconPath( const QString& filename );
 
     void setHotSpot( const QPointF& hotSpot, GeoDataHotSpot::Units xunits, \
GeoDataHotSpot::Units yunits );  const QPointF& hotSpot() const;
--- trunk/KDE/kdeedu/marble/src/lib/geodata/handlers/kml/KmlHrefTagHandler.cpp \
#902732:902733 @@ -43,8 +43,7 @@
     if ( parentItem.represents( kmlTag_Icon ) ) {
         // we need a more elaborate version of this part
         QString content = parser.readElementText().trimmed();
-        QString filename = QUrl( content ).toLocalFile();
-        parentItem.nodeAs<GeoDataIconStyle>()->setIcon( filename );
+        parentItem.nodeAs<GeoDataIconStyle>()->setIconPath( content );
 #ifdef DEBUG_TAGS
         qDebug() << "Parsed <" << kmlTag_href << "> containing: " << content
                  << " parent item name: " << parentItem.qualifiedName().first;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic