[Marble-commits] KDE/kdeedu/marble/src/lib
Thibaut Gridel
tgridel at free.fr
Fri Jul 16 23:09:40 CEST 2010
SVN commit 1150813 by tgridel:
GeoDataContainer: store GeoDataFeature* in GeoDataContainer
also provide a pointer-based api which doesn't detach() to access a pointer
last, use iterators for GeoDataFeature* to iterate features
M +7 -4 FileManager.cpp
M +76 -30 geodata/data/GeoDataContainer.cpp
M +11 -9 geodata/data/GeoDataContainer.h
M +11 -1 geodata/data/GeoDataContainer_p.h
M +3 -3 geodata/writers/kml/KmlDocumentTagWriter.cpp
--- trunk/KDE/kdeedu/marble/src/lib/FileManager.cpp #1150812:1150813
@@ -183,13 +183,16 @@
// now get the document that will be preserved throughout the life time
GeoDataDocument* doc = item->document();
// remove the hashes in front of the styles.
- QVector<GeoDataFeature>::Iterator end = doc->end();
- QVector<GeoDataFeature>::Iterator itr = doc->begin();
+ QVector<GeoDataFeature*>::Iterator end = doc->end();
+ QVector<GeoDataFeature*>::Iterator itr = doc->begin();
for ( ; itr != end; ++itr ) {
// use *itr (or itr.value()) here
- QString styleUrl = itr->styleUrl().remove('#');
- itr->setStyle( &doc->style( styleUrl ) );
+ QString styleUrl = (*itr)->styleUrl().remove('#');
+ if ( ! styleUrl.isEmpty() )
+ {
+ (*itr)->setStyle( &doc->style( styleUrl ) );
}
+ }
// do not set this file if it only contains points
if ( doc->isVisible() && d->m_datafacade->geometryModel() )
--- trunk/KDE/kdeedu/marble/src/lib/geodata/data/GeoDataContainer.cpp #1150812:1150813
@@ -64,15 +64,16 @@
{
QVector<GeoDataFolder> results;
- QVector<GeoDataFeature>::const_iterator it = p()->m_vector.constBegin();
- QVector<GeoDataFeature>::const_iterator end = p()->m_vector.constEnd();
+ QVector<GeoDataFeature*>::const_iterator it = p()->m_vector.constBegin();
+ QVector<GeoDataFeature*>::const_iterator end = p()->m_vector.constEnd();
for (; it != end; ++it) {
- GeoDataFeature feature = *it;
- if ( feature.featureId() == GeoDataFolderId )
+ if ( (*it)->featureId() == GeoDataFolderId ) {
+ GeoDataFeature feature = **it;
results.append( feature );
}
+ }
return results;
}
@@ -81,12 +82,12 @@
{
QVector<GeoDataPlacemark> results;
- QVector<GeoDataFeature>::const_iterator it = p()->m_vector.constBegin();
- QVector<GeoDataFeature>::const_iterator end = p()->m_vector.constEnd();
+ QVector<GeoDataFeature*>::const_iterator it = p()->m_vector.constBegin();
+ QVector<GeoDataFeature*>::const_iterator end = p()->m_vector.constEnd();
for (; it != end; ++it) {
- if ( GeoDataPlacemarkId == it->featureId() ) {
- GeoDataPlacemark placemark = *it;
+ if ( GeoDataPlacemarkId == (*it)->featureId() ) {
+ GeoDataPlacemark placemark = **it;
results.append( placemark );
}
}
@@ -94,17 +95,64 @@
return results;
}
-QVector<GeoDataFeature>& GeoDataContainer::features() const
+QVector<GeoDataFeature*> GeoDataContainer::featureList() const
{
return p()->m_vector;
}
-void GeoDataContainer::append( const GeoDataFeature& other )
+QVector<GeoDataFeature> GeoDataContainer::features() const
{
+ QVector<GeoDataFeature> results;
+
+ QVector<GeoDataFeature*>::const_iterator it = p()->m_vector.constBegin();
+ QVector<GeoDataFeature*>::const_iterator end = p()->m_vector.constEnd();
+
+ for (; it != end; ++it) {
+ GeoDataFeature f = **it;
+ results.append( f );
+ }
+
+ return results;
+}
+
+/**
+ * @brief returns the requested child item
+ */
+GeoDataFeature* GeoDataContainer::child( int i )
+{
+ return p()->m_vector.at(i);
+}
+
+/**
+ * @brief returns the position of an item in the list
+ */
+int GeoDataContainer::childPosition( GeoDataFeature* object )
+{
+ for ( int i=0; i< p()->m_vector.size(); i++ )
+ {
+ if ( p()->m_vector.at( i ) == object )
+ {
+ return i;
+ }
+ }
+ return -1;
+}
+
+
+void GeoDataContainer::append( GeoDataFeature *other )
+{
detach();
p()->m_vector.append( other );
}
+
+void GeoDataContainer::append( const GeoDataFeature& other )
+{
+ detach();
+ GeoDataFeature *f = new GeoDataFeature(other);
+ p()->m_vector.append( f );
+}
+
int GeoDataContainer::size() const
{
return p()->m_vector.size();
@@ -113,34 +161,34 @@
GeoDataFeature& GeoDataContainer::at( int pos )
{
detach();
- return p()->m_vector[ pos ];
+ return *(p()->m_vector[ pos ]);
}
const GeoDataFeature& GeoDataContainer::at( int pos ) const
{
- return p()->m_vector.at( pos );
+ return *(p()->m_vector.at( pos ));
}
GeoDataFeature& GeoDataContainer::last()
{
detach();
- return p()->m_vector.last();
+ return *(p()->m_vector.last());
}
const GeoDataFeature& GeoDataContainer::last() const
{
- return p()->m_vector.last();
+ return *(p()->m_vector.last());
}
GeoDataFeature& GeoDataContainer::first()
{
detach();
- return p()->m_vector.first();
+ return *(p()->m_vector.first());
}
const GeoDataFeature& GeoDataContainer::first() const
{
- return p()->m_vector.first();
+ return *(p()->m_vector.first());
}
void GeoDataContainer::clear()
@@ -149,24 +197,22 @@
p()->m_vector.clear();
}
-QVector<GeoDataFeature>::Iterator GeoDataContainer::begin()
+QVector<GeoDataFeature*>::Iterator GeoDataContainer::begin()
{
- GeoDataContainer::detach();
return p()->m_vector.begin();
}
-QVector<GeoDataFeature>::Iterator GeoDataContainer::end()
+QVector<GeoDataFeature*>::Iterator GeoDataContainer::end()
{
- GeoDataContainer::detach();
return p()->m_vector.end();
}
-QVector<GeoDataFeature>::ConstIterator GeoDataContainer::constBegin() const
+QVector<GeoDataFeature*>::ConstIterator GeoDataContainer::constBegin() const
{
return p()->m_vector.constBegin();
}
-QVector<GeoDataFeature>::ConstIterator GeoDataContainer::constEnd() const
+QVector<GeoDataFeature*>::ConstIterator GeoDataContainer::constEnd() const
{
return p()->m_vector.constEnd();
}
@@ -177,13 +223,13 @@
stream << p()->m_vector.count();
- for ( QVector <GeoDataFeature>::const_iterator iterator = p()->m_vector.constBegin();
+ for ( QVector <GeoDataFeature*>::const_iterator iterator = p()->m_vector.constBegin();
iterator != p()->m_vector.constEnd();
++iterator )
{
- const GeoDataFeature& feature = *iterator;
- stream << feature.featureId();
- feature.pack( stream );
+ const GeoDataFeature *feature = *iterator;
+ stream << feature->featureId();
+ feature->pack( stream );
}
}
@@ -203,15 +249,15 @@
/* not usable!!!! */ break;
case GeoDataFolderId:
{
- GeoDataFolder folder;
- folder.unpack( stream );
+ GeoDataFolder *folder = new GeoDataFolder;
+ folder->unpack( stream );
p()->m_vector.append( folder );
}
break;
case GeoDataPlacemarkId:
{
- GeoDataPlacemark placemark;
- placemark.unpack( stream );
+ GeoDataPlacemark *placemark = new GeoDataPlacemark;
+ placemark->unpack( stream );
p()->m_vector.append( placemark );
}
break;
--- trunk/KDE/kdeedu/marble/src/lib/geodata/data/GeoDataContainer.h #1150812:1150813
@@ -71,7 +71,8 @@
*
* @see GeoDataFeature
*/
- QVector<GeoDataFeature>& features() const;
+ QVector<GeoDataFeature*> featureList() const;
+ QVector<GeoDataFeature> features() const;
/**
* @brief A convenience function that returns all placemarks in this container.
@@ -84,18 +85,19 @@
/**
* @brief returns the requested child item
*/
-// virtual GeoDataObject* child( int );
+ GeoDataFeature* child( int );
/**
* @brief returns the position of an item in the list
*/
-// virtual int childPosition( GeoDataObject* );
+ int childPosition( GeoDataFeature *child);
/**
- * @brief returns the number of items in the list
+ * @brief add an element
*/
-// virtual int childCount();
+ void append( GeoDataFeature *other );
+
/**
* @brief add an element
*/
@@ -123,10 +125,10 @@
GeoDataFeature& first();
const GeoDataFeature& first() const;
- QVector<GeoDataFeature>::Iterator begin();
- QVector<GeoDataFeature>::Iterator end();
- QVector<GeoDataFeature>::ConstIterator constBegin() const;
- QVector<GeoDataFeature>::ConstIterator constEnd() const;
+ QVector<GeoDataFeature*>::Iterator begin();
+ QVector<GeoDataFeature*>::Iterator end();
+ QVector<GeoDataFeature*>::ConstIterator constBegin() const;
+ QVector<GeoDataFeature*>::ConstIterator constEnd() const;
void clear();
/**
--- trunk/KDE/kdeedu/marble/src/lib/geodata/data/GeoDataContainer_p.h #1150812:1150813
@@ -25,6 +25,16 @@
{
}
+ ~GeoDataContainerPrivate()
+ {
+ QVector<GeoDataFeature*>::Iterator i = m_vector.begin();
+ QVector<GeoDataFeature*>::Iterator end = m_vector.end();
+ for( ; i != end; ++i )
+ {
+ delete *i;
+ }
+ }
+
virtual void* copy()
{
GeoDataContainerPrivate* copy = new GeoDataContainerPrivate;
@@ -42,7 +52,7 @@
return GeoDataFolderId;
}
- QVector<GeoDataFeature> m_vector;
+ QVector<GeoDataFeature*> m_vector;
};
} // namespace Marble
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writers/kml/KmlDocumentTagWriter.cpp #1150812:1150813
@@ -34,11 +34,11 @@
writer.writeStartElement( kml::kmlTag_Document );
- QVector<GeoDataFeature>::ConstIterator it = document.constBegin();
- QVector<GeoDataFeature>::ConstIterator const end = document.constEnd();
+ QVector<GeoDataFeature*>::ConstIterator it = document.constBegin();
+ QVector<GeoDataFeature*>::ConstIterator const end = document.constEnd();
for ( ; it != end; ++it ) {
- writeElement( (*it), writer );
+ writeElement( (**it), writer );
}
//Write the actual important stuff!
More information about the Marble-commits
mailing list