1 // SPDX-FileCopyrightText: 2002 Dominique Devriese <devriese@kde.org>
2 
3 // SPDX-License-Identifier: GPL-2.0-or-later
4 
5 #include "object_imp.h"
6 
7 #include "bogus_imp.h"
8 
9 #include "../misc/coordinate.h"
10 
11 #include <map>
12 
13 class ObjectImpType::StaticPrivate
14 {
15 public:
16   std::map<QByteArray, const ObjectImpType*> namemap;
17 };
18 
ObjectImp()19 ObjectImp::ObjectImp()
20 {
21 }
22 
~ObjectImp()23 ObjectImp::~ObjectImp()
24 {
25 }
26 
valid() const27 bool ObjectImp::valid() const
28 {
29   return ! type()->inherits( InvalidImp::stype() );
30 }
31 
fillInNextEscape(QString &,const KigDocument &) const32 void ObjectImp::fillInNextEscape( QString&, const KigDocument& ) const
33 {
34   assert( false );
35 }
36 
properties() const37 const QByteArrayList ObjectImp::properties() const
38 {
39   QByteArrayList ret;
40   ret << I18N_NOOP( "Object Type" );
41   return ret;
42 }
43 
numberOfProperties() const44 int ObjectImp::numberOfProperties() const
45 {
46   return 1;
47 }
48 
propertiesInternalNames() const49 const QByteArrayList ObjectImp::propertiesInternalNames() const
50 {
51   QByteArrayList ret;
52   ret << "base-object-type";
53   return ret;
54 }
55 
property(int i,const KigDocument &) const56 ObjectImp* ObjectImp::property( int i, const KigDocument& ) const
57 {
58   if ( i == 0 ) return new StringImp( type()->translatedName() );
59   return new InvalidImp;
60 }
61 
impRequirementForProperty(int) const62 const ObjectImpType* ObjectImp::impRequirementForProperty( int ) const
63 {
64   return ObjectImp::stype();
65 }
66 
visit(const ObjectImp * imp)67 void ObjectImpVisitor::visit( const ObjectImp* imp )
68 {
69   imp->visit( this );
70 }
71 
visit(const IntImp *)72 void ObjectImpVisitor::visit( const IntImp* )
73 {
74 }
75 
visit(const DoubleImp *)76 void ObjectImpVisitor::visit( const DoubleImp* )
77 {
78 }
79 
visit(const StringImp *)80 void ObjectImpVisitor::visit( const StringImp* )
81 {
82 }
83 
visit(const InvalidImp *)84 void ObjectImpVisitor::visit( const InvalidImp* )
85 {
86 }
87 
visit(const HierarchyImp *)88 void ObjectImpVisitor::visit( const HierarchyImp* )
89 {
90 }
91 
visit(const LineImp *)92 void ObjectImpVisitor::visit( const LineImp* )
93 {
94 }
95 
visit(const PointImp *)96 void ObjectImpVisitor::visit( const PointImp* )
97 {
98 }
99 
visit(const TextImp *)100 void ObjectImpVisitor::visit( const TextImp* )
101 {
102 }
103 
visit(const AngleImp *)104 void ObjectImpVisitor::visit( const AngleImp* )
105 {
106 }
107 
visit(const VectorImp *)108 void ObjectImpVisitor::visit( const VectorImp* )
109 {
110 }
111 
visit(const LocusImp *)112 void ObjectImpVisitor::visit( const LocusImp* )
113 {
114 }
115 
visit(const CircleImp *)116 void ObjectImpVisitor::visit( const CircleImp* )
117 {
118 }
119 
visit(const ConicImp *)120 void ObjectImpVisitor::visit( const ConicImp* )
121 {
122 }
123 
visit(const CubicImp *)124 void ObjectImpVisitor::visit( const CubicImp* )
125 {
126 }
127 
visit(const SegmentImp *)128 void ObjectImpVisitor::visit( const SegmentImp* )
129 {
130 }
131 
visit(const RayImp *)132 void ObjectImpVisitor::visit( const RayImp* )
133 {
134 }
135 
visit(const ArcImp *)136 void ObjectImpVisitor::visit( const ArcImp* )
137 {
138 }
139 
visit(const FilledPolygonImp *)140 void ObjectImpVisitor::visit( const FilledPolygonImp* )
141 {
142 }
143 
visit(const ClosedPolygonalImp *)144 void ObjectImpVisitor::visit( const ClosedPolygonalImp* )
145 {
146 }
147 
visit(const OpenPolygonalImp *)148 void ObjectImpVisitor::visit( const OpenPolygonalImp* )
149 {
150 }
151 
visit(const BezierImp *)152 void ObjectImpVisitor::visit( const BezierImp* )
153 {
154 }
155 
visit(const RationalBezierImp *)156 void ObjectImpVisitor::visit( const RationalBezierImp* )
157 {
158 }
159 
~ObjectImpVisitor()160 ObjectImpVisitor::~ObjectImpVisitor()
161 {
162 
163 }
164 
visit(const TransformationImp *)165 void ObjectImpVisitor::visit( const TransformationImp* )
166 {
167 }
168 
visit(const TestResultImp *)169 void ObjectImpVisitor::visit( const TestResultImp* )
170 {
171 }
172 
iconForProperty(int) const173 const char* ObjectImp::iconForProperty( int ) const
174 {
175   return "kig_text";
176 }
177 
canFillInNextEscape() const178 bool ObjectImp::canFillInNextEscape() const
179 {
180   return false;
181 }
182 
ObjectImpType(const ObjectImpType * parent,const char * internalname,const char * translatedname,const char * selectstatement,const char * selectnamestatement,const char * removeastatement,const char * addastatement,const char * moveastatement,const char * attachtothisstatement,const char * showastatement,const char * hideastatement)183 ObjectImpType::ObjectImpType( const ObjectImpType* parent,
184                               const char* internalname,
185                               const char* translatedname,
186                               const char* selectstatement,
187                               const char* selectnamestatement,
188                               const char* removeastatement,
189                               const char* addastatement,
190                               const char* moveastatement,
191                               const char* attachtothisstatement,
192                               const char* showastatement,
193                               const char* hideastatement )
194   : mparent( parent ), minternalname( internalname ),
195     mtranslatedname( translatedname ), mselectstatement( selectstatement ),
196     mselectnamestatement( selectnamestatement ),
197     mremoveastatement( removeastatement ), maddastatement( addastatement ),
198     mmoveastatement( moveastatement ),
199     mattachtothisstatement( attachtothisstatement ),
200     mshowastatement( showastatement ),
201     mhideastatement( hideastatement )
202 {
203   sd()->namemap[minternalname] = this;
204 }
205 
~ObjectImpType()206 ObjectImpType::~ObjectImpType()
207 {
208 }
209 
inherits(const ObjectImpType * t) const210 bool ObjectImpType::inherits( const ObjectImpType* t ) const
211 {
212 //  return t == this || (mparent && mparent->inherits( t ) );
213   return t->match( this ) || (mparent && mparent->inherits( t ) );
214 }
215 
match(const ObjectImpType * t) const216 bool ObjectImpType::match( const ObjectImpType* t ) const
217 {
218   return t == this;
219 }
220 
internalName() const221 const char* ObjectImpType::internalName() const
222 {
223   return minternalname;
224 }
225 
translatedName() const226 QString ObjectImpType::translatedName() const
227 {
228   return i18n( mtranslatedname );
229 }
230 
selectStatement() const231 const char* ObjectImpType::selectStatement() const
232 {
233   return mselectstatement;
234 }
235 
selectNameStatement() const236 const char* ObjectImpType::selectNameStatement() const
237 {
238   return mselectnamestatement;
239 }
240 
removeAStatement() const241 QString ObjectImpType::removeAStatement() const
242 {
243   return i18n( mremoveastatement );
244 }
245 
addAStatement() const246 QString ObjectImpType::addAStatement() const
247 {
248   return i18n( maddastatement );
249 }
250 
moveAStatement() const251 QString ObjectImpType::moveAStatement() const
252 {
253   return i18n( mmoveastatement );
254 }
255 
typeFromInternalName(const char * string)256 const ObjectImpType* ObjectImpType::typeFromInternalName( const char* string )
257 {
258   QByteArray s( string );
259   std::map<QByteArray, const ObjectImpType*>::iterator i = sd()->namemap.find( s );
260   if ( i == sd()->namemap.end() )
261     return 0;
262   else return i->second;
263 }
264 
inherits(const ObjectImpType * t) const265 bool ObjectImp::inherits( const ObjectImpType* t ) const
266 {
267   return type()->inherits( t );
268 }
269 
stype()270 const ObjectImpType* ObjectImp::stype()
271 {
272   static const ObjectImpType t(
273     0, "any",
274     I18N_NOOP( "Object" ),
275     I18N_NOOP( "Select this object" ),
276     I18N_NOOP( "Select object %1" ),
277     I18N_NOOP( "Remove an object" ),
278     I18N_NOOP( "Add an object" ),
279     I18N_NOOP( "Move an object" ),
280     I18N_NOOP( "Attach to this object" ),
281     I18N_NOOP( "Show an object" ),
282     I18N_NOOP( "Hide an object" ) );
283   return &t;
284 }
285 
sd()286 ObjectImpType::StaticPrivate* ObjectImpType::sd()
287 {
288   static StaticPrivate d;
289   return &d;
290 }
291 
isCache() const292 bool ObjectImp::isCache() const
293 {
294   return false;
295 }
296 
attachToThisStatement() const297 QString ObjectImpType::attachToThisStatement() const
298 {
299   return i18n( mattachtothisstatement );
300 }
301 
showAStatement() const302 QString ObjectImpType::showAStatement() const
303 {
304   return i18n( mshowastatement );
305 }
306 
hideAStatement() const307 QString ObjectImpType::hideAStatement() const
308 {
309   return i18n( mhideastatement );
310 }
311 
isPropertyDefinedOnOrThroughThisImp(int) const312 bool ObjectImp::isPropertyDefinedOnOrThroughThisImp( int ) const
313 {
314   return false;
315 }
316 
317 static QByteArrayList propertiesGlobalInternalNames;
318 
getPropGid(const char * pname) const319 int ObjectImp::getPropGid( const char* pname ) const
320 {
321   int wp = propertiesGlobalInternalNames.indexOf( pname );
322   if ( wp >= 0 ) return wp;
323 
324   int lp = propertiesInternalNames().indexOf( pname );
325   if ( lp < 0 ) return lp; // insist that this exists as a property
326 
327   propertiesGlobalInternalNames << pname;
328   wp = propertiesGlobalInternalNames.indexOf( pname );
329   assert( wp >= 0 );
330   return wp;
331 }
332 
getPropLid(int propgid) const333 int ObjectImp::getPropLid( int propgid ) const
334 {
335   assert( propgid >= 0 && propgid < propertiesGlobalInternalNames.size() );
336   int proplid = propertiesInternalNames().indexOf(
337               propertiesGlobalInternalNames[propgid] );
338 //  printf ("getPropLid: converting %d in %d\n", propgid, proplid);
339   return proplid;
340 }
341 
getPropName(int propgid) const342 const char* ObjectImp::getPropName( int propgid ) const
343 {
344   assert( propgid >= 0 && propgid < propertiesGlobalInternalNames.size() );
345   return propertiesGlobalInternalNames[propgid];
346 }
347