[Kst] branches/work/kst/portto4/kst/src
Peter Kümmel
syntheticpp at yahoo.com
Mon Apr 26 14:33:29 CEST 2010
SVN commit 1119028 by kuemmel:
no leaks after simple start/quit of kst2
M +3 -6 libkst/datacollection.cpp
M +16 -27 libkst/datasourcepluginmanager.cpp
M +17 -0 libkst/datasourcepluginmanager.h
M +5 -8 libkstmath/dataobject.cpp
M +2 -0 libkstmath/dataobject.h
M +3 -6 libkstmath/dialoglauncher.cpp
--- branches/work/kst/portto4/kst/src/libkst/datacollection.cpp #1119027:1119028
@@ -66,22 +66,19 @@
Data *Data::self() {
- if (!_self) {
- _self = new Data;
- qAddPostRoutine(Data::cleanup);
- }
+ Q_ASSERT(_self);
return _self;
}
void Data::replaceSelf(Data *newInstance) {
- delete _self;
- _self = 0L;
+ cleanup();
_self = newInstance;
}
Data::Data() {
+ qAddPostRoutine(Data::cleanup);
}
--- branches/work/kst/portto4/kst/src/libkst/datasourcepluginmanager.cpp #1119027:1119028
@@ -45,19 +45,15 @@
using namespace Kst;
+QSettings DataSourcePluginManager::settingsObject("kst", "data");
+QMap<QString,QString> DataSourcePluginManager::url_map;
-static QSettings *settingsObject = 0L;
-static QMap<QString,QString> url_map;
const QMap<QString,QString> DataSourcePluginManager::urlMap() {
return url_map;
}
void DataSourcePluginManager::init() {
- if (!settingsObject) {
- QSettings *settingsObj = new QSettings("kst", "data");
- settingsObject = settingsObj;
- }
initPlugins();
}
@@ -67,8 +63,6 @@
void DataSourcePluginManager::cleanupForExit() {
_pluginList.clear();
qDebug() << "cleaning up for exit in datasource";
- delete settingsObject;
- settingsObject = 0L;
// for (QMap<QString,QString>::Iterator i = urlMap.begin(); i != urlMap.end(); ++i) {
// KIO::NetAccess::removeTempFile(i.value());
// }
@@ -76,7 +70,7 @@
}
-static QString obtainFile(const QString& source) {
+QString DataSourcePluginManager::obtainFile(const QString& source) {
QUrl url;
if (QFile::exists(source) && QFileInfo(source).isRelative()) {
@@ -185,23 +179,18 @@
}
-namespace {
-class PluginSortContainer {
- public:
- SharedPtr<DataSourcePluginInterface> plugin;
- int match;
- int operator<(const PluginSortContainer& x) const {
+
+int DataSourcePluginManager::PluginSortContainer::operator<(const PluginSortContainer& x) const {
return match > x.match; // yes, this is by design. biggest go first
}
- int operator==(const PluginSortContainer& x) const {
+int DataSourcePluginManager::PluginSortContainer::operator==(const PluginSortContainer& x) const {
return match == x.match;
}
-};
-}
-static QList<PluginSortContainer> bestPluginsForSource(const QString& filename, const QString& type) {
+QList<DataSourcePluginManager::PluginSortContainer> DataSourcePluginManager::bestPluginsForSource(const QString& filename, const QString& type) {
+
QList<PluginSortContainer> bestPlugins;
DataSourcePluginManager::init();
@@ -224,7 +213,7 @@
for (PluginList::Iterator it = info.begin(); it != info.end(); ++it) {
PluginSortContainer psc;
if (DataSourcePluginInterface *p = dynamic_cast<DataSourcePluginInterface*>((*it).data())) {
- if ((psc.match = p->understands(settingsObject, filename)) > 0) {
+ if ((psc.match = p->understands(&settingsObject, filename)) > 0) {
psc.plugin = p;
bestPlugins.append(psc);
}
@@ -237,13 +226,13 @@
}
-static DataSourcePtr findPluginFor(ObjectStore *store, const QString& filename, const QString& type, const QDomElement& e = QDomElement()) {
+DataSourcePtr DataSourcePluginManager::findPluginFor(ObjectStore *store, const QString& filename, const QString& type, const QDomElement& e) {
QList<PluginSortContainer> bestPlugins = bestPluginsForSource(filename, type);
// we don't actually iterate here, unless the first plugin fails. (Not sure this helps at all.)
for (QList<PluginSortContainer>::Iterator i = bestPlugins.begin(); i != bestPlugins.end(); ++i) {
- DataSourcePtr plugin = (*i).plugin->create(store, settingsObject, filename, QString::null, e);
+ DataSourcePtr plugin = (*i).plugin->create(store, &settingsObject, filename, QString::null, e);
if (plugin) {
return plugin;
}
@@ -305,7 +294,7 @@
for (PluginList::Iterator it = info.begin(); it != info.end(); ++it) {
if (DataSourcePluginInterface *p = dynamic_cast<DataSourcePluginInterface*>((*it).data())) {
- if ((p->understands(settingsObject, filename)) > 0) {
+ if ((p->understands(&settingsObject, filename)) > 0) {
return true;
}
}
@@ -339,7 +328,7 @@
for (PluginList::Iterator it = info.begin(); it != info.end(); ++it) {
if (DataSourcePluginInterface *p = dynamic_cast<DataSourcePluginInterface*>((*it).data())) {
if (p->pluginName() == plugin) {
- return p->configWidget(settingsObject, QString::null);
+ return p->configWidget(&settingsObject, QString::null);
}
}
}
@@ -380,7 +369,7 @@
QList<PluginSortContainer> bestPlugins = bestPluginsForSource(fn, type);
for (QList<PluginSortContainer>::Iterator i = bestPlugins.begin(); i != bestPlugins.end(); ++i) {
- DataSourceConfigWidget *w = (*i).plugin->configWidget(settingsObject, fn);
+ DataSourceConfigWidget *w = (*i).plugin->configWidget(&settingsObject, fn);
// Don't iterate.
return w;
}
@@ -471,7 +460,7 @@
QStringList rc;
for (QList<PluginSortContainer>::Iterator i = bestPlugins.begin(); i != bestPlugins.end(); ++i) {
QString typeSuggestion;
- rc = (*i).plugin->scalarList(settingsObject, fn, QString::null, &typeSuggestion, complete);
+ rc = (*i).plugin->scalarList(&settingsObject, fn, QString::null, &typeSuggestion, complete);
if (!rc.isEmpty()) {
if (outType) {
if (typeSuggestion.isEmpty()) {
@@ -502,7 +491,7 @@
QStringList rc;
for (QList<PluginSortContainer>::Iterator i = bestPlugins.begin(); i != bestPlugins.end(); ++i) {
QString typeSuggestion;
- rc = (*i).plugin->stringList(settingsObject, fn, QString::null, &typeSuggestion, complete);
+ rc = (*i).plugin->stringList(&settingsObject, fn, QString::null, &typeSuggestion, complete);
if (!rc.isEmpty()) {
if (outType) {
if (typeSuggestion.isEmpty()) {
--- branches/work/kst/portto4/kst/src/libkst/datasourcepluginmanager.h #1119027:1119028
@@ -17,6 +17,10 @@
#include "sharedptr.h"
#include "datasource.h"
+#include <QSettings>
+#include <QMap>
+
+
namespace Kst {
class ObjectStore;
@@ -53,7 +57,20 @@
static QStringList stringListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
+ private:
+ static QSettings settingsObject;
+ static QMap<QString,QString> url_map;
+ static QString obtainFile(const QString& source);
+
+ struct PluginSortContainer {
+ SharedPtr<DataSourcePluginInterface> plugin;
+ int match;
+ int operator<(const PluginSortContainer& x) const;
+ int operator==(const PluginSortContainer& x) const;
};
+ static QList<PluginSortContainer> bestPluginsForSource(const QString& filename, const QString& type);
+ static DataSourcePtr findPluginFor(ObjectStore *store, const QString& filename, const QString& type, const QDomElement& e = QDomElement());
+};
}
--- branches/work/kst/portto4/kst/src/libkstmath/dataobject.cpp #1119027:1119028
@@ -40,14 +40,11 @@
namespace Kst {
-static QSettings *settingsObject = 0L;
-static QMap<QString,QString> urlMap;
-void DataObject::init() {
- if (!settingsObject) {
- QSettings *settingsObj = new QSettings("kst", "data");
- settingsObject = settingsObj;
- }
+QSettings DataObject::settingsObject("kst", "data");
+QMap<QString,QString> DataObject::url_map;
+
+void DataObject::init() {
initPlugins();
}
@@ -202,7 +199,7 @@
for (DataObjectPluginList::ConstIterator it = _pluginList.begin(); it != _pluginList.end(); ++it) {
if ((*it)->pluginName() == name) {
if ((*it)->hasConfigWidget()) {
- return (*it)->configWidget(settingsObject);
+ return (*it)->configWidget(&settingsObject);
}
break;
}
--- branches/work/kst/portto4/kst/src/libkstmath/dataobject.h #1119027:1119028
@@ -176,6 +176,8 @@
QString _library;
private:
+ static QSettings settingsObject;
+ static QMap<QString,QString> url_map;
static void scanPlugins();
};
--- branches/work/kst/portto4/kst/src/libkstmath/dialoglauncher.cpp #1119027:1119028
@@ -29,22 +29,19 @@
DialogLauncher *DialogLauncher::self() {
- if (!_self) {
- _self = new DialogLauncher;
- qAddPostRoutine(DialogLauncher::cleanup);
- }
+ Q_ASSERT(_self);
return _self;
}
void DialogLauncher::replaceSelf(DialogLauncher *newInstance) {
- delete _self;
- _self = 0L;
+ cleanup();
_self = newInstance;
}
DialogLauncher::DialogLauncher() {
+ qAddPostRoutine(DialogLauncher::cleanup);
}
More information about the Kst
mailing list