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

Dennis Nienhüser earthwings at gentoo.org
Tue Jan 18 21:19:08 CET 2011


SVN commit 1215463 by nienhueser:

Add a method to set the root document, i.e. use GeoDataTreeModel from memory without a FileLoader between.

 M  +30 -2     GeoDataTreeModel.cpp  
 M  +6 -0      GeoDataTreeModel.h  


--- trunk/KDE/kdeedu/marble/src/lib/GeoDataTreeModel.cpp #1215462:1215463
@@ -33,13 +33,29 @@
 
 class GeoDataTreeModel::Private {
  public:
-    Private() : m_rootDocument( new GeoDataDocument ) {}
-    ~Private() { delete m_rootDocument; }
+    Private();
+    ~Private();
 
     GeoDataDocument* m_rootDocument;
     FileManager     *m_fileManager;
+    bool             m_ownsRootDocument;
 };
 
+GeoDataTreeModel::Private::Private() :
+    m_rootDocument( new GeoDataDocument ),
+    m_fileManager( 0 ),
+    m_ownsRootDocument( true )
+{
+    // nothing to do
+}
+
+GeoDataTreeModel::Private::~Private()
+{
+    if ( m_ownsRootDocument ) {
+        delete m_rootDocument;
+    }
+}
+
 GeoDataTreeModel::GeoDataTreeModel( QObject *parent )
     : QAbstractItemModel( parent ),
     d( new Private )
@@ -450,4 +466,16 @@
     reset();
 }
 
+void GeoDataTreeModel::setRootDocument( GeoDataDocument* document )
+{
+    beginResetModel();
+    if ( d->m_ownsRootDocument ) {
+        delete d->m_rootDocument;
+        d->m_ownsRootDocument = false;
+    }
+
+    d->m_rootDocument = document;
+    endResetModel();
+}
+
 #include "GeoDataTreeModel.moc"
--- trunk/KDE/kdeedu/marble/src/lib/GeoDataTreeModel.h #1215462:1215463
@@ -71,6 +71,12 @@
      */
     void setFileManager ( FileManager *fileManager );
 
+    /**
+      * Sets the root document to use. This replaces previously loaded data, if any.
+      * @param document The new root document. Ownership retains with the caller,
+      *   i.e. GeoDataTreeModel will not delete the passed document at its destruction.
+      */
+    void setRootDocument( GeoDataDocument* document );
 
   public Q_SLOTS:
     void addDocument( int index );


More information about the Marble-commits mailing list