1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-19 04:52:12 +01:00

LP-29 fix OSGGroup update logic

This commit is contained in:
Philippe Renon 2016-03-29 09:15:59 +02:00
parent 567b7f1040
commit 7c0e92fb1b
3 changed files with 40 additions and 22 deletions

View File

@ -70,6 +70,7 @@ public:
void setDirty(int mask)
{
// qDebug() << "DirtySupport::setDirty" << mask;
if (!dirtyFlags) {
osg::Node *node = self->hookNode();
if (node) {
@ -97,7 +98,9 @@ public:
void update()
{
// qDebug() << "DirtySupport::update";
if (dirtyFlags) {
// qDebug() << "DirtySupport::update - updating...";
self->update();
}
clearDirty();

View File

@ -56,7 +56,7 @@ public:
void appendChild(OSGNode *childNode)
{
cache[childNode] = childNode->node();
// qDebug() << "OSGGroup::appendChild" << childNode;
children.append(childNode);
connect(childNode, SIGNAL(nodeChanged(osg::Node *)), this, SLOT(onChildNodeChanged(osg::Node *)), Qt::UniqueConnection);
self->setDirty(Children);
@ -102,19 +102,23 @@ public:
QListIterator<OSGNode *> i(children);
while (i.hasNext()) {
OSGNode *childNode = i.next();
if (index < group->getNumChildren()) {
updated |= group->replaceChild(group->getChild(index), childNode->node());
} else {
updated |= group->addChild(childNode->node());
// qDebug() << "OSGGroup::updateChildren - child" << childNode;
if (childNode->node()) {
if (index < group->getNumChildren()) {
updated |= group->replaceChild(group->getChild(index), childNode->node());
} else {
updated |= group->addChild(childNode->node());
}
cache.insert(childNode, childNode->node());
index++;
}
index++;
}
// removing eventual left overs
if (index < group->getNumChildren()) {
updated |= group->removeChild(index, group->getNumChildren() - index);
}
// if (updated) {
self->emitNodeChanged();
// self->emitNodeChanged();
// }
}
@ -149,27 +153,39 @@ public:
}
private slots:
void onChildNodeChanged(osg::Node *node)
void onChildNodeChanged(osg::Node *child)
{
qDebug() << "OSGGroup::onChildNodeChanged" << node;
// qDebug() << "OSGGroup::onChildNodeChanged" << node;
osg::Group *group = static_cast<osg::Group *>(self->node());
if (!group) {
qWarning() << "OSGGroup::onChildNodeChanged - null group";
return;
}
OSGNode *obj = qobject_cast<OSGNode *>(sender());
if (obj) {
osg::Node *cacheNode = cache.value(obj, NULL);
if (cacheNode) {
group->replaceChild(cacheNode, node);
} else {
// should not happen...
}
cache[obj] = node;
// emit self->nodeChanged(group.get());
OSGNode *childNode = qobject_cast<OSGNode *>(sender());
// qDebug() << "OSGGroup::onChildNodeChanged - child node" << obj;
if (!childNode) {
qWarning() << "OSGGroup::onChildNodeChanged - sender is not an OSGNode" << sender();
return;
}
if (childNode->node() != child) {
qWarning() << "OSGGroup::onChildNodeChanged - child node is not valid" << childNode;
return;
}
bool updated = false;
osg::Node *current = cache.value(childNode, NULL);
if (current) {
updated |= group->replaceChild(current, child);
} else {
// should not happen...
qWarning() << "OSGGroup::onChildNodeChanged - child node is not a child" << childNode;
}
cache[childNode] = childNode->node();
// if (updated) {
// emit self->nodeChanged(group.get());
// }
}
};

View File

@ -136,14 +136,14 @@ void OSGNode::emitNodeChanged()
void OSGNode::classBegin()
{
qDebug() << "OSGNode::classBegin" << this;
// qDebug() << "OSGNode::classBegin" << this;
setNode(createNode());
}
void OSGNode::componentComplete()
{
qDebug() << "OSGNode::componentComplete" << this;
// qDebug() << "OSGNode::componentComplete" << this;
updateNode();
clearDirty();
@ -151,7 +151,6 @@ void OSGNode::componentComplete()
if (!h->node.valid()) {
qWarning() << "OSGNode::componentComplete - node is not valid!" << this;
}
qDebug() << "OSGNode::componentComplete DONE" << this;
}
} // namespace osgQtQuick