Skip to content

Commit

Permalink
Handle temporary data sources
Browse files Browse the repository at this point in the history
Handle data sources which are temporarily typed into the
data source selector, but which are not actually used.
-Delete them when another source is selected
-Delete them if the window is closed
-Delete them if a non-dataobject is created instead.

Additionally, when a data source is deleted, delete its slave
primitives as well.
  • Loading branch information
netterfield committed Jan 4, 2014
1 parent 4476bf6 commit 099413d
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/libkst/datasource.cpp
Expand Up @@ -249,6 +249,9 @@ void DataSource::checkUpdate() {


void DataSource::deleteDependents() {
foreach (const PrimitivePtr &p, slavePrimitives) {
store()->removeObject(p);
}
}


Expand Down
3 changes: 3 additions & 0 deletions src/libkst/datasource.h
Expand Up @@ -217,6 +217,8 @@ class KSTCORE_EXPORT DataSource : public Object
*/
virtual ObjectList<Object> autoCurves(ObjectStore&) { return ObjectList<Object>(); }

PrimitiveList slavePrimitives;


public Q_SLOTS:
virtual void checkUpdate();
Expand Down Expand Up @@ -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.
};
Expand Down
2 changes: 2 additions & 0 deletions src/libkst/datasourcepluginmanager.cpp
Expand Up @@ -295,6 +295,7 @@ DataSourcePtr DataSourcePluginManager::findPluginFor(ObjectStore *store, const Q
s->setProvider(plugin);
s->setSlaveName(key);
s->setValue(value);
plugin->slavePrimitives.append(s);
}
}

Expand All @@ -308,6 +309,7 @@ DataSourcePtr DataSourcePluginManager::findPluginFor(ObjectStore *store, const Q
ScalarPtr s = store->createObject<Scalar>();
s->setProvider(plugin);
s->setSlaveName(key);
plugin->slavePrimitives.append(s);
s->setValue(value);
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/libkst/objectstore.cpp
Expand Up @@ -57,15 +57,9 @@ bool ObjectStore::removeObject(Object *o) {
DataSourcePtr ds = kst_cast<DataSource>(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;
}

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/libkstapp/changefiledialog.cpp
Expand Up @@ -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()));
Expand Down Expand Up @@ -144,6 +145,8 @@ void ChangeFileDialog::sourceValid(QString filename, int requestID) {
updateButtons();
_configure->setEnabled(_dataSource->hasConfigWidget());

_store->cleanUpDataSourceList();

}


Expand Down
1 change: 1 addition & 0 deletions src/libkstapp/datamanager.cpp
Expand Up @@ -503,6 +503,7 @@ void DataManager::purge() {
do {
setUsedFlags();
} while (_doc->objectStore()->deleteUnsetUsedFlags());
_doc->objectStore()->cleanUpDataSourceList();
UpdateServer::self()->requestUpdateSignal();
_session->reset();
}
Expand Down
1 change: 1 addition & 0 deletions src/libkstapp/datawizard.cpp
Expand Up @@ -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()));

Expand Down
4 changes: 4 additions & 0 deletions src/libkstapp/mainwindow.cpp
Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions src/libkstapp/mainwindow.h
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/libkstapp/matrixdialog.cpp
Expand Up @@ -13,6 +13,7 @@
#define NO_GENERATED_OPTIONS

#include "matrixdialog.h"
#include "application.h"

#include "dialogpage.h"
#include "datasourcedialog.h"
Expand Down Expand Up @@ -550,6 +551,8 @@ void MatrixTab::sourceValid(QString filename, int requestID) {

validating = false;

_store->cleanUpDataSourceList();

emit sourceChanged();
}

Expand Down Expand Up @@ -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();
}

Expand Down
7 changes: 7 additions & 0 deletions src/libkstapp/scalardialog.cpp
Expand Up @@ -11,6 +11,8 @@
***************************************************************************/

#include "scalardialog.h"
#include "application.h"

#include "datasourcedialog.h"

#include "enodes.h"
Expand Down Expand Up @@ -203,6 +205,8 @@ void ScalarTab::sourceValid(QString filename, int requestID) {

_dataSource->unlock();
modified();

_store->cleanUpDataSourceList();
emit sourceChanged();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -346,6 +351,8 @@ ObjectPtr ScalarDialog::createNewGeneratedScalar(){
_dataObjectName = scalar->Name();

//UpdateServer::self()->requestUpdateSignal();
_scalarTab->setDataSource(0L);
_document->objectStore()->cleanUpDataSourceList();

return static_cast<ObjectPtr>(scalar);
}
Expand Down
9 changes: 7 additions & 2 deletions src/libkstapp/stringdialog.cpp
Expand Up @@ -11,6 +11,7 @@
***************************************************************************/
#include "stringdialog.h"

#include "application.h"
#include "datasourcedialog.h"
#include "enodes.h"
#include "document.h"
Expand Down Expand Up @@ -164,8 +165,10 @@ void StringTab::sourceValid(QString filename, int requestID) {
_configure->setEnabled(_dataSource->hasConfigWidget());

_dataSource->unlock();

_store->cleanUpDataSourceList();

emit sourceChanged();
// emit valueChanged();
}


Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -281,7 +285,8 @@ ObjectPtr StringDialog::createNewGeneratedString(){

_dataObjectName = string->Name();

//UpdateServer::self()->requestUpdateSignal();
_stringTab->setDataSource(0L);
_document->objectStore()->cleanUpDataSourceList();

return static_cast<ObjectPtr>(string);
}
Expand Down
7 changes: 6 additions & 1 deletion src/libkstapp/vectordialog.cpp
Expand Up @@ -133,7 +133,6 @@ QString VectorTab::file() const {


void VectorTab::setFile(const QString &file) {
QFileInfo info(file);
_fileName->setFile(file);
}

Expand Down Expand Up @@ -282,6 +281,8 @@ void VectorTab::sourceValid(QString filename, int requestID) {

validating = false;

_store->cleanUpDataSourceList();

emit sourceChanged();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -527,6 +529,9 @@ ObjectPtr VectorDialog::createNewGeneratedVector() {

_dataObjectName = vector->Name();

_vectorTab->setDataSource(0L);
_document->objectStore()->cleanUpDataSourceList();

//UpdateServer::self()->requestUpdateSignal();
return vector;
}
Expand Down

0 comments on commit 099413d

Please sign in to comment.