本文整理汇总了C++中QSGNode::removeChildNode方法的典型用法代码示例。如果您正苦于以下问题:C++ QSGNode::removeChildNode方法的具体用法?C++ QSGNode::removeChildNode怎么用?C++ QSGNode::removeChildNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSGNode
的用法示例。
在下文中一共展示了QSGNode::removeChildNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updatePaintNode
QSGNode* BrowserUtils::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* updatePaintNodeData)
{
Q_UNUSED(updatePaintNodeData);
if (!(m_webview && (flags() & QQuickItem::ItemHasContents))) {
return oldNode;
}
setFlag(QQuickItem::ItemHasContents, false);
#if 0
QQuickWebPage* page = m_webview->page();
qreal xmin = qMin(page->width(), m_webview->width());
qreal ymin = qMin(m_webview->height(), page->height());
#else
// Here the screenshot of the page might be too large if the page is tiny
qreal xmin = m_webview->width();
qreal ymin = m_webview->height();
#endif
ymin = qMin(static_cast<int>(ymin), m_imageSize.height());
xmin = qMin(static_cast<int>(xmin), m_imageSize.width());
QSize size(xmin, ymin);
QSGNode* node = QQuickItemPrivate::get(m_webview)->itemNode();
QSGNode* parent = node->QSGNode::parent();
QSGNode* previousSibling = node->previousSibling();
if (parent) {
parent->removeChildNode(node);
}
QSGRootNode root;
root.appendChildNode(node);
QSGRenderer* renderer;
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
renderer = QQuickItemPrivate::get(this)->sceneGraphContext()->createRenderer();
#else
renderer = QQuickItemPrivate::get(this)->sceneGraphRenderContext()->createRenderer();
#endif
renderer->setRootNode(static_cast<QSGRootNode*>(&root));
QOpenGLFramebufferObject fbo(size);
renderer->setDeviceRect(size);
renderer->setViewportRect(size);
renderer->setProjectionMatrixToRect(QRectF(QPointF(), size));
renderer->setClearColor(Qt::transparent);
renderer->renderScene(BindableFbo(&fbo));
fbo.release();
QImage image = fbo.toImage().scaled(m_imageSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QFileInfo imageInfo(m_outFile);
QDir imageDir(imageInfo.path());
if (!imageDir.exists()) {
imageDir.mkpath(".");
}
bool saved = image.save(m_outFile);
root.removeChildNode(node);
renderer->setRootNode(0);
delete renderer;
if (parent) {
if (previousSibling) {
parent->insertChildNodeAfter(node, previousSibling);
} else {
parent->prependChildNode(node);
}
}
Q_EMIT webViewSaved(saved, m_outFile);
return oldNode;
}
示例2: grab
//.........这里部分代码省略.........
updateBindOptions(true);
m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo);
} else {
delete m_fbo;
delete m_secondaryFbo;
m_fbo = new QOpenGLFramebufferObject(m_size, format);
m_secondaryFbo = 0;
funcs->glBindTexture(GL_TEXTURE_2D, m_fbo->texture());
updateBindOptions(true);
m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_fbo);
}
}
}
if (m_recursive && !m_secondaryFbo) {
// m_fbo already created, m_recursive was just set.
Q_ASSERT(m_fbo);
Q_ASSERT(!m_multisampling);
m_secondaryFbo = new QOpenGLFramebufferObject(m_size, m_fbo->format());
funcs->glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture());
updateBindOptions(true);
}
// Render texture.
root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip and opacity update.
m_renderer->nodeChanged(root, QSGNode::DirtyForceUpdate); // Force render list update.
#ifdef QSG_DEBUG_FBO_OVERLAY
if (qmlFboOverlay()) {
if (!m_debugOverlay)
m_debugOverlay = new QSGSimpleRectNode();
m_debugOverlay->setRect(QRectF(0, 0, m_size.width(), m_size.height()));
m_debugOverlay->setColor(QColor(0xff, 0x00, 0x80, 0x40));
root->appendChildNode(m_debugOverlay);
}
#endif
m_dirtyTexture = false;
m_renderer->setDeviceRect(m_size);
m_renderer->setViewportRect(m_size);
QRectF mirrored(m_mirrorHorizontal ? m_rect.right() : m_rect.left(),
m_mirrorVertical ? m_rect.bottom() : m_rect.top(),
m_mirrorHorizontal ? -m_rect.width() : m_rect.width(),
m_mirrorVertical ? -m_rect.height() : m_rect.height());
m_renderer->setProjectionMatrixToRect(mirrored);
m_renderer->setClearColor(Qt::transparent);
if (m_multisampling) {
m_renderer->renderScene(BindableFbo(m_secondaryFbo, m_depthStencilBuffer.data()));
if (deleteFboLater) {
delete m_fbo;
QOpenGLFramebufferObjectFormat format;
format.setInternalTextureFormat(m_format);
format.setAttachment(QOpenGLFramebufferObject::NoAttachment);
format.setMipmap(m_mipmap);
format.setSamples(0);
m_fbo = new QOpenGLFramebufferObject(m_size, format);
funcs->glBindTexture(GL_TEXTURE_2D, m_fbo->texture());
updateBindOptions(true);
}
QRect r(QPoint(), m_size);
QOpenGLFramebufferObject::blitFramebuffer(m_fbo, r, m_secondaryFbo, r);
} else {
if (m_recursive) {
m_renderer->renderScene(BindableFbo(m_secondaryFbo, m_depthStencilBuffer.data()));
if (deleteFboLater) {
delete m_fbo;
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
format.setInternalTextureFormat(m_format);
format.setMipmap(m_mipmap);
m_fbo = new QOpenGLFramebufferObject(m_size, format);
funcs->glBindTexture(GL_TEXTURE_2D, m_fbo->texture());
updateBindOptions(true);
}
qSwap(m_fbo, m_secondaryFbo);
} else {
m_renderer->renderScene(BindableFbo(m_fbo, m_depthStencilBuffer.data()));
}
}
if (m_mipmap) {
funcs->glBindTexture(GL_TEXTURE_2D, textureId());
funcs->glGenerateMipmap(GL_TEXTURE_2D);
}
root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip, opacity and render list update.
#ifdef QSG_DEBUG_FBO_OVERLAY
if (qmlFboOverlay())
root->removeChildNode(m_debugOverlay);
#endif
if (m_recursive)
markDirtyTexture(); // Continuously update if 'live' and 'recursive'.
}
示例3: updatePaintNode
QSGNode* NodeConnectionLines::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*) {
if (!m_nodeObject) return nullptr;
const QVector<QPointer<NodeBase>>& connectedNodes = m_nodeObject->getConnectedNodes();
int connectionCount = connectedNodes.size();
// -------------------- Prepare QSG Nodes:
QSGNode* parentNode = oldNode;
if (!oldNode) {
parentNode = new QSGNode();
} else {
// update color in case it changed:
// FIXME: is there a more efficient way to do this?
for (int i=0; i<parentNode->childCount(); ++i) {
QSGGeometryNode* childNode = static_cast<QSGGeometryNode*>(parentNode->childAtIndex(i));
if (!childNode) continue;
QSGFlatColorMaterial* material = static_cast<QSGFlatColorMaterial*>(childNode->material());
if (!material) continue;
material->setColor(m_color);
}
}
// adapt child count:
int childCount = parentNode->childCount();
if (childCount < connectionCount) {
for (int i=0; i<(connectionCount - childCount); ++i) {
QSGGeometryNode* node = new QSGGeometryNode;
QSGGeometry* geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 3);
geometry->setDrawingMode(GL_TRIANGLE_STRIP);
node->setGeometry(geometry);
node->setFlag(QSGNode::OwnsGeometry);
QSGFlatColorMaterial* material = new QSGFlatColorMaterial;
material->setColor(m_color);
node->setMaterial(material);
node->setFlag(QSGNode::OwnsMaterial);
parentNode->appendChildNode(node);
}
} else if (childCount > connectionCount) {
for (int i=0; i<(childCount - connectionCount); ++i) {
parentNode->removeChildNode(parentNode->childAtIndex(0));
}
}
Q_ASSERT(parentNode->childCount() == connectionCount);
// calculate common start point:
const QPointF p0(width(), height() / 2);
double widthOffset = m_lineWidth / 2;
//const QPointF posInScene = mapToScene(QPointF(0, 0));
for (int i=0; i<connectionCount; ++i) {
NodeBase* otherNode = connectedNodes[i];
if (!otherNode) continue;
QQuickItem* otherGuiItem = otherNode->getGuiItem();
if (!otherGuiItem) continue;
const QPointF p3 = mapFromItem(otherGuiItem, QPointF(-otherGuiItem->width() / 2, otherGuiItem->height() / 2));
int handleLength = std::max(50, std::min(int(p3.x() - p0.x()), 80));
const QPointF p1(p0.x() + handleLength, p0.y());
const QPointF p2(p3.x() - handleLength, p3.y());
// calculate reasonable segment count:
int segmentCount = qMax(16.0, qMin(qAbs(p3.y() - p0.y()) / 25, 50.0));
int verticesCount = segmentCount * 2;
QSGGeometryNode* qsgNode = static_cast<QSGGeometryNode*>(parentNode->childAtIndex(i));
if (!qsgNode) continue;
QSGGeometry* geometry = qsgNode->geometry();
if (!geometry) continue;
geometry->allocate(verticesCount);
QSGGeometry::Point2D* vertices = geometry->vertexDataAsPoint2D();
// triangulate cubic bezier curve:
for (int i = 0; i < segmentCount; ++i) {
// t is the position on the line:
const qreal t = i / qreal(segmentCount - 1);
// pos is the point on the curve at "t":
const QPointF pos = calculateBezierPoint(t, p0, p1, p2, p3);
// normal is the normal vector at that point
const QPointF normal = normalFromTangent(calculateBezierTangent(t, p0, p1, p2, p3));
// first is a point offsetted in the normal direction by lineWidth / 2 from pos
const QPointF first = pos - normal * widthOffset;
// ssecond is a point offsetted in the negative normal direction by lineWidth / 2 from pos
const QPointF second = pos + normal * widthOffset;
// add first and second as vertices to this geometry:
vertices[i*2].set(first.x(), first.y());
vertices[i*2+1].set(second.x(), second.y());
}
// tell Scene Graph that this items needs to be drawn:
qsgNode->markDirty(QSGNode::DirtyGeometry);
}
return parentNode;
}