[vlmc-devel] commit: Cleanup: Use the available QSingleton, instead of re-implementing it. (Hugo Beauzee-Luyssen )

git at videolan.org git at videolan.org
Fri Mar 12 00:38:11 CET 2010


vlmc | branch: master | Hugo Beauzee-Luyssen <beauze.h at gmail.com> | Fri Mar 12 00:37:46 2010 +0100| [111cbd6a4928ff0e6b49fb9456a71402e998cf20] | committer: Hugo Beauzee-Luyssen 

Cleanup: Use the available QSingleton, instead of re-implementing it.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=111cbd6a4928ff0e6b49fb9456a71402e998cf20
---

 src/Gui/About.cpp             |   10 ----------
 src/Gui/About.h               |   10 +++++-----
 src/Gui/DockWidgetManager.cpp |   10 ----------
 src/Gui/DockWidgetManager.h   |    8 +++++---
 src/Gui/MainWindow.cpp        |   10 +++++-----
 5 files changed, 15 insertions(+), 33 deletions(-)

diff --git a/src/Gui/About.cpp b/src/Gui/About.cpp
index 745ef1c..6e7dbb8 100644
--- a/src/Gui/About.cpp
+++ b/src/Gui/About.cpp
@@ -26,8 +26,6 @@
 #include <QPlainTextEdit>
 #include "About.h"
 
-About* About::m_instance = NULL;
-
 About::About( QWidget *parent ) :
     QDialog( parent )
 {
@@ -55,14 +53,6 @@ void About::changeEvent( QEvent *e )
     }
 }
 
-About* About::instance()
-{
-    if ( m_instance )
-        return m_instance;
-    m_instance = new About();
-    return m_instance;
-}
-
 void About::setText( const QString& filename, QPlainTextEdit* widget )
 {
     QFile file( filename );
diff --git a/src/Gui/About.h b/src/Gui/About.h
index ec1546f..868f709 100644
--- a/src/Gui/About.h
+++ b/src/Gui/About.h
@@ -24,17 +24,16 @@
 #define ABOUT_H
 
 #include <QDialog>
+
+#include "QSingleton.hpp"
 #include "ui_About.h"
 
 class QPlainTextEdit;
 
-class About : public QDialog
+class About : public QDialog, public QSingleton<About>
 {
     Q_OBJECT
     Q_DISABLE_COPY( About )
-public:
-    static About* instance();
-
 protected:
     virtual void    changeEvent( QEvent *e );
 
@@ -42,7 +41,8 @@ private:
     explicit        About( QWidget *parent = 0 );
     void            setText( const QString& filename, QPlainTextEdit* widget );
     Ui::AboutVLMC   m_ui;
-    static About*   m_instance;
+
+    friend class    QSingleton<About>;
 };
 
 #endif // ABOUT_H
diff --git a/src/Gui/DockWidgetManager.cpp b/src/Gui/DockWidgetManager.cpp
index 108537a..4793c60 100644
--- a/src/Gui/DockWidgetManager.cpp
+++ b/src/Gui/DockWidgetManager.cpp
@@ -27,16 +27,6 @@
 #include "DockWidgetManager.h"
 #include "MainWindow.h"
 
-DockWidgetManager *DockWidgetManager::m_instance = 0;
-
-DockWidgetManager *DockWidgetManager::instance( QObject *parent )
-{
-    if (m_instance == 0)
-        m_instance = new DockWidgetManager( parent );
-
-    return (m_instance);
-}
-
 void DockWidgetManager::setMainWindow( MainWindow *mainWin )
 {
     m_mainWin = mainWin;
diff --git a/src/Gui/DockWidgetManager.h b/src/Gui/DockWidgetManager.h
index 1705656..cfd78ad 100644
--- a/src/Gui/DockWidgetManager.h
+++ b/src/Gui/DockWidgetManager.h
@@ -23,6 +23,8 @@
 #ifndef DOCKWIDGETMANAGER_H
 #define DOCKWIDGETMANAGER_H
 
+#include "QSingleton.hpp"
+
 #include <QObject>
 #include <QWidget>
 #include <QDockWidget>
@@ -31,7 +33,7 @@
 
 class MainWindow;
 
-class DockWidgetManager : public QObject
+class DockWidgetManager : public QObject, public QSingleton<DockWidgetManager>
 {
     Q_OBJECT
 
@@ -55,10 +57,10 @@ class DockWidgetManager : public QObject
 
         MainWindow *m_mainWin;
         QMap<QString, QDockWidget*> m_dockWidgets;
-        static DockWidgetManager *m_instance;
-
     public slots:
         void transLateWidgetTitle();
+
+        friend  class   QSingleton<DockWidgetManager>;
 };
 
 #endif
diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp
index 905617e..32070e1 100644
--- a/src/Gui/MainWindow.cpp
+++ b/src/Gui/MainWindow.cpp
@@ -84,7 +84,7 @@ MainWindow::MainWindow( QWidget *parent ) :
     initVlmcPreferences();
 
     // GUI
-    DockWidgetManager::instance( this )->setMainWindow( this );
+    DockWidgetManager::getInstance( this )->setMainWindow( this );
     createGlobalPreferences();
     createProjectPreferences();
     initializeDockWidgets();
@@ -95,7 +95,7 @@ MainWindow::MainWindow( QWidget *parent ) :
 
     // Translations
     connect( this, SIGNAL( translateDockWidgetTitle() ),
-             DockWidgetManager::instance(), SLOT( transLateWidgetTitle() ) );
+             DockWidgetManager::getInstance(), SLOT( transLateWidgetTitle() ) );
 
     // Zoom
     connect( m_zoomSlider, SIGNAL( valueChanged( int ) ),
@@ -242,7 +242,7 @@ MainWindow::setupLibrary()
     const ClipRenderer* clipRenderer = qobject_cast<const ClipRenderer*>( m_clipPreview->getGenericRenderer() );
     Q_ASSERT( clipRenderer != NULL );
 
-    DockWidgetManager::instance()->addDockedWidget( libraryWidget, tr( "Media Library" ),
+    DockWidgetManager::getInstance()->addDockedWidget( libraryWidget, tr( "Media Library" ),
                                                     Qt::AllDockWidgetAreas,
                                                     QDockWidget::AllDockWidgetFeatures,
                                                     Qt::LeftDockWidgetArea );
@@ -343,7 +343,7 @@ void MainWindow::initializeDockWidgets( void )
     m_timeline->show();
     setCentralWidget( m_timeline );
 
-    DockWidgetManager *dockManager = DockWidgetManager::instance();
+    DockWidgetManager *dockManager = DockWidgetManager::getInstance();
 
     m_clipPreview = new PreviewWidget( new ClipRenderer, this );
     dockManager->addDockedWidget( m_clipPreview,
@@ -413,7 +413,7 @@ void MainWindow::on_actionPreferences_triggered()
 
 void MainWindow::on_actionAbout_triggered()
 {
-    About::instance()->exec();
+    About::getInstance()->exec();
 }
 
 void MainWindow::on_actionTranscode_triggered()



More information about the Vlmc-devel mailing list