Skip to content
Browse files

qtcollider: declare factories without the use of static initialization

  • Loading branch information...
1 parent c46a680 commit 054e14ad2c8e0d67409eba9f94a45e906034aa07 @jleben jleben committed
View
1 QtCollider/CMakeLists.txt
@@ -41,6 +41,7 @@ set( QT_COLLIDER_HDRS
set( QT_COLLIDER_SRCS
${QT_COLLIDER_DIR}/debug.cpp
${QT_COLLIDER_DIR}/interface.cpp
+ ${QT_COLLIDER_DIR}/factories.cpp
${QT_COLLIDER_DIR}/QcApplication.cpp
${QT_COLLIDER_DIR}/Common.cpp
${QT_COLLIDER_DIR}/QObjectProxy.cpp
View
7 QtCollider/QcObjectFactory.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -23,8 +23,11 @@
#include "QcObjectFactory.h"
namespace QtCollider {
- QcFactoryHash & factories () {
+
+ QcFactoryHash & factories ()
+ {
static QcFactoryHash *factoryHash = new QcFactoryHash();
return *factoryHash;
}
+
}
View
22 QtCollider/QcObjectFactory.h
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -44,19 +44,13 @@ namespace QtCollider {
class QcAbstractFactory
{
public:
- QcAbstractFactory( const char *className ) {
- qcDebugMsg( 2, QString("Declaring class '%1'").arg(className) );
- QtCollider::factories().insert( className, this );
- }
virtual const QMetaObject *metaObject() = 0;
virtual QObjectProxy *newInstance( PyrObject *, QtCollider::Variant arg[10] ) = 0;
};
-
template <class QOBJECT> class QcObjectFactory : public QcAbstractFactory
{
public:
- QcObjectFactory() : QcAbstractFactory( QOBJECT::staticMetaObject.className() ) {}
const QMetaObject *metaObject() {
return &QOBJECT::staticMetaObject;
@@ -104,6 +98,20 @@ template <class QOBJECT> class QcObjectFactory : public QcAbstractFactory
virtual void initialize( QObjectProxy *proxy, QOBJECT *obj ) {};
};
+#define QC_DECLARE_FACTORY( QOBJECT, FACTORY ) \
+ namespace QtCollider { \
+ void add_factory_##QOBJECT () { \
+ QcAbstractFactory *factory = new FACTORY; \
+ factories().insert( factory->metaObject()->className(), factory ); \
+ } \
+ }
+
+#define QC_DECLARE_QOBJECT_FACTORY( QOBJECT ) QC_DECLARE_FACTORY( QOBJECT, QcObjectFactory<QOBJECT> )
+
+#define QC_ADD_FACTORY( QOBJECT ) \
+ void add_factory_##QOBJECT(); \
+ add_factory_##QOBJECT()
+
#endif //QC_OBJECT_FACTORY_H
View
4 QtCollider/QcWidgetFactory.h
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -110,4 +110,6 @@ class QcWidgetFactory : public QcObjectFactory<QWIDGET>
virtual void initialize( QWidgetProxy *proxy, QWIDGET *obj ) {};
};
+#define QC_DECLARE_QWIDGET_FACTORY( QWIDGET ) QC_DECLARE_FACTORY( QWIDGET, QcWidgetFactory<QWIDGET> )
+
#endif
View
62 QtCollider/factories.cpp
@@ -0,0 +1,62 @@
+/************************************************************************
+*
+* Copyright 2012 Jakob Leben (jakob.leben@gmail.com)
+*
+* This file is part of SuperCollider Qt GUI.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+************************************************************************/
+
+#include "QcObjectFactory.h"
+
+namespace QtCollider {
+
+void loadFactories () {
+ QC_ADD_FACTORY( QcDefaultWidget );
+ QC_ADD_FACTORY( QcHLayoutWidget );
+ QC_ADD_FACTORY( QcVLayoutWidget );
+ QC_ADD_FACTORY( QLabel );
+ QC_ADD_FACTORY( QcTextField );
+ QC_ADD_FACTORY( QcCheckBox );
+ QC_ADD_FACTORY( QcListWidget );
+ QC_ADD_FACTORY( QcPopUpMenu );
+ QC_ADD_FACTORY( QcButton );
+ QC_ADD_FACTORY( QcCustomPainted );
+ QC_ADD_FACTORY( QcFileDialog );
+ QC_ADD_FACTORY( QcGraph );
+ QC_ADD_FACTORY( QcLevelIndicator );
+ QC_ADD_FACTORY( QcMultiSlider );
+ QC_ADD_FACTORY( QcNumberBox );
+ QC_ADD_FACTORY( QcPenPrinter );
+ QC_ADD_FACTORY( QcRangeSlider );
+ QC_ADD_FACTORY( QcScope );
+ QC_ADD_FACTORY( QcScopeShm );
+ QC_ADD_FACTORY( QcScrollWidget );
+ QC_ADD_FACTORY( QcScrollArea );
+ QC_ADD_FACTORY( QcSlider );
+ QC_ADD_FACTORY( QcSlider2D );
+ QC_ADD_FACTORY( QcSoundFileView );
+ QC_ADD_FACTORY( QcWaveform );
+ QC_ADD_FACTORY( QcTextEdit );
+ QC_ADD_FACTORY( QcTreeWidget );
+ QC_ADD_FACTORY( WebView );
+ QC_ADD_FACTORY( QcWindow );
+ QC_ADD_FACTORY( QcScrollWindow );
+ QC_ADD_FACTORY( QcHBoxLayout );
+ QC_ADD_FACTORY( QcVBoxLayout );
+ QC_ADD_FACTORY( QcGridLayout );
+}
+
+} // namespace QtCollider
View
9 QtCollider/interface.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2011 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2011-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -34,10 +34,17 @@
#include <clocale>
+namespace QtCollider {
+ void loadFactories ();
+}
+
QC_PUBLIC
void QtCollider::init() {
if( !QApplication::instance() ) {
qcDebugMsg( 1, "Initializing QtCollider" );
+
+ QtCollider::loadFactories();
+
#ifdef Q_WS_X11
XInitThreads();
#endif
View
8 QtCollider/layouts/layouts.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -21,9 +21,9 @@
#include "layouts.hpp"
-static QcObjectFactory<QcHBoxLayout> hBoxLayoutFactory;
-static QcObjectFactory<QcVBoxLayout> vBoxLayoutFactory;
-static QcObjectFactory<QcGridLayout> gridLayoutFactory;
+QC_DECLARE_QOBJECT_FACTORY(QcHBoxLayout);
+QC_DECLARE_QOBJECT_FACTORY(QcVBoxLayout);
+QC_DECLARE_QOBJECT_FACTORY(QcGridLayout);
void QcGridLayout::addItem( const VariantList &dataList )
{
View
22 QtCollider/widgets/BasicWidgets.cpp
@@ -30,12 +30,12 @@
# include <QMacStyle>
#endif
-QcWidgetFactory<QcDefaultWidget> defaultWidgetFactory;
-QcWidgetFactory<QcHLayoutWidget> hLayoutWidgetFactory;
-QcWidgetFactory<QcVLayoutWidget> vLayoutWidgetFactory;
-QcWidgetFactory<QLabel> labelFactory;
-QcWidgetFactory<QcTextField> textFieldFactory;
-QcWidgetFactory<QcCheckBox> checkBoxFactory;
+QC_DECLARE_QWIDGET_FACTORY( QcDefaultWidget );
+QC_DECLARE_QWIDGET_FACTORY( QcHLayoutWidget );
+QC_DECLARE_QWIDGET_FACTORY( QcVLayoutWidget );
+QC_DECLARE_QWIDGET_FACTORY( QLabel );
+QC_DECLARE_QWIDGET_FACTORY( QcTextField );
+QC_DECLARE_QWIDGET_FACTORY( QcCheckBox );
//////////////////////////// QcListWidget //////////////////////////////////////
@@ -46,7 +46,7 @@ class QcListWidgetFactory : public QcWidgetFactory<QcListWidget>
}
};
-QcListWidgetFactory listWidgetFactory;
+QC_DECLARE_FACTORY( QcListWidget, QcListWidgetFactory );
QcListWidget::QcListWidget() : _emitAction(true)
{
@@ -97,7 +97,7 @@ void QcListWidget::keyPressEvent( QKeyEvent *e )
////////////////////////// QcPopUpMenu /////////////////////////////////////////
-QcWidgetFactory<QcPopUpMenu> popUpMenuFactory;
+QC_DECLARE_QWIDGET_FACTORY(QcPopUpMenu);
QcPopUpMenu::QcPopUpMenu()
: lastChoice( -1 ), _reactivation(false)
@@ -122,7 +122,7 @@ void QcPopUpMenu::doAction( int choice )
/////////////////////////////// QcButton ///////////////////////////////////////
-QcWidgetFactory<QcButton> buttonFactory;
+QC_DECLARE_QWIDGET_FACTORY(QcButton);
QcButton::QcButton()
: currentState(0), defaultPalette( palette() )
@@ -203,6 +203,8 @@ void QcButton::doAction()
Q_EMIT( action((int)QApplication::keyboardModifiers()) );
}
+/////////////////////////////////////////////////////////////////////////
+
class QcCustomPaintedFactory : public QcWidgetFactory<QcCustomPainted>
{
protected:
@@ -213,4 +215,4 @@ class QcCustomPaintedFactory : public QcWidgetFactory<QcCustomPainted>
}
};
-static QcCustomPaintedFactory customPaintedFactory;
+QC_DECLARE_FACTORY( QcCustomPainted, QcCustomPaintedFactory );
View
2 QtCollider/widgets/QcFileDialog.cpp
@@ -22,7 +22,7 @@
#include "QcFileDialog.h"
#include "../QcObjectFactory.h"
-static QcObjectFactory<QcFileDialog> fileDialogFactory;
+QC_DECLARE_QOBJECT_FACTORY(QcFileDialog);
QcFileDialog::QcFileDialog( int fileMode, int acceptMode ) {
dialog = new QFileDialog();
View
4 QtCollider/widgets/QcGraph.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -28,7 +28,7 @@
#include <cmath>
-static QcWidgetFactory<QcGraph> factory;
+QC_DECLARE_QWIDGET_FACTORY(QcGraph);
void QcGraphModel::append( QcGraphElement * e ) {
if( _elems.count() ) {
View
4 QtCollider/widgets/QcLevelIndicator.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -24,7 +24,7 @@
#include <QPainter>
-static QcWidgetFactory<QcLevelIndicator> factory;
+QC_DECLARE_QWIDGET_FACTORY(QcLevelIndicator);
QcLevelIndicator::QcLevelIndicator()
: _value( 0.f ), _warning(0.6), _critical(0.8),
View
4 QtCollider/widgets/QcMultiSlider.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -28,7 +28,7 @@
#include <cmath>
-static QcWidgetFactory<QcMultiSlider> factory;
+QC_DECLARE_QWIDGET_FACTORY(QcMultiSlider);
QcMultiSlider::QcMultiSlider() :
_currentIndex(0),
View
4 QtCollider/widgets/QcNumberBox.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -30,7 +30,7 @@
#include <math.h>
#include <qmath.h>
-static QcWidgetFactory<QcNumberBox> factory;
+QC_DECLARE_QWIDGET_FACTORY(QcNumberBox);
QcNumberBox::QcNumberBox()
: scroll( true ),
View
3 QtCollider/widgets/QcPenPrinter.cpp
@@ -1,6 +1,7 @@
/************************************************************************
*
* Copyright 2011 Jonatan Liljedahl <lijon@kymatica.com>
+* Copyright 2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -22,4 +23,4 @@
#include "QcPenPrinter.h"
#include "../QcObjectFactory.h"
-static QcObjectFactory<QcPenPrinter> penPrinterFactory;
+QC_DECLARE_QOBJECT_FACTORY(QcPenPrinter);
View
4 QtCollider/widgets/QcRangeSlider.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -27,7 +27,7 @@
#include <QApplication>
#include <QPainter>
-static QcWidgetFactory<QcRangeSlider> factory;
+QC_DECLARE_QWIDGET_FACTORY(QcRangeSlider);
QcRangeSlider::QcRangeSlider() :
_lo( 0.f ),
View
4 QtCollider/widgets/QcScope.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -25,7 +25,7 @@
#include <QPainter>
#include <QTimer>
-static QcWidgetFactory<QcScope> factory;
+QC_DECLARE_QWIDGET_FACTORY(QcScope);
QcScope::QcScope()
: bufNum( 0 ),
View
4 QtCollider/widgets/QcScopeShm.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010-2011 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of Qt GUI for SuperCollider.
*
@@ -28,7 +28,7 @@
#include <QTimer>
#include <QResizeEvent>
-static QcWidgetFactory<QcScopeShm> factory;
+QC_DECLARE_QWIDGET_FACTORY(QcScopeShm);
QcScopeShm::QcScopeShm() :
_srvPort(-1),
View
6 QtCollider/widgets/QcScrollArea.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -38,7 +38,7 @@ class QcScrollWidgetFactory : public QcWidgetFactory<QcScrollWidget>
}
};
-static QcScrollWidgetFactory scrollWidgetFactory;
+QC_DECLARE_FACTORY( QcScrollWidget, QcScrollWidgetFactory );
QcScrollWidget::QcScrollWidget( QWidget *parent ) : QcCanvas( parent )
{
@@ -84,7 +84,7 @@ bool QcScrollWidget::eventFilter ( QObject * watched, QEvent * event ) {
-static QcWidgetFactory<QcScrollArea> scrollAreaFactory;
+QC_DECLARE_QWIDGET_FACTORY(QcScrollArea);
QcScrollArea::QcScrollArea()
{
View
4 QtCollider/widgets/QcSlider.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -24,7 +24,7 @@
#include <QApplication>
-static QcWidgetFactory<QcSlider> factory;
+QC_DECLARE_QWIDGET_FACTORY(QcSlider);
QcSlider::QcSlider()
: lastVal(0), bDoAction( false )
View
4 QtCollider/widgets/QcSlider2D.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -27,7 +27,7 @@
#include <QApplication>
#include <QPainter>
-static QcWidgetFactory<QcSlider2D> factory;
+QC_DECLARE_QWIDGET_FACTORY(QcSlider2D);
QcSlider2D::QcSlider2D() :
_x( 0.f ),
View
6 QtCollider/widgets/QcSoundFileView.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -30,8 +30,8 @@
#include <climits>
#include <cmath>
-static QcWidgetFactory<QcSoundFileView> sfViewFactory;
-static QcWidgetFactory<QcWaveform> waveformFactory;
+QC_DECLARE_QWIDGET_FACTORY(QcSoundFileView);
+QC_DECLARE_QWIDGET_FACTORY(QcWaveform);
const int kMaxRawFrames = 300000;
const int kMaxFramesPerCacheUnit = 128;
View
4 QtCollider/widgets/QcTextEdit.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -33,7 +33,7 @@ class QcTextEditFactory : public QcWidgetFactory<QcTextEdit>
}
};
-static QcTextEditFactory factory;
+QC_DECLARE_FACTORY( QcTextEdit, QcTextEditFactory );
QcTextEdit::QcTextEdit() : _interpretSelection(false)
{
View
4 QtCollider/widgets/QcTreeWidget.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2011 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2011-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -31,7 +31,7 @@ class QcTreeWidgetFactory : public QcWidgetFactory<QcTreeWidget>
}
};
-static QcTreeWidgetFactory treeWidgetFactory;
+QC_DECLARE_FACTORY( QcTreeWidget, QcTreeWidgetFactory );
QcTreeWidget::QcTreeWidget()
{
View
4 QtCollider/widgets/QcWebView.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2011 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2011-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -30,7 +30,7 @@
#include <QStyle>
#include <QClipboard>
-static QcWidgetFactory<QtCollider::WebView> factory;
+QC_DECLARE_QWIDGET_FACTORY(WebView);
namespace QtCollider {
View
6 QtCollider/widgets/QcWindow.cpp
@@ -1,6 +1,6 @@
/************************************************************************
*
-* Copyright 2010-2011 Jakob Leben (jakob.leben@gmail.com)
+* Copyright 2010-2012 Jakob Leben (jakob.leben@gmail.com)
*
* This file is part of SuperCollider Qt GUI.
*
@@ -51,8 +51,8 @@ class QcScrollWindowFactory : public QcObjectFactory<QcScrollWindow>
}
};
-static QcWindowFactory winFactory;
-static QcScrollWindowFactory scrollWinFactory;
+QC_DECLARE_FACTORY( QcWindow, QcWindowFactory );
+QC_DECLARE_FACTORY( QcScrollWindow, QcScrollWindowFactory );
static void qcInitWindow
( QWidget *window, const QString &title, const QRectF & geom_, bool resizable, bool frame )

0 comments on commit 054e14a

Please sign in to comment.
Something went wrong with that request. Please try again.