Bug 89889

Summary: unused datasources saved in .kst file
Product: [Applications] kst Reporter: Nicolas Brisset <nicolas.brisset>
Component: generalAssignee: George Staikos <staikos>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 1.x   
Target Milestone: ---   
Platform: unspecified   
OS: Solaris   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Nicolas Brisset 2004-09-20 18:13:59 UTC
Version:           1.0.0_devel (using KDE 3.3.0, compiled sources)
Compiler:          gcc version 3.3.2
OS:                SunOS (sun4u) release 5.8

When using the most excellent "Data->Change data file" feature, I noticed the following problem: all files used at least are remembered and saved in the .kst file, even if they are no longer in use (i.e. no vector depends on them). 
This is very much sub-optimal as datasources are instantiated for each of these files, which in some cases can take a lot of time and resources; the expected behavior when saving a plot is to save only the datasources currently in use.

Steps to reproduce in case the explanation is not clear:
1) create a plot with a couple of vars from file1.dat
2) use the "Data->Change data file" feature to select file2.dat as datasource for all the vectors
3) save the plot in test.kst
4) open test.kst in your favorite editor: file1.dat is there, and if you have the chance (!) of having a slow datasource you will clearly notice that a datasource instance is created for file1.dat even though it is useless.
Comment 1 George Staikos 2004-09-20 20:51:44 UTC
Agreed, will fix.
Comment 2 George Staikos 2004-09-21 18:12:42 UTC
CVS commit by staikos: 

Only save data sources that are in use in the Kst file
CCMAIL: 89889-done@bugs.kde.org


  M +11 -4     kstdoc.cpp   1.119


--- kdeextragear-2/kst/kst/kstdoc.cpp  #1.118:1.119
@@ -401,10 +401,18 @@ void KstDoc::saveDocument(QTextStream& t
   ts << " <updateDelay>" << delay() << "</updateDelay>" << endl;
 
+  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
+
   // save files
   KST::dataSourceList.lock().readLock();
   for (uint i = 0; i < KST::dataSourceList.count(); i++) {
+    KstDataSourcePtr dsp = KST::dataSourceList[i];
+    for (KstRVectorList::Iterator it = rvl.begin(); it != rvl.end(); ++it) {
+      if ((*it)->dataSource() == dsp) {
     ts << " <kstfile>" << endl;
-    KST::dataSourceList[i]->save(ts);
+        dsp->save(ts);
     ts << " </kstfile>" << endl;
+        break;
+      }
+    }
   }
   KST::dataSourceList.lock().readUnlock();
@@ -420,5 +428,4 @@ void KstDoc::saveDocument(QTextStream& t
 
   // save vectors
-  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
   for (KstRVectorList::Iterator it = rvl.begin(); it != rvl.end(); ++it) {
     ts << " <vector>" << endl;