[Kst] branches/work/kst/portto4/kst/src
Peter Kümmel
syntheticpp at gmx.net
Sat Aug 28 13:45:46 CEST 2010
SVN commit 1169081 by kuemmel:
cleanup _watcher code
M +6 -13 datasources/dirfilesource/dirfilesource.cpp
M +19 -14 libkst/datasource.cpp
M +1 -0 libkst/datasource.h
--- branches/work/kst/portto4/kst/src/datasources/dirfilesource/dirfilesource.cpp #1169080:1169081
@@ -153,13 +153,8 @@
-DirFileSource::~DirFileSource() {
- if (_watcher) {
- disconnect(_watcher, SIGNAL(fileChanged ( const QString & )), this, SLOT(checkUpdate()));
- disconnect(_watcher, SIGNAL(directoryChanged ( const QString & )), this, SLOT(checkUpdate()));
- delete _watcher;
- _watcher = 0L;
- }
+DirFileSource::~DirFileSource()
+{
delete _config;
_config = 0L;
delete _dirfile;
@@ -167,16 +162,13 @@
}
-void DirFileSource::reset() {
- disconnect(_watcher, SIGNAL(fileChanged ( const QString & )), this, SLOT(checkUpdate()));
- disconnect(_watcher, SIGNAL(directoryChanged ( const QString & )), this, SLOT(checkUpdate()));
+void DirFileSource::reset()
+{
+ resetFileWatcher();
if (_dirfile) {
delete _dirfile;
}
- delete _watcher;
- _watcher = 0L;
-
init();
Object::reset();
}
@@ -213,6 +205,7 @@
_writable = true;
_frameCount = _dirfile->NFrames();
}
+
_watcher = new QFileSystemWatcher();
if (_fieldList.count() > 1) {
QString filePath = _dirfile->ReferenceFilename();
--- branches/work/kst/portto4/kst/src/libkst/datasource.cpp #1169080:1169081
@@ -130,7 +130,6 @@
Object(),
_filename(filename),
_cfg(cfg),
- _updateCheckType(File),
interf_scalar(new NotSupportedImp<DataScalar>),
interf_string(new NotSupportedImp<DataString>),
interf_vector(new NotSupportedImp<DataVector>),
@@ -151,29 +150,26 @@
QString tn = i18n("DS-%1", shortFilename);
_shortName = tn;
- if (_updateCheckType == Timer) {
- QTimer::singleShot(UpdateManager::self()->minimumUpdatePeriod()-1, this, SLOT(checkUpdate()));
- } else if (_updateCheckType == File) {
- _watcher = new QFileSystemWatcher();
- _watcher->addPath(_filename);
- connect(_watcher, SIGNAL(fileChanged ( const QString & )), this, SLOT(checkUpdate()));
- connect(_watcher, SIGNAL(directoryChanged ( const QString & )), this, SLOT(checkUpdate()));
+ // TODO What is the better default?
+ setUpdateType(File);
}
+
+DataSource::~DataSource() {
+ resetFileWatcher();
+ delete interf_scalar;
+ delete interf_string;
+ delete interf_vector;
+ delete interf_matrix;
}
-DataSource::~DataSource() {
+void DataSource::resetFileWatcher() {
if (_watcher) {
disconnect(_watcher, SIGNAL(fileChanged ( const QString & )), this, SLOT(checkUpdate()));
disconnect(_watcher, SIGNAL(directoryChanged ( const QString & )), this, SLOT(checkUpdate()));
delete _watcher;
_watcher = 0L;
}
-
- delete interf_scalar;
- delete interf_string;
- delete interf_vector;
- delete interf_matrix;
}
@@ -202,7 +198,16 @@
void DataSource::setUpdateType(UpdateCheckType updateType)
{
_updateCheckType = updateType;
+ resetFileWatcher();
+ if (_updateCheckType == Timer) {
+ QTimer::singleShot(UpdateManager::self()->minimumUpdatePeriod()-1, this, SLOT(checkUpdate()));
+ } else if (_updateCheckType == File) {
+ _watcher = new QFileSystemWatcher();
+ _watcher->addPath(_filename);
+ connect(_watcher, SIGNAL(fileChanged ( const QString & )), this, SLOT(checkUpdate()));
+ connect(_watcher, SIGNAL(directoryChanged ( const QString & )), this, SLOT(checkUpdate()));
}
+}
void DataSource::checkUpdate() {
--- branches/work/kst/portto4/kst/src/libkst/datasource.h #1169080:1169081
@@ -217,6 +217,7 @@
QSettings *_cfg;
UpdateCheckType _updateCheckType;
+ void resetFileWatcher();
virtual QString _automaticDescriptiveName() const;
void _initializeShortName();
More information about the Kst
mailing list