diff --git a/src/libkst/datasource.cpp b/src/libkst/datasource.cpp index c301e9b8f..9db7d72e3 100644 --- a/src/libkst/datasource.cpp +++ b/src/libkst/datasource.cpp @@ -249,6 +249,9 @@ void DataSource::checkUpdate() { void DataSource::deleteDependents() { + foreach (const PrimitivePtr &p, slavePrimitives) { + store()->removeObject(p); + } } diff --git a/src/libkst/datasource.h b/src/libkst/datasource.h index 8380783c7..c219b0345 100644 --- a/src/libkst/datasource.h +++ b/src/libkst/datasource.h @@ -217,6 +217,8 @@ class KSTCORE_EXPORT DataSource : public Object */ virtual ObjectList autoCurves(ObjectStore&) { return ObjectList(); } + PrimitiveList slavePrimitives; + public Q_SLOTS: virtual void checkUpdate(); @@ -274,6 +276,7 @@ class KSTCORE_EXPORT DataSource : public Object QFileSystemWatcher *_watcher; QColor _color; + // NOTE: You must bump the version key if you add new member variables // or change or add virtual functions. }; diff --git a/src/libkst/datasourcepluginmanager.cpp b/src/libkst/datasourcepluginmanager.cpp index fbddcee3c..6ac84e237 100644 --- a/src/libkst/datasourcepluginmanager.cpp +++ b/src/libkst/datasourcepluginmanager.cpp @@ -295,6 +295,7 @@ DataSourcePtr DataSourcePluginManager::findPluginFor(ObjectStore *store, const Q s->setProvider(plugin); s->setSlaveName(key); s->setValue(value); + plugin->slavePrimitives.append(s); } } @@ -308,6 +309,7 @@ DataSourcePtr DataSourcePluginManager::findPluginFor(ObjectStore *store, const Q ScalarPtr s = store->createObject(); s->setProvider(plugin); s->setSlaveName(key); + plugin->slavePrimitives.append(s); s->setValue(value); } } diff --git a/src/libkst/objectstore.cpp b/src/libkst/objectstore.cpp index 1b52665da..17dd327c8 100644 --- a/src/libkst/objectstore.cpp +++ b/src/libkst/objectstore.cpp @@ -57,15 +57,9 @@ bool ObjectStore::removeObject(Object *o) { DataSourcePtr ds = kst_cast(o); if (ds) { if (!_dataSourceList.contains(ds)) { -#if NAMEDEBUG > 1 - qDebug() << "Trying to delete a non-existent data source from the store: " << ds->tag().tagString(); -#endif return false; } } else if (!_list.contains(o)) { -#if NAMEDEBUG > 1 - qDebug() << "Trying to delete a non-existent object from the store: " << o->tag().tagString(); -#endif return false; } @@ -139,6 +133,9 @@ void ObjectStore::cleanUpDataSourceList() { for (DataSourceList::Iterator it = currentSourceList.begin(); it != currentSourceList.end(); ++it) { if ((*it)->getUsage() <= 1) { removeObject(*it); + //qDebug() << "remove" << (*it)->fileName() << "usage" << (*it)->getUsage(); + } else { + //qDebug() << " keep" << (*it)->fileName() << "usage" << (*it)->getUsage(); } } currentSourceList.clear(); diff --git a/src/libkstapp/changefiledialog.cpp b/src/libkstapp/changefiledialog.cpp index 4ff7abf2e..1f78e1fd1 100644 --- a/src/libkstapp/changefiledialog.cpp +++ b/src/libkstapp/changefiledialog.cpp @@ -66,6 +66,7 @@ ChangeFileDialog::ChangeFileDialog(QWidget *parent) connect(_duplicateSelected, SIGNAL(toggled(bool)), _duplicateDependents, SLOT(setEnabled(bool))); connect(_dataFile, SIGNAL(changed(const QString &)), this, SLOT(fileNameChanged(const QString &))); + connect(_dataFile, SIGNAL(destroyed()), kstApp->mainWindow(), SLOT(cleanUpDataSourceList())); connect(_buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); connect(_buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(OKClicked())); @@ -144,6 +145,8 @@ void ChangeFileDialog::sourceValid(QString filename, int requestID) { updateButtons(); _configure->setEnabled(_dataSource->hasConfigWidget()); + _store->cleanUpDataSourceList(); + } diff --git a/src/libkstapp/datamanager.cpp b/src/libkstapp/datamanager.cpp index 4ab3fcf6f..005be3e90 100644 --- a/src/libkstapp/datamanager.cpp +++ b/src/libkstapp/datamanager.cpp @@ -503,6 +503,7 @@ void DataManager::purge() { do { setUsedFlags(); } while (_doc->objectStore()->deleteUnsetUsedFlags()); + _doc->objectStore()->cleanUpDataSourceList(); UpdateServer::self()->requestUpdateSignal(); _session->reset(); } diff --git a/src/libkstapp/datawizard.cpp b/src/libkstapp/datawizard.cpp index 4e5a359dc..8f7ec40c5 100644 --- a/src/libkstapp/datawizard.cpp +++ b/src/libkstapp/datawizard.cpp @@ -740,6 +740,7 @@ DataWizard::DataWizard(QWidget *parent, const QString& fileToOpen) connect(_pageDataSource, SIGNAL(dataSourceChanged()), _pageVectors, SLOT(updateVectors())); connect(_pageDataSource, SIGNAL(dataSourceChanged()), _pageDataPresentation, SLOT(updateVectors())); + connect(_pageDataSource, SIGNAL(destroyed()), kstApp->mainWindow(), SLOT(cleanUpDataSourceList())); disconnect(button(QWizard::FinishButton), SIGNAL(clicked()), (QDialog*)this, SLOT(accept())); connect(button(QWizard::FinishButton), SIGNAL(clicked()), this, SLOT(finished())); diff --git a/src/libkstapp/mainwindow.cpp b/src/libkstapp/mainwindow.cpp index cb12374f3..4c7a7c524 100644 --- a/src/libkstapp/mainwindow.cpp +++ b/src/libkstapp/mainwindow.cpp @@ -2028,6 +2028,10 @@ void MainWindow::dropEvent(QDropEvent *event) event->accept(); } +void MainWindow::cleanUpDataSourceList() { + _doc->objectStore()->cleanUpDataSourceList(); +} + #if defined(__QNX__) bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (!qApp->activeWindow()) { diff --git a/src/libkstapp/mainwindow.h b/src/libkstapp/mainwindow.h index 1189dcf08..8c78fc4ef 100644 --- a/src/libkstapp/mainwindow.h +++ b/src/libkstapp/mainwindow.h @@ -107,6 +107,7 @@ class MainWindow : public QMainWindow void open(); void newDoc(bool force=false); void openFile(const QString &file); + void cleanUpDataSourceList(); #ifndef KST_NO_PRINTER void print(); void setPrinterDefaults(QPrinter *printer); diff --git a/src/libkstapp/matrixdialog.cpp b/src/libkstapp/matrixdialog.cpp index 591239f2e..6d67700db 100644 --- a/src/libkstapp/matrixdialog.cpp +++ b/src/libkstapp/matrixdialog.cpp @@ -13,6 +13,7 @@ #define NO_GENERATED_OPTIONS #include "matrixdialog.h" +#include "application.h" #include "dialogpage.h" #include "datasourcedialog.h" @@ -550,6 +551,8 @@ void MatrixTab::sourceValid(QString filename, int requestID) { validating = false; + _store->cleanUpDataSourceList(); + emit sourceChanged(); } @@ -625,6 +628,8 @@ MatrixDialog::MatrixDialog(ObjectPtr dataObject, QWidget *parent) connect(this, SIGNAL(editMultipleMode()), this, SLOT(editMultipleMode())); connect(this, SIGNAL(editSingleMode()), this, SLOT(editSingleMode())); connect(_matrixTab, SIGNAL(modified()), this, SLOT(modified())); + connect(_matrixTab, SIGNAL(destroyed()), kstApp->mainWindow(), SLOT(cleanUpDataSourceList())); + updateButtons(); } diff --git a/src/libkstapp/scalardialog.cpp b/src/libkstapp/scalardialog.cpp index 30f8d3c84..8ba473695 100644 --- a/src/libkstapp/scalardialog.cpp +++ b/src/libkstapp/scalardialog.cpp @@ -11,6 +11,8 @@ ***************************************************************************/ #include "scalardialog.h" +#include "application.h" + #include "datasourcedialog.h" #include "enodes.h" @@ -203,6 +205,8 @@ void ScalarTab::sourceValid(QString filename, int requestID) { _dataSource->unlock(); modified(); + + _store->cleanUpDataSourceList(); emit sourceChanged(); } @@ -251,6 +255,7 @@ ScalarDialog::ScalarDialog(ObjectPtr dataObject, QWidget *parent) connect(_scalarTab, SIGNAL(valueChanged()), this, SLOT(updateButtons())); connect(_scalarTab, SIGNAL(valueChanged()), this, SLOT(modified())); + connect(_scalarTab, SIGNAL(destroyed()), kstApp->mainWindow(), SLOT(cleanUpDataSourceList())); updateButtons(); } @@ -346,6 +351,8 @@ ObjectPtr ScalarDialog::createNewGeneratedScalar(){ _dataObjectName = scalar->Name(); //UpdateServer::self()->requestUpdateSignal(); + _scalarTab->setDataSource(0L); + _document->objectStore()->cleanUpDataSourceList(); return static_cast(scalar); } diff --git a/src/libkstapp/stringdialog.cpp b/src/libkstapp/stringdialog.cpp index 5232516fc..f6eedba59 100644 --- a/src/libkstapp/stringdialog.cpp +++ b/src/libkstapp/stringdialog.cpp @@ -11,6 +11,7 @@ ***************************************************************************/ #include "stringdialog.h" +#include "application.h" #include "datasourcedialog.h" #include "enodes.h" #include "document.h" @@ -164,8 +165,10 @@ void StringTab::sourceValid(QString filename, int requestID) { _configure->setEnabled(_dataSource->hasConfigWidget()); _dataSource->unlock(); + + _store->cleanUpDataSourceList(); + emit sourceChanged(); -// emit valueChanged(); } @@ -210,6 +213,7 @@ StringDialog::StringDialog(ObjectPtr dataObject, QWidget *parent) connect(_stringTab, SIGNAL(valueChanged()), this, SLOT(updateButtons())); connect(_stringTab, SIGNAL(sourceChanged()), this, SLOT(updateButtons())); + connect(_stringTab, SIGNAL(destroyed()), kstApp->mainWindow(), SLOT(cleanUpDataSourceList())); updateButtons(); } @@ -281,7 +285,8 @@ ObjectPtr StringDialog::createNewGeneratedString(){ _dataObjectName = string->Name(); - //UpdateServer::self()->requestUpdateSignal(); + _stringTab->setDataSource(0L); + _document->objectStore()->cleanUpDataSourceList(); return static_cast(string); } diff --git a/src/libkstapp/vectordialog.cpp b/src/libkstapp/vectordialog.cpp index ab51899ff..b88a280b7 100644 --- a/src/libkstapp/vectordialog.cpp +++ b/src/libkstapp/vectordialog.cpp @@ -133,7 +133,6 @@ QString VectorTab::file() const { void VectorTab::setFile(const QString &file) { - QFileInfo info(file); _fileName->setFile(file); } @@ -282,6 +281,8 @@ void VectorTab::sourceValid(QString filename, int requestID) { validating = false; + _store->cleanUpDataSourceList(); + emit sourceChanged(); } @@ -334,6 +335,7 @@ VectorDialog::VectorDialog(ObjectPtr dataObject, QWidget *parent) connect(this, SIGNAL(editSingleMode()), this, SLOT(editSingleMode())); connect(_vectorTab, SIGNAL(modified()), this, SLOT(modified())); + connect(_vectorTab, SIGNAL(destroyed()), kstApp->mainWindow(), SLOT(cleanUpDataSourceList())); updateButtons(); } @@ -527,6 +529,9 @@ ObjectPtr VectorDialog::createNewGeneratedVector() { _dataObjectName = vector->Name(); + _vectorTab->setDataSource(0L); + _document->objectStore()->cleanUpDataSourceList(); + //UpdateServer::self()->requestUpdateSignal(); return vector; }