本文整理汇总了C++中ModelNode::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ ModelNode::isValid方法的具体用法?C++ ModelNode::isValid怎么用?C++ ModelNode::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelNode
的用法示例。
在下文中一共展示了ModelNode::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createSubNode
void TestPropertyEditor::createSubNode()
{
std::auto_ptr<QWidget> widget(new QWidget());
QScopedPointer<Model> model(Model::create("import Qt 4.6\n Item {}"));
QVERIFY(model.data());
QScopedPointer<TestView> view(new TestView);
QVERIFY(view.data());
model->attachView(view.data());
setupPropertyEditor(widget.get(), model.data());
QVERIFY(view->rootModelNode().isValid());
selectThrough(view->rootModelNode());
ModelNode childNode = view->createModelNode("Qt/Rectangle", 4, 6);
view->rootModelNode().nodeListProperty("data").reparentHere(childNode);
QVERIFY(childNode.isValid());
QVERIFY(view->rootModelNode().allDirectSubModelNodes().contains(childNode));
QVERIFY(childNode.parentProperty().parentModelNode() == view->rootModelNode());
QCOMPARE(childNode.type(), QString("Qt/Rectangle"));
selectThrough(childNode);
QVERIFY(childNode.id().isEmpty());
childNode.setId("Blah");
QCOMPARE(childNode.id(), QString("Blah"));
QCOMPARE(childNode.id(), QString("Blah"));
}
示例2: searchForComponentAndAddToList
void ComponentView::searchForComponentAndAddToList(const ModelNode &node)
{
QList<ModelNode> nodeList;
nodeList.append(node);
nodeList.append(node.allSubModelNodes());
foreach (const ModelNode &node, nodeList) {
if (node.nodeSourceType() == ModelNode::ComponentSource) {
if (!node.id().isEmpty()) {
QStandardItem *item = new QStandardItem(node.id());
item->setData(QVariant::fromValue(node), ModelNodeRole);
item->setEditable(false);
removeSingleNodeFromList(node); //remove node if already present
m_standardItemModel->appendRow(item);
} else {
QString description;
ModelNode parentNode = node.parentProperty().parentModelNode();
if (parentNode.isValid())
if (!parentNode.id().isEmpty())
description = node.parentProperty().parentModelNode().id() + QLatin1Char(' ');
else
description = node.parentProperty().parentModelNode().simplifiedTypeName() + QLatin1Char(' ');
description += node.parentProperty().name();
QStandardItem *item = new QStandardItem(description);
item->setData(QVariant::fromValue(node), ModelNodeRole);
item->setEditable(false);
removeSingleNodeFromList(node); //remove node if already present
m_standardItemModel->appendRow(item);
}
}
}
}
示例3: instanceForModelNode
/*!
Returns the node instance for \a node, which must be valid.
Returns an invalid node instance if no node instance for this model node
exists.
\sa NodeInstance
*/
NodeInstance NodeInstanceView::instanceForModelNode(const ModelNode &node) const
{
Q_ASSERT(node.isValid());
Q_ASSERT(m_nodeInstanceHash.contains(node));
Q_ASSERT(m_nodeInstanceHash.value(node).modelNode() == node);
return m_nodeInstanceHash.value(node);
}
示例4: selectModelNodeUnderTextCursor
void QmlDesignerPlugin::selectModelNodeUnderTextCursor()
{
const int cursorPos = currentDesignDocument()->plainTextEdit()->textCursor().position();
ModelNode node = currentDesignDocument()->rewriterView()->nodeAtTextCursorPosition(cursorPos);
if (currentDesignDocument()->rewriterView() && node.isValid())
currentDesignDocument()->rewriterView()->setSelectedModelNodes(QList<ModelNode>() << node);
}
示例5: setupGradient
void GradientLineQmlAdaptor::setupGradient()
{
if (!active())
return;
ModelNode modelNode = m_itemNode.modelNode();
QLinearGradient newGradient;
QVector<QGradientStop> stops;
if (!modelNode.isValid())
return;
if (modelNode.hasBindingProperty(gradientName()))
return;
if (modelNode.hasProperty(gradientName())) { //gradient exists
ModelNode gradientNode = modelNode.nodeProperty(gradientName()).modelNode();
QList<ModelNode> stopList = gradientNode.nodeListProperty("stops").toModelNodeList();
foreach (const ModelNode &stopNode, stopList) {
QmlObjectNode stopObjectNode = stopNode;
if (stopObjectNode.isValid()) {
qreal position = stopObjectNode.modelValue("position").toReal();
QColor color = stopObjectNode.modelValue("color").value<QColor>();
stops.append( QPair<qreal, QColor>(position, color));
}
}
示例6: nodeSlidAround
void ModelToTextMerger::nodeSlidAround(const ModelNode &movingNode, const ModelNode &inFrontOfNode)
{
if (!inFrontOfNode.isValid() || movingNode.parentProperty() == inFrontOfNode.parentProperty())
schedule(new MoveNodeRewriteAction(movingNode, inFrontOfNode));
else
Q_ASSERT(!"Nodes do not belong to the same containing property");
}
示例7: resolveBinding
static ModelNode resolveBinding(const QString &binding, ModelNode currentNode, AbstractView* view)
{
int i = 0;
QString element = binding.split(QLatin1Char('.')).at(0);
while (!element.isEmpty())
{
if (element == "parent") {
if (currentNode.hasParentProperty())
currentNode = currentNode.parentProperty().toNodeAbstractProperty().parentModelNode();
else
return ModelNode(); //binding not valid
} else if (currentNode.hasProperty(element)) {
if (currentNode.property(element).isNodeProperty()) {
currentNode = currentNode.nodeProperty(element).modelNode();
} else {
currentNode = view->modelNodeForId(element); //id
if (!currentNode.isValid())
return ModelNode(); //binding not valid
}
} else {
currentNode = view->modelNodeForId(element); //id
}
i++;
if (i < binding.split(QLatin1Char('.')).count())
element = binding.split(QLatin1Char('.')).at(i);
else
element.clear();
}
return currentNode;
}
示例8: compareTree
// TODO: this need to e updated for states
static bool compareTree(const ModelNode &node1, const ModelNode &node2)
{
if (!node1.isValid() || !node2.isValid()) {
return false;
}
if (node1.type() != node2.type()) {
return false;
}
// Compare properties
{
const QList<AbstractProperty> propList1 = node1.properties();
const QList<AbstractProperty> propList2 = node2.properties();
QList<AbstractProperty>::const_iterator iter1 = propList1.constBegin();
QList<AbstractProperty>::const_iterator iter2 = propList2.constBegin();
for (;
iter1 != propList1.constEnd() && iter2 != propList2.constEnd();
iter1++, iter2++) {
if (!compareProperty(*iter1, *iter2))
return false;
}
if (iter1 != propList1.constEnd() || iter2 != propList2.constEnd())
return false;
}
// Compare list of children
{
const QList<ModelNode> childList1 = node1.allDirectSubModelNodes();
const QList<ModelNode> childList2 = node2.allDirectSubModelNodes();
QList<ModelNode>::const_iterator iter1;
QList<ModelNode>::const_iterator iter2;
for (iter1 = childList1.constBegin(), iter2 = childList2.constBegin();
iter1 != childList1.constEnd() && iter2 != childList2.constEnd();
iter1++, iter2++) {
if (!compareTree((*iter1), (*iter2)))
return false;
}
if (iter1 != childList1.constEnd() || iter2 != childList2.constEnd())
return false;
}
return true;
}
示例9: data
QVariant StatesEditorModel::data(const QModelIndex &index, int role) const
{
if (index.parent().isValid() || index.column() != 0 || m_statesEditorView.isNull() || !m_statesEditorView->hasModelNodeForInternalId(index.internalId()))
return QVariant();
ModelNode stateNode;
if (index.internalId() > 0)
stateNode = m_statesEditorView->modelNodeForInternalId(index.internalId());
switch (role) {
case StateNameRole: {
if (index.row() == 0) {
return QString(tr("base state", "Implicit default state"));
} else {
if (stateNode.hasVariantProperty("name"))
return stateNode.variantProperty("name").value();
else
return QVariant();
}
}
case StateImageSourceRole: {
static int randomNumber = 0;
randomNumber++;
if (index.row() == 0)
return QString("image://qmldesigner_stateseditor/baseState-%1").arg(randomNumber);
else
return QString("image://qmldesigner_stateseditor/%1-%2").arg(index.internalId()).arg(randomNumber);
}
case InternalNodeId: return index.internalId();
case HasWhenCondition: return stateNode.isValid() && stateNode.hasProperty("when");
case WhenConditionString: {
if (stateNode.isValid() && stateNode.hasBindingProperty("when"))
return stateNode.bindingProperty("when").expression();
else
return QString();
}
}
return QVariant();
}
示例10: isFileComponent
static bool isFileComponent(const ModelNode &node)
{
if (node.isValid()
&& node.metaInfo().isValid()
&& node.metaInfo().isFileComponent())
return true;
return false;
}
示例11: paint
void NameItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (option.state & QStyle::State_Selected)
drawSelectionBackground(painter, option);
QString displayString;
QPoint displayStringOffset;
painter->save();
QFontMetrics fm(option.font);
int width = 0;
if (index.data(Qt::UserRole).isValid()) {
int pixmapSide = 16;
if (m_TreeModel->isNodeInvisible( index ))
painter->setOpacity(0.5);
ModelNode node = m_TreeModel->nodeForIndex(index);
QIcon icon;
if (node.isValid()) {
// if node has no own icon, search for it in the itemlibrary
const ItemLibraryInfo *libraryInfo = node.model()->metaInfo().itemLibraryInfo();
QList <ItemLibraryEntry> infoList = libraryInfo->entriesForType(node.type(),
node.majorVersion(),
node.minorVersion());
foreach (const ItemLibraryEntry &entry, infoList) {
if (icon.isNull()) {
icon = entry.icon();
break;
}
}
}
// if the library was also empty, use the default icon
if (icon.isNull())
icon = QIcon(QLatin1String(":/ItemLibrary/images/item-default-icon.png"));
if (!node.metaInfo().isValid())
icon = QIcon(QLatin1String(":/ItemLibrary/images/item-invalid-icon.png"));
// If no icon is present, leave an empty space of 24 pixels anyway
QPixmap pixmap = icon.pixmap(pixmapSide, pixmapSide);
painter->drawPixmap(option.rect.x()+1,option.rect.y()+2,pixmap);
displayString = node.id();
if (displayString.isEmpty())
displayString = node.simplifiedTypeName();
// Check text length does not exceed available space
int extraSpace=12+pixmapSide;
displayString = fm.elidedText(displayString,Qt::ElideMiddle,option.rect.width()-extraSpace);
displayStringOffset = QPoint(5+pixmapSide,-5);
width = fm.width(displayString);
}
示例12: hasSourceWithFileComponent
static bool hasSourceWithFileComponent(const ModelNode &modelNode)
{
if (modelNode.isValid()
&& modelNode.metaInfo().isValid()
&& modelNode.metaInfo().isSubclassOf("QtQuick.Loader")
&& modelNode.hasVariantProperty("source"))
return true;
return false;
}
示例13: removeNode
void TestPropertyEditor::removeNode()
{
std::auto_ptr<QWidget> widget(new QWidget());
QScopedPointer<Model> model(Model::create("import Qt 4.6\n Item {}"));
QVERIFY(model.data());
QScopedPointer<TestView> view(new TestView);
QVERIFY(view.data());
model->attachView(view.data());
setupPropertyEditor(widget.get(), model.data());
QCOMPARE(view->rootModelNode().allDirectSubModelNodes().count(), 0);
selectThrough(view->rootModelNode());
ModelNode childNode = view->createModelNode("Qt/Rectangle", 4, 6);
view->rootModelNode().nodeListProperty("data").reparentHere(childNode);
QVERIFY(childNode.isValid());
QCOMPARE(view->rootModelNode().allDirectSubModelNodes().count(), 1);
QVERIFY(view->rootModelNode().allDirectSubModelNodes().contains(childNode));
QVERIFY(childNode.parentProperty().parentModelNode() == view->rootModelNode());
selectThrough(childNode);
ModelNode subChildNode = view->createModelNode("Qt/Rectangle", 4, 6);
childNode.nodeListProperty("data").reparentHere(subChildNode);
QVERIFY(subChildNode.isValid());
QCOMPARE(childNode.allDirectSubModelNodes().count(), 1);
QVERIFY(childNode.allDirectSubModelNodes().contains(subChildNode));
QVERIFY(subChildNode.parentProperty().parentModelNode() == childNode);
selectThrough(subChildNode);
childNode.destroy();
QCOMPARE(view->rootModelNode().allDirectSubModelNodes().count(), 0);
QVERIFY(!view->rootModelNode().allDirectSubModelNodes().contains(childNode));
QVERIFY(!childNode.isValid());
QVERIFY(!subChildNode.isValid());
}
示例14: hasDelegateWithFileComponent
static bool hasDelegateWithFileComponent(const ModelNode &node)
{
if (node.isValid()
&& node.metaInfo().isValid()
&& node.metaInfo().isView()
&& node.hasNodeProperty("delegate")
&& node.nodeProperty("delegate").modelNode().metaInfo().isFileComponent())
return true;
return false;
}
示例15: variantPropertyForRow
VariantProperty DynamicPropertiesModel::variantPropertyForRow(int rowNumber) const
{
const int internalId = data(index(rowNumber, TargetModelNodeRow), Qt::UserRole + 1).toInt();
const QString targetPropertyName = data(index(rowNumber, TargetModelNodeRow), Qt::UserRole + 2).toString();
ModelNode modelNode = connectionView()->modelNodeForInternalId(internalId);
if (modelNode.isValid())
return modelNode.variantProperty(targetPropertyName.toLatin1());
return VariantProperty();
}