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

KParts

  • sources
  • kde-4.14
  • kdelibs
  • kparts
genericfactory.h
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2001 Simon Hausmann <hausmann@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 #ifndef KPARTS_GENERICFACTORY_H
20 #define KPARTS_GENERICFACTORY_H
21 
22 #include <kparts/factory.h>
23 #include <kparts/part.h>
24 #include <kgenericfactory.h>
25 #include <kaboutdata.h>
26 #include <kdebug.h>
27 
28 namespace KParts
29 {
30 
34  template <class T>
35  class GenericFactoryBase : public KParts::Factory
36  {
37  public:
38  GenericFactoryBase()
39  {
40  if ( s_self )
41  {
42  kWarning() << "KParts::GenericFactory instantiated more than once!";
43  }
44  s_self = this;
45  }
46  virtual ~GenericFactoryBase()
47  {
48  delete s_aboutData;
49  delete s_componentData;
50  s_aboutData = 0;
51  s_componentData = 0;
52  s_self = 0;
53  }
54 
55  static const KComponentData &componentData();
56  static KAboutData *aboutData();
57  virtual KComponentData partComponentData()
58  {
59  return componentData();
60  }
61 
62 
63  protected:
64  virtual KComponentData *createComponentData()
65  {
66  return new KComponentData(aboutData());
67  }
68 
69 
70  private:
71  static GenericFactoryBase<T> *s_self;
72  static KComponentData *s_componentData;
73  static KAboutData *s_aboutData;
74  };
75 
109  template <class T>
110  class KDE_DEPRECATED GenericFactory : public GenericFactoryBase<T>
111  {
112  public:
113  GenericFactory() { }
114 
115  virtual KParts::Part *createPartObject( QWidget *parentWidget,
116  QObject *parent,
117  const char *className,
118  const QStringList &args )
119  {
120  T *part = KDEPrivate::ConcreteFactory<T>::create( parentWidget,
121  parent,
122  className,
123  args );
124 
125  if ( part && !qstrcmp( className, "KParts::ReadOnlyPart" ) )
126  {
127  KParts::ReadWritePart *rwp = dynamic_cast<KParts::ReadWritePart *>( part );
128  if ( rwp )
129  rwp->setReadWrite( false );
130  }
131  return part;
132  }
133  };
134 
135  template <class T1, class T2>
136  class GenericFactory< KTypeList<T1, T2> > : public GenericFactoryBase<T1>
137  {
138  public:
139  GenericFactory() { }
140 
141  virtual KParts::Part *createPartObject( QWidget *parentWidget,
142  QObject *parent,
143  const char *className,
144  const QStringList &args )
145  {
146  QObject *object = KDEPrivate::MultiFactory< KTypeList<T1, T2> >::create( parentWidget,
147  parent,
148  className,
149  args );
150 
151  // (this cast is guaranteed to work...)
152  KParts::Part *part = dynamic_cast<KParts::Part *>( object );
153 
154  if ( part && !qstrcmp( className, "KParts::ReadOnlyPart" ) )
155  {
156  KParts::ReadWritePart *rwp = dynamic_cast<KParts::ReadWritePart *>( part );
157  if ( rwp )
158  rwp->setReadWrite( false );
159  }
160  return part;
161  }
162  };
163 
167  template <class T>
168  GenericFactoryBase<T> *GenericFactoryBase<T>::s_self = 0;
169 
173  template <class T>
174  KComponentData *GenericFactoryBase<T>::s_componentData = 0;
175 
179  template <class T>
180  KAboutData *GenericFactoryBase<T>::s_aboutData = 0;
181 
185  template <class T>
186  const KComponentData &GenericFactoryBase<T>::componentData()
187  {
188  if ( !s_componentData )
189  {
190  if ( s_self )
191  s_componentData = s_self->createComponentData();
192  else
193  s_componentData = new KComponentData(aboutData());
194  }
195  return *s_componentData;
196  }
197 
201  template <class T>
202  KAboutData *GenericFactoryBase<T>::aboutData()
203  {
204  if ( !s_aboutData )
205  s_aboutData = T::createAboutData();
206  return s_aboutData;
207  }
208 
209 }
210 
211 #endif
212 
QObject::className
const char * className() const
KParts::GenericFactoryBase::GenericFactoryBase
GenericFactoryBase()
Definition: genericfactory.h:38
KParts::GenericFactoryBase::componentData
static const KComponentData & componentData()
Definition: genericfactory.h:186
QWidget
kdebug.h
KParts::GenericFactoryBase::~GenericFactoryBase
virtual ~GenericFactoryBase()
Definition: genericfactory.h:46
T
#define T
KParts::Part
Base class for parts.
Definition: part.h:215
KParts::GenericFactoryBase::partComponentData
virtual KComponentData partComponentData()
If you have a part contained in a shared library you might want to query for meta-information like th...
Definition: genericfactory.h:57
KParts::ReadWritePart
Base class for an "editor" part.
Definition: part.h:745
KTypeList
KParts::GenericFactoryBase
Definition: genericfactory.h:35
QObject
KParts::GenericFactory::createPartObject
virtual KParts::Part * createPartObject(QWidget *parentWidget, QObject *parent, const char *className, const QStringList &args)
Reimplement this method in your implementation to create the Part.
Definition: genericfactory.h:115
KAboutData
KParts::Factory
A generic factory object to create a Part.
Definition: factory.h:42
QStringList
factory.h
KParts::GenericFactory< KTypeList< T1, T2 > >::createPartObject
virtual KParts::Part * createPartObject(QWidget *parentWidget, QObject *parent, const char *className, const QStringList &args)
Reimplement this method in your implementation to create the Part.
Definition: genericfactory.h:141
KParts::GenericFactory< KTypeList< T1, T2 > >::GenericFactory
GenericFactory()
Definition: genericfactory.h:139
KParts::ReadWritePart::setReadWrite
virtual void setReadWrite(bool readwrite=true)
Changes the behavior of this part to readonly or readwrite.
Definition: part.cpp:782
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KParts::GenericFactory::GenericFactory
GenericFactory()
Definition: genericfactory.h:113
KParts::GenericFactoryBase::createComponentData
virtual KComponentData * createComponentData()
Definition: genericfactory.h:64
kaboutdata.h
QObject::parent
QObject * parent() const
kgenericfactory.h
KParts::GenericFactoryBase::aboutData
static KAboutData * aboutData()
Definition: genericfactory.h:202
KParts::GenericFactory
A template for a KParts::Factory implementation.
Definition: genericfactory.h:110
KComponentData
part.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KParts

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal