summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmprototypemanager.h
blob: 025b82136d37220d2cd66f1da1c50a6f424f7c5a (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
146
147
148
149
//-*-C++-*-
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2000-2002 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 PMPTMANAGER_H
#define PMPTMANAGER_H

#include "pmobject.h"
#include <qdict.h>
#include <qmap.h>
#include <qvaluelist.h>

class PMPart;

/**
 * Description class for declarations types, used by @ref PMPrototypeManager
 * and @ref PMDeclare
 */
class PMDeclareDescription
{
public:
   PMDeclareDescription( ) { }
   PMDeclareDescription( const PMDeclareDescription& d )
   {
      type = d.type;
      description = d.description;
      pixmap = d.pixmap;
   }
   PMDeclareDescription( PMMetaObject* t, const QString& d, const QString& p )
   {
      type = t;
      description = d;
      pixmap = p;
   }
   PMDeclareDescription& operator=( const PMDeclareDescription& d )
   {
      type = d.type;
      description = d.description;
      pixmap = d.pixmap;
      return *this;
   }
   PMMetaObject* type;
   QString description;
   QString pixmap;
};

/**
 * Prototype manager for @ref PMObject.
 *
 * This class stores class and inheritance information for each
 * available object type.
 *
 * Each @ref PMPart class holds one instance of this class. The
 * available objects depend on the loaded plugins.
 *
 * Patterns: Prototype
 */
class PMPrototypeManager
{
public:
   /**
    * Creates a prototype manager for the part.
    */
   PMPrototypeManager( PMPart* part );
   /**
    * Deletes the prototype manager
    */
   ~PMPrototypeManager( );
   /**
    * Adds the object to the list of prototypes. The prototype becomes
    * the owner of the object and will be delete immediately by the
    * prototype manager.
    */
   void addPrototype( PMObject* obj );
   /**
    * Adds a declaration type. Needed information is the class type,
    * the @ref description( ) and the @ref pixmap( )
    */
   void addDeclarationType( const QString& className,
                            const QString& description,
                            const QString& pixmap );
   /**
    * Returns an iterator to the list of available objects
    */
   QPtrListIterator<PMMetaObject> prototypeIterator( ) const;
   /**
    * Returns an iterator to the list of available declaration types
    */
   const QValueList<PMDeclareDescription>& declarationTypes( ) const;
   /**
    * Returns a new PMObject by class name
    */
   PMObject* newObject( const QString& name ) const;
   /**
    * Returns the meta object by class name or 0 if this class does
    * not exist.
    * @see PMMetaObject
    */
   PMMetaObject* metaObject( const QString& name ) const;
   /**
    * Returns true if the class exists
    */
   bool existsClass( const QString& name ) const
   {
      return metaObject( name );
   }
   /**
    * Returns true if the second class is a base class for
    * the first class
    */
   bool isA( const QString& className, const QString& baseClassName ) const;
   /**
    * Returns true if the second class is a base class for
    * the first class
    */
   bool isA( PMMetaObject* c, const QString& baseClassName ) const;
   /**
    * Returns the real class if only the lower case version is know.
    * Used by the xml parser
    */
   QString className( const QString& lowercase ) const;
   /**
    * Returns a pointer to the part
    */
   PMPart* part( ) const { return m_pPart; }

private:
   QPtrList<PMMetaObject> m_prototypes;
   QDict<PMMetaObject> m_metaDict;
   QMap<QString, QString> m_lowerCaseDict;
   QValueList<PMDeclareDescription> m_declareDescriptions;
   PMPart* m_pPart;
};
#endif