本文整理汇总了C++中QmlItemNode::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ QmlItemNode::isValid方法的具体用法?C++ QmlItemNode::isValid怎么用?C++ QmlItemNode::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QmlItemNode
的用法示例。
在下文中一共展示了QmlItemNode::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createQmlItemNode
QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentQmlItemNode)
{
if (!parentQmlItemNode.isValid())
parentQmlItemNode = QmlItemNode(view->rootModelNode());
Q_ASSERT(parentQmlItemNode.isValid());
NodeAbstractProperty parentProperty = parentQmlItemNode.defaultNodeAbstractProperty();
return QmlItemNode::createQmlItemNode(view, itemLibraryEntry, position, parentProperty);
}
示例2: createQmlItemNode
QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentNode)
{
if (!parentNode.isValid())
parentNode = rootQmlItemNode();
Q_ASSERT(parentNode.isValid());
QmlItemNode newNode;
RewriterTransaction transaction = beginRewriterTransaction();
{
QList<QPair<QString, QVariant> > propertyPairList;
propertyPairList.append(qMakePair(QString("x"), QVariant(round(position.x(), 4))));
propertyPairList.append(qMakePair(QString("y"), QVariant(round(position.y(), 4))));
foreach (const PropertyContainer &property, itemLibraryEntry.properties())
propertyPairList.append(qMakePair(property.name(), property.value()));
newNode = createQmlItemNode(itemLibraryEntry.typeName(), itemLibraryEntry.majorVersion(), itemLibraryEntry.minorVersion(), propertyPairList);
parentNode.nodeAbstractProperty("data").reparentHere(newNode);
Q_ASSERT(newNode.isValid());
QString id;
int i = 1;
QString name(itemLibraryEntry.name().toLower());
//remove forbidden characters
name.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_"));
do {
id = name + QString::number(i);
i++;
} while (hasId(id)); //If the name already exists count upwards
try {
newNode.setId(id);
} catch (InvalidIdException &e) {
// should never happen
QMessageBox::warning(0, tr("Invalid Id"), e.description());
}
if (!currentState().isBaseState()) {
newNode.modelNode().variantProperty("opacity") = 0;
newNode.setVariantProperty("opacity", 1);
}
Q_ASSERT(newNode.isValid());
}
Q_ASSERT(newNode.isValid());
return newNode;
}
示例3: createQmlItemNodeFromImage
QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, const QPointF &position, QmlItemNode parentNode)
{
if (!parentNode.isValid())
parentNode = rootQmlItemNode();
if (!parentNode.isValid())
return QmlItemNode();
QmlItemNode newNode;
RewriterTransaction transaction = beginRewriterTransaction();
{
QList<QPair<QString, QVariant> > propertyPairList;
propertyPairList.append(qMakePair(QString("x"), QVariant( round(position.x(), 4))));
propertyPairList.append(qMakePair(QString("y"), QVariant( round(position.y(), 4))));
QString relativeImageName = imageName;
//use relative path
if (QFileInfo(model()->fileUrl().toLocalFile()).exists()) {
QDir fileDir(QFileInfo(model()->fileUrl().toLocalFile()).absolutePath());
relativeImageName = fileDir.relativeFilePath(imageName);
}
propertyPairList.append(qMakePair(QString("source"), QVariant(relativeImageName)));
newNode = createQmlItemNode("Qt/Image",4, 7, propertyPairList);
parentNode.nodeAbstractProperty("data").reparentHere(newNode);
Q_ASSERT(newNode.isValid());
QString id;
int i = 1;
QString name("image");
name.remove(QLatin1Char(' '));
do {
id = name + QString::number(i);
i++;
} while (hasId(id)); //If the name already exists count upwards
newNode.setId(id);
if (!currentState().isBaseState()) {
newNode.modelNode().variantProperty("opacity") = 0;
newNode.setVariantProperty("opacity", 1);
}
Q_ASSERT(newNode.isValid());
}
Q_ASSERT(newNode.isValid());
return newNode;
}
示例4: boundingBox
QRectF QmlAnchorBindingProxy::boundingBox(const QmlItemNode &node)
{
if (node.isValid())
return node.instanceTransformWithContentTransform().mapRect(node.instanceBoundingRect());
return QRect();
}
示例5: itemIsResizable
bool itemIsResizable(const QmlItemNode &qmlItemNode)
{
return qmlItemNode.isValid()
&& qmlItemNode.instanceIsResizable()
&& qmlItemNode.modelIsMovable()
&& qmlItemNode.modelIsResizable()
&& !qmlItemNode.instanceHasRotationTransform()
&& !qmlItemNode.instanceIsInLayoutable();
}
示例6: allQmlItemsRecursive
static QList<QmlItemNode> allQmlItemsRecursive(const QmlItemNode &qmlItemNode)
{
QList<QmlItemNode> qmlItemNodeList;
if (qmlItemNode.isValid()) {
qmlItemNodeList.append(qmlItemNode);
foreach (const ModelNode &modelNode, qmlItemNode.modelNode().directSubModelNodes()) {
if (QmlItemNode::isValidQmlItemNode(modelNode))
qmlItemNodeList.append(allQmlItemsRecursive(modelNode));
}
}
示例7: removeNodeFromScene
void FormEditorView::removeNodeFromScene(const QmlItemNode &qmlItemNode)
{
if (qmlItemNode.isValid()) {
QList<QmlItemNode> nodeList;
nodeList.append(qmlItemNode.allSubModelNodes());
nodeList.append(qmlItemNode);
QList<FormEditorItem*> removedItemList;
removedItemList.append(scene()->itemsForQmlItemNodes(nodeList));
m_currentTool->itemsAboutToRemoved(removedItemList);
qDeleteAll(removedItemList);
}
}
示例8: allFxItemsRecursive
static QList<QmlItemNode> allFxItemsRecursive(const QmlItemNode &fxNode)
{
QList<QmlItemNode> returnList;
if (fxNode.isValid()) {
returnList.append(fxNode);
QList<QmlItemNode> allChildNodes;
foreach (const ModelNode &node, fxNode.modelNode().allDirectSubModelNodes()) {
if (QmlItemNode(node).isValid())
allChildNodes.append(node);
}
foreach (const QmlItemNode &node, allChildNodes) {
returnList.append(allFxItemsRecursive(node));
}
示例9: updateContext
virtual void updateContext()
{
defaultAction()->setSelectionContext(selectionContext());
if (selectionContext().isValid()) {
defaultAction()->setEnabled(isEnabled(selectionContext()));
defaultAction()->setVisible(isVisible(selectionContext()));
defaultAction()->setCheckable(true);
QmlItemNode itemNode = QmlItemNode(selectionContext().currentSingleSelectedNode());
if (itemNode.isValid())
defaultAction()->setChecked(itemNode.instanceValue("visible").toBool());
else
defaultAction()->setEnabled(false);
}
}
示例10: hideNodeFromScene
void FormEditorView::hideNodeFromScene(const QmlItemNode &qmlItemNode)
{
if (qmlItemNode.isValid()) {
FormEditorItem *item = m_scene->itemForQmlItemNode(qmlItemNode);
QList<QmlItemNode> nodeList;
nodeList.append(qmlItemNode.allSubModelNodes());
nodeList.append(qmlItemNode);
QList<FormEditorItem*> removedItemList;
removedItemList.append(scene()->itemsForQmlItemNodes(nodeList));
m_currentTool->itemsAboutToRemoved(removedItemList);
item->setFormEditorVisible(false);
}
}
示例11: createQmlItemNodeFromImage
void DragTool::createQmlItemNodeFromImage(const QString &imageName,
const QmlItemNode &parentNode,
const QPointF &scenePosition)
{
if (parentNode.isValid()) {
MetaInfo metaInfo = MetaInfo::global();
FormEditorItem *parentItem = scene()->itemForQmlItemNode(parentNode);
QPointF positonInItemSpace = parentItem->qmlItemNode().instanceSceneContentItemTransform().inverted().map(scenePosition);
m_dragNode = QmlItemNode::createQmlItemNodeFromImage(view(), imageName, positonInItemSpace, parentNode);
QList<QmlItemNode> nodeList;
nodeList.append(m_dragNode);
m_selectionIndicator.setItems(scene()->itemsForQmlItemNodes(nodeList));
}
}
示例12: synchronizeParent
void MoveManipulator::synchronizeParent(const QList<FormEditorItem*> &itemList, const ModelNode &parentNode)
{
bool snapperUpdated = false;
foreach (FormEditorItem *item, itemList) {
if (m_itemList.contains(item)) {
QmlItemNode parentItemNode = QmlItemNode(parentNode);
if (parentItemNode.isValid()) {
if (snapperUpdated == false && m_snapper.containerFormEditorItem() != m_view->scene()->itemForQmlItemNode(parentItemNode)) {
m_snapper.setContainerFormEditorItem(m_view->scene()->itemForQmlItemNode(parentItemNode));
m_snapper.setTransformtionSpaceFormEditorItem(m_snapper.containerFormEditorItem());
m_snapper.updateSnappingLines(m_itemList);
snapperUpdated = true;
}
}
}
}
}
示例13: createQmlItemNode
QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentNode)
{
if (!parentNode.isValid())
parentNode = rootQmlItemNode();
Q_ASSERT(parentNode.isValid());
QmlItemNode newNode;
try {
RewriterTransaction transaction = beginRewriterTransaction();
if (itemLibraryEntry.typeName().contains('.')) {
const QString newImportUrl = itemLibraryEntry.requiredImport();
if (!itemLibraryEntry.requiredImport().isEmpty()) {
const QString newImportVersion = QString("%1.%2").arg(QString::number(itemLibraryEntry.majorVersion()), QString::number(itemLibraryEntry.minorVersion()));
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
foreach (const Import &import, model()->imports()) {
if (import.isLibraryImport()
&& import.url() == newImport.url()
&& import.version() == newImport.version()) {
// reuse this import
newImport = import;
break;
}
}
if (!model()->hasImport(newImport, true, true)) {
model()->changeImports(QList<Import>() << newImport, QList<Import>());
}
}
}
QList<QPair<QString, QVariant> > propertyPairList;
propertyPairList.append(qMakePair(QString("x"), QVariant(round(position.x(), 4))));
propertyPairList.append(qMakePair(QString("y"), QVariant(round(position.y(), 4))));
if (itemLibraryEntry.qml().isEmpty()) {
foreach (const PropertyContainer &property, itemLibraryEntry.properties())
propertyPairList.append(qMakePair(property.name(), property.value()));
newNode = createQmlItemNode(itemLibraryEntry.typeName(), itemLibraryEntry.majorVersion(), itemLibraryEntry.minorVersion(), propertyPairList);
} else {
QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0, model()));
inputModel->setFileUrl(model()->fileUrl());
QPlainTextEdit textEdit;
textEdit.setPlainText(Utils::FileReader::fetchQrc(itemLibraryEntry.qml()));
NotIndentingTextEditModifier modifier(&textEdit);
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
rewriterView->setCheckSemanticErrors(false);
rewriterView->setTextModifier(&modifier);
inputModel->attachView(rewriterView.data());
if (rewriterView->errors().isEmpty() && rewriterView->rootModelNode().isValid()) {
ModelNode rootModelNode = rewriterView->rootModelNode();
inputModel->detachView(rewriterView.data());
rootModelNode.variantProperty("x") = propertyPairList.first().second;
rootModelNode.variantProperty("y") = propertyPairList.at(1).second;
ModelMerger merger(this);
newNode = merger.insertModel(rootModelNode);
}
}
if (parentNode.hasDefaultProperty()) {
parentNode.nodeAbstractProperty(parentNode.defaultProperty()).reparentHere(newNode);
}
if (!newNode.isValid())
return newNode;
QString id;
int i = 1;
QString name(itemLibraryEntry.name().toLower());
//remove forbidden characters
name.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_"));
do {
id = name + QString::number(i);
i++;
} while (hasId(id)); //If the name already exists count upwards
newNode.setId(id);
if (!currentState().isBaseState()) {
newNode.modelNode().variantProperty("opacity") = 0;
newNode.setVariantProperty("opacity", 1);
}
Q_ASSERT(newNode.isValid());
}
示例14: createQmlItemNodeFromImage
QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, const QPointF &position, QmlItemNode parentNode)
{
if (!parentNode.isValid())
parentNode = rootQmlItemNode();
if (!parentNode.isValid())
return QmlItemNode();
QmlItemNode newNode;
RewriterTransaction transaction = beginRewriterTransaction();
{
const QString newImportUrl = QLatin1String("QtQuick");
const QString newImportVersion = QLatin1String("1.0");
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
foreach (const Import &import, model()->imports()) {
if (import.isLibraryImport()
&& import.url() == newImport.url()
&& import.version() == newImport.version()) {
// reuse this import
newImport = import;
break;
}
}
if (!model()->imports().contains(newImport)) {
model()->changeImports(QList<Import>() << newImport, QList<Import>());
}
QList<QPair<QString, QVariant> > propertyPairList;
propertyPairList.append(qMakePair(QString("x"), QVariant( round(position.x(), 4))));
propertyPairList.append(qMakePair(QString("y"), QVariant( round(position.y(), 4))));
QString relativeImageName = imageName;
//use relative path
if (QFileInfo(model()->fileUrl().toLocalFile()).exists()) {
QDir fileDir(QFileInfo(model()->fileUrl().toLocalFile()).absolutePath());
relativeImageName = fileDir.relativeFilePath(imageName);
}
propertyPairList.append(qMakePair(QString("source"), QVariant(relativeImageName)));
newNode = createQmlItemNode("QtQuick.Image", 1, 0, propertyPairList);
parentNode.nodeAbstractProperty("data").reparentHere(newNode);
Q_ASSERT(newNode.isValid());
QString id;
int i = 1;
QString name("image");
name.remove(QLatin1Char(' '));
do {
id = name + QString::number(i);
i++;
} while (hasId(id)); //If the name already exists count upwards
newNode.setId(id);
if (!currentState().isBaseState()) {
newNode.modelNode().variantProperty("opacity") = 0;
newNode.setVariantProperty("opacity", 1);
}
Q_ASSERT(newNode.isValid());
}
Q_ASSERT(newNode.isValid());
return newNode;
}
示例15: createQmlItemNode
QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentQmlItemNode)
{
if (!parentQmlItemNode.isValid())
parentQmlItemNode = QmlItemNode(view->rootModelNode());
Q_ASSERT(parentQmlItemNode.isValid());
QmlItemNode newQmlItemNode;
try {
RewriterTransaction transaction = view->beginRewriterTransaction();
NodeMetaInfo metaInfo = view->model()->metaInfo(itemLibraryEntry.typeName());
int minorVersion = metaInfo.minorVersion();
int majorVersion = metaInfo.majorVersion();
if (itemLibraryEntry.typeName().contains('.')) {
const QString newImportUrl = itemLibraryEntry.requiredImport();
if (!itemLibraryEntry.requiredImport().isEmpty()) {
const QString newImportVersion = QString("%1.%2").arg(QString::number(itemLibraryEntry.majorVersion()), QString::number(itemLibraryEntry.minorVersion()));
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
if (itemLibraryEntry.majorVersion() == -1 && itemLibraryEntry.minorVersion() == -1)
newImport = Import::createFileImport(newImportUrl, QString());
else
newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
foreach (const Import &import, view->model()->imports()) {
if (import.isLibraryImport()
&& import.url() == newImport.url()
&& import.version() == newImport.version()) {
// reuse this import
newImport = import;
break;
}
}
if (!view->model()->hasImport(newImport, true, true))
view->model()->changeImports(QList<Import>() << newImport, QList<Import>());
}
}
if (itemLibraryEntry.qmlSource().isEmpty()) {
QList<QPair<PropertyName, QVariant> > propertyPairList;
propertyPairList.append(qMakePair(PropertyName("x"), QVariant(qRound(position.x()))));
propertyPairList.append(qMakePair(PropertyName("y"), QVariant(qRound(position.y()))));
foreach (const PropertyContainer &property, itemLibraryEntry.properties())
propertyPairList.append(qMakePair(property.name(), property.value()));
newQmlItemNode = QmlItemNode(view->createModelNode(itemLibraryEntry.typeName(), majorVersion, minorVersion, propertyPairList));
} else {
newQmlItemNode = createQmlItemNodeFromSource(view, itemLibraryEntry.qmlSource(), position);
}
if (parentQmlItemNode.hasDefaultPropertyName())
parentQmlItemNode.nodeAbstractProperty(parentQmlItemNode.defaultPropertyName()).reparentHere(newQmlItemNode);
if (!newQmlItemNode.isValid())
return newQmlItemNode;
newQmlItemNode.setId(view->generateNewId(itemLibraryEntry.name()));
if (!view->currentState().isBaseState()) {
newQmlItemNode.modelNode().variantProperty("opacity").setValue(0);
newQmlItemNode.setVariantProperty("opacity", 1);
}
Q_ASSERT(newQmlItemNode.isValid());
}