File: object_imp.cc

package info (click to toggle)
kig 4%3A25.08.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,716 kB
  • sloc: cpp: 41,465; xml: 851; python: 486; perl: 23; sh: 17; makefile: 3
file content (352 lines) | stat: -rw-r--r-- 7,543 bytes parent folder | download
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// SPDX-FileCopyrightText: 2002 Dominique Devriese <devriese@kde.org>

// SPDX-License-Identifier: GPL-2.0-or-later

#include "object_imp.h"

#include "bogus_imp.h"

#include "../misc/coordinate.h"

#include <KLazyLocalizedString>
#include <map>

class ObjectImpType::StaticPrivate
{
public:
    std::map<QByteArray, const ObjectImpType *> namemap;
};

ObjectImp::ObjectImp()
{
}

ObjectImp::~ObjectImp()
{
}

bool ObjectImp::valid() const
{
    return !type()->inherits(InvalidImp::stype());
}

void ObjectImp::fillInNextEscape(QString &, const KigDocument &) const
{
    assert(false);
}

const QList<KLazyLocalizedString> ObjectImp::properties() const
{
    QList<KLazyLocalizedString> ret;
    ret << kli18n("Object Type");
    return ret;
}

int ObjectImp::numberOfProperties() const
{
    return 1;
}

const QByteArrayList ObjectImp::propertiesInternalNames() const
{
    QByteArrayList ret;
    ret << "base-object-type";
    return ret;
}

ObjectImp *ObjectImp::property(int i, const KigDocument &) const
{
    if (i == 0)
        return new StringImp(type()->translatedName());
    return new InvalidImp;
}

const ObjectImpType *ObjectImp::impRequirementForProperty(int) const
{
    return ObjectImp::stype();
}

void ObjectImpVisitor::visit(const ObjectImp *imp)
{
    imp->visit(this);
}

void ObjectImpVisitor::visit(const IntImp *)
{
}

void ObjectImpVisitor::visit(const DoubleImp *)
{
}

void ObjectImpVisitor::visit(const StringImp *)
{
}

void ObjectImpVisitor::visit(const InvalidImp *)
{
}

void ObjectImpVisitor::visit(const HierarchyImp *)
{
}

void ObjectImpVisitor::visit(const LineImp *)
{
}

void ObjectImpVisitor::visit(const PointImp *)
{
}

void ObjectImpVisitor::visit(const TextImp *)
{
}

void ObjectImpVisitor::visit(const AngleImp *)
{
}

void ObjectImpVisitor::visit(const VectorImp *)
{
}

void ObjectImpVisitor::visit(const LocusImp *)
{
}

void ObjectImpVisitor::visit(const CircleImp *)
{
}

void ObjectImpVisitor::visit(const ConicImp *)
{
}

void ObjectImpVisitor::visit(const CubicImp *)
{
}

void ObjectImpVisitor::visit(const SegmentImp *)
{
}

void ObjectImpVisitor::visit(const RayImp *)
{
}

void ObjectImpVisitor::visit(const ArcImp *)
{
}

void ObjectImpVisitor::visit(const FilledPolygonImp *)
{
}

void ObjectImpVisitor::visit(const ClosedPolygonalImp *)
{
}

void ObjectImpVisitor::visit(const OpenPolygonalImp *)
{
}

void ObjectImpVisitor::visit(const BezierImp *)
{
}

void ObjectImpVisitor::visit(const RationalBezierImp *)
{
}

ObjectImpVisitor::~ObjectImpVisitor()
{
}

void ObjectImpVisitor::visit(const TransformationImp *)
{
}

void ObjectImpVisitor::visit(const TestResultImp *)
{
}

const char *ObjectImp::iconForProperty(int) const
{
    return "kig_text";
}

bool ObjectImp::canFillInNextEscape() const
{
    return false;
}

ObjectImpType::ObjectImpType(const ObjectImpType *parent,
                             const char *internalname,
                             const KLazyLocalizedString &translatedname,
                             const KLazyLocalizedString &selectstatement,
                             const KLazyLocalizedString &selectnamestatement,
                             const KLazyLocalizedString &removeastatement,
                             const KLazyLocalizedString &addastatement,
                             const KLazyLocalizedString &moveastatement,
                             const KLazyLocalizedString &attachtothisstatement,
                             const KLazyLocalizedString &showastatement,
                             const KLazyLocalizedString &hideastatement)
    : mparent(parent)
    , minternalname(internalname)
    , mtranslatedname(translatedname)
    , mselectstatement(selectstatement)
    , mselectnamestatement(selectnamestatement)
    , mremoveastatement(removeastatement)
    , maddastatement(addastatement)
    , mmoveastatement(moveastatement)
    , mattachtothisstatement(attachtothisstatement)
    , mshowastatement(showastatement)
    , mhideastatement(hideastatement)
{
    sd()->namemap[minternalname] = this;
}

ObjectImpType::~ObjectImpType()
{
}

bool ObjectImpType::inherits(const ObjectImpType *t) const
{
    //  return t == this || (mparent && mparent->inherits( t ) );
    return t->match(this) || (mparent && mparent->inherits(t));
}

bool ObjectImpType::match(const ObjectImpType *t) const
{
    return t == this;
}

const char *ObjectImpType::internalName() const
{
    return minternalname;
}

QString ObjectImpType::translatedName() const
{
    return mtranslatedname.toString();
}

QString ObjectImpType::selectStatement() const
{
    return mselectstatement.toString();
}

QString ObjectImpType::selectNameStatement() const
{
    return mselectnamestatement.toString();
}

QString ObjectImpType::removeAStatement() const
{
    return mremoveastatement.toString();
}

QString ObjectImpType::addAStatement() const
{
    return maddastatement.toString();
}

QString ObjectImpType::moveAStatement() const
{
    return mmoveastatement.toString();
}

const ObjectImpType *ObjectImpType::typeFromInternalName(const char *string)
{
    QByteArray s(string);
    std::map<QByteArray, const ObjectImpType *>::iterator i = sd()->namemap.find(s);
    if (i == sd()->namemap.end())
        return nullptr;
    else
        return i->second;
}

bool ObjectImp::inherits(const ObjectImpType *t) const
{
    return type()->inherits(t);
}

const ObjectImpType *ObjectImp::stype()
{
    static const ObjectImpType t(nullptr,
                                 "any",
                                 kli18n("Object"),
                                 kli18n("Select this object"),
                                 kli18n("Select object %1"),
                                 kli18n("Remove an object"),
                                 kli18n("Add an object"),
                                 kli18n("Move an object"),
                                 kli18n("Attach to this object"),
                                 kli18n("Show an object"),
                                 kli18n("Hide an object"));
    return &t;
}

ObjectImpType::StaticPrivate *ObjectImpType::sd()
{
    static StaticPrivate d;
    return &d;
}

bool ObjectImp::isCache() const
{
    return false;
}

QString ObjectImpType::attachToThisStatement() const
{
    return mattachtothisstatement.toString();
}

QString ObjectImpType::showAStatement() const
{
    return mshowastatement.toString();
}

QString ObjectImpType::hideAStatement() const
{
    return mhideastatement.toString();
}

bool ObjectImp::isPropertyDefinedOnOrThroughThisImp(int) const
{
    return false;
}

static QByteArrayList propertiesGlobalInternalNames;

int ObjectImp::getPropGid(const char *pname) const
{
    int wp = propertiesGlobalInternalNames.indexOf(pname);
    if (wp >= 0)
        return wp;

    int lp = propertiesInternalNames().indexOf(pname);
    if (lp < 0)
        return lp; // insist that this exists as a property

    propertiesGlobalInternalNames << pname;
    wp = propertiesGlobalInternalNames.indexOf(pname);
    assert(wp >= 0);
    return wp;
}

int ObjectImp::getPropLid(int propgid) const
{
    assert(propgid >= 0 && propgid < propertiesGlobalInternalNames.size());
    int proplid = propertiesInternalNames().indexOf(propertiesGlobalInternalNames[propgid]);
    //  printf ("getPropLid: converting %d in %d\n", propgid, proplid);
    return proplid;
}

const char *ObjectImp::getPropName(int propgid) const
{
    assert(propgid >= 0 && propgid < propertiesGlobalInternalNames.size());
    return propertiesGlobalInternalNames[propgid];
}