[Marble-commits] KDE/kdeedu/marble/src/lib
Thibaut Gridel
tgridel at free.fr
Sun Dec 26 14:55:59 CET 2010
SVN commit 1209333 by tgridel:
GeoDataTreeModel: huge performance boost to get rid of dynamic_cast
and use nodeType instead.
The overall performance of model especially with proxies depend on
optimisation of model code.
M +64 -49 GeoDataTreeModel.cpp
--- trunk/KDE/kdeedu/marble/src/lib/GeoDataTreeModel.cpp #1209332:1209333
@@ -69,18 +69,19 @@
return false;
}
- GeoDataContainer *container = dynamic_cast<GeoDataContainer*>( parentItem );
- if ( container ) {
+ if ( parentItem->nodeType() == GeoDataTypes::GeoDataFolderType
+ || parentItem->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
+ GeoDataContainer *container = static_cast<GeoDataContainer*>( parentItem );
return container->size();
}
- GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( parentItem );
- if ( placemark ) {
+ if ( parentItem->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
+ GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( parentItem );
return placemark->geometry();
}
- GeoDataMultiGeometry *geometry = dynamic_cast<GeoDataMultiGeometry*>( parentItem );
- if ( geometry ) {
+ if ( parentItem->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) {
+ GeoDataMultiGeometry *geometry = static_cast<GeoDataMultiGeometry*>( parentItem );
return geometry->size();
}
@@ -108,26 +109,22 @@
return 0;
}
- GeoDataContainer *container = dynamic_cast<GeoDataContainer*>( parentItem );
- if ( container ) {
+ if ( parentItem->nodeType() == GeoDataTypes::GeoDataFolderType
+ || parentItem->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
+ GeoDataContainer *container = static_cast<GeoDataContainer*>( parentItem );
// mDebug() << "rowCount " << type << "(" << parentItem << ") =" << container->size();
return container->size();
// } else {
// mDebug() << "rowCount bad container " << container;
}
- GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( parentItem );
- if ( placemark ) {
- if ( placemark->geometry() ) {
+ if ( parentItem->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
// mDebug() << "rowCount " << type << "(" << parentItem << ") = 1";
return 1;
}
-// mDebug() << "rowCount " << type << "(" << parentItem << ") = 0";
- return 0;
- }
- GeoDataMultiGeometry *geometry = dynamic_cast<GeoDataMultiGeometry*>( parentItem );
- if ( geometry ) {
+ if ( parentItem->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) {
+ GeoDataMultiGeometry *geometry = static_cast<GeoDataMultiGeometry*>( parentItem );
// mDebug() << "rowCount " << parent << " " << type << " " << geometry->size();
return geometry->size();
// } else {
@@ -170,9 +167,8 @@
GeoDataObject *object = static_cast<GeoDataObject*>( index.internalPointer() );
if ( role == Qt::DisplayRole ) {
- GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( object );
-
- if ( placemark ) {
+ if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
+ GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( object );
if ( index.column() == 0 ){
return QVariant( placemark->name() );
}
@@ -186,8 +182,9 @@
return QVariant( placemark->popularityIndex() );
}
}
- GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
- if ( feature ) {
+ if ( object->nodeType() == GeoDataTypes::GeoDataFolderType
+ || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
+ GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
if ( index.column() == 0 ){
return QVariant( feature->name() );
}
@@ -209,8 +206,10 @@
}
else if ( role == Qt::CheckStateRole
&& index.column() == 0 ) {
- GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
- if ( feature ) {
+ if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType
+ || object->nodeType() == GeoDataTypes::GeoDataFolderType
+ || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
+ GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
if ( feature->isVisible() ) {
return QVariant( Qt::Checked );
}
@@ -221,17 +220,30 @@
}
else if ( role == Qt::DecorationRole
&& index.column() == 0 ) {
- GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
- if ( feature )
+ if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType
+ || object->nodeType() == GeoDataTypes::GeoDataFolderType
+ || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
+ GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
return QVariant(feature->style()->iconStyle().icon());
+ }
} else if ( role == MarblePlacemarkModel::ObjectPointerRole ) {
return qVariantFromValue( object );
} else if ( role == MarblePlacemarkModel::PopularityIndexRole ) {
- GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( object );
- if ( placemark ) {
+ if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
+ GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( object );
return QVariant( placemark->popularityIndex() );
}
+ } else if ( role == MarblePlacemarkModel::PopularityRole ) {
+ if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
+ GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( object );
+ return QVariant( placemark->popularity() );
}
+ } else if ( role == MarblePlacemarkModel::CoordinateRole ) {
+ if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
+ GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( object );
+ return qVariantFromValue( placemark->coordinate() );
+ }
+ }
return QVariant();
}
@@ -258,27 +270,26 @@
GeoDataObject *childItem = 0;
- GeoDataContainer *container = dynamic_cast<GeoDataContainer*>( parentItem );
- if ( container ) {
+
+ if ( parentItem->nodeType() == GeoDataTypes::GeoDataFolderType
+ || parentItem->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
+ GeoDataContainer *container = static_cast<GeoDataContainer*>( parentItem );
childItem = container->child( row );
+ return createIndex( row, column, childItem );
}
- GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( parentItem );
- if ( placemark ) {
+ if ( parentItem->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
+ GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( parentItem );
childItem = placemark->geometry();
+ return createIndex( row, column, childItem );
}
- GeoDataMultiGeometry *geometry = dynamic_cast<GeoDataMultiGeometry*>( parentItem );
- if ( geometry ) {
+ if ( parentItem->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) {
+ GeoDataMultiGeometry *geometry = static_cast<GeoDataMultiGeometry*>( parentItem );
childItem = geometry->child( row );
+ return createIndex( row, column, childItem );
}
-
- if ( childItem ) {
-// mDebug() << "index " << type << "[" << row << "](" << parentItem << ") ="
-// << childItem->nodeType() << "(" << childItem << ")";
- return createIndex( row, column, childItem );
- }
return QModelIndex();
}
@@ -304,8 +315,9 @@
GeoDataObject *greatParentObject = parentObject->parent();
// greatParent can be a container
- GeoDataContainer *greatparentContainer = dynamic_cast<GeoDataContainer*>( greatParentObject );
- if ( greatparentContainer ) {
+ if ( greatParentObject->nodeType() == GeoDataTypes::GeoDataFolderType
+ || greatParentObject->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
+ GeoDataContainer *greatparentContainer = static_cast<GeoDataContainer*>( greatParentObject );
GeoDataFeature *parentFeature = static_cast<GeoDataFeature*>( parentObject );
// mDebug() << "parent " << childObject->nodeType() << "(" << childObject << ") = "
// << parentObject->nodeType() << "[" << greatparentContainer->childPosition( parentFeature ) << "](" << parentObject << ")";
@@ -313,16 +325,16 @@
}
// greatParent can be a placemark
- GeoDataPlacemark *greatparentPlacemark = dynamic_cast<GeoDataPlacemark*>( greatParentObject );
- if ( greatparentPlacemark ) {
+ if ( greatParentObject->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
+// GeoDataPlacemark *greatparentPlacemark = static_cast<GeoDataPlacemark*>( greatParentObject );
// mDebug() << "parent " << childObject->nodeType() << "(" << childObject << ") = "
// << parentObject->nodeType() << "[0](" << parentObject << ")";
return createIndex( 0, 0, parentObject );
}
// greatParent can be a multigeometry
- GeoDataMultiGeometry *greatparentMultiGeo = dynamic_cast<GeoDataMultiGeometry*>( greatParentObject );
- if ( greatparentMultiGeo ) {
+ if ( greatParentObject->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) {
+ GeoDataMultiGeometry *greatparentMultiGeo = static_cast<GeoDataMultiGeometry*>( greatParentObject );
GeoDataGeometry *parentGeometry = static_cast<GeoDataGeometry*>( parentObject );
// mDebug() << "parent " << childObject->nodeType() << "(" << childObject << ") = "
// << parentObject->nodeType() << "[" << greatParentItem->childPosition( parentGeometry ) << "](" << parentObject << ")";
@@ -347,8 +359,10 @@
GeoDataObject *object = static_cast<GeoDataObject*>( index.internalPointer() );
if ( role == Qt::CheckStateRole ) {
- GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
- if ( feature ) {
+ if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType
+ || object->nodeType() == GeoDataTypes::GeoDataFolderType
+ || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
+ GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
feature->setVisible( value.toBool() );
mDebug() << "setData " << feature->name() << " " << value.toBool();
emit dataChanged( index, index );
@@ -365,8 +379,9 @@
return Qt::NoItemFlags;
GeoDataObject *object = static_cast<GeoDataObject*>( index.internalPointer() );
- GeoDataFeature *feature = dynamic_cast<GeoDataFeature*>( object );
- if ( feature ) {
+ if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType
+ || object->nodeType() == GeoDataTypes::GeoDataFolderType
+ || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
}
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
More information about the Marble-commits
mailing list