[Marble-commits] KDE/kdeedu/marble/src/lib
Thibaut Gridel
tgridel at free.fr
Sat Jul 17 10:59:54 CEST 2010
SVN commit 1150959 by tgridel:
GeoDataTree: get rid of NodeType for type determination
M +57 -32 GeoDataTreeModel.cpp
M +2 -0 GeoDataTreeModel.h
--- trunk/KDE/kdeedu/marble/src/lib/GeoDataTreeModel.cpp #1150958:1150959
@@ -48,6 +48,41 @@
delete d;
}
+bool GeoDataTreeModel::hasChildren( const QModelIndex &parent ) const
+{
+ GeoDataObject *parentItem;
+ if ( parent.column() > 0 ) {
+ return false;
+ }
+
+ if ( !parent.isValid() ) {
+ parentItem = d->m_rootDocument;
+ } else {
+ parentItem = static_cast<GeoDataObject*>( parent.internalPointer() );
+ }
+
+ if ( !parentItem ) {
+ return false;
+ }
+
+ GeoDataContainer *container = dynamic_cast<GeoDataContainer*>( parentItem );
+ if ( container ) {
+ return container->size();
+ }
+
+ GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( parentItem );
+ if ( placemark ) {
+ return placemark->geometry();
+ }
+
+ GeoDataMultiGeometry *geometry = dynamic_cast<GeoDataMultiGeometry*>( parentItem );
+ if ( geometry ) {
+ return geometry->size();
+ }
+
+ return false;
+}
+
int GeoDataTreeModel::rowCount( const QModelIndex &parent ) const
{
// mDebug() << "rowCount";
@@ -69,21 +104,15 @@
return 0;
}
- QString type = parentItem->nodeType();
- if ( type == GeoDataTypes::GeoDataContainerType
- || type == GeoDataTypes::GeoDataDocumentType
- || type == GeoDataTypes::GeoDataFolderType ) {
- GeoDataContainer *container = static_cast<GeoDataContainer*>( parentItem );
+ GeoDataContainer *container = dynamic_cast<GeoDataContainer*>( parentItem );
if ( container ) {
// mDebug() << "rowCount " << type << "(" << parentItem << ") =" << container->size();
return container->size();
- } else {
+// } else {
// mDebug() << "rowCount bad container " << container;
}
- }
- if ( type == GeoDataTypes::GeoDataPlacemarkType ) {
- GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( parentItem );
+ GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( parentItem );
if ( placemark ) {
if ( placemark->geometry() ) {
// mDebug() << "rowCount " << type << "(" << parentItem << ") = 1";
@@ -92,17 +121,14 @@
// mDebug() << "rowCount " << type << "(" << parentItem << ") = 0";
return 0;
}
- }
- if ( type == GeoDataTypes::GeoDataMultiGeometryType ) {
- GeoDataMultiGeometry *geometry = static_cast<GeoDataMultiGeometry*>( parentItem );
+ GeoDataMultiGeometry *geometry = dynamic_cast<GeoDataMultiGeometry*>( parentItem );
if ( geometry ) {
// mDebug() << "rowCount " << parent << " " << type << " " << geometry->size();
return geometry->size();
- } else {
+// } else {
// mDebug() << "rowCount bad geometry " << geometry;
}
- }
// mDebug() << "rowcount end";
return 0;//parentItem->childCount();
@@ -118,6 +144,10 @@
GeoDataObject *object = static_cast<GeoDataObject*>( index.internalPointer() );
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())) );
+
GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
if ( feature )
return QVariant( feature->nodeType().append("-").append(feature->name()) );
@@ -170,16 +200,13 @@
GeoDataObject *childItem = 0;
- QString type = parentItem->nodeType();
- if ( type == GeoDataTypes::GeoDataContainerType
- || type == GeoDataTypes::GeoDataDocumentType
- || type == GeoDataTypes::GeoDataFolderType ) {
- GeoDataContainer *container = static_cast<GeoDataContainer*>( parentItem );
+ GeoDataContainer *container = dynamic_cast<GeoDataContainer*>( parentItem );
+ if ( container ) {
childItem = container->child( row );
}
- if ( type == GeoDataTypes::GeoDataPlacemarkType ) {
- GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( parentItem );
+ GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( parentItem );
+ if ( placemark ) {
childItem = placemark->geometry();
// TODO: this parenting is needed because the parser doesn't use
// the pointer-based API. This should happen there.
@@ -188,8 +215,8 @@
}
}
- if ( type == GeoDataTypes::GeoDataMultiGeometryType ) {
- GeoDataMultiGeometry *geometry = static_cast<GeoDataMultiGeometry*>( parentItem );
+ GeoDataMultiGeometry *geometry = dynamic_cast<GeoDataMultiGeometry*>( parentItem );
+ if ( geometry ) {
childItem = geometry->child( row );
// TODO: this parenting is needed because the parser doesn't use
// the pointer-based API. This should happen there.
@@ -227,33 +254,31 @@
}
GeoDataObject *greatParentObject = parentObject->parent();
- QString greatParentType = greatParentObject->nodeType();
// greatParent can be a container
- if ( greatParentType == GeoDataTypes::GeoDataContainerType
- || greatParentType == GeoDataTypes::GeoDataDocumentType
- || greatParentType == GeoDataTypes::GeoDataFolderType ) {
+ GeoDataContainer *greatparentContainer = dynamic_cast<GeoDataContainer*>( greatParentObject );
+ if ( greatparentContainer ) {
GeoDataFeature *parentFeature = static_cast<GeoDataFeature*>( parentObject );
- GeoDataContainer * greatparentContainer = static_cast<GeoDataContainer*>( greatParentObject );
// mDebug() << "parent " << childObject->nodeType() << "(" << childObject << ") = "
// << parentObject->nodeType() << "[" << greatparentContainer->childPosition( parentFeature ) << "](" << parentObject << ")";
return createIndex( greatparentContainer->childPosition( parentFeature ), 0, parentObject );
}
// greatParent can be a placemark
- if ( greatParentType == GeoDataTypes::GeoDataPlacemarkType ) {
+ GeoDataPlacemark *greatparentPlacemark = dynamic_cast<GeoDataPlacemark*>( greatParentObject );
+ if ( greatparentPlacemark ) {
// mDebug() << "parent " << childObject->nodeType() << "(" << childObject << ") = "
// << parentObject->nodeType() << "[0](" << parentObject << ")";
return createIndex( 0, 0, parentObject );
}
// greatParent can be a multigeometry
- if ( greatParentType == GeoDataTypes::GeoDataMultiGeometryType ) {
+ GeoDataMultiGeometry *greatparentMultiGeo = dynamic_cast<GeoDataMultiGeometry*>( greatParentObject );
+ if ( greatparentMultiGeo ) {
GeoDataGeometry *parentGeometry = static_cast<GeoDataGeometry*>( parentObject );
- GeoDataMultiGeometry * greatParentItem = static_cast<GeoDataMultiGeometry*>( greatParentObject );
// mDebug() << "parent " << childObject->nodeType() << "(" << childObject << ") = "
// << parentObject->nodeType() << "[" << greatParentItem->childPosition( parentGeometry ) << "](" << parentObject << ")";
- return createIndex( greatParentItem->childPosition( parentGeometry ), 0, parentObject );
+ return createIndex( greatparentMultiGeo->childPosition( parentGeometry ), 0, parentObject );
}
}
--- trunk/KDE/kdeedu/marble/src/lib/GeoDataTreeModel.h #1150958:1150959
@@ -41,6 +41,8 @@
*/
~GeoDataTreeModel();
+ virtual bool hasChildren( const QModelIndex &parent ) const;
+
/**
* Return the number of Items in the Model.
*/
More information about the Marble-commits
mailing list