From aa1604ec041e379f4256085b27cd902036db2eeb Mon Sep 17 00:00:00 2001
From: Julien Malik <julien.malik@c-s.fr>
Date: Thu, 7 Mar 2013 19:24:06 +0100
Subject: [PATCH] ENH: implement display settings save

---
 Code/Common/mvdDatasetDescriptor.cxx | 67 ++++++++++++++++++++++------
 Code/Common/mvdDatasetDescriptor.h   |  2 +-
 2 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/Code/Common/mvdDatasetDescriptor.cxx b/Code/Common/mvdDatasetDescriptor.cxx
index be07d0adbd..e90107ba2e 100644
--- a/Code/Common/mvdDatasetDescriptor.cxx
+++ b/Code/Common/mvdDatasetDescriptor.cxx
@@ -181,11 +181,11 @@ DatasetDescriptor
 /*******************************************************************************/
 bool
 DatasetDescriptor
-::SetImageModel( int id, void* settings )
+::SetImageModel( int id, void* imageSettings )
 {
   qDebug() << "DatasetDescriptor::SetImageModel(" << id << ")";
 
-  assert( settings!=NULL );
+  assert( imageSettings!=NULL );  
 
   // Access image information element.
   QDomElement imageInfoElt( GetImageElement( id ) );
@@ -199,20 +199,61 @@ DatasetDescriptor
   // TODO: Manage XML structure errors.
   assert( !settingsElt.isNull() );  
 
-  // RGB
-  QDomElement rgbElt(
-    settingsElt.firstChildElement( TAG_NAMES[ ELEMENT_RGB_CHANNELS  ] )
-  );
-  // TODO: Manage XML structure errors.
-  assert( !rgbElt.isNull() );
-  // TODO: Set RGB text here.
+  VectorImageModel::Settings* settings =
+    static_cast< VectorImageModel::Settings* >( imageSettings );
+  
+  {
+    // RGB
+    QDomElement rgbElt(
+      settingsElt.firstChildElement( TAG_NAMES[ ELEMENT_RGB_CHANNELS  ] )
+    );
+    // TODO: Manage XML structure errors.
+    assert( !rgbElt.isNull() );
+    
+    QDomNode node = rgbElt.firstChild();
+    // TODO: Manage XML structure errors.
+    assert( !node.isNull() );
+    assert( node.isText() );
+    
+    QDomText textNode( node.toText() );
+    // TODO: Manage XML structure errors.
+    assert( !textNode.isNull() );
+    
+    textNode.setData(
+      ContainerToString(
+        settings->GetRgbChannels().begin(),
+        settings->GetRgbChannels().end()
+      )
+    );
+  }
 
+  {
+    // Dynamics
+    QDomElement dynamicsElt(
+      settingsElt.firstChildElement( TAG_NAMES[ ELEMENT_DYNAMICS_PARAMETERS ] )
+    );
+    // TODO: Manage XML structure errors.
+    assert( !dynamicsElt.isNull() );
+    
+    QDomNode node = dynamicsElt.firstChild();
+    // TODO: Manage XML structure errors.
+    assert( !node.isNull() );
+    assert( node.isText() );
+    
+    QDomText textNode( node.toText() );
+    // TODO: Manage XML structure errors.
+    assert( !textNode.isNull() );
+    
+    textNode.setData(
+      ContainerToString(
+        settings->GetDynamicsParams().begin(),
+        settings->GetDynamicsParams().end()
+      )
+    );
+  }
   // Dynamics
-  QDomElement dynamicsElt(
-    settingsElt.firstChildElement( TAG_NAMES[ ELEMENT_DYNAMICS_PARAMETERS ] )
-  );
   // TODO: Manage XML structure errors.
-  assert( !dynamicsElt.isNull() );
+  
   // TODO: Set dynamics text here.
   
   
diff --git a/Code/Common/mvdDatasetDescriptor.h b/Code/Common/mvdDatasetDescriptor.h
index ef2116dafd..ccb229ded7 100644
--- a/Code/Common/mvdDatasetDescriptor.h
+++ b/Code/Common/mvdDatasetDescriptor.h
@@ -310,7 +310,7 @@ DatasetDescriptor
   QDomElement imageElt;
 
   for( imageElt = FirstImageElement();
-       !imageElt.isNull() && imageElt.attribute( "id" ).toInt()==id;
+       !imageElt.isNull() && imageElt.attribute( "id" ).toInt()!=id;
        imageElt = DatasetDescriptor::NextImageSiblingElement( imageElt ) );
 
   return imageElt;
-- 
GitLab