1 // SPDX-FileCopyrightText: 2002 Dominique Devriese <devriese@kde.org>
2
3 // SPDX-License-Identifier: GPL-2.0-or-later
4
5 #include "bogus_imp.h"
6
7 #include <QStringList>
8
9 #include "../misc/rect.h"
10
attachPoint() const11 Coordinate BogusImp::attachPoint( ) const
12 {
13 return Coordinate::invalidCoord();
14 }
15
draw(KigPainter &) const16 void BogusImp::draw( KigPainter& ) const
17 {
18 }
19
contains(const Coordinate &,int,const KigWidget &) const20 bool BogusImp::contains( const Coordinate&, int, const KigWidget& ) const
21 {
22 return false;
23 }
24
inRect(const Rect &,int,const KigWidget &) const25 bool BogusImp::inRect( const Rect&, int, const KigWidget& ) const
26 {
27 return false;
28 }
29
DoubleImp(const double d)30 DoubleImp::DoubleImp( const double d )
31 : mdata( d )
32 {
33 }
34
IntImp(const int d)35 IntImp::IntImp( const int d )
36 : mdata( d )
37 {
38 }
39
StringImp(const QString & d)40 StringImp::StringImp( const QString& d )
41 : mdata( d )
42 {
43 }
44
copy() const45 DoubleImp* DoubleImp::copy() const
46 {
47 return new DoubleImp( mdata );
48 }
49
copy() const50 IntImp* IntImp::copy() const
51 {
52 return new IntImp( mdata );
53 }
54
copy() const55 StringImp* StringImp::copy() const
56 {
57 return new StringImp( mdata );
58 }
59
transform(const Transformation &) const60 ObjectImp* BogusImp::transform( const Transformation& ) const
61 {
62 return copy();
63 }
64
copy() const65 InvalidImp* InvalidImp::copy() const
66 {
67 return new InvalidImp();
68 }
69
InvalidImp()70 InvalidImp::InvalidImp()
71 {
72 }
73
fillInNextEscape(QString & s,const KigDocument &) const74 void InvalidImp::fillInNextEscape( QString& s, const KigDocument& ) const
75 {
76 s = s.arg( QStringLiteral("[invalid]") );
77 }
78
fillInNextEscape(QString & s,const KigDocument &) const79 void DoubleImp::fillInNextEscape( QString& s, const KigDocument& ) const
80 {
81 s = s.arg( mdata );
82 }
83
fillInNextEscape(QString & s,const KigDocument &) const84 void IntImp::fillInNextEscape( QString& s, const KigDocument& ) const
85 {
86 s = s.arg( mdata );
87 }
88
fillInNextEscape(QString & s,const KigDocument &) const89 void StringImp::fillInNextEscape( QString& s, const KigDocument& ) const
90 {
91 s = s.arg( mdata );
92 }
93
HierarchyImp(const ObjectHierarchy & h)94 HierarchyImp::HierarchyImp( const ObjectHierarchy& h )
95 : BogusImp(), mdata( h )
96 {
97 }
98
copy() const99 HierarchyImp* HierarchyImp::copy() const
100 {
101 return new HierarchyImp( mdata );
102 }
103
visit(ObjectImpVisitor * vtor) const104 void InvalidImp::visit( ObjectImpVisitor* vtor ) const
105 {
106 vtor->visit( this );
107 }
108
visit(ObjectImpVisitor * vtor) const109 void DoubleImp::visit( ObjectImpVisitor* vtor ) const
110 {
111 vtor->visit( this );
112 }
113
visit(ObjectImpVisitor * vtor) const114 void IntImp::visit( ObjectImpVisitor* vtor ) const
115 {
116 vtor->visit( this );
117 }
118
visit(ObjectImpVisitor * vtor) const119 void StringImp::visit( ObjectImpVisitor* vtor ) const
120 {
121 vtor->visit( this );
122 }
123
visit(ObjectImpVisitor * vtor) const124 void HierarchyImp::visit( ObjectImpVisitor* vtor ) const
125 {
126 vtor->visit( this );
127 }
128
TransformationImp(const Transformation & h)129 TransformationImp::TransformationImp( const Transformation& h )
130 : mdata( h )
131 {
132 }
133
copy() const134 TransformationImp* TransformationImp::copy() const
135 {
136 return new TransformationImp( mdata );
137 }
138
visit(ObjectImpVisitor * vtor) const139 void TransformationImp::visit( ObjectImpVisitor* vtor ) const
140 {
141 vtor->visit( this );
142 }
143
equals(const ObjectImp & rhs) const144 bool InvalidImp::equals( const ObjectImp& rhs ) const
145 {
146 return !rhs.valid();
147 }
148
equals(const ObjectImp & rhs) const149 bool DoubleImp::equals( const ObjectImp& rhs ) const
150 {
151 return rhs.inherits( DoubleImp::stype() ) &&
152 static_cast<const DoubleImp&>( rhs ).data() == mdata;
153 }
154
equals(const ObjectImp & rhs) const155 bool IntImp::equals( const ObjectImp& rhs ) const
156 {
157 return rhs.inherits( IntImp::stype() ) &&
158 static_cast<const IntImp&>( rhs ).data() == mdata;
159 }
160
equals(const ObjectImp & rhs) const161 bool StringImp::equals( const ObjectImp& rhs ) const
162 {
163 return rhs.inherits( StringImp::stype() ) &&
164 static_cast<const StringImp&>( rhs ).data() == mdata;
165 }
166
equals(const ObjectImp & rhs) const167 bool HierarchyImp::equals( const ObjectImp& rhs ) const
168 {
169 return rhs.inherits( HierarchyImp::stype() ) &&
170 static_cast<const HierarchyImp&>( rhs ).data() == mdata;
171 }
172
equals(const ObjectImp & rhs) const173 bool TransformationImp::equals( const ObjectImp& rhs ) const
174 {
175 return rhs.inherits( TransformationImp::stype() ) &&
176 static_cast<const TransformationImp&>( rhs ).data() == mdata;
177 }
178
canFillInNextEscape() const179 bool InvalidImp::canFillInNextEscape() const
180 {
181 return true;
182 }
183
canFillInNextEscape() const184 bool DoubleImp::canFillInNextEscape() const
185 {
186 return true;
187 }
188
canFillInNextEscape() const189 bool IntImp::canFillInNextEscape() const
190 {
191 return true;
192 }
193
canFillInNextEscape() const194 bool StringImp::canFillInNextEscape() const
195 {
196 return true;
197 }
198
stype()199 const ObjectImpType* InvalidImp::stype()
200 {
201 static const ObjectImpType t(
202 Parent::stype(), "invalid", "", "", "", "", "", "", "", "", "" );
203 return &t;
204 }
205
stype()206 const ObjectImpType* StringImp::stype()
207 {
208 static const ObjectImpType t(
209 Parent::stype(), "string",
210 "string", "", "", "", "", "", "", "", "" );
211 return &t;
212 }
stype()213 const ObjectImpType* HierarchyImp::stype()
214 {
215 static const ObjectImpType t(
216 Parent::stype(), "hierarchy", "", "", "", "", "", "", "", "", "" );
217 return &t;
218 }
stype()219 const ObjectImpType* TransformationImp::stype()
220 {
221 static const ObjectImpType t(
222 Parent::stype(), "transformation", "", "", "", "", "", "", "", "", "");
223 return &t;
224 }
225
type() const226 const ObjectImpType* InvalidImp::type() const
227 {
228 return InvalidImp::stype();
229 }
230
type() const231 const ObjectImpType* DoubleImp::type() const
232 {
233 return DoubleImp::stype();
234 }
235
type() const236 const ObjectImpType* IntImp::type() const
237 {
238 return IntImp::stype();
239 }
240
type() const241 const ObjectImpType* StringImp::type() const
242 {
243 return StringImp::stype();
244 }
245
type() const246 const ObjectImpType* HierarchyImp::type() const
247 {
248 return HierarchyImp::stype();
249 }
250
type() const251 const ObjectImpType* TransformationImp::type() const
252 {
253 return TransformationImp::stype();
254 }
255
stype()256 const ObjectImpType* DoubleImp::stype()
257 {
258 static const ObjectImpType t(
259 Parent::stype(), "double",
260 "double", "", "", "", "", "", "", "", "" );
261 return &t;
262 }
263
stype()264 const ObjectImpType* IntImp::stype()
265 {
266 static const ObjectImpType t(
267 Parent::stype(), "int",
268 "int", "", "", "", "", "", "", "", "" );
269 return &t;
270 }
271
stype()272 const ObjectImpType* BogusImp::stype()
273 {
274 static const ObjectImpType t(
275 Parent::stype(), "bogus",
276 "", "", "", "", "", "", "", "", "" );
277 return &t;
278 }
279
stype()280 const ObjectImpType* TestResultImp::stype()
281 {
282 static const ObjectImpType t(
283 Parent::stype(), "testresult", "", "", "", "", "", "", "", "", "" );
284 return &t;
285
286 }
287
TestResultImp(bool t,const QString & s)288 TestResultImp::TestResultImp( bool t, const QString& s )
289 : StringImp( s ), mtruth( t )
290 {
291 }
292
copy() const293 TestResultImp* TestResultImp::copy() const
294 {
295 return new TestResultImp( mtruth, data() );
296 }
297
type() const298 const ObjectImpType* TestResultImp::type() const
299 {
300 return stype();
301 }
302
visit(ObjectImpVisitor * vtor) const303 void TestResultImp::visit( ObjectImpVisitor* vtor ) const
304 {
305 vtor->visit( this );
306 }
307
equals(const ObjectImp & rhs) const308 bool TestResultImp::equals( const ObjectImp& rhs ) const
309 {
310 return rhs.inherits( TestResultImp::stype() ) &&
311 // (FIXME?) static_cast<const TestResultImp&>( rhs ).mdata == mdata &&
312 static_cast<const TestResultImp&>( rhs ).mtruth == mtruth;
313
314 }
315
numberOfProperties() const316 int TestResultImp::numberOfProperties() const
317 {
318 return Parent::numberOfProperties() + 1;
319 }
320
properties() const321 const QByteArrayList TestResultImp::properties() const
322 {
323 QByteArrayList l = Parent::properties();
324 l << I18N_NOOP( "Test Result" );
325 assert( l.size() == TestResultImp::numberOfProperties() );
326 return l;
327 }
328
propertiesInternalNames() const329 const QByteArrayList TestResultImp::propertiesInternalNames() const
330 {
331 QByteArrayList s = Parent::propertiesInternalNames();
332 s << "test-result";
333 assert( s.size() == TestResultImp::numberOfProperties() );
334 return s;
335 }
336
property(int which,const KigDocument & d) const337 ObjectImp* TestResultImp::property( int which, const KigDocument& d ) const
338 {
339 if ( which < Parent::numberOfProperties() )
340 return Parent::property( which, d );
341 if ( which == Parent::numberOfProperties() )
342 return new StringImp( data() );
343 else assert( false );
344 return new InvalidImp;
345 }
346
iconForProperty(int which) const347 const char* TestResultImp::iconForProperty( int which ) const
348 {
349 if ( which < Parent::numberOfProperties() )
350 return Parent::iconForProperty( which );
351 if ( which == Parent::numberOfProperties() )
352 return ""; // test-result
353 else assert( false );
354 return "";
355 }
356
impRequirementForProperty(int which) const357 const ObjectImpType* TestResultImp::impRequirementForProperty( int which ) const
358 {
359 if ( which < Parent::numberOfProperties() )
360 return Parent::impRequirementForProperty( which );
361 else return TestResultImp::stype();
362 }
363
isPropertyDefinedOnOrThroughThisImp(int which) const364 bool TestResultImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
365 {
366 if ( which < Parent::numberOfProperties() )
367 return Parent::impRequirementForProperty( which );
368 else return false;
369 }
370
surroundingRect() const371 Rect BogusImp::surroundingRect() const
372 {
373 return Rect::invalidRect();
374 }
375