static bool isFileComponent(const ModelNode &node) { if (node.isValid() && node.metaInfo().isValid() && node.metaInfo().isFileComponent()) return true; return false; }
static bool hasSourceWithFileComponent(const ModelNode &modelNode) { if (modelNode.isValid() && modelNode.metaInfo().isValid() && modelNode.metaInfo().isSubclassOf("QtQuick.Loader") && modelNode.hasVariantProperty("source")) return true; return false; }
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; }
static int getMajorVersionFromNode(const ModelNode &modelNode) { if (modelNode.metaInfo().isValid()) { if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item") return modelNode.majorVersion(); foreach (const NodeMetaInfo &superClass, modelNode.metaInfo().superClasses()) { if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item") return superClass.majorVersion(); } } return 1; //default }
static bool isLoaderWithSourceComponent(const ModelNode &modelNode) { if (modelNode.isValid() && modelNode.metaInfo().isValid() && modelNode.metaInfo().isSubclassOf("QtQuick.Loader")) { if (modelNode.hasNodeProperty("sourceComponent")) return true; if (modelNode.hasNodeListProperty("component")) return true; } return false; }
int ColorTool::wantHandleItem(const ModelNode &modelNode) const { if (modelNode.metaInfo().hasProperty("color")) return 10; return 0; }
static void handleDelegate(const ModelNode &modelNode) { if (modelNode.metaInfo().isView() && modelNode.hasNodeProperty("delegate") && modelNode.nodeProperty("delegate").modelNode().nodeSourceType() == ModelNode::NodeWithComponentSource) designDocument()->changeToSubComponent(modelNode.nodeProperty("delegate").modelNode()); }
int TextTool::wantHandleItem(const ModelNode &modelNode) const { if (modelNode.metaInfo().hasProperty("text")) return 20; return 0; }
static ModelNode findTabViewModelNode(const ModelNode ¤tModelNode) { if (currentModelNode.metaInfo().isSubclassOf("QtQuick.Controls.TabView", -1, -1)) return currentModelNode; else return findTabViewModelNode(currentModelNode.parentProperty().parentModelNode()); }
static void openComponentSourcePropertyOfLoader(const ModelNode &modelNode) { QmlDesignerPlugin::instance()->viewManager().nextFileIsCalledInternally(); QHash<PropertyName, QVariant> propertyHash; getProperties(modelNode, propertyHash); ModelNode componentModelNode; if (modelNode.hasNodeProperty("sourceComponent")) { componentModelNode = modelNode.nodeProperty("sourceComponent").modelNode(); } else if (modelNode.hasNodeListProperty("component")) { /* * The component property should be a NodeProperty, but currently is a NodeListProperty, because * the default property is always implcitly a NodeListProperty. This is something that has to be fixed. */ componentModelNode = modelNode.nodeListProperty("component").toModelNodeList().first(); } Core::EditorManager::openEditor(componentModelNode.metaInfo().componentFileName(), Core::Id(), Core::EditorManager::DoNotMakeVisible); ModelNode rootModelNode = currentDesignDocument()->rewriterView()->rootModelNode(); applyProperties(rootModelNode, propertyHash); }
static QList<ModelNode> acceptedModelNodeChildren(const ModelNode &parentNode) { QList<ModelNode> children; PropertyNameList properties; if (parentNode.metaInfo().hasDefaultProperty()) properties.append(parentNode.metaInfo().defaultPropertyName()); #ifndef DISABLE_VISIBLE_PROPERTIES properties.append(visibleProperties(parentNode)); #endif foreach (const PropertyName &propertyName, properties) { AbstractProperty property(parentNode.property(propertyName)); if (property.isNodeAbstractProperty()) children.append(property.toNodeAbstractProperty().directSubNodes()); }
NavigatorTreeModel::ItemRow NavigatorTreeModel::createItemRow(const ModelNode &node) { Q_ASSERT(node.isValid()); uint hash = node.internalId(); const bool dropEnabled = node.metaInfo().isValid(); QStandardItem *idItem = new QStandardItem; idItem->setDragEnabled(true); idItem->setDropEnabled(dropEnabled); idItem->setEditable(true); idItem->setData(hash, NavigatorRole); if (node.metaInfo().isValid()) idItem->setToolTip(node.type()); else idItem->setToolTip(msgUnknownItem(node.type())); # ifdef _LOCK_ITEMS_ QStandardItem *lockItem = new QStandardItem; lockItem->setDragEnabled(true); lockItem->setDropEnabled(dropEnabled); lockItem->setEditable(false); lockItem->setCheckable(true); lockItem->setData(hash, NavigatorRole); # endif QStandardItem *visibilityItem = new QStandardItem; visibilityItem->setDropEnabled(dropEnabled); visibilityItem->setCheckable(true); visibilityItem->setEditable(false); visibilityItem->setData(hash, NavigatorRole); if (node.isRootNode()) visibilityItem->setCheckable(false); QMap<QString, QStandardItem *> propertyItems; foreach (const QString &propertyName, visibleProperties(node)) { QStandardItem *propertyItem = new QStandardItem; propertyItem->setSelectable(false); propertyItem->setDragEnabled(false); propertyItem->setDropEnabled(dropEnabled); propertyItem->setEditable(false); propertyItem->setData(propertyName, Qt::DisplayRole); propertyItems.insert(propertyName, propertyItem); idItem->appendRow(propertyItem); }
static inline void openInlineComponent(const ModelNode &modelNode) { if (!modelNode.metaInfo().isValid()) return; handleComponent(modelNode); handleDelegate(modelNode); handleTabComponent(modelNode); }
void NodeInstanceView::currentStateChanged(const ModelNode &node) { NodeInstance newStateInstance = instanceForModelNode(node); if (newStateInstance.isValid() && node.metaInfo().isSubclassOf("QtQuick.State", 1, 0)) nodeInstanceView()->activateState(newStateInstance); else nodeInstanceView()->activateBaseState(); }
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); }
static void openFileComponent(const ModelNode &modelNode) { QmlDesignerPlugin::instance()->viewManager().nextFileIsCalledInternally(); QHash<PropertyName, QVariant> propertyHash; getProperties(modelNode, propertyHash); Core::EditorManager::openEditor(modelNode.metaInfo().componentFileName(), Core::Id(), Core::EditorManager::DoNotMakeVisible); ModelNode rootModelNode = currentDesignDocument()->rewriterView()->rootModelNode(); applyProperties(rootModelNode, propertyHash); }
void ComponentView::searchForComponentAndAddToList(const ModelNode &node) { QList<ModelNode> nodeList; nodeList.append(node); nodeList.append(node.allSubModelNodes()); foreach (const ModelNode &childNode, nodeList) { if (childNode.type() == "Qt/Component") { if (!childNode.id().isEmpty()) { QStandardItem *item = new QStandardItem(childNode.id()); item->setData(QVariant::fromValue(childNode), ModelNodeRole); item->setEditable(false); m_standardItemModel->appendRow(item); } } else if (node.metaInfo().isValid() && node.metaInfo().isComponent() && !m_componentList.contains(node.type())) { m_componentList.append(node.type()); m_componentList.sort(); m_listChanged = true; } } }
static bool isInEditedPath(const NodeAbstractProperty &propertyParent, const ModelNode &editingPathViewModelNode) { if (editingPathViewModelNode.isValid()) { if (editingPathViewModelNode.hasNodeProperty("path")) { ModelNode pathModelNode = editingPathViewModelNode.nodeProperty("path").modelNode(); if (pathModelNode.metaInfo().isSubclassOf("QtQuick.Path")) { if (propertyParent.name() == "pathElements" && propertyParent.parentModelNode() == pathModelNode) return true; } } } return false; }
void NodeInstanceView::modelAttached(Model *model) { AbstractView::modelAttached(model); m_nodeInstanceServer = new NodeInstanceServerProxy(this, m_runModus, m_currentKit); m_lastCrashTime.start(); connect(m_nodeInstanceServer.data(), SIGNAL(processCrashed()), this, SLOT(handleChrash())); if (!isSkippedRootNode(rootModelNode())) nodeInstanceServer()->createScene(createCreateSceneCommand()); ModelNode stateNode = currentStateNode(); if (stateNode.isValid() && stateNode.metaInfo().isSubclassOf("QtQuick.State", 1, 0)) { NodeInstance newStateInstance = instanceForModelNode(stateNode); activateState(newStateInstance); } }
static inline void openInlineComponent(const ModelNode &modelNode) { if (!modelNode.isValid() || !modelNode.metaInfo().isValid()) return; if (!currentDesignDocument()) return; QHash<PropertyName, QVariant> propertyHash; getProperties(modelNode, propertyHash); handleComponent(modelNode); handleDelegate(modelNode); handleTabComponent(modelNode); ModelNode rootModelNode = currentDesignDocument()->rewriterView()->rootModelNode(); applyProperties(rootModelNode, propertyHash); }
QStringList DynamicPropertiesModel::possibleTargetProperties(const BindingProperty &bindingProperty) const { const ModelNode modelNode = bindingProperty.parentModelNode(); if (!modelNode.isValid()) { qWarning() << " BindingModel::possibleTargetPropertiesForRow invalid model node"; return QStringList(); } NodeMetaInfo metaInfo = modelNode.metaInfo(); if (metaInfo.isValid()) { QStringList possibleProperties; foreach (const PropertyName &propertyName, metaInfo.propertyNames()) { if (metaInfo.propertyIsWritable(propertyName)) possibleProperties << QString::fromLatin1(propertyName); } return possibleProperties; }
static QIcon getTypeIcon(const ModelNode &modelNode) { QIcon icon; if (modelNode.isValid()) { // if node has no own icon, search for it in the itemlibrary const ItemLibraryInfo *libraryInfo = modelNode.model()->metaInfo().itemLibraryInfo(); QList <ItemLibraryEntry> itemLibraryEntryList = libraryInfo->entriesForType(modelNode.type(), modelNode.majorVersion(), modelNode.minorVersion()); if (!itemLibraryEntryList.isEmpty()) return itemLibraryEntryList.first().typeIcon(); else if (modelNode.metaInfo().isValid()) return QIcon(QStringLiteral(":/ItemLibrary/images/item-default-icon.png")); else return QIcon(QStringLiteral(":/ItemLibrary/images/item-invalid-icon.png")); } return QIcon(QStringLiteral(":/ItemLibrary/images/item-invalid-icon.png")); }
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; } } } } if (!parentNode.metaInfo().isLayoutable()) update(m_lastPosition, Snapper::NoSnapping, UseBaseState); }
static void drawRedWavyUnderLine(QPainter *painter, const QStyleOptionViewItem &styleOption, const QModelIndex &modelIndex, const QRect &textFrame , NavigatorTreeModel *navigatorTreeModel) { if (navigatorTreeModel->hasNodeForIndex(modelIndex)) { ModelNode modelNode = navigatorTreeModel->nodeForIndex(modelIndex); if (!modelNode.metaInfo().isValid()) { painter->translate(0, textFrame.y() + 1); QPen pen; pen.setColor(Qt::red); const qreal underlineOffset = styleOption.fontMetrics.underlinePos(); const QPixmap wave = getWavyPixmap(qMax(underlineOffset, pen.widthF()), pen); const int descent = styleOption.fontMetrics.descent(); painter->setBrushOrigin(painter->brushOrigin().x(), 0); painter->fillRect(textFrame.x(), 0, qCeil(textFrame.width()), qMin(wave.height(), descent), wave); } } }
NavigatorTreeModel::ItemRow NavigatorTreeModel::createItemRow(const ModelNode &node) { Q_ASSERT(node.isValid()); uint hash = qHash(node); const bool dropEnabled = node.metaInfo().isValid(); QStandardItem *idItem = new QStandardItem; idItem->setDragEnabled(true); idItem->setDropEnabled(dropEnabled); idItem->setEditable(true); idItem->setData(hash, Qt::UserRole); #ifdef _LOCK_ITEMS_ QStandardItem *lockItem = new QStandardItem; lockItem->setDragEnabled(true); lockItem->setDropEnabled(dropEnabled); lockItem->setEditable(false); lockItem->setCheckable(true); lockItem->setData(hash, Qt::UserRole); #endif QStandardItem *visibilityItem = new QStandardItem; visibilityItem->setDropEnabled(dropEnabled); visibilityItem->setCheckable(true); visibilityItem->setEditable(false); visibilityItem->setData(hash, Qt::UserRole); if (node.isRootNode()) { visibilityItem->setCheckable(false); } #ifdef _LOCK_ITEMS_ return ItemRow(idItem, lockItem, visibilityItem); #else return ItemRow(idItem, visibilityItem); #endif }
void NodeInstanceView::restartProcess() { if (m_restartProcessTimerId) killTimer(m_restartProcessTimerId); if (model()) { delete nodeInstanceServer(); m_nodeInstanceServer = new NodeInstanceServerProxy(this, m_runModus, m_currentKit); connect(m_nodeInstanceServer.data(), SIGNAL(processCrashed()), this, SLOT(handleChrash())); if (!isSkippedRootNode(rootModelNode())) nodeInstanceServer()->createScene(createCreateSceneCommand()); ModelNode stateNode = currentStateNode(); if (stateNode.isValid() && stateNode.metaInfo().isSubclassOf("QtQuick.State", 1, 0)) { NodeInstance newStateInstance = instanceForModelNode(stateNode); activateState(newStateInstance); } } m_restartProcessTimerId = 0; }
bool NavigatorTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &dropIndex) { if (action == Qt::IgnoreAction) return true; if (action != Qt::LinkAction) return false; if (!data->hasFormat("application/vnd.modelnode.list")) return false; if (column > 1) return false; if (dropIndex.model() != this) return false; QModelIndex parentIndex, parentItemIndex; PropertyName parentPropertyName; int targetIndex; parentIndex = dropIndex.sibling(dropIndex.row(), 0); targetIndex = (row > -1)? row : rowCount(parentIndex); if (this->data(parentIndex, NavigatorRole).isValid()) { parentItemIndex = parentIndex; ModelNode parentNode = nodeForIndex(parentItemIndex); if (!parentNode.metaInfo().hasDefaultProperty()) return false; targetIndex -= visibleProperties(parentNode).count(); parentPropertyName = parentNode.metaInfo().defaultPropertyName(); } else { parentItemIndex = parentIndex.parent(); parentPropertyName = parentIndex.data(Qt::DisplayRole).toByteArray(); } // Disallow dropping items between properties, which are listed first. if (targetIndex < 0) return false; Q_ASSERT(parentItemIndex.isValid()); QByteArray encodedData = data->data("application/vnd.modelnode.list"); QDataStream stream(&encodedData, QIODevice::ReadOnly); QList<ModelNode> nodeList; while (!stream.atEnd()) { uint nodeHash; stream >> nodeHash; if (containsNodeHash(nodeHash)) { ModelNode node(nodeForHash(nodeHash)); nodeList.append(node); } } ModelNode parentNode(nodeForIndex(parentItemIndex)); NodeAbstractProperty parentProperty = parentNode.nodeAbstractProperty(parentPropertyName); if (parentProperty.isNodeProperty() && nodeList.count() > 1) { return false; } moveNodesInteractive(parentProperty, nodeList, targetIndex); propagateInvisible(parentNode, isNodeInvisible(parentNode)); return false; // don't let the view do drag&drop on its own }
bool isTabView(const ModelNode &modelNode) { return modelNode.metaInfo().isSubclassOf("QtQuick.Controls.TabView", -1, -1); }
static void openFileComponent(const ModelNode &modelNode) { QmlDesignerPlugin::instance()->viewManager().nextFileIsCalledInternally(); Core::EditorManager::openEditor(modelNode.metaInfo().componentFileName(), Core::Id(), Core::EditorManager::DoNotMakeVisible); }
bool isTabAndParentIsTabView(const ModelNode &modelNode) { return modelNode.metaInfo().isSubclassOf("QtQuick.Controls.Tab", -1, -1) && modelNode.hasParentProperty() && modelNode.parentProperty().parentModelNode().metaInfo().isSubclassOf("QtQuick.Controls.TabView", -1, -1); }