summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmviewfactory.h
blob: 78f8981f31a71416daf9dc9fd0cf8aee120f8d11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2003 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  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 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/

#ifndef PMVIEWFACTORY_H
#define PMVIEWFACTORY_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <tqstring.h>
#include <tqptrlist.h>
#include <tqdict.h>
#include <kstaticdeleter.h>

class PMViewBase;
class TQWidget;
class PMPart;
class TQDomElement;
class PMViewOptions;
class PMViewOptionsWidget;

/**
 * Factory and description class for one view type
 * @see PMViewFactory
 */
class PMViewTypeFactory
{
public:
   /**
    * Default constructor
    */
   PMViewTypeFactory( ) { }
   /**
    * Destructor
    */
   virtual ~PMViewTypeFactory( ) { }
   /**
    * Returns the id for the view type. Choose an unique name.
    */
   virtual TQString viewType( ) const = 0;
   /**
    * Returns a i18n'ed description for the view type
    */
   virtual TQString description( ) const = 0;
   /**
    * Returns a i18n'ed description for the view type, dependent
    * on the options. Calls the method above by default.
    */
   virtual TQString description( PMViewOptions* ) const
   {
      return description( );
   }
   /**
    * Returns the icon name for the view
    */
   virtual TQString iconName( ) const = 0;
   /**
    * Returns a new view instance
    */
   virtual PMViewBase* newInstance( TQWidget* tqparent, PMPart* part ) const = 0;
   /**
    * Creates a config object for the view type.
    * If the view doesn't have special attributes, the function returns 0;
    */
   virtual PMViewOptions* newOptionsInstance( ) const { return 0; }
   /**
    * Creates a widget to configure the custom options
    */
   virtual PMViewOptionsWidget* newOptionsWidget( TQWidget*, PMViewOptions* )
   {
      return 0;
   }
};


/**
 * Factory class for KPovModeler views.
 *
 * Plugins can add new view types by adding new
 * @ref PMViewTypeFactory objects.
 */
class PMViewFactory
{
public:
   /**
    * Destructor
    */
   ~PMViewFactory( );
   /**
    * Returns the factory instance
    */
   static PMViewFactory* theFactory( );

   /**
    * Adds a new view type
    *
    * The factory becomes the owner of the object
    */
   void addViewType( PMViewTypeFactory* vt );
   /**
    * Returns a new view of type viewType if available
    */
   PMViewBase* newViewInstance( const TQString& viewType,
                                TQWidget* tqparent, PMPart* part ) const;
   /**
    * Returns a new view option instance for the given view type
    */
   PMViewOptions* newOptionsInstance( const TQString& viewType ) const;
   /**
    * Returns the factory for the given view type
    */
   PMViewTypeFactory* viewFactory( const TQString& viewType ) const;
   /**
    * Returns the list of available view types
    */
   const TQPtrList<PMViewTypeFactory>& viewTypes( ) const;
private:
   /**
    * Constructor
    */
   PMViewFactory( );

   TQPtrList<PMViewTypeFactory> m_viewTypes;
   TQDict<PMViewTypeFactory> m_dict;
   
   static PMViewFactory* s_pInstance;
   static KStaticDeleter<PMViewFactory> s_staticDeleter;   
};

#endif