• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KParts

genericfactory.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Simon Hausmann <hausmann@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to the
00016    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 #ifndef KPARTS_GENERICFACTORY_H
00020 #define KPARTS_GENERICFACTORY_H
00021 
00022 #include <kparts/factory.h>
00023 #include <kparts/part.h>
00024 #include <kgenericfactory.h>
00025 #include <kaboutdata.h>
00026 #include <kdebug.h>
00027 
00028 namespace KParts
00029 {
00030 
00034     template <class T>
00035     class GenericFactoryBase : public KParts::Factory
00036     {
00037     public:
00038         GenericFactoryBase()
00039         {
00040             if ( s_self )
00041                 kWarning() << "KParts::GenericFactory instantiated more than once!";
00042             s_self = this;
00043         }
00044         virtual ~GenericFactoryBase()
00045         {
00046             delete s_aboutData;
00047             delete s_componentData;
00048             s_aboutData = 0;
00049             s_componentData = 0;
00050             s_self = 0;
00051         }
00052 
00053         static const KComponentData &componentData();
00054         static KAboutData *aboutData();
00055         virtual KComponentData partComponentData()
00056         {
00057             return componentData();
00058         }
00059 
00060 
00061     protected:
00062         virtual KComponentData *createComponentData()
00063         {
00064             return new KComponentData(aboutData());
00065         }
00066 
00067 
00068     private:
00069         static GenericFactoryBase<T> *s_self;
00070         static KComponentData *s_componentData;
00071         static KAboutData *s_aboutData;
00072     };
00073 
00107     template <class T>
00108     class GenericFactory : public GenericFactoryBase<T>
00109     {
00110     public:
00111         GenericFactory() { }
00112 
00113         virtual KParts::Part *createPartObject( QWidget *parentWidget,
00114                                                 QObject *parent,
00115                                                 const char *className,
00116                                                 const QStringList &args )
00117         {
00118             T *part = KDEPrivate::ConcreteFactory<T>::create( parentWidget,
00119                                                               parent,
00120                                                               className,
00121                                                               args );
00122 
00123             if ( part && !qstrcmp( className, "KParts::ReadOnlyPart" ) )
00124             {
00125                 KParts::ReadWritePart *rwp = dynamic_cast<KParts::ReadWritePart *>( part );
00126                 if ( rwp )
00127                     rwp->setReadWrite( false );
00128             }
00129             return part;
00130         }
00131     };
00132 
00133     template <class T1, class T2>
00134     class GenericFactory< KTypeList<T1, T2> > : public GenericFactoryBase<T1>
00135     {
00136     public:
00137         GenericFactory() { }
00138 
00139         virtual KParts::Part *createPartObject( QWidget *parentWidget,
00140                                                 QObject *parent,
00141                                                 const char *className,
00142                                                 const QStringList &args )
00143         {
00144             QObject *object = KDEPrivate::MultiFactory< KTypeList<T1, T2> >::create( parentWidget,
00145                                                                                      parent,
00146                                                                                      className,
00147                                                                                      args );
00148 
00149             // (this cast is guaranteed to work...)
00150             KParts::Part *part = dynamic_cast<KParts::Part *>( object );
00151 
00152             if ( part && !qstrcmp( className, "KParts::ReadOnlyPart" ) )
00153             {
00154                 KParts::ReadWritePart *rwp = dynamic_cast<KParts::ReadWritePart *>( part );
00155                 if ( rwp )
00156                     rwp->setReadWrite( false );
00157             }
00158             return part;
00159         }
00160     };
00161 
00165     template <class T>
00166     GenericFactoryBase<T> *GenericFactoryBase<T>::s_self = 0;
00167 
00171     template <class T>
00172     KComponentData *GenericFactoryBase<T>::s_componentData = 0;
00173 
00177     template <class T>
00178     KAboutData *GenericFactoryBase<T>::s_aboutData = 0;
00179 
00183     template <class T>
00184     const KComponentData &GenericFactoryBase<T>::componentData()
00185     {
00186         if ( !s_componentData )
00187         {
00188             if ( s_self )
00189                 s_componentData = s_self->createComponentData();
00190             else
00191                 s_componentData = new KComponentData(aboutData());
00192         }
00193         return *s_componentData;
00194     }
00195 
00199     template <class T>
00200     KAboutData *GenericFactoryBase<T>::aboutData()
00201     {
00202         if ( !s_aboutData )
00203             s_aboutData = T::createAboutData();
00204         return s_aboutData;
00205     }
00206 
00207 }
00208 
00209 #endif
00210 

KParts

Skip menu "KParts"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal