summaryrefslogtreecommitdiffstats
path: root/src/mof/qmofclassifier.cpp
blob: a5a8f2efbb4284e635fd52a873996efd0cf6e877 (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
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
/****************************************************************************
**
** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtMof module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qmofclassifier.h"

#include <QtMof/QMofClass>
#include <QtMof/QMofComment>
#include <QtMof/QMofConstraint>
#include <QtMof/QMofElement>
#include <QtMof/QMofElementImport>
#include <QtMof/QMofFeature>
#include <QtMof/QMofGeneralization>
#include <QtMof/QMofNamedElement>
#include <QtMof/QMofObject>
#include <QtMof/QMofPackage>
#include <QtMof/QMofPackageableElement>
#include <QtMof/QMofPackageImport>
#include <QtMof/QMofProperty>

QT_BEGIN_NAMESPACE

/*!
    \class QMofClassifier

    \inmodule QtMof

    \brief A classifier is a classification of instances - it describes a set of instances that have features in common. A classifier can specify a generalization hierarchy by referencing its general classifiers.
 */
QMofClassifier::QMofClassifier() :
    _isAbstract(false),
    _isFinalSpecialization(false)
{
}

QModelingElement *QMofClassifier::clone() const
{
    QMofClassifier *c = new QMofClassifier;
    foreach (QMofComment *element, ownedComments())
        c->addOwnedComment(dynamic_cast<QMofComment *>(element->clone()));
    c->setName(name());
    c->setVisibility(visibility());
    if (package())
        c->setPackage(dynamic_cast<QMofPackage *>(package()->clone()));
    c->setLeaf(isLeaf());
    foreach (QMofElementImport *element, elementImports())
        c->addElementImport(dynamic_cast<QMofElementImport *>(element->clone()));
    foreach (QMofConstraint *element, ownedRules())
        c->addOwnedRule(dynamic_cast<QMofConstraint *>(element->clone()));
    foreach (QMofPackageImport *element, packageImports())
        c->addPackageImport(dynamic_cast<QMofPackageImport *>(element->clone()));
    foreach (QMofGeneralization *element, generalizations())
        c->addGeneralization(dynamic_cast<QMofGeneralization *>(element->clone()));
    c->setAbstract(isAbstract());
    c->setFinalSpecialization(isFinalSpecialization());
    foreach (QMofClassifier *element, redefinedClassifiers())
        c->addRedefinedClassifier(dynamic_cast<QMofClassifier *>(element->clone()));
    return c;
}

// OWNED ATTRIBUTES

/*!
    Refers to all of the Properties that are direct (i.e. not inherited or imported) attributes of the classifier.
 */
const QSet<QMofProperty *> QMofClassifier::attributes() const
{
    // This is a read-only derived union association end

    return _attributes;
}

void QMofClassifier::addAttribute(QMofProperty *attribute)
{
    // This is a read-only derived union association end

    if (!_attributes.contains(attribute)) {
        _attributes.insert(attribute);
        if (attribute && attribute->asQModelingObject() && this->asQModelingObject())
            QObject::connect(attribute->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeAttribute(QObject *)));

        // Adjust subsetted properties
        addFeature(attribute);
    }
}

void QMofClassifier::removeAttribute(QMofProperty *attribute)
{
    // This is a read-only derived union association end

    if (_attributes.contains(attribute)) {
        _attributes.remove(attribute);

        // Adjust subsetted properties
        removeFeature(attribute);
    }
}

/*!
    Specifies each feature defined in the classifier.
 */
const QSet<QMofFeature *> QMofClassifier::features() const
{
    // This is a read-only derived union association end

    return _features;
}

void QMofClassifier::addFeature(QMofFeature *feature)
{
    // This is a read-only derived union association end

    if (!_features.contains(feature)) {
        _features.insert(feature);
        if (feature && feature->asQModelingObject() && this->asQModelingObject())
            QObject::connect(feature->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeFeature(QObject *)));

        // Adjust subsetted properties
        addMember(feature);

        // Adjust opposite properties
        if (feature) {
            feature->addFeaturingClassifier(this);
        }
    }
}

void QMofClassifier::removeFeature(QMofFeature *feature)
{
    // This is a read-only derived union association end

    if (_features.contains(feature)) {
        _features.remove(feature);

        // Adjust subsetted properties
        removeMember(feature);

        // Adjust opposite properties
        if (feature) {
            feature->removeFeaturingClassifier(this);
        }
    }
}

/*!
    Specifies the general Classifiers for this Classifier.
 */
const QSet<QMofClassifier *> QMofClassifier::generals() const
{
    // This is a read-write derived association end

    qWarning("QMofClassifier::generals(): to be implemented (this is a derived association end)");

    return QSet<QMofClassifier *>();
}

void QMofClassifier::addGeneral(QMofClassifier *general)
{
    // This is a read-write derived association end

    qWarning("QMofClassifier::addGeneral(): to be implemented (this is a derived association end)");
    Q_UNUSED(general);

    if (false /* <derivedexclusion-criteria> */) {
        // <derived-code>
    }
}

void QMofClassifier::removeGeneral(QMofClassifier *general)
{
    // This is a read-write derived association end

    qWarning("QMofClassifier::removeGeneral(): to be implemented (this is a derived association end)");
    Q_UNUSED(general);

    if (false /* <derivedexclusion-criteria> */) {
        // <derived-code>
    }
}

/*!
    Specifies the Generalization relationships for this Classifier. These Generalizations navigaten to more general classifiers in the generalization hierarchy.
 */
const QSet<QMofGeneralization *> QMofClassifier::generalizations() const
{
    // This is a read-write association end

    return _generalizations;
}

void QMofClassifier::addGeneralization(QMofGeneralization *generalization)
{
    // This is a read-write association end

    if (!_generalizations.contains(generalization)) {
        _generalizations.insert(generalization);
        if (generalization && generalization->asQModelingObject() && this->asQModelingObject())
            QObject::connect(generalization->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeGeneralization(QObject *)));
        generalization->asQModelingObject()->setParent(this->asQModelingObject());

        // Adjust subsetted properties
        addOwnedElement(generalization);

        // Adjust opposite properties
        if (generalization) {
            generalization->setSpecific(this);
        }
    }
}

void QMofClassifier::removeGeneralization(QMofGeneralization *generalization)
{
    // This is a read-write association end

    if (_generalizations.contains(generalization)) {
        _generalizations.remove(generalization);
        if (generalization->asQModelingObject())
            generalization->asQModelingObject()->setParent(0);

        // Adjust subsetted properties
        removeOwnedElement(generalization);

        // Adjust opposite properties
        if (generalization) {
            generalization->setSpecific(0);
        }
    }
}

/*!
    Specifies all elements inherited by this classifier from the general classifiers.
 */
const QSet<QMofNamedElement *> QMofClassifier::inheritedMembers() const
{
    // This is a read-only derived association end

    qWarning("QMofClassifier::inheritedMembers(): to be implemented (this is a derived association end)");

    return QSet<QMofNamedElement *>();
}

void QMofClassifier::addInheritedMember(QMofNamedElement *inheritedMember)
{
    // This is a read-only derived association end

    qWarning("QMofClassifier::addInheritedMember(): to be implemented (this is a derived association end)");
    Q_UNUSED(inheritedMember);

    if (false /* <derivedexclusion-criteria> */) {
        // <derived-code>

        // Adjust subsetted properties
        addMember(inheritedMember);
    }
}

void QMofClassifier::removeInheritedMember(QMofNamedElement *inheritedMember)
{
    // This is a read-only derived association end

    qWarning("QMofClassifier::removeInheritedMember(): to be implemented (this is a derived association end)");
    Q_UNUSED(inheritedMember);

    if (false /* <derivedexclusion-criteria> */) {
        // <derived-code>

        // Adjust subsetted properties
        removeMember(inheritedMember);
    }
}

/*!
    If true, the Classifier does not provide a complete declaration and can typically not be instantiated. An abstract classifier is intended to be used by other classifiers e.g. as the target of general metarelationships or generalization relationships.
 */
bool QMofClassifier::isAbstract() const
{
    // This is a read-write property

    return _isAbstract;
}

void QMofClassifier::setAbstract(bool isAbstract)
{
    // This is a read-write property

    if (_isAbstract != isAbstract) {
        _isAbstract = isAbstract;
        _qModelingObject->modifiedResettableProperties() << QStringLiteral("isAbstract");
    }
}

/*!
    If true, the Classifier cannot be specialized by generalization. Note that this property is preserved through package merge operations; that is, the capability to specialize a Classifier (i.e., isFinalSpecialization =false) must be preserved in the resulting Classifier of a package merge operation where a Classifier with isFinalSpecialization =false is merged with a matching Classifier with isFinalSpecialization =true: the resulting Classifier will have isFinalSpecialization =false.
 */
bool QMofClassifier::isFinalSpecialization() const
{
    // This is a read-write property

    return _isFinalSpecialization;
}

void QMofClassifier::setFinalSpecialization(bool isFinalSpecialization)
{
    // This is a read-write property

    if (_isFinalSpecialization != isFinalSpecialization) {
        _isFinalSpecialization = isFinalSpecialization;
        _qModelingObject->modifiedResettableProperties() << QStringLiteral("isFinalSpecialization");
    }
}

/*!
    References the Classifiers that are redefined by this Classifier.
 */
const QSet<QMofClassifier *> QMofClassifier::redefinedClassifiers() const
{
    // This is a read-write association end

    return _redefinedClassifiers;
}

void QMofClassifier::addRedefinedClassifier(QMofClassifier *redefinedClassifier)
{
    // This is a read-write association end

    if (!_redefinedClassifiers.contains(redefinedClassifier)) {
        _redefinedClassifiers.insert(redefinedClassifier);
        if (redefinedClassifier && redefinedClassifier->asQModelingObject() && this->asQModelingObject())
            QObject::connect(redefinedClassifier->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeRedefinedClassifier(QObject *)));

        // Adjust subsetted properties
        addRedefinedElement(redefinedClassifier);
    }
}

void QMofClassifier::removeRedefinedClassifier(QMofClassifier *redefinedClassifier)
{
    // This is a read-write association end

    if (_redefinedClassifiers.contains(redefinedClassifier)) {
        _redefinedClassifiers.remove(redefinedClassifier);

        // Adjust subsetted properties
        removeRedefinedElement(redefinedClassifier);
    }
}

// OPERATIONS

/*!
    The query allFeatures() gives all of the features in the namespace of the classifier. In general, through mechanisms such as inheritance, this will be a larger set than feature.
 */
QSet<QMofFeature *> QMofClassifier::allFeatures() const
{
    qWarning("QMofClassifier::allFeatures(): to be implemented (operation)");

    return QSet<QMofFeature *> ();
}

/*!
    The query allParents() gives all of the direct and indirect ancestors of a generalized Classifier.
 */
QSet<QMofClassifier *> QMofClassifier::allParents() const
{
    qWarning("QMofClassifier::allParents(): to be implemented (operation)");

    return QSet<QMofClassifier *> ();
}

/*!
    The query conformsTo() gives true for a classifier that defines a type that conforms to another. This is used, for example, in the specification of signature conformance for operations.
 */
bool QMofClassifier::conformsTo(QMofClassifier *other) const
{
    qWarning("QMofClassifier::conformsTo(): to be implemented (operation)");

    Q_UNUSED(other);
    return bool ();
}

/*!
    The query hasVisibilityOf() determines whether a named element is visible in the classifier. By default all are visible. It is only called when the argument is something owned by a parent.
 */
bool QMofClassifier::hasVisibilityOf(QMofNamedElement *n) const
{
    qWarning("QMofClassifier::hasVisibilityOf(): to be implemented (operation)");

    Q_UNUSED(n);
    return bool ();
}

/*!
    The query inherit() defines how to inherit a set of elements. Here the operation is defined to inherit them all. It is intended to be redefined in circumstances where inheritance is affected by redefinition.
 */
QSet<QMofNamedElement *> QMofClassifier::inherit(QSet<QMofNamedElement *> inhs) const
{
    qWarning("QMofClassifier::inherit(): to be implemented (operation)");

    Q_UNUSED(inhs);
    return QSet<QMofNamedElement *> ();
}

/*!
    The query inheritableMembers() gives all of the members of a classifier that may be inherited in one of its descendants, subject to whatever visibility restrictions apply.
 */
QSet<QMofNamedElement *> QMofClassifier::inheritableMembers(QMofClassifier *c) const
{
    qWarning("QMofClassifier::inheritableMembers(): to be implemented (operation)");

    Q_UNUSED(c);
    return QSet<QMofNamedElement *> ();
}

/*!
    The query maySpecializeType() determines whether this classifier may have a generalization relationship to classifiers of the specified type. By default a classifier may specialize classifiers of the same or a more general type. It is intended to be redefined by classifiers that have different specialization constraints.
 */
bool QMofClassifier::maySpecializeType(QMofClassifier *c) const
{
    qWarning("QMofClassifier::maySpecializeType(): to be implemented (operation)");

    Q_UNUSED(c);
    return bool ();
}

/*!
    The query parents() gives all of the immediate ancestors of a generalized Classifier.
 */
QSet<QMofClassifier *> QMofClassifier::parents() const
{
    qWarning("QMofClassifier::parents(): to be implemented (operation)");

    return QSet<QMofClassifier *> ();
}

QT_END_NAMESPACE