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

Thibaut Gridel tgridel at free.fr
Sat Jul 17 00:35:20 CEST 2010


SVN commit 1150830 by tgridel:

GeoDataTreeModel: provide visibility checkbox and decoration

 M  +53 -6     lib/GeoDataTreeModel.cpp  
 M  +4 -0      lib/GeoDataTreeModel.h  
 M  +2 -0      lib/MarbleModel.cpp  
 M  +4 -0      plugins/render/geodata/GeoRendererView.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/GeoDataTreeModel.cpp #1150829:1150830
@@ -22,6 +22,7 @@
 #include "GeoDataContainer.h"
 #include "GeoDataPlacemark.h"
 #include "GeoDataParser.h"
+#include "GeoDataStyle.h"
 #include "GeoDataTypes.h"
 #include "FileManager.h"
 #include "KmlFileViewItem.h"
@@ -114,21 +115,36 @@
     if ( !index.isValid() )
         return QVariant();
 
-    if ( role != Qt::DisplayRole )
-        return QVariant();
+    GeoDataObject *object = static_cast<GeoDataObject*>( index.internalPointer() );
+    if ( role == Qt::DisplayRole ) {
 
-    GeoDataFeature *feature = static_cast<GeoDataFeature*>( index.internalPointer() );
+        GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
     if ( feature )
-        return QVariant( feature->nodeType() );
+            return QVariant( feature->nodeType().append("-").append(feature->name()) );
 
-    GeoDataGeometry *geometry = static_cast<GeoDataGeometry*>( index.internalPointer() );
+        GeoDataGeometry *geometry = dynamic_cast<GeoDataGeometry*>( object );
     if ( geometry )
         return QVariant( geometry->nodeType() );
 
-    GeoDataObject *item = static_cast<GeoDataObject*>( index.internalPointer() );
+        GeoDataObject *item = dynamic_cast<GeoDataObject*>( object );
     if ( item )
         return QVariant( item->nodeType() );
 
+    }
+    else if ( role == Qt::CheckStateRole ) {
+        GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
+        if ( feature )
+            if ( feature->isVisible() )
+                return QVariant( Qt::Checked );
+            else
+                return QVariant( Qt::Unchecked );
+    }
+    else if ( role == Qt::DecorationRole ) {
+        GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
+        if ( feature )
+            return QVariant(feature->style()->iconStyle().icon());
+    }
+
     return QVariant();
 }
 
@@ -258,6 +274,37 @@
     }
 }
 
+bool GeoDataTreeModel::setData ( const QModelIndex & index, const QVariant & value, int role )
+{
+    if ( !index.isValid() )
+        return false;
+
+    GeoDataObject *object = static_cast<GeoDataObject*>( index.internalPointer() );
+    if ( role == Qt::CheckStateRole ) {
+        GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
+        if ( feature ) {
+            feature->setVisible( value.toBool() );
+            mDebug() << "setData " << feature->name() << " " << value.toBool();
+            emit dataChanged( index, index );
+            return true;
+        }
+    }
+}
+
+Qt::ItemFlags GeoDataTreeModel::flags ( const QModelIndex & index ) const
+{
+    if ( !index.isValid() )
+        return Qt::NoItemFlags;
+
+    GeoDataObject *object = static_cast<GeoDataObject*>( index.internalPointer() );
+    GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
+    if ( feature ) {
+        return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable;
+    }
+    return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+}
+
+
 void GeoDataTreeModel::setFileManager( FileManager *fileManager )
 {
     d->m_fileManager = fileManager;
--- trunk/KDE/kdeedu/marble/src/lib/GeoDataTreeModel.h #1150829:1150830
@@ -55,6 +55,10 @@
 
     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
 
+    Qt::ItemFlags flags ( const QModelIndex & index ) const;
+
+    bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
+
     void reset() { QAbstractItemModel::reset(); }
 
     /**
--- trunk/KDE/kdeedu/marble/src/lib/MarbleModel.cpp #1150829:1150830
@@ -174,6 +174,8 @@
     t.start();
     MarbleModelPrivate::refCounter.ref();
     d->m_dataFacade = new MarbleDataFacade( this );
+    connect(d->m_dataFacade->treeModel(), SIGNAL( dataChanged(QModelIndex,QModelIndex) ),
+            this, SIGNAL( modelChanged() ) );
 
     d->m_tileLoader = new StackedTileLoader( d->m_mapThemeManager, d->textureLayerProperties(),
                                              d->m_downloadManager, this );
--- trunk/KDE/kdeedu/marble/src/plugins/render/geodata/GeoRendererView.cpp #1150829:1150830
@@ -111,7 +111,11 @@
                 return;
             }
         }
+        GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( indexObject );
+        if ( feature && !feature->isVisible() ) {
+            return;
     }
+    }
 
     int rowCount = model()->rowCount( index );
    


More information about the Marble-commits mailing list