[Kst] extragear/graphics/kst/src/libkstapp

George Staikos staikos at kde.org
Thu Apr 6 06:19:36 CEST 2006


SVN commit 526967 by staikos:

attempt to cache datasources.  I received no feedback on this one so far, but
it seems to work fine.  Will not backport.


 M  +1 -0      datawizard.ui  
 M  +29 -10    datawizard.ui.h  


--- trunk/extragear/graphics/kst/src/libkstapp/datawizard.ui #526966:526967
@@ -1336,6 +1336,7 @@
     <variable access="private">QString _file;</variable>
     <variable access="private">bool _inTest;</variable>
     <variable access="private">QGuardedPtr&lt;QWidget&gt; _configWidget;</variable>
+    <variable access="private">KstDataSourceList _sourceCache;</variable>
 </variables>
 <slots>
     <slot access="public">setInput( const QString &amp; input )</slot>
--- trunk/extragear/graphics/kst/src/libkstapp/datawizard.ui.h #526966:526967
@@ -253,17 +253,27 @@
     if (page == _pageVectors) {
 	KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(_file);
 	if (!ds) {
-	    ds = KstDataSource::loadSource(_file);
-#if 0
-	    // Enable this once we cleanup the unused pointers
-	    KST::dataSourceList.lock().writeLock();
-	    KST::dataSourceList.append(ds);
-	    KST::dataSourceList.lock().writeUnlock();
-#endif
+	    for (KstDataSourceList::Iterator i = _sourceCache.begin(); i != _sourceCache.end(); ++i) {
+		if ((*i)->fileName() == _file) {
+		    ds = *i;
+		    break;
+		}
+	    }
+
+	    if (!ds) {
+		ds = KstDataSource::loadSource(_file);
+		if (ds) {
+		    _sourceCache.append(ds);
+		}
+	    }
 	}
-	ds->readLock();
+	if (ds) {
+	    ds->readLock();
+	}
 	_kstDataRange->setAllowTime(ds && ds->supportsTimeConversions());
-	ds->readUnlock();
+	if (ds) {
+	    ds->readUnlock();
+	}
 	_vectorReduction->setFocus();
     } else if (page == _pageFilters) {
 	QString save = _filterList->currentText();
@@ -490,14 +500,23 @@
     
     KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(_file);
     if (!ds) {
-	ds = KstDataSource::loadSource(_file);
+	for (KstDataSourceList::Iterator i = _sourceCache.begin(); i != _sourceCache.end(); ++i) {
+	    if ((*i)->fileName() == _file) {
+		ds = *i;
+		break;
+	    }
+	}
 	if (!ds) {
+	    ds = KstDataSource::loadSource(_file);
+	}
+	if (!ds) {
 	    KMessageBox::sorry(this, i18n("<qt>Sorry, unable to load the data file '<b>%1</b>'.").arg(_file));
 	    return;
 	}
 	KST::dataSourceList.lock().writeLock();
 	KST::dataSourceList.append(ds);
 	KST::dataSourceList.lock().writeUnlock();
+	_sourceCache.clear();
     }
 
     // check for sufficient memory


More information about the Kst mailing list