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

Thibaut Gridel tgridel at free.fr
Sat Jul 17 11:09:33 CEST 2010


SVN commit 1150965 by tgridel:

GeoDataTreeModel: provide column information for Popularity

 M  +4 -0      FileManager.cpp  
 M  +48 -18    GeoDataTreeModel.cpp  
 M  +3 -0      GeoDataTreeModel.h  
 M  +5 -1      MarbleControlBox.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/FileManager.cpp #1150964:1150965
@@ -180,6 +180,10 @@
 
     // now get the document that will be preserved throughout the life time
     GeoDataDocument* doc = item->document();
+    if ( doc->name().isEmpty() && !doc->fileName().isEmpty() )
+    {
+        doc->setName( doc->fileName() );
+    }
     // remove the hashes in front of the styles.
     QVector<GeoDataFeature*>::Iterator end = doc->end();
     QVector<GeoDataFeature*>::Iterator itr = doc->begin();
--- trunk/KDE/kdeedu/marble/src/lib/GeoDataTreeModel.cpp #1150964:1150965
@@ -134,7 +134,31 @@
     return 0;//parentItem->childCount();
 }
 
+QVariant GeoDataTreeModel::headerData(int section, Qt::Orientation orientation,
+                            int role) const
+{
+    if (role != Qt::DisplayRole)
+         return QVariant();
 
+    if ( orientation == Qt::Horizontal )
+    {
+        switch ( section ) {
+        case 0:
+            return QString("Name");
+            break;
+        case 1:
+             return QString("Type");
+             break;
+        case 2:
+            return QString("Popularity");
+            break;
+        case 3:
+            return QString("PopIndex");
+            break;
+        }
+    }
+}
+
 QVariant GeoDataTreeModel::data( const QModelIndex &index, int role ) const
 {
 //    mDebug() << "data";
@@ -145,23 +169,35 @@
     if ( role == Qt::DisplayRole ) {
 
         GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( object );
-        if ( placemark )
-            return QVariant( placemark->nodeType().append("-").append(placemark->name()).append(QString::number(placemark->popularity())) );
-
+        if ( placemark ) {
+            if ( index.column() == 0 )
+                return QVariant( placemark->name() );
+            else if ( index.column() == 1 )
+                return QVariant( placemark->nodeType() );
+            else if ( index.column() == 2 )
+                return QVariant( placemark->popularity() );
+            else if ( index.column() == 3 )
+                return QVariant( placemark->popularityIndex() );
+        }
         GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
-        if ( feature )
-            return QVariant( feature->nodeType().append("-").append(feature->name()) );
+        if ( feature ) {
+            if ( index.column() == 0 )
+                return QVariant( feature->name() );
+            else if ( index.column() == 1 )
+                return QVariant( feature->nodeType() );
+        }
 
         GeoDataGeometry *geometry = dynamic_cast<GeoDataGeometry*>( object );
-        if ( geometry )
+        if ( geometry && index.column() == 1 )
             return QVariant( geometry->nodeType() );
 
         GeoDataObject *item = dynamic_cast<GeoDataObject*>( object );
-        if ( item )
+        if ( item && index.column() == 1 )
             return QVariant( item->nodeType() );
 
     }
-    else if ( role == Qt::CheckStateRole ) {
+    else if ( role == Qt::CheckStateRole
+              && index.column() == 0 ) {
         GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
         if ( feature )
             if ( feature->isVisible() )
@@ -169,7 +205,8 @@
             else
                 return QVariant( Qt::Unchecked );
     }
-    else if ( role == Qt::DecorationRole ) {
+    else if ( role == Qt::DecorationRole
+              && index.column() == 0 ) {
         GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
         if ( feature )
             return QVariant(feature->style()->iconStyle().icon());
@@ -277,17 +314,10 @@
     return QModelIndex();
 }
 
-int GeoDataTreeModel::columnCount( const QModelIndex &node ) const
+int GeoDataTreeModel::columnCount( const QModelIndex &index ) const
 {
-//    mDebug() << "columncount";
-    if ( node.isValid() ) {
-//        mDebug() << "columncount valid";
-        return 1;
-    } else {
-//        mDebug() << "columncount invalid";
-        return 1;
+    return 4;
     }
-}
 
 bool GeoDataTreeModel::setData ( const QModelIndex & index, const QVariant & value, int role )
 {
--- trunk/KDE/kdeedu/marble/src/lib/GeoDataTreeModel.h #1150964:1150965
@@ -48,6 +48,9 @@
      */
     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
 
+    QVariant headerData(int section, Qt::Orientation orientation,
+                                int role = Qt::DisplayRole) const;
+
     QVariant data( const QModelIndex &index, int role ) const;
 
     QModelIndex index( int row, int column,
--- trunk/KDE/kdeedu/marble/src/lib/MarbleControlBox.cpp #1150964:1150965
@@ -294,7 +294,11 @@
              widget->fileViewModel(),       SLOT( saveFile() ) );
     connect( d->m_fileViewUi.m_closeButton, SIGNAL( clicked() ) ,
              widget->fileViewModel(),    SLOT( closeFile() ) );
-    d->m_fileViewUi.m_treeView->setModel(widget->model()->treeModel());
+    QSortFilterProxyModel *sortModel = new QSortFilterProxyModel(this);
+    sortModel->setSourceModel( widget->model()->treeModel() );
+    sortModel->setDynamicSortFilter( true );
+    d->m_fileViewUi.m_treeView->setModel( sortModel );
+    d->m_fileViewUi.m_treeView->setSortingEnabled( true );
 
     // Initialize the MarbleLegendBrowser
     d->m_legendUi.marbleLegendBrowser->setMarbleWidget( d->m_widget );


More information about the Marble-commits mailing list