summaryrefslogtreecommitdiff
path: root/src/shared/qml/metatype/nodemetainfo.cpp
blob: 907083b7523cb18ec0a9daecb92214273620f2e7 (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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#include "invalidmetainfoexception.h"
#include "metainfo.h"
#include "nodemetainfo.h"
#include "propertymetainfo.h"

#include <QtCore/QSharedData>
#include <QtCore/QtDebug>
#include <QtGui/QIcon>
#include <QtDeclarative/QmlMetaType>
#include <QtDeclarative/QmlContext>
#include <QtDeclarative/QmlEngine>
#include <QtDeclarative/QmlComponent>
#include <private/qmlvaluetype_p.h>

namespace Qml {
namespace Internal {

class NodeMetaInfoData : public QSharedData
{
public:
    typedef enum {
        No = -1,
        Unknown = 0,
        Yes = 1,
    } TristateBoolean;

public:
    NodeMetaInfoData(const MetaInfo &metaInfo) :
            metaInfo(metaInfo),
            isContainer(false),
            isVisibleToItemLibrary(false),
            isFXItem(Unknown),
            icon(),
            category("misc")
    { }

    MetaInfo metaInfo;
    QString typeName;
    bool isContainer;
    bool isVisibleToItemLibrary;
    TristateBoolean isFXItem;
    QHash<QString, PropertyMetaInfo> propertyMetaInfoHash;
    QIcon icon;
    QString category;
    QString qmlFile;
    QString defaultProperty;
    int majorVersion;
    int minorVersion;
};

} // namespace Internal

/*!
\class QKineticDesigner::NodeMetaInfo
\ingroup CoreModel
\brief The NodeMetaInfo class provides meta information about a qml type.

A NodeMetaInfo object can be created via ModelNode::metaInfo, or MetaInfo::nodeMetaInfo.

The object can be invalid - you can check this by calling isValid().
The object is invalid if you ask for meta information for
an non-existing qml property. Also the node meta info can become invalid
if the enclosing type is deregistered from the meta type system (e.g.
a sub component qml file is deleted). Trying to call any accessor methods on an invalid
NodeMetaInfo object will result in an InvalidMetaInfoException being thrown.

\see QKineticDesigner::MetaInfo, QKineticDesigner::PropertyMetaInfo, QKineticDesigner::EnumeratorMetaInfo
*/

NodeMetaInfo::NodeMetaInfo()
    : m_data(0)
{
    // create invalid node
}

NodeMetaInfo::NodeMetaInfo(const MetaInfo &metaInfo)
    : m_data(new Internal::NodeMetaInfoData(metaInfo))
{
}

NodeMetaInfo::~NodeMetaInfo()
{
}

/*!
  \brief Creates a copy of the handle.
  */
NodeMetaInfo::NodeMetaInfo(const NodeMetaInfo &other)
    : m_data(other.m_data)
{
}

/*!
  \brief Copies the handle.
  */
NodeMetaInfo &NodeMetaInfo::operator=(const NodeMetaInfo &other)
{
    if (this != &other)
        this->m_data = other.m_data;

    return *this;
}

/*!
  \brief Returns whether the meta information system knows about this type.
  */
bool NodeMetaInfo::isValid() const
{
    return (m_data.data() != 0);
}

MetaInfo NodeMetaInfo::metaInfo() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    return m_data->metaInfo;
}

/*!
  \brief Creates an instance of the qml type in the given qml context.

  \throws InvalidArgumentException when the context argument is a null pointer
  \throws InvalidMetaInfoException if the object is not valid
  */
QObject *NodeMetaInfo::createInstance(QmlContext *parentContext) const
{
    if (!parentContext) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Context cannot be null");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    QObject *object = 0;
    if (isComponent()) {
        // qml component
        // TODO: This is maybe expensive ...
        QmlComponent component(parentContext->engine(), QUrl::fromLocalFile(m_data->qmlFile));
        object = component.create(parentContext);
    } else {
        // primitive
        object = QmlMetaType::qmlType(typeName().toAscii(), 4, 6)->create();
        if (object && parentContext)
            QmlEngine::setContextForObject(object, new QmlContext(parentContext, object));
    }
    return object;
}

/*!
  \brief Returns all (direct and indirect) ancestor types.

  \throws InvalidMetaInfoException if the object is not valid
  */
QList<NodeMetaInfo> NodeMetaInfo::superClasses() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    return m_data->metaInfo.superClasses(*this);
}

/*!
  \brief Returns direct ancestor types.

  \throws InvalidMetaInfoException if the object is not valid
  */
QList<NodeMetaInfo> NodeMetaInfo::directSuperClasses() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    return m_data->metaInfo.directSuperClasses(*this);
}

/*!
  \brief Returns meta information for all properties, including properties inherited from base types.

  Returns a Hash with the name of the property as key and property meta information as value. Node
  In case there are multiple properties with the same name in the hierarchy the property defined
  in the more concrete subclass is chosen.

  \throws InvalidMetaInfoException if the object is not valid
  */
QHash<QString,PropertyMetaInfo> NodeMetaInfo::properties(bool resolveDotSyntax ) const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    QHash<QString,PropertyMetaInfo> propertiesInfo;
    propertiesInfo = m_data->propertyMetaInfoHash;
    foreach (const NodeMetaInfo &nodeInfo, directSuperClasses()) {
        QHash<QString,PropertyMetaInfo> superClassProperties = nodeInfo.properties();
        QHashIterator<QString,PropertyMetaInfo> iter(superClassProperties);
        while (iter.hasNext()) {
            iter.next();
            if (!propertiesInfo.contains(iter.key()))
                propertiesInfo.insert(iter.key(), iter.value());
        }
    }
    if (resolveDotSyntax) {
        QHashIterator<QString,PropertyMetaInfo> iter(dotProperties());
        while (iter.hasNext()) {
            iter.next();
            if (!propertiesInfo.contains(iter.key()))
                propertiesInfo.insert(iter.key(), iter.value());
        }
    }
    return propertiesInfo;
}

/*!
  \brief Returns meta information for all dot properties, including properties inherited from base types.

  */
QHash<QString,PropertyMetaInfo> NodeMetaInfo::dotProperties() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    QHash<QString,PropertyMetaInfo> propertiesInfo;

    foreach (const QString &propertyName, properties().keys()) {
        if (property(propertyName).hasDotSubProperties()) {
                QString propertyType = property(propertyName).type();
                if (propertyType.right(1) == "*")
                    propertyType = propertyType.left(propertyType.size() - 1).trimmed();
                NodeMetaInfo nodeInfo(m_data->metaInfo.nodeMetaInfo(propertyType, majorVersion(), minorVersion()));
                if (nodeInfo.isValid()) {
                    QHashIterator<QString,PropertyMetaInfo> iter(nodeInfo.properties());
                    while (iter.hasNext()) {
                        iter.next();
                        if (!propertiesInfo.contains(iter.key()) && iter.key() != "objectName")
                            propertiesInfo.insert(propertyName + "." + iter.key(), iter.value());
                    }
            }
        }
    }
    return propertiesInfo;
}

/*!
  \brief Returns meta information for a property. An invalid PropertyMetaInfo object if the given property name is unknown.

  \throws InvalidMetaInfoException if the object is not valid
  */
PropertyMetaInfo NodeMetaInfo::property(const QString &propertyName, bool resolveDotSyntax) const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    if (resolveDotSyntax && propertyName.contains('.')) {
        const QStringList nameParts = propertyName.split('.');
        NodeMetaInfo nodeInfo = *this;
        const int partCount = nameParts.size();
        for (int i = 0; i < partCount; ++i) {
            const QString namePart(nameParts.at(i));
            const PropertyMetaInfo propInfo = nodeInfo.property(namePart, false);

            if (!propInfo.isValid())
                break;

            if (i + 1 == partCount)
                return propInfo;

            QString propertyType = propInfo.type();
            if (propertyType.right(1) == "*")
                propertyType = propertyType.left(propertyType.size() - 1).trimmed();
            nodeInfo = m_data->metaInfo.nodeMetaInfo(propertyType, majorVersion(), minorVersion());
            if (!nodeInfo.isValid()) {
                qDebug() << "no type info available for" << propertyType;
                break;
            }
        }

        return PropertyMetaInfo();
    } else {
        PropertyMetaInfo propertyMetaInfo;

        if (hasLocalProperty(propertyName)) {
            propertyMetaInfo = m_data->propertyMetaInfoHash.value(propertyName, PropertyMetaInfo());
        } else {
            foreach (const NodeMetaInfo &superTypeMetaInfo, directSuperClasses()) {
                Q_ASSERT(superTypeMetaInfo.isValid());
                propertyMetaInfo = superTypeMetaInfo.property(propertyName);
                if (propertyMetaInfo.isValid())
                    break;
            }
        }

        return propertyMetaInfo;
    }
}

/*!
  \brief Returns whether the type has a (not inherited) property.

  \throws InvalidMetaInfoException if the object is not valid
  */
bool NodeMetaInfo::hasLocalProperty(const QString &propertyName, bool resolveDotSyntax) const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    if (resolveDotSyntax && propertyName.contains('.')) {
        const QStringList nameParts = propertyName.split('.');
        NodeMetaInfo nodeInfo = *this;
        const int partCount = nameParts.size();
        for (int i = 0; i < partCount; ++i) {
            QString namePart(nameParts.at(i));
            const PropertyMetaInfo propInfo = nodeInfo.property(namePart, false);

            if (!propInfo.isValid())
                break;

            if (i + 1 == partCount)
                return true;

            QString propertyType = propInfo.type();
            if (propertyType.right(1) == "*")
                propertyType = propertyType.left(propertyType.size() - 1).trimmed();
            nodeInfo = m_data->metaInfo.nodeMetaInfo(propertyType, majorVersion(), minorVersion());
            if (!nodeInfo.isValid()) {
                qDebug() << "no type info available for" << propertyType;
                break;
            }
        }

        return false;
    } else {
        return m_data->propertyMetaInfoHash.contains(propertyName);
    }
}

/*!
  \brief Returns whether the type has a (inherited or not inherited) property.

  \throws InvalidMetaInfoException if the object is not valid
  */
bool NodeMetaInfo::hasProperty(const QString &propertyName, bool resolveDotSyntax) const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    if (hasLocalProperty(propertyName, resolveDotSyntax))
        return true;

    foreach (const NodeMetaInfo &nodeMetaInfo, directSuperClasses()) {
        if (nodeMetaInfo.hasProperty(propertyName, resolveDotSyntax))
            return true;
    }

    return false;
}

void NodeMetaInfo::addProperty(const PropertyMetaInfo &property)
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    m_data->propertyMetaInfoHash.insert(property.name(), property);
}

/*!
  \brief Returns the name of the qml type.

  This is not necessarily the class name: E.g. the class defining "Item" is QmlGraphicsItem.

  \throws InvalidMetaInfoException if the object is not valid
  */
QString NodeMetaInfo::typeName() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    return m_data->typeName;
}

/*!
  \brief Returns the name of the major number of the qml type.

  \throws InvalidMetaInfoException if the object is not valid
*/
int NodeMetaInfo::majorVersion() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    return 4;
}


/*!
  \brief Returns the name of the minor number of the qml type to which the type is used.

  \throws InvalidMetaInfoException if the object is not valid
*/
int NodeMetaInfo::minorVersion() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    return m_data->minorVersion;
}

bool NodeMetaInfo::hasDefaultProperty() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    return m_data->defaultProperty.isNull();
}

QString NodeMetaInfo::defaultProperty() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    return m_data->defaultProperty;
}

void NodeMetaInfo::setDefaultProperty(const QString &defaultProperty)
{
     if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    m_data->defaultProperty = defaultProperty;
}

void NodeMetaInfo::setMajorVersion(int version)
{
    m_data->majorVersion = version;
}

void NodeMetaInfo::setMinorVersion(int version)
{
     m_data->minorVersion = version;
}

void NodeMetaInfo::setInvalid()
{
    if (!isValid())
        return;

    m_data = 0;
}

void NodeMetaInfo::setTypeName(const QString &typeName)
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    m_data->typeName = typeName;
}

uint qHash(const NodeMetaInfo &nodeMetaInfo)
{
    if (!nodeMetaInfo.isValid())
        return 0;
    return qHash(nodeMetaInfo.m_data->typeName);
}

bool operator==(const NodeMetaInfo &firstNodeInfo,
                const NodeMetaInfo &secondNodeInfo)
{
    if (!firstNodeInfo.isValid() || !secondNodeInfo.isValid())
        return false;
    return firstNodeInfo.m_data->typeName == secondNodeInfo.m_data->typeName;
}

/*!
  \brief Returns whether objects of these type can have children.

  \throws InvalidMetaInfoException if the object is not valid
  */
bool NodeMetaInfo::isContainer() const
{
    // TODO KAI: Is this too generic?
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    return m_data->isContainer;
}

bool NodeMetaInfo::isVisibleToItemLibrary() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    return m_data->isVisibleToItemLibrary;
}

void NodeMetaInfo::setIsContainer(bool isContainer)
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    m_data->isContainer = isContainer;
}

void NodeMetaInfo::setIsVisibleToItemLibrary(bool isVisibleToItemLibrary)
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    m_data->isVisibleToItemLibrary = isVisibleToItemLibrary;
}

QIcon NodeMetaInfo::icon() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    return m_data->icon;
}

QString NodeMetaInfo::category() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    return m_data->category;
}

void NodeMetaInfo::setIcon(const QIcon &icon)
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    m_data->icon = icon;
}

void NodeMetaInfo::setCategory(const QString &category)
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    m_data->category = category;
}

/*!
  \brief Returns whether the type inherits from "QWidget".

  \throws InvalidMetaInfoException if the object is not valid
  */
bool NodeMetaInfo::isWidget() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    return m_data->metaInfo.isSubclassOf(m_data->typeName, "Qt/QWidget");
}

/*!
  \brief Returns whether the type inherits from "QGraphicsWidget".

  \throws InvalidMetaInfoException if the object is not valid
  */
bool NodeMetaInfo::isGraphicsWidget() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    return m_data->metaInfo.isSubclassOf(m_data->typeName, "Qt/QGraphicsWidget");
}

/*!
  \brief Returns whether the type inherits from "QGraphicsObject".

  \throws InvalidMetaInfoException if the object is not valid
  */
bool NodeMetaInfo::isGraphicsObject() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    return m_data->metaInfo.isSubclassOf(m_data->typeName, "QGraphicsObject");
}

/*!
  \brief Returns whether the type inherits from "Item/QmlGraphicsItem".

  \throws InvalidMetaInfoException if the object is not valid
  */
bool NodeMetaInfo::isQmlGraphicsItem() const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }

    if (m_data->isFXItem == Internal::NodeMetaInfoData::Unknown) {
        m_data->isFXItem = m_data->metaInfo.isSubclassOf(m_data->typeName, "Qt/Item") ? Internal::NodeMetaInfoData::Yes : Internal::NodeMetaInfoData::No;
    }

    return m_data->isFXItem == Internal::NodeMetaInfoData::Yes;
}

bool NodeMetaInfo::isComponent() const
{
    return !m_data->qmlFile.isEmpty();
}

/*!
  \brief Returns whether the type inherits from a type.

  \throws InvalidMetaInfoException if the object is not valid
  */
bool NodeMetaInfo::isSubclassOf(const QString &type, int /*majorVersion*/, int /*minorVersion*/) const
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    return m_data->metaInfo.isSubclassOf(m_data->typeName, type);
}

void NodeMetaInfo::setQmlFile(const QString &filePath)
{
    if (!isValid()) {
        Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
        throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
    }
    m_data->qmlFile = filePath;
}

} // namespace Qml