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
|
/*
bindingnode.cpp
This file is part of GammaRay, the Qt application inspection and manipulation tool.
SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Anton Kreuzkamp <anton.kreuzkamp@kdab.com>
SPDX-License-Identifier: GPL-2.0-or-later
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
// Own
#include "bindingnode.h"
#include <core/util.h>
// Qt
#include <QDebug>
#include <QFile>
#include <QMetaProperty>
using namespace GammaRay;
BindingNode::BindingNode(QObject *obj, int propIndex, BindingNode *parent)
: m_parent(parent)
, m_object(obj)
, m_propertyIndex(propIndex)
{
Q_ASSERT(obj);
m_canonicalName = m_object->metaObject() ? m_object->metaObject()->property(m_propertyIndex).name() : QStringLiteral(":(");
refreshValue();
checkForLoops();
}
bool BindingNode::operator==(const BindingNode &other) const
{
return m_object == other.m_object && m_propertyIndex == other.m_propertyIndex;
}
void BindingNode::checkForLoops()
{
BindingNode *ancestor = m_parent;
while (ancestor) {
if (ancestor->m_object == m_object
&& ancestor->m_propertyIndex == m_propertyIndex) {
m_foundBindingLoop = true;
return;
}
ancestor = ancestor->m_parent;
}
m_foundBindingLoop = false;
}
QMetaProperty BindingNode::property() const
{
return m_object->metaObject()->property(m_propertyIndex);
}
QVariant BindingNode::cachedValue() const
{
return m_value;
}
QVariant BindingNode::readValue() const
{
return m_object->metaObject()->property(m_propertyIndex).read(m_object);
}
void BindingNode::refreshValue()
{
m_value = m_object->metaObject()->property(m_propertyIndex).read(m_object);
}
void BindingNode::setParent(BindingNode *newParent)
{
m_parent = newParent;
checkForLoops();
}
GammaRay::BindingNode *GammaRay::BindingNode::parent() const
{
return m_parent;
}
QObject *GammaRay::BindingNode::object() const
{
return m_object;
}
int GammaRay::BindingNode::propertyIndex() const
{
return m_propertyIndex;
}
const QString &GammaRay::BindingNode::canonicalName() const
{
return m_canonicalName;
}
bool GammaRay::BindingNode::hasFoundBindingLoop() const
{
return m_foundBindingLoop;
}
bool GammaRay::BindingNode::isPartOfBindingLoop() const
{
if (m_foundBindingLoop) {
return true;
}
for (const auto &dependency : m_dependencies) {
if (dependency->isPartOfBindingLoop()) {
return true;
}
}
return false;
}
GammaRay::SourceLocation GammaRay::BindingNode::sourceLocation() const
{
return m_sourceLocation;
}
std::vector<std::unique_ptr<BindingNode>> &GammaRay::BindingNode::dependencies()
{
return m_dependencies;
}
const std::vector<std::unique_ptr<BindingNode>> &GammaRay::BindingNode::dependencies() const
{
return m_dependencies;
}
void BindingNode::setCanonicalName(const QString &name)
{
m_canonicalName = name;
}
void BindingNode::setSourceLocation(const SourceLocation &location)
{
m_sourceLocation = location;
}
uint BindingNode::depth() const
{
uint depth = 0;
if (m_foundBindingLoop) {
return std::numeric_limits<uint>::max(); // to be considered as infinity.
}
for (const auto &dependency : m_dependencies) {
uint depDepth = dependency->depth();
if (depDepth == std::numeric_limits<uint>::max()) {
depth = depDepth;
break;
} else if (depDepth + 1 > depth) {
depth = depDepth + 1;
}
}
return depth;
}
|