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

Adam Treat treat at kde.org
Wed Jul 4 00:21:06 CEST 2007


SVN commit 683016 by treat:

* Get rid of bunch of static deleters


 M  +9 -3      libkst/kstdatacollection.cpp  
 M  +1 -2      libkst/kstdatacollection.h  
 M  +9 -10     libkst/kstdatasource.cpp  
 M  +8 -11     libkst/kstdebug.cpp  
 M  +3 -5      libkst/kstdebug.h  
 M  +10 -3     libkstmath/dialoglauncher.cpp  
 M  +1 -2      libkstmath/dialoglauncher.h  
 M  +23 -9     libkstmath/kstcolorsequence.cpp  
 M  +1 -2      libkstmath/kstcolorsequence.h  
 M  +8 -3      libkstmath/kstsettings.cpp  
 M  +1 -0      libkstmath/kstsettings.h  


--- branches/work/kst/portto4/kst/src/libkst/kstdatacollection.cpp #683015:683016
@@ -18,6 +18,7 @@
 #include <config.h>
 
 #include <stdlib.h>
+#include <qapplication.h>
 
 #include "kstdatacollection.h"
 
@@ -70,12 +71,17 @@
 }
 
 
-static KStaticDeleter<KstData> sdData;
 KstData *KstData::_self = 0L;
+void KstData::cleanup() {
+    delete _self;
+    _self = 0;
+}
 
+
 KstData *KstData::self() {
   if (!_self) {
-    _self = sdData.setObject(_self, new KstData);
+    _self = new KstData;
+    qAddPostRoutine(KstData::cleanup);
   }
   return _self;
 }
@@ -84,7 +90,7 @@
 void KstData::replaceSelf(KstData *newInstance) {
   delete _self;
   _self = 0L;
-  _self = sdData.setObject(_self, newInstance);
+  _self = newInstance;
 }
 
 
--- branches/work/kst/portto4/kst/src/libkst/kstdatacollection.h #683015:683016
@@ -18,7 +18,6 @@
 #ifndef KSTDATACOLLECTION_H
 #define KSTDATACOLLECTION_H
 
-#include <kstaticdeleter.h>
 #include "kstdatasource.h"
 #include "kststring.h"
 #include "kstvector.h"
@@ -30,9 +29,9 @@
 class KstBaseCurve;
 
 class KstData {
-  friend class KStaticDeleter<KstData>;
   protected:
     static KstData *_self;
+    static void cleanup();
     KstData();
     virtual ~KstData();
 
--- branches/work/kst/portto4/kst/src/libkst/kstdatasource.cpp #683015:683016
@@ -20,7 +20,6 @@
 #include <assert.h>
 
 #include <qdebug.h>
-#include <kio/netaccess.h>
 #include <klocale.h>
 
 #include <qfile.h>
@@ -48,9 +47,9 @@
 void KstDataSource::cleanupForExit() {
   _pluginList.clear();
   settingsObject = 0L;
-  for (QMap<QString,QString>::Iterator i = urlMap.begin(); i != urlMap.end(); ++i) {
-    KIO::NetAccess::removeTempFile(i.value());
-  }
+//   for (QMap<QString,QString>::Iterator i = urlMap.begin(); i != urlMap.end(); ++i) {
+//     KIO::NetAccess::removeTempFile(i.value());
+//   }
   urlMap.clear();
 }
 
@@ -74,16 +73,16 @@
 
   // FIXME: come up with a way to indicate the "widget" and fill it in here so
   //        that KIO dialogs are associated with the proper window
-  if (!KIO::NetAccess::exists(url, true, 0L)) {
-    return QString::null;
-  }
+//   if (!KIO::NetAccess::exists(url, true, 0L)) {
+//     return QString::null;
+//   }
 
   QString tmpFile;
   // FIXME: come up with a way to indicate the "widget" and fill it in here so
   //        that KIO dialogs are associated with the proper window
-  if (!KIO::NetAccess::download(url, tmpFile, 0L)) {
-    return QString::null;
-  }
+//   if (!KIO::NetAccess::download(url, tmpFile, 0L)) {
+//     return QString::null;
+//   }
 
   urlMap[source] = tmpFile;
 
--- branches/work/kst/portto4/kst/src/libkst/kstdebug.cpp #683015:683016
@@ -20,23 +20,25 @@
 #include "kstrevision.h"
 #include "logevents.h"
 
-#include <kapplication.h>
-#include <ktoolinvocation.h>
+#include <qapplication.h>
 #include <qdebug.h>
-#include <kglobal.h>
 #include <klocale.h>
 
 #include <ksttimers.h>
 
-static KStaticDeleter<KstDebug> sd;
-
 KstDebug *KstDebug::_self = 0L;
+void KstDebug::cleanup() {
+    delete _self;
+    _self = 0;
+}
 
+
 static QMutex soLock;
 KstDebug *KstDebug::self() {
   QMutexLocker ml(&soLock);
   if (!_self) {
-    sd.setObject(_self, new KstDebug);
+    _self = new KstDebug;
+    qAddPostRoutine(KstDebug::cleanup);
   }
 
   return _self;
@@ -157,11 +159,6 @@
 }
 
 
-void KstDebug::sendEmail() {
-  KToolInvocation::invokeMailer(QString::null, QString::null, QString::null, i18n("Kst Debugging Information"), text());
-}
-
-
 QList<KstDebug::LogMessage> KstDebug::messages() const {
   QMutexLocker ml(&_lock);
   return _messages;
--- branches/work/kst/portto4/kst/src/libkst/kstdebug.h #683015:683016
@@ -25,14 +25,11 @@
 #include <qobject.h>
 #include <qmutex.h>
 
-#include <kstaticdeleter.h>
-
 #include "kst_export.h"
 
 // This class has to be threadsafe
 class KST_EXPORT KstDebug : public QObject {
   Q_OBJECT
-  friend class KStaticDeleter<KstDebug>;
   public:
     enum LogLevel { Unknown = 0, Notice = 1, Warning = 2, Error = 4, Debug = 8, None = 16384 };
     struct LogMessage {
@@ -44,9 +41,8 @@
 
     void clear();
     void log(const QString& msg, LogLevel level = Notice);
-    void setLimit(bool applyLimit, int limit);   
+    void setLimit(bool applyLimit, int limit);
     QString text();
-    void sendEmail();
 
     int logLength() const;
     QList<LogMessage> messages() const;
@@ -71,6 +67,8 @@
     ~KstDebug();
 
     static KstDebug *_self;
+    static void cleanup();
+
     QList<LogMessage> _messages;
     bool _applyLimit;
     bool _hasNewError;
--- branches/work/kst/portto4/kst/src/libkstmath/dialoglauncher.cpp #683015:683016
@@ -17,12 +17,19 @@
 
 #include "dialoglauncher.h"
 
-static KStaticDeleter<KstDialogs> sdDialogs;
+#include <qapplication.h>
+
 KstDialogs *KstDialogs::_self = 0L;
+void KstDialogs::cleanup() {
+    delete _self;
+    _self = 0;
+}
 
+
 KstDialogs *KstDialogs::self() {
   if (!_self) {
-    _self = sdDialogs.setObject(_self, new KstDialogs);
+    _self = new KstDialogs;
+    qAddPostRoutine(KstDialogs::cleanup);
   }
   return _self;
 }
@@ -31,7 +38,7 @@
 void KstDialogs::replaceSelf(KstDialogs *newInstance) {
   delete _self;
   _self = 0L;
-  _self = sdDialogs.setObject(_self, newInstance);
+  _self = newInstance;
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstmath/dialoglauncher.h #683015:683016
@@ -18,15 +18,14 @@
 #ifndef DIALOGLAUNCHER_H
 #define DIALOGLAUNCHER_H
 #include <qstring.h>
-#include <kstaticdeleter.h>
 #include "kst_export.h"
 
 class QWidget;
 
 class KstDialogs {
-  friend class KStaticDeleter<KstDialogs>;
   protected:
     static KstDialogs *_self;
+    static void cleanup();
     KstDialogs();
     virtual ~KstDialogs();
 
--- branches/work/kst/portto4/kst/src/libkstmath/kstcolorsequence.cpp #683015:683016
@@ -26,6 +26,7 @@
 #include "kstcolorsequence.h"
 #include "kstsettings.h"
 #include <QVector>
+#include <qapplication.h>
 
 // Default palette that is used if "Kst Colors" is not found.
 static const char *const colors[] = { "red",
@@ -38,7 +39,6 @@
                                       "#105010"
                                       };
 static const int colorcnt = sizeof(colors) / sizeof(char*);
-static KStaticDeleter<KstColorSequence> sdColorSequence;
 
 
 KstColorSequence::KstColorSequence()
@@ -76,6 +76,12 @@
 }
 
 
+void KstColorSequence::cleanup() {
+    delete _self;
+    _self = 0;
+}
+
+
 QColor KstColorSequence::next(const KstVCurveList& curves, const QColor& badColor) {
   QColor color;
   int dark_factor;
@@ -83,7 +89,8 @@
   int start;
 
   if (!_self) {
-    _self = sdColorSequence.setObject(_self, new KstColorSequence);
+    _self = new KstColorSequence;
+    qAddPostRoutine(KstColorSequence::cleanup);
   }
   _self->createPalette();
   
@@ -156,7 +163,8 @@
 
 QColor KstColorSequence::next() {
   if (!_self) {
-    sdColorSequence.setObject(_self, new KstColorSequence);
+    _self = new KstColorSequence;
+    qAddPostRoutine(KstColorSequence::cleanup);
   }
   _self->createPalette();
 
@@ -174,7 +182,8 @@
   int dark_factor;
 
   if (!_self) {
-    sdColorSequence.setObject(_self, new KstColorSequence);
+    _self = new KstColorSequence;
+    qAddPostRoutine(KstColorSequence::cleanup);
   }
   _self->createPalette();
 
@@ -241,7 +250,8 @@
 
 KstColorSequence::ColorMode KstColorSequence::colorMode() {
   if (!_self) {
-    sdColorSequence.setObject(_self, new KstColorSequence);
+    _self = new KstColorSequence;
+    qAddPostRoutine(KstColorSequence::cleanup);
   }
 
   return _self->_mode;
@@ -250,7 +260,8 @@
 
 void KstColorSequence::setColorMode(KstColorSequence::ColorMode mode) {
   if (!_self) {
-    sdColorSequence.setObject(_self, new KstColorSequence);
+    _self = new KstColorSequence;
+    qAddPostRoutine(KstColorSequence::cleanup);
   }
 
   _self->_mode = mode;
@@ -259,7 +270,8 @@
 
 int KstColorSequence::count() {
   if (!_self) {
-    sdColorSequence.setObject(_self, new KstColorSequence);
+    _self = new KstColorSequence;
+    qAddPostRoutine(KstColorSequence::cleanup);
   }
   _self->createPalette();
 
@@ -269,7 +281,8 @@
 
 void KstColorSequence::reset() {
   if (!_self) {
-    sdColorSequence.setObject(_self, new KstColorSequence);
+    _self = new KstColorSequence;
+    qAddPostRoutine(KstColorSequence::cleanup);
   }
 
   _self->_ptr = 0;
@@ -278,7 +291,8 @@
 
 QColor KstColorSequence::entry(int ptr) {
   if (!_self) {
-    sdColorSequence.setObject(_self, new KstColorSequence);
+    _self = new KstColorSequence;
+    qAddPostRoutine(KstColorSequence::cleanup);
   }
   _self->createPalette();
 
--- branches/work/kst/portto4/kst/src/libkstmath/kstcolorsequence.h #683015:683016
@@ -19,14 +19,12 @@
 #define _KST_CS_H
 
 #include <qcolor.h>
-#include <kstaticdeleter.h>
 #include "kstvcurve.h"
 #include "kst_export.h"
 
 class KPalette;
 
 class KstColorSequence {
-  friend class KStaticDeleter<KstColorSequence>;
   public:
     enum ColorMode { MonoChrome, GrayScale, Color };
     KST_EXPORT void createPalette();
@@ -44,6 +42,7 @@
     KstColorSequence();
     ~KstColorSequence();
     static KstColorSequence* _self;
+    static void cleanup();
     KPalette* _pal;
     int _count;
     int _ptr;  // pointer to the next color
--- branches/work/kst/portto4/kst/src/libkstmath/kstsettings.cpp #683015:683016
@@ -18,10 +18,10 @@
 // include files for KDE
 #include <kemailsettings.h>
 #include <kprinter.h>
-#include <kstaticdeleter.h>
 #include "ksttimezones.h"
 
 #include <qsettings.h>
+#include <qapplication.h>
 
 // application specific includes
 #include "kstsettings.h"
@@ -138,11 +138,16 @@
 
 
 KstSettings *KstSettings::_self = 0L;
-static KStaticDeleter<KstSettings> kstsettingssd;
+void KstSettings::cleanup() {
+    delete _self;
+    _self = 0;
+}
 
+
 KstSettings *KstSettings::globalSettings() {
   if (!_self) {
-    kstsettingssd.setObject(_self, new KstSettings);
+    _self = new KstSettings;
+    qAddPostRoutine(KstSettings::cleanup);
     _self->reload();
   }
 
--- branches/work/kst/portto4/kst/src/libkstmath/kstsettings.h #683015:683016
@@ -118,6 +118,7 @@
 
   private:
     static KstSettings *_self;
+    static void cleanup();
 };
 
 #endif


More information about the Kst mailing list