#include "CNode.h" CNode::CNode(QObject *parent) : QObject(parent) { } const CNode *CNode::pNode() const { return dynamic_cast(QObject::parent()); } const CNode *CNode::rNode() const { if (pNode() == nullptr) { return this; } return pNode()->rNode(); } QList CNode::cNodes() const { QList l; for (QObject *o : children()) { CNode *n = dynamic_cast(o); if (n != nullptr) { l.append(n); } } return l; } int CNode::height() const { int h = 1; for (CNode *n : cNodes()) { h = std::max(h, n->height() + 1); } return h; } int CNode::depth() const { int d = 1; const CNode *n = this; while (n->pNode() != nullptr) { d++; n = n->pNode(); } return d; } int CNode::leaves() const { int d = 1; if (cNodes().count() > 0) { d = 0; for (CNode *n : cNodes()) { d += n->leaves(); } } return d; } int CNode::sizeOfLevel(int lev) const { if (lev < 1) { return 0; } if (lev == 1) { return 1; } int size = 0; for (CNode *n : cNodes()) { size += n->sizeOfLevel(lev - 1); } return size; }