int Model::nextComponentId () { if (!this->_rootComponent) { return 0; } else { QDomDocument doc; QString rootXml; rootXml.append("<model> \n"); rootXml.append(rootComponent()->xml ()); rootXml.append("\n</model>"); doc.setContent (rootXml); int rv = doc.elementsByTagName ("Component").length (); int maxVal = 0; for (int i=0; i<doc.elementsByTagName ("Component").length (); i++) { QDomElement element = doc.elementsByTagName("Component").item(i).toElement (); if (element.hasAttribute ("id")) { int id = element.attribute ("id").toInt(); if (id > maxVal) { maxVal = id; } } } maxVal++; rv = maxVal; // qDebug() << "new component Id" << rv; return rv; } return -1; }
QString Model::xml() { QDomDocument doc; QString rootXml; rootXml.append("<model> \n"); rootXml.append(rootComponent()->xml ()); rootXml.append("\n</model>"); doc.setContent (rootXml); return doc.toString(); }
void DVWindow::initializeGL() { QOpenGLExtraFunctions* f = context()->extraFunctions(); qDebug("GL Vendor: \"%s\", Renderer: \"%s\".", f->glGetString(GL_VENDOR), f->glGetString(GL_RENDERER)); loadShaders(); loadPlugins(); QQmlComponent rootComponent(qmlEngine); rootComponent.loadUrl(QUrl(QStringLiteral("qrc:/qml/Window.qml"))); /* Wait for it to load... */ while(rootComponent.isLoading()); /* The program can't run if there was an error. */ if (rootComponent.isError()) qFatal(qPrintable(rootComponent.errorString())); qmlRoot = qobject_cast<QQuickItem*>(rootComponent.create()); /* Critical error! abort! abort! */ if (qmlRoot == nullptr) qFatal(qPrintable(rootComponent.errorString())); /* This is the root item, make it so. */ qmlRoot->setParentItem(qmlWindow->contentItem()); player = qmlRoot->findChild<QtAV::AVPlayer*>(); if (player == nullptr) qFatal("Unable to find AVPlayer!"); /* Init to this window's OpenGL context. */ qmlRenderControl->initialize(context()); /* The setGeometry() and setState() calls may try to set the qmlRoot geometry, * which means this needs to be done after QML is all set up. */ if (settings.childGroups().contains("Window")) { /* Restore window state from the stored geometry. */ settings.beginGroup("Window"); setGeometry(settings.value("Geometry").toRect()); setWindowState(Qt::WindowState(settings.value("State").toInt())); settings.endGroup(); } }
void Model::parseComponentXML(QDomElement &componentElement, Component* targetComponent) { QDomElement instructionListElement = componentElement.firstChildElement ("InstructionList"); targetComponent->initInstructionList (); targetComponent->initSubComponentList (); // newComponent->initInstructionList (); targetComponent->instructionList ()->parseInstructionListElementXML (instructionListElement, targetComponent); // newComponent->initSubComponentList (); QDomElement subComponentListElement = componentElement.firstChildElement ("SubComponentList"); //QDomNodeList subComponentElements = subComponentListElement.elementsByTagName ("Component"); //for (int i=0; i<subComponentElements.length(); i++) { for(QDomNode n = subComponentListElement.firstChild(); !n.isNull(); n = n.nextSibling()) { QDomElement subComponentElement = n.toElement(); SubComponentList* list = targetComponent->subComponentList (); newComponent = this->createComponent (rootComponent()); list->addComponent (newComponent); this->parseComponentXML (subComponentElement, newComponent); } // targetComponent->subComponentList ()->addComponent (newComponent); }