summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmiomanager.h
blob: ac3b78ebe2654a9537090e4f1a3c272c3d6236f7 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
**************************************************************************
                                 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 PMIOMANAGER
#define PMIOMANAGER

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

#include <qstring.h>
#include <qstringlist.h>
#include <qptrlist.h>
#include <qdict.h>

class PMParser;
class PMSerializer;
class PMRenderer;
class PMPart;

class QIODevice;

/**
 * Description class for input and output formats.
 *
 * A format may provide the following services:
 *
 * Import: The class can provide a parser to load and import data
 *
 * Export: The class can provide a output device to export and save data
 *
 * Renderer: A renderer exists to render the exported data
 *
 * The class @ref PMIOManager stores a list of instances
 * of this class
 */
class PMIOFormat
{
public:
   /**
    * Format type enum
    */
   enum Services { Import = 1, Export = 2, Renderer = 4,
                   AllServices = Import | Export | Renderer };
   /**
    * Default constructor
    */
   PMIOFormat( );
   /**
    * Destructor
    */
   virtual ~PMIOFormat( );

   /**
    * Returns an unique name of this format.
    */
   virtual QString name( ) const = 0;
   /**
    * Returns a translated description of this format
    */
   virtual QString description( ) const = 0;
   /**
    * Returns the supported services
    * (a bitwise combination of the Services enum values)
    */
   virtual int services( ) const = 0;
   /**
    * Returns a parser to parse the io device.
    *
    * The caller is responsible to delete the returned parser.
    */
   virtual PMParser* newParser( PMPart*, QIODevice* ) const
   {
      return 0;
   };
   /**
    * Returns a parser to parse the byte array.
    *
    * The caller is responsible to delete the returned parser.
    */
   virtual PMParser* newParser( PMPart*, const QByteArray& ) const
   {
      return 0;
   };
   /**
    * Returns an output device to export objects or the complete
    * scene to the given io device.
    *
    * The caller is responsible to delete the returned device
    */
   virtual PMSerializer* newSerializer( QIODevice* )
   {
      return 0;
   }
   /**
    * Returns a new renderer
    */
   virtual PMRenderer* newRenderer( PMPart* ) const
   {
      return 0;
   }
   /**
    * Returns the mime type for this format
    */
   virtual QString mimeType( ) const
   {
      return QString::null;
   }
   /**
    * Returns a list of patterns for the import file dialog
    */
   virtual QStringList importPatterns( ) const
   {
      return QStringList( );
   }
   /**
    * Returns a list of patterns for the export file dialog
    */
   virtual QStringList exportPatterns( ) const
   {
      return QStringList( );
   }
};

/**
 * Manager class that handles all available input and output formats
 * as well as renderers for one part
 */
class PMIOManager
{
public:
   /**
    * Creates an io manager for the part
    */
   PMIOManager( PMPart* part );
   /**
    * Deletes the io manager
    */
   ~PMIOManager( );

   /**
    * Adds a new format
    */
   void addFormat( PMIOFormat* format );
   /**
    * Removes a format by name
    */
   void removeFormat( const QString& name );

   /**
    * Returns the list of registered io formats
    */
   const QPtrList<PMIOFormat>& formats( ) const { return m_formats; }
   /**
    * Returns a view type by name
    */
   PMIOFormat* format( const QString& name ) const;
   /**
    * Returns the first io format that can handle the mime type
    * or 0 if there is none
    */
   PMIOFormat* formatForMimeType( const QString& mime ) const;

private:
   QPtrList<PMIOFormat> m_formats;
   QDict<PMIOFormat> m_dict;
   PMPart* m_pPart;
};

#endif