[Kst] branches/work/kst/portto4/kst/src

Barth Netterfield netterfield at astro.utoronto.ca
Sat Oct 31 01:51:20 CET 2009


SVN commit 1042899 by netterfield:

Fixed reload so it works (tested for dirfiles and ascii).



 M  +2 -2      datasources/ascii/ascii.cpp  
 M  +15 -9     datasources/dirfilesource/dirfilesource.cpp  
 M  +1 -1      libkst/datavector.cpp  
 M  +14 -19    libkst/objectstore.cpp  
 M  +0 -1      libkst/updatemanager.cpp  


--- branches/work/kst/portto4/kst/src/datasources/ascii/ascii.cpp #1042898:1042899
@@ -226,7 +226,7 @@
     _rowIndex = 0L;
     _numLinesAlloc = 0;
   }
-
+  _numFrames = 0;
   _haveHeader = false;
   _fieldListComplete = false;
   _fieldList.clear();
@@ -234,7 +234,7 @@
   _matrixList.clear();
   _stringList.clear();
 
-  update(); // Yuck - same problem as in the constructor presently.
+  checkUpdate();
 
   return true;
 }
--- branches/work/kst/portto4/kst/src/datasources/dirfilesource/dirfilesource.cpp #1042898:1042899
@@ -64,15 +64,6 @@
   init();
   update();
 
-  _watcher = new QFileSystemWatcher();
-  if (_fieldList.count() > 1) {
-    QString filePath = _dirfile->ReferenceFilename();
-    _watcher->addPath(filePath);
-  }
-
-  connect(_watcher, SIGNAL(fileChanged ( const QString & )), this, SLOT(checkUpdate()));
-  connect(_watcher, SIGNAL(directoryChanged ( const QString & )), this, SLOT(checkUpdate()));
-
 }
 
 
@@ -91,9 +82,15 @@
 
 
 bool DirFileSource::reset() {
+  disconnect(_watcher, SIGNAL(fileChanged ( const QString & )), this, SLOT(checkUpdate()));
+  disconnect(_watcher, SIGNAL(directoryChanged ( const QString & )), this, SLOT(checkUpdate()));
   if (_dirfile) {
     delete _dirfile;
   }
+
+  delete _watcher;
+  _watcher = 0L;
+
   init();
   return true;
 }
@@ -131,6 +128,15 @@
     _writable = true;
   }
 
+  _watcher = new QFileSystemWatcher();
+  if (_fieldList.count() > 1) {
+    QString filePath = _dirfile->ReferenceFilename();
+    _watcher->addPath(filePath);
+  }
+
+  connect(_watcher, SIGNAL(fileChanged ( const QString & )), this, SLOT(checkUpdate()));
+  connect(_watcher, SIGNAL(directoryChanged ( const QString & )), this, SLOT(checkUpdate()));
+
   return update() == Kst::Object::UPDATE;
 }
 
--- branches/work/kst/portto4/kst/src/libkst/datavector.cpp #1042898:1042899
@@ -626,7 +626,6 @@
       assert(newsrc != _file);
       if (newsrc) {
         _file->unlock();
-        // FIXME: need to writelock store?
         if (store()) {
           store()->removeObject(_file);
         }
@@ -638,6 +637,7 @@
     }
     _resetFieldMetadata();
     _file->unlock();
+    update();
   }
 }
 
--- branches/work/kst/portto4/kst/src/libkst/objectstore.cpp #1042898:1042899
@@ -148,39 +148,34 @@
 
 void ObjectStore::rebuildDataSourceList() {
 
-  DataSourceList newDataSourceList;
+  DataSourceList dataSourceList;
 
-  foreach(ObjectPtr object, _list) {
-  DataSourcePtr new_data_source;
-    DataVectorPtr object_P = kst_cast<DataVector>(object);
+  for (int i=0; i<_list.count(); i++) {
+    DataVectorPtr object_P = kst_cast<DataVector>(_list.at(i));
     if (object_P) {
+      DataSourcePtr dataSource;
       object_P->readLock();
-      QString filename = object_P->filename();
+      dataSource = object_P->dataSource();
       object_P->unlock();
-      new_data_source = newDataSourceList.findReusableFileName(filename);
-      if (new_data_source == 0) {
-        new_data_source = DataSource::loadSource(this, filename);
-        new_data_source->readLock();
-        newDataSourceList.append(new_data_source);
-        new_data_source->unlock();
+
+      if (!dataSourceList.contains(dataSource)) {
+        object_P->writeLock();
+        object_P->reload();
+        object_P->unlock();
+        dataSourceList.append(dataSource);
       }
-      object_P->writeLock();
-      //object_P->changeFile(new_data_source);
-      object_P->update();
-      object_P->unlock();
     }
   }
 
+  dataSourceList.clear();
+  dataSourceList.append(_dataSourceList);
 
   // clean up unused data sources
-  for (DataSourceList::Iterator it = _dataSourceList.begin(); it != _dataSourceList.end(); ++it) {
-    qDebug() << "Usage: " << (*it)->getUsage() << " fileName: " << (*it)->fileName();
+  for (DataSourceList::Iterator it = dataSourceList.begin(); it != dataSourceList.end(); ++it) {
     if ((*it)->getUsage() == 1) {
       removeObject(*it);
     }
   }
-  qDebug() << "removed";
-  newDataSourceList.clear();
 }
 
 bool ObjectStore::isEmpty() const {
--- branches/work/kst/portto4/kst/src/libkst/updatemanager.cpp #1042898:1042899
@@ -58,7 +58,6 @@
 
 void UpdateManager::requestUpdate(ObjectPtr object) {
   if (!_updateRequests.contains(object)) {
-//    qDebug() << "xxx    appending object to update requests";
     _updateRequests.append(object);
   }
 #if DEBUG_UPDATE_CYCLE > 1


More information about the Kst mailing list