void QQuickLoaderPrivate::setInitialState(QObject *obj) { Q_Q(QQuickLoader); QQuickItem *item = qmlobject_cast<QQuickItem*>(obj); if (item) { // If the item doesn't have an explicit size, but the Loader // does, then set the item's size now before bindings are // evaluated, otherwise we will end up resizing the item // later and triggering any affected bindings/anchors. if (widthValid && !QQuickItemPrivate::get(item)->widthValid) item->setWidth(q->width()); if (heightValid && !QQuickItemPrivate::get(item)->heightValid) item->setHeight(q->height()); item->setParentItem(q); } if (obj) { QQml_setParent_noEvent(itemContext, obj); QQml_setParent_noEvent(obj, q); itemContext = 0; } if (initialPropertyValues.isUndefined()) return; QQmlComponentPrivate *d = QQmlComponentPrivate::get(component); Q_ASSERT(d && d->engine); QV4::ExecutionEngine *v4 = qmlGlobalForIpv.engine(); Q_ASSERT(v4); QV4::Scope scope(v4); QV4::ScopedValue ipv(scope, initialPropertyValues.value()); d->initializeObjectWithInitialProperties(qmlGlobalForIpv, ipv, obj); }
QT_BEGIN_NAMESPACE QQuickItem *QQuickTextUtil::createCursor( QQmlComponent *component, QQuickItem *parent, const QRectF &rectangle, const char *className) { QQuickItem *item = 0; if (component->isReady()) { QQmlContext *creationContext = component->creationContext(); if (QObject *object = component->beginCreate(creationContext ? creationContext : qmlContext(parent))) { if ((item = qobject_cast<QQuickItem *>(object))) { QQml_setParent_noEvent(item, parent); item->setParentItem(parent); item->setPosition(rectangle.topLeft()); item->setHeight(rectangle.height()); } else { qmlInfo(parent) << tr("%1 does not support loading non-visual cursor delegates.") .arg(QString::fromUtf8(className)); } component->completeCreate(); return item; } } else if (component->isLoading()) { QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)), parent, SLOT(createCursor()), Qt::UniqueConnection); return item; } qmlInfo(parent, component->errors()) << tr("Could not load cursor delegate"); return item; }
int FloodingRT::view_full_table(QQmlApplicationEngine *engine, QQuickItem *panel) { //=============================== //Populate Flooding Routing Table //=============================== // Check to make sure all vectors are of the same size if (destination_node_pool.size() != gateway_node_pool.size() || gateway_node_pool.size() != weight_pool.size() || weight_pool.size() != destination_node_pool.size()) return -1; // return -1 for an error // Get the iterators for the different vectors std::vector<Node*>::iterator dest_iter = destination_node_pool.begin(); std::vector<Node*>::iterator gate_iter = gateway_node_pool.begin(); std::vector<int>::iterator weight_iter = weight_pool.begin(); // Creating a QObject for the routing table model, this is where // all of the items get added to QQmlComponent comp(engine, QUrl("qrc:/qml_files/flooding_model.qml")); QObject *object = comp.create(); QQuickItem *model = qobject_cast<QQuickItem*>(object); /* // While loop setup - Make sure all iterators are not at the end while (dest_iter != destination_node_pool.end() && gate_iter != gateway_node_pool.end() && weight_iter != weight_pool.end()) { // Grab the reference to the next item in each vector // This is the information for a row in the routing table Node *dest = *dest_iter; Node *gate = *gate_iter; int weight = *weight_iter; // Creating the routing table item QObject QQmlComponent component(engine, QUrl("qrc:/qml_files/flooding_item.qml")); object = component.create(); QQuickItem *item = qobject_cast<QQuickItem*>(object); // Setting the properties of the QObject item->setProperty("destination", dest->get_name()); item->setProperty("gateway", gate->get_name()); item->setProperty("weight", weight); // Adding the routing table item to the model item->setParentItem(model); // Moving the iterators to the next item dest_iter++; gate_iter++; weight_iter++; } */ // Create the routing table to actually be displayed QQmlComponent comp1(engine, QUrl("qrc:/qml_files/flooding_routing_table.qml")); QObject *obj = comp1.create(); QQuickItem *routing_table = qobject_cast<QQuickItem*>(obj); obj->findChild<QObject*>("table"); model->setParentItem(routing_table); obj->setProperty("model", "flooding_routing_table_model"); // Add the routing table to the main panel for viewing routing_table->setParentItem(panel); return 0; }//end of view_full_table
QQuickItem * DataSetView::createColumnHeader(int col) { //std::cout << "createColumnHeader("<<col<<") called!\n" << std::flush; if(_columnHeaderDelegate == NULL) { _columnHeaderDelegate = new QQmlComponent(qmlEngine(this)); _columnHeaderDelegate->setData("import QtQuick 2.10\nItem {\n" "property alias text: tekst.text\n" "Rectangle { color: \"lightGrey\"; anchors.fill: parent }\n" "Text { id: tekst; anchors.centerIn: parent }\n" "}", QUrl()); } QQuickItem * columnHeader = NULL; if(_columnHeaderItems.count(col) == 0 || _columnHeaderItems[col] == NULL) { if(_columnHeaderStorage.size() > 0) { #ifdef DEBUG_VIEWPORT std::cout << "createColumnHeader("<<col<<") from storage!\n" << std::flush; #endif columnHeader = _columnHeaderStorage.top(); _columnHeaderStorage.pop(); } else { #ifdef DEBUG_VIEWPORT std::cout << "createColumnHeader("<<col<<") ex nihilo!\n" << std::flush; #endif columnHeader = qobject_cast<QQuickItem*>(_columnHeaderDelegate->create()); columnHeader->setParent(this); columnHeader->setParentItem(this); } columnHeader->setProperty("z", 10); columnHeader->setProperty("text", _model->headerData(col, Qt::Orientation::Horizontal).toString()); columnHeader->setZ(-3); columnHeader->setHeight(_dataRowsMaxHeight); columnHeader->setWidth(_dataColsMaxWidth[col]); columnHeader->setVisible(true); _columnHeaderItems[col] = columnHeader; } else columnHeader = _columnHeaderItems[col]; columnHeader->setX(_colXPositions[col]); columnHeader->setY(_viewportY); return columnHeader; }
QQuickItem * DataSetView::createRowNumber(int row) { //std::cout << "createRowNumber("<<row<<") called!\n" << std::flush; if(_rowNumberDelegate == NULL) { _rowNumberDelegate = new QQmlComponent(qmlEngine(this)); _rowNumberDelegate->setData("import QtQuick 2.10\nItem {\n" "property alias text: tekst.text\n" "Rectangle { color: \"lightGrey\"; anchors.fill: parent }\n" "Text { id: tekst; anchors.centerIn: parent }\n" "}", QUrl()); } QQuickItem * rowNumber = NULL; if(_rowNumberItems.count(row) == 0 || _rowNumberItems[row] == NULL) { if(_rowNumberStorage.size() > 0) { #ifdef DEBUG_VIEWPORT std::cout << "createRowNumber("<<row<<") from storage!\n" << std::flush; #endif rowNumber = _rowNumberStorage.top(); _rowNumberStorage.pop(); } else { #ifdef DEBUG_VIEWPORT std::cout << "createRowNumber("<<row<<") ex nihilo!\n" << std::flush; #endif rowNumber = qobject_cast<QQuickItem*>(_rowNumberDelegate->create()); rowNumber->setParent(this); rowNumber->setParentItem(this); } rowNumber->setProperty("z", 10); rowNumber->setProperty("text", QString::fromStdString(std::to_string(row + 1))); //Nobody wants zero-based rows... rowNumber->setY(_dataRowsMaxHeight * (1 + row)); rowNumber->setZ(-3); rowNumber->setHeight(_dataRowsMaxHeight); rowNumber->setWidth(_rowNumberMaxWidth); rowNumber->setVisible(true); _rowNumberItems[row] = rowNumber; } else rowNumber = _rowNumberItems[row]; rowNumber->setX(_viewportX); return _rowNumberItems[row]; }
// qquickviewinspector.cpp::142 void reparentQmlObject(QObject *object, QObject *newParent) { if (!newParent) return; object->setParent(newParent); QQuickItem *newParentItem = qobject_cast<QQuickItem*>(newParent); QQuickItem *item = qobject_cast<QQuickItem*>(object); if (newParentItem && item) item->setParentItem(newParentItem); }
static QQmlPrivate::AutoParentResult qquickitem_autoParent(QObject *obj, QObject *parent) { // When setting a parent (especially during dynamic object creation) in QML, // also try to set up the analogous item/window relationship. QQuickItem *parentItem = qmlobject_cast<QQuickItem *>(parent); if (parentItem) { QQuickItem *item = qmlobject_cast<QQuickItem *>(obj); if (item) { // An Item has another Item item->setParentItem(parentItem); return QQmlPrivate::Parented; } else if (parentItem->window()) { QQuickWindow *win = qmlobject_cast<QQuickWindow *>(obj); if (win) { // A Window inside an Item should be transient for that item's window win->setTransientParent(parentItem->window()); return QQmlPrivate::Parented; } } return QQmlPrivate::IncompatibleObject; } else { QQuickWindow *parentWindow = qmlobject_cast<QQuickWindow *>(parent); if (parentWindow) { QQuickWindow *win = qmlobject_cast<QQuickWindow *>(obj); if (win) { // A Window inside a Window should be transient for it win->setTransientParent(parentWindow); return QQmlPrivate::Parented; } else { QQuickItem *item = qmlobject_cast<QQuickItem *>(obj); if (item) { // The parent of an Item inside a Window is actually the implicit content Item item->setParentItem(parentWindow->contentItem()); return QQmlPrivate::Parented; } } return QQmlPrivate::IncompatibleObject; } } return QQmlPrivate::IncompatibleParent; }
void Graph::press_and_hold_node(QString node_name) { QQmlComponent component(engine, QUrl("qrc:/qml_files/node_dialog.qml")); QObject *object = component.create(); object->setParent(panel); QQuickItem *item = qobject_cast<QQuickItem*>(object); item->setParentItem(qobject_cast<QQuickItem*>(panel)); QObject::connect(object,SIGNAL(destroy_dialog(void)),this,SLOT(destroy_dialog(void))); if (started && !paused) this->pause_animation(); Node* node = get_node_by_name(node_name); }
void MarSystemControlView::recreate(Marsyas::MarSystem * system, QQmlComponent * delegate) { foreach(QObject * item, m_items) delete item; m_items.clear(); control_map_t controls = system->controls(); control_map_t::iterator it; for (it = controls.begin(); it != controls.end(); ++it) { cout << "a control: " << it->first << endl; const MarControlPtr & control = it->second; QString name = QString::fromStdString( control->getName() ); QVariant value; std::string type = control->getType(); if (type == "mrs_real") value = QString::number( control->to<mrs_real>() ); else if (type == "mrs_natural") value = QString::number( control->to<mrs_natural>() ); else if (type == "mrs_bool") value = QVariant( control->to<mrs_bool>() ).convert(QVariant::String); else if (type == "mrs_string") value = QString::fromStdString(control->to<mrs_string>()); else value = QString("<undefined>"); //value.convert(QVariant::String); QQmlPropertyMap *data = new QQmlPropertyMap; data->insert("name", name); data->insert("value", value); QQmlContext *context = new QQmlContext( delegate->creationContext() ); context->setContextProperty("control", data); QObject * object = delegate->create(context); context->setParent(object); m_items.append(object); QQuickItem *item = qobject_cast<QQuickItem*>(object); if (!item) return; item->setParentItem( this->parentItem() ); } }
QQuickItem * DataSetView::createTextItem(int row, int col) { //std::cout << "createTextItem("<<row<<", "<<col<<") called!\n" << std::flush; if((_cellTextItems.count(col) == 0 && _cellTextItems[col].count(row) == 0) || _cellTextItems[col][row] == NULL) { if(_itemDelegate == NULL) { _itemDelegate = new QQmlComponent(qmlEngine(this)); _itemDelegate->setData("import QtQuick 2.10\nText { property bool active: true; text: \"???\"; color: active ? 'black' : 'grey' }", QUrl()); } QQuickItem * textItem = NULL; if(_textItemStorage.size() > 0) { #ifdef DEBUG_VIEWPORT std::cout << "createTextItem("<<row<<", "<<col<<") from storage!\n" << std::flush; #endif textItem = _textItemStorage.top(); _textItemStorage.pop(); } else { #ifdef DEBUG_VIEWPORT std::cout << "createTextItem("<<row<<", "<<col<<") ex nihilo!\n" << std::flush; #endif textItem = qobject_cast<QQuickItem*>(_itemDelegate->create()); textItem->setParent(this); textItem->setParentItem(this); } QModelIndex ind(_model->index(row, col)); bool active = _model->data(ind, _roleNameToRole["active"]).toBool(); textItem->setProperty("color", active ? "black" : "grey"); textItem->setProperty("text", _model->data(ind)); textItem->setX(_colXPositions[col] + _itemHorizontalPadding); textItem->setY(-2 + _dataRowsMaxHeight + _itemVerticalPadding + row * _dataRowsMaxHeight); textItem->setZ(-4); textItem->setVisible(true); _cellTextItems[col][row] = textItem; } return _cellTextItems[col][row]; }
void TelegramImageElement::initImage() { if(p->image) return; QQmlEngine *engine = qmlEngine(this); QQmlContext *context = qmlContext(this); if(!engine || !context) return; QQmlComponent component(engine); QString qmlImageCreationCode = p->qmlImageCreationCode; if(qmlImageCreationCode.isEmpty()) qmlImageCreationCode = QString("import QtQuick %1\n" "Image { anchors.fill: parent; }").arg(p->qtQuickVersion); component.setData(qmlImageCreationCode.toUtf8(), QUrl()); QQuickItem *item = qobject_cast<QQuickItem *>(component.create(context)); if(!item) return; item->setParent(this); item->setParentItem(this); QHashIterator<QString, QVariant> i(p->properties); while(i.hasNext()) { i.next(); item->setProperty(i.key().toUtf8(), i.value()); } connect(item, SIGNAL(asynchronousChanged()), this, SIGNAL(asynchronousChanged())); #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) connect(item, SIGNAL(autoTransformChanged()), this, SIGNAL(autoTransformChanged())); #endif connect(item, SIGNAL(cacheChanged()), this, SIGNAL(cacheChanged())); connect(item, SIGNAL(fillModeChanged()), this, SIGNAL(fillModeChanged())); connect(item, SIGNAL(mirrorChanged()), this, SIGNAL(mirrorChanged())); connect(item, SIGNAL(sourceSizeChanged()), this, SIGNAL(sourceSizeChanged())); p->image = item; }
void VCButton::render(QQuickView *view, QQuickItem *parent) { if (view == NULL || parent == NULL) return; QQmlComponent *component = new QQmlComponent(view->engine(), QUrl("qrc:/VCButtonItem.qml")); if (component->isError()) { qDebug() << component->errors(); return; } QQuickItem *item = qobject_cast<QQuickItem*>(component->create()); item->setParentItem(parent); item->setProperty("buttonObj", QVariant::fromValue(this)); }
QObject *FlameGraph::appendChild(QObject *parentObject, QQuickItem *parentItem, QQmlContext *context, const QModelIndex &childIndex, qreal position, qreal size) { QObject *childObject = m_delegate->beginCreate(context); if (parentItem) { QQuickItem *childItem = qobject_cast<QQuickItem *>(childObject); if (childItem) childItem->setParentItem(parentItem); } childObject->setParent(parentObject); FlameGraphAttached *attached = FlameGraph::qmlAttachedProperties(childObject); attached->setRelativePosition(position); attached->setRelativeSize(size); attached->setModelIndex(childIndex); m_delegate->completeCreate(); return childObject; }
void Packet::create_packet(QString name, QObject *main_panel, QQmlApplicationEngine *engine) { // Load Node QML file QQmlComponent component(engine, QUrl("qrc:/qml_files/packet.qml")); // Create QObject pac_obj = component.create(); // Cast it as a QQuickItem QQuickItem *item = qobject_cast<QQuickItem*>(pac_obj); // Set the parent as the main_panel (this changes when added to a link) item->setParentItem(qobject_cast<QQuickItem*>(main_panel)); item->setProperty("pack_name", name); #ifdef Q_OS_ANDROID item->setProperty("packet_size", 50); offset = 25; #else item->setProperty("packet_size", 20); offset = 13; #endif this->name = name; }
void tst_StatusIndicator::benchmarkCreation() { QFETCH(bool, active); QQuickWindow window; window.resize(240, 240); window.create(); QQmlEngine engine; // TODO: fix QString path = QString::fromLatin1(SRCDIR "/LotsOfIndicators%1.qml").arg(active ? "Active" : "Inactive"); QQmlComponent component(&engine, QUrl::fromLocalFile(path)); QVERIFY2(!component.isError(), qPrintable(component.errorString())); QVERIFY(component.isReady()); QBENCHMARK { QQuickItem *root = qobject_cast<QQuickItem*>(component.create()); root->setParentItem(window.contentItem()); window.grabWindow(); } }
void Graph::_drawLabel(float x, float y, QString text, QHash<QString, QQuickItem*> &labelCache) { if(labelComponent == NULL) { QQmlEngine * engine = new QQmlEngine(); labelComponent = new QQmlComponent(engine, QUrl("qrc:/src/qml/controls/common/_Text.qml", QUrl::StrictMode)); if( labelComponent->status() != QQmlComponent::Ready) { qDebug() << ("Error:"+ labelComponent->errorString() ); return; // or maybe throw } } if( labelComponent->status() != QQmlComponent::Ready) { return; } QQuickItem * label = labelCache[text]; if (!label) { //TODO: Someday, scene graph might have a better text renderer label= qobject_cast<QQuickItem*>(labelComponent->create()); label->setParentItem(this->parentItem()); //TODO: Who REALLY owns this item? The component? Or the Hash? label->setProperty("text", text); label->setProperty("width", "parent.width"); label->children().first()->setProperty("color", m_primaryLineColor.darker()); labelCache[text] = label; } if (label != NULL) { label->setProperty("x", x); label->setProperty("y", y); } }
void tst_applicationwindow::attachedProperties() { QQmlEngine engine; QQmlComponent component(&engine); component.loadUrl(testFileUrl("attachedProperties.qml")); QScopedPointer<QObject> object(component.create()); QVERIFY2(!object.isNull(), qPrintable(component.errorString())); QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(object.data()); QVERIFY(window); QQuickItem *childControl = object->property("childControl").value<QQuickItem *>(); QVERIFY(childControl); QCOMPARE(childControl->property("attached_window").value<QQuickApplicationWindow *>(), window); QCOMPARE(childControl->property("attached_contentItem").value<QQuickItem *>(), window->contentItem()); QCOMPARE(childControl->property("attached_activeFocusControl").value<QQuickItem *>(), window->activeFocusControl()); QCOMPARE(childControl->property("attached_header").value<QQuickItem *>(), window->header()); QCOMPARE(childControl->property("attached_footer").value<QQuickItem *>(), window->footer()); QCOMPARE(childControl->property("attached_overlay").value<QQuickItem *>(), window->overlay()); QQuickItem *childItem = object->property("childItem").value<QQuickItem *>(); QVERIFY(childItem); QCOMPARE(childItem->property("attached_window").value<QQuickApplicationWindow *>(), window); QCOMPARE(childItem->property("attached_contentItem").value<QQuickItem *>(), window->contentItem()); QCOMPARE(childItem->property("attached_activeFocusControl").value<QQuickItem *>(), window->activeFocusControl()); QCOMPARE(childItem->property("attached_header").value<QQuickItem *>(), window->header()); QCOMPARE(childItem->property("attached_footer").value<QQuickItem *>(), window->footer()); QCOMPARE(childItem->property("attached_overlay").value<QQuickItem *>(), window->overlay()); QObject *childObject = object->property("childObject").value<QObject *>(); QVERIFY(childObject); QVERIFY(!childObject->property("attached_window").value<QQuickApplicationWindow *>()); QVERIFY(!childObject->property("attached_contentItem").value<QQuickItem *>()); QVERIFY(!childObject->property("attached_activeFocusControl").value<QQuickItem *>()); QVERIFY(!childObject->property("attached_header").value<QQuickItem *>()); QVERIFY(!childObject->property("attached_footer").value<QQuickItem *>()); QVERIFY(!childObject->property("attached_overlay").value<QQuickItem *>()); QQuickWindow *childWindow = object->property("childWindow").value<QQuickWindow *>(); QVERIFY(childWindow); QVERIFY(!childWindow->property("attached_window").value<QQuickApplicationWindow *>()); QVERIFY(!childWindow->property("attached_contentItem").value<QQuickItem *>()); QVERIFY(!childWindow->property("attached_activeFocusControl").value<QQuickItem *>()); QVERIFY(!childWindow->property("attached_header").value<QQuickItem *>()); QVERIFY(!childWindow->property("attached_footer").value<QQuickItem *>()); QVERIFY(!childWindow->property("attached_overlay").value<QQuickItem *>()); QQuickItem *childWindowControl = object->property("childWindowControl").value<QQuickItem *>(); QVERIFY(childWindowControl); QVERIFY(!childWindowControl->property("attached_window").value<QQuickApplicationWindow *>()); QVERIFY(!childWindowControl->property("attached_contentItem").value<QQuickItem *>()); QVERIFY(!childWindowControl->property("attached_activeFocusControl").value<QQuickItem *>()); QVERIFY(!childWindowControl->property("attached_header").value<QQuickItem *>()); QVERIFY(!childWindowControl->property("attached_footer").value<QQuickItem *>()); QVERIFY(!childWindowControl->property("attached_overlay").value<QQuickItem *>()); QQuickItem *childWindowItem = object->property("childWindowItem").value<QQuickItem *>(); QVERIFY(childWindowItem); QVERIFY(!childWindowItem->property("attached_window").value<QQuickApplicationWindow *>()); QVERIFY(!childWindowItem->property("attached_contentItem").value<QQuickItem *>()); QVERIFY(!childWindowItem->property("attached_activeFocusControl").value<QQuickItem *>()); QVERIFY(!childWindowItem->property("attached_header").value<QQuickItem *>()); QVERIFY(!childWindowItem->property("attached_footer").value<QQuickItem *>()); QVERIFY(!childWindowItem->property("attached_overlay").value<QQuickItem *>()); QObject *childWindowObject = object->property("childWindowObject").value<QObject *>(); QVERIFY(childWindowObject); QVERIFY(!childWindowObject->property("attached_window").value<QQuickApplicationWindow *>()); QVERIFY(!childWindowObject->property("attached_contentItem").value<QQuickItem *>()); QVERIFY(!childWindowObject->property("attached_activeFocusControl").value<QQuickItem *>()); QVERIFY(!childWindowObject->property("attached_header").value<QQuickItem *>()); QVERIFY(!childWindowObject->property("attached_footer").value<QQuickItem *>()); QVERIFY(!childWindowObject->property("attached_overlay").value<QQuickItem *>()); QQuickApplicationWindow *childAppWindow = object->property("childAppWindow").value<QQuickApplicationWindow *>(); QVERIFY(childAppWindow); QVERIFY(!childAppWindow->property("attached_window").value<QQuickApplicationWindow *>()); QVERIFY(!childAppWindow->property("attached_contentItem").value<QQuickItem *>()); QVERIFY(!childAppWindow->property("attached_activeFocusControl").value<QQuickItem *>()); QVERIFY(!childAppWindow->property("attached_header").value<QQuickItem *>()); QVERIFY(!childAppWindow->property("attached_footer").value<QQuickItem *>()); QVERIFY(!childAppWindow->property("attached_overlay").value<QQuickItem *>()); QQuickItem *childAppWindowControl = object->property("childAppWindowControl").value<QQuickItem *>(); QVERIFY(childAppWindowControl); QCOMPARE(childAppWindowControl->property("attached_window").value<QQuickApplicationWindow *>(), childAppWindow); QCOMPARE(childAppWindowControl->property("attached_contentItem").value<QQuickItem *>(), childAppWindow->contentItem()); QCOMPARE(childAppWindowControl->property("attached_activeFocusControl").value<QQuickItem *>(), childAppWindow->activeFocusControl()); QCOMPARE(childAppWindowControl->property("attached_header").value<QQuickItem *>(), childAppWindow->header()); QCOMPARE(childAppWindowControl->property("attached_footer").value<QQuickItem *>(), childAppWindow->footer()); QCOMPARE(childAppWindowControl->property("attached_overlay").value<QQuickItem *>(), childAppWindow->overlay()); QQuickItem *childAppWindowItem = object->property("childAppWindowItem").value<QQuickItem *>(); QVERIFY(childAppWindowItem); QCOMPARE(childAppWindowItem->property("attached_window").value<QQuickApplicationWindow *>(), childAppWindow); QCOMPARE(childAppWindowItem->property("attached_contentItem").value<QQuickItem *>(), childAppWindow->contentItem()); QCOMPARE(childAppWindowItem->property("attached_activeFocusControl").value<QQuickItem *>(), childAppWindow->activeFocusControl()); QCOMPARE(childAppWindowItem->property("attached_header").value<QQuickItem *>(), childAppWindow->header()); QCOMPARE(childAppWindowItem->property("attached_footer").value<QQuickItem *>(), childAppWindow->footer()); QCOMPARE(childAppWindowItem->property("attached_overlay").value<QQuickItem *>(), childAppWindow->overlay()); QObject *childAppWindowObject = object->property("childAppWindowObject").value<QObject *>(); QVERIFY(childAppWindowObject); QVERIFY(!childAppWindowObject->property("attached_window").value<QQuickApplicationWindow *>()); QVERIFY(!childAppWindowObject->property("attached_contentItem").value<QQuickItem *>()); QVERIFY(!childAppWindowObject->property("attached_activeFocusControl").value<QQuickItem *>()); QVERIFY(!childAppWindowObject->property("attached_header").value<QQuickItem *>()); QVERIFY(!childAppWindowObject->property("attached_footer").value<QQuickItem *>()); QVERIFY(!childAppWindowObject->property("attached_overlay").value<QQuickItem *>()); window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); QVERIFY(!childControl->hasActiveFocus()); childControl->forceActiveFocus(); QTRY_VERIFY(childControl->hasActiveFocus()); QCOMPARE(window->activeFocusItem(), childControl); QCOMPARE(childControl->property("attached_activeFocusControl").value<QQuickItem *>(), childControl); QQuickItem *header = new QQuickItem; window->setHeader(header); QCOMPARE(window->header(), header); QCOMPARE(childControl->property("attached_header").value<QQuickItem *>(), header); QQuickItem *footer = new QQuickItem; window->setFooter(footer); QCOMPARE(window->footer(), footer); QCOMPARE(childControl->property("attached_footer").value<QQuickItem *>(), footer); childAppWindow->show(); childAppWindow->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(childAppWindow)); QVERIFY(!childAppWindowControl->hasActiveFocus()); childAppWindowControl->forceActiveFocus(); QTRY_VERIFY(childAppWindowControl->hasActiveFocus()); QCOMPARE(childAppWindow->activeFocusItem(), childAppWindowControl); QCOMPARE(childAppWindowControl->property("attached_activeFocusControl").value<QQuickItem *>(), childAppWindowControl); childControl->setParentItem(childAppWindow->contentItem()); QCOMPARE(childControl->window(), childAppWindow); QCOMPARE(childControl->property("attached_window").value<QQuickApplicationWindow *>(), childAppWindow); QCOMPARE(childControl->property("attached_contentItem").value<QQuickItem *>(), childAppWindow->contentItem()); QCOMPARE(childControl->property("attached_activeFocusControl").value<QQuickItem *>(), childAppWindow->activeFocusControl()); QCOMPARE(childControl->property("attached_header").value<QQuickItem *>(), childAppWindow->header()); QCOMPARE(childControl->property("attached_footer").value<QQuickItem *>(), childAppWindow->footer()); QCOMPARE(childControl->property("attached_overlay").value<QQuickItem *>(), childAppWindow->overlay()); childItem->setParentItem(childAppWindow->contentItem()); QCOMPARE(childItem->window(), childAppWindow); QCOMPARE(childItem->property("attached_window").value<QQuickApplicationWindow *>(), childAppWindow); QCOMPARE(childItem->property("attached_contentItem").value<QQuickItem *>(), childAppWindow->contentItem()); QCOMPARE(childItem->property("attached_activeFocusControl").value<QQuickItem *>(), childAppWindow->activeFocusControl()); QCOMPARE(childItem->property("attached_header").value<QQuickItem *>(), childAppWindow->header()); QCOMPARE(childItem->property("attached_footer").value<QQuickItem *>(), childAppWindow->footer()); QCOMPARE(childItem->property("attached_overlay").value<QQuickItem *>(), childAppWindow->overlay()); childControl->setParentItem(Q_NULLPTR); QVERIFY(!childControl->window()); QVERIFY(!childControl->property("attached_window").value<QQuickApplicationWindow *>()); QVERIFY(!childControl->property("attached_contentItem").value<QQuickItem *>()); QVERIFY(!childControl->property("attached_activeFocusControl").value<QQuickItem *>()); QVERIFY(!childControl->property("attached_header").value<QQuickItem *>()); QVERIFY(!childControl->property("attached_footer").value<QQuickItem *>()); QVERIFY(!childControl->property("attached_overlay").value<QQuickItem *>()); childItem->setParentItem(Q_NULLPTR); QVERIFY(!childItem->window()); QVERIFY(!childItem->property("attached_window").value<QQuickApplicationWindow *>()); QVERIFY(!childItem->property("attached_contentItem").value<QQuickItem *>()); QVERIFY(!childItem->property("attached_activeFocusControl").value<QQuickItem *>()); QVERIFY(!childItem->property("attached_header").value<QQuickItem *>()); QVERIFY(!childItem->property("attached_footer").value<QQuickItem *>()); QVERIFY(!childItem->property("attached_overlay").value<QQuickItem *>()); // ### A temporary workaround to unblock the CI until the crash caused // by https://codereview.qt-project.org/#/c/108517/ has been fixed... window->hide(); qApp->processEvents(); }
QQuickItem* Window::message( QString text, QtMsgType type, bool force ) { ENTER()(text)(type)(force); if( !force && displayed_.contains(text) ) RETURN( nullptr ); QString colour; QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::NoIcon; switch( type ) { case QtInfoMsg: colour = "#006400"; icon = QSystemTrayIcon::Information; break; case QtWarningMsg: colour = "#FF8C00"; icon = QSystemTrayIcon::Warning; break; case QtCriticalMsg: colour = "#8B0000"; icon = QSystemTrayIcon::Critical; break; case QtDebugMsg: case QtFatalMsg: DEBUG() << "Error: Unsupported message type"; RETURN( nullptr ); } QQuickItem* item = nullptr; // If tray icon is displayed, only show a tray notification if( mainWindow_ && mainWindow_->trayIcon() ) { mainWindow_->trayIcon()->showMessage( mainWindow()->title(), text, icon ); } else { int timeout = 5000; QQuickView* view = new QQuickView( QUrl(QStringLiteral("qrc:/qml/MessageBox.qml")), this ); item = view->rootObject(); item->setParentItem( item_ ); item->findChild<QQuickItem*>("message")->setProperty( "color", colour ); item->findChild<QQuickItem*>("message")->setProperty( "text", text ); if( type != QtCriticalMsg ) { QTimer* timer = new QTimer( this ); timer->setSingleShot( true ); timer->setInterval( timeout ); timer->start(); connect( timer, &QTimer::timeout, this, [=](){ if(item) item->deleteLater(); } ); } } displayed_.insert( text, true ); RETURN( item ); }
void MainView2D::createFixtureItem(quint32 fxID, quint16 headIndex, quint16 linkedIndex, QVector3D pos, bool mmCoords) { if (isEnabled() == false) return; if (m_gridItem == NULL) initialize2DProperties(); qDebug() << "[MainView2D] Creating fixture with ID" << fxID << headIndex << linkedIndex << "pos:" << pos; Fixture *fixture = m_doc->fixture(fxID); if (fixture == NULL) return; quint32 itemID = FixtureUtils::fixtureItemID(fxID, headIndex, linkedIndex); QLCFixtureMode *fxMode = fixture->fixtureMode(); QQuickItem *newFixtureItem = qobject_cast<QQuickItem*>(fixtureComponent->create()); quint32 itemFlags = m_monProps->fixtureFlags(fxID, headIndex, linkedIndex); newFixtureItem->setParentItem(m_gridItem); newFixtureItem->setProperty("itemID", itemID); if (itemFlags & MonitorProperties::HiddenFlag) newFixtureItem->setProperty("visible", false); if (fxMode != NULL && fixture->type() != QLCFixtureDef::Dimmer) { QLCPhysical phy = fxMode->physical(); //qDebug() << "Current mode fixture heads:" << fxMode->heads().count(); newFixtureItem->setProperty("headsNumber", fxMode->heads().count()); if (fixture->channelNumber(QLCChannel::Pan, QLCChannel::MSB) != QLCChannel::invalid()) { int panDeg = phy.focusPanMax(); if (panDeg == 0) panDeg = 360; newFixtureItem->setProperty("panMaxDegrees", panDeg); } if (fixture->channelNumber(QLCChannel::Tilt, QLCChannel::MSB) != QLCChannel::invalid()) { int tiltDeg = phy.focusTiltMax(); if (tiltDeg == 0) tiltDeg = 270; newFixtureItem->setProperty("tiltMaxDegrees", tiltDeg); } } QPointF itemPos; QSizeF size = FixtureUtils::item2DDimension(fixture->type() == QLCFixtureDef::Dimmer ? NULL : fxMode, m_monProps->pointOfView()); if (mmCoords == false && (pos.x() != 0 || pos.y() != 0)) { float gridUnits = m_monProps->gridUnits() == MonitorProperties::Meters ? 1000.0 : 304.8; itemPos.setX((pos.x() * gridUnits) / m_cellPixels); itemPos.setY((pos.y() * gridUnits) / m_cellPixels); } if (m_monProps->containsItem(fxID, headIndex, linkedIndex)) { itemPos = FixtureUtils::item2DPosition(m_monProps, m_monProps->pointOfView(), pos); newFixtureItem->setProperty("rotation", FixtureUtils::item2DRotation(m_monProps->pointOfView(), m_monProps->fixtureRotation(fxID, headIndex, linkedIndex))); } else { itemPos = FixtureUtils::available2DPosition(m_doc, m_monProps->pointOfView(), QRectF(itemPos.x(), itemPos.y(), size.width(), size.height())); // add the new fixture to the Doc monitor properties QVector3D newPos = FixtureUtils::item3DPosition(m_monProps, itemPos, 1000.0); m_monProps->setFixturePosition(fxID, headIndex, linkedIndex, newPos); m_monProps->setFixtureFlags(fxID, headIndex, linkedIndex, 0); Tardis::instance()->enqueueAction(Tardis::FixtureSetPosition, itemID, QVariant(QVector3D(0, 0, 0)), QVariant(newPos)); } newFixtureItem->setProperty("mmXPos", itemPos.x()); newFixtureItem->setProperty("mmYPos", itemPos.y()); newFixtureItem->setProperty("mmWidth", size.width()); newFixtureItem->setProperty("mmHeight", size.height()); newFixtureItem->setProperty("fixtureName", fixture->name()); // and finally add the new item to the items map m_itemsMap[itemID] = newFixtureItem; QByteArray values; updateFixture(fixture, values); }
void MarSystemView::createItem( MarSystem *system, QQmlComponent * delegate, QQuickItem * parent ) { int level = -1; MarSystem *s = system; while(s) { s = s->getParent(); ++level; } QQmlPropertyMap *data = new QQmlPropertyMap; data->insert("level", level); // Get controls QQmlPropertyMap *defaultControls = new QQmlPropertyMap; defaultControls->insert("inSamples", variantFromControl(system->getControl("mrs_natural/inSamples"))); defaultControls->insert("onSamples", variantFromControl(system->getControl("mrs_natural/onSamples"))); defaultControls->insert("inObservations", variantFromControl(system->getControl("mrs_natural/inObservations"))); defaultControls->insert("onObservations", variantFromControl(system->getControl("mrs_natural/onObservations"))); defaultControls->insert("israte", variantFromControl(system->getControl("mrs_real/israte"))); defaultControls->insert("osrate", variantFromControl(system->getControl("mrs_real/osrate"))); defaultControls->insert("inStabilizingDelay", variantFromControl(system->getControl("mrs_natural/inStabilizingDelay"))); defaultControls->insert("onStabilizingDelay", variantFromControl(system->getControl("mrs_natural/onStabilizingDelay"))); defaultControls->insert("inObsNames", variantFromControl(system->getControl("mrs_string/inObsNames"))); defaultControls->insert("onObsNames", variantFromControl(system->getControl("mrs_string/onObsNames"))); defaultControls->insert("active", variantFromControl(system->getControl("mrs_bool/active"))); defaultControls->insert("mute", variantFromControl(system->getControl("mrs_bool/mute"))); defaultControls->insert("debug", variantFromControl(system->getControl("mrs_bool/debug"))); defaultControls->insert("verbose", variantFromControl(system->getControl("mrs_bool/verbose"))); defaultControls->insert("processedData", variantFromControl(system->getControl("mrs_realvec/processedData"))); QQmlPropertyMap *customControls = new QQmlPropertyMap; control_map_t controls = system->controls(); control_map_t::iterator it; for (it = controls.begin(); it != controls.end(); ++it) { const MarControlPtr & control = it->second; QString name = QString::fromStdString( control->getName() ); name = name.split('/').last(); if (defaultControls->contains(name)) continue; customControls->insert(name, variantFromControl(control)); } data->insert("defaultControls", QVariant::fromValue<QObject*>(defaultControls)); data->insert("controls", QVariant::fromValue<QObject*>(customControls)); data->insert("absolutePath", QString::fromStdString(system->getAbsPath())); data->insert("path", QString::fromStdString(system->getPrefix())); // Set context QQmlContext *context = new QQmlContext( delegate->creationContext() ); context->setContextProperty("system", data); QObject *object = delegate->create(context); object->setParent(parent); m_items.append(object); QQuickItem *item = qobject_cast<QQuickItem*>(object); if (!item) return; QString path = QString::fromStdString(system->getPrefix()); std::vector<MarSystem*> children = system->getChildren(); int children_count = children.size(); bool has_children = children_count > 0; bool create_if_not_existent = true; MarSystemViewAttached *attached = qobject_cast<MarSystemViewAttached*>(qmlAttachedPropertiesObject<MarSystemView>(item, create_if_not_existent) ); Q_ASSERT(attached); attached->setPath(path); attached->setHasChildren(has_children); attached->setSystem(system); QQuickItem *children_area = attached->childrenArea(); if (!children_area) children_area = item; for (int child_idx = 0; child_idx < children_count; ++child_idx) { MarSystem *child_system = children[child_idx]; createItem(child_system, delegate, children_area); } item->setParentItem(parent); }
void ShowManager::addItem(QQuickItem *parent, int trackIdx, int startTime, quint32 functionID) { // if no show is selected, then create a new one if (m_currentShow == NULL) { QString defaultName = QString("%1 %2").arg(tr("New Show")).arg(m_doc->nextFunctionID()); m_currentShow = new Show(m_doc); m_currentShow->setName(defaultName); Function *f = qobject_cast<Function*>(m_currentShow); if (m_doc->addFunction(f) == false) { qDebug() << "Error in creating a new Show !"; m_currentShow = NULL; return; } connect(m_currentShow, SIGNAL(timeChanged(quint32)), this, SLOT(slotTimeChanged(quint32))); emit currentShowIDChanged(m_currentShow->id()); emit showNameChanged(m_currentShow->name()); } Track *selectedTrack = NULL; // if no Track index is provided, then add a new one if (trackIdx == -1) { selectedTrack = new Track(); selectedTrack->setName(tr("Track %1").arg(m_currentShow->tracks().count() + 1)); m_currentShow->addTrack(selectedTrack); trackIdx = m_currentShow->tracks().count() - 1; emit tracksChanged(); } else { if (trackIdx >= m_currentShow->tracks().count()) { qDebug() << "Track index out of bounds !" << trackIdx; return; } selectedTrack = m_currentShow->tracks().at(trackIdx); } // and now create the actual ShowFunction and the QML item Function *func = m_doc->function(functionID); if (func == NULL) return; ShowFunction *showFunc = selectedTrack->createShowFunction(functionID); showFunc->setStartTime(startTime); showFunc->setDuration(func->totalDuration()); showFunc->setColor(ShowFunction::defaultColor(func->type())); QQuickItem *newItem = qobject_cast<QQuickItem*>(siComponent->create()); newItem->setParentItem(parent); newItem->setProperty("trackIndex", trackIdx); newItem->setProperty("sfRef", QVariant::fromValue(showFunc)); newItem->setProperty("funcRef", QVariant::fromValue(func)); quint32 itemIndex = m_itemsMap.isEmpty() ? 0 : m_itemsMap.lastKey() + 1; quint32 itemID = trackIdx << 16 | itemIndex; m_itemsMap[itemID] = newItem; emit showDurationChanged(m_currentShow->totalDuration()); }
void OffscreenSurface::finishQmlLoad(QQmlComponent* qmlComponent, QQmlContext* qmlContext, QQuickItem* parent, const QmlContextObjectCallback& callback) { disconnect(qmlComponent, &QQmlComponent::statusChanged, this, 0); if (qmlComponent->isError()) { for (const auto& error : qmlComponent->errors()) { qCWarning(qmlLogging) << error.url() << error.line() << error; } qmlComponent->deleteLater(); return; } QObject* newObject = qmlComponent->beginCreate(qmlContext); if (qmlComponent->isError()) { for (const auto& error : qmlComponent->errors()) { qCWarning(qmlLogging) << error.url() << error.line() << error; } if (!getRootItem()) { qFatal("Unable to finish loading QML root"); } qmlComponent->deleteLater(); return; } if (!newObject) { if (!getRootItem()) { qFatal("Could not load object as root item"); return; } qCWarning(qmlLogging) << "Unable to load QML item"; return; } qmlContext->engine()->setObjectOwnership(this, QQmlEngine::CppOwnership); // All quick items should be focusable QQuickItem* newItem = qobject_cast<QQuickItem*>(newObject); if (newItem) { // Make sure we make items focusable (critical for // supporting keyboard shortcuts) newItem->setFlag(QQuickItem::ItemIsFocusScope, true); #ifdef DEBUG for (auto frame : newObject->findChildren<QQuickItem *>("Frame")) { frame->setProperty("qmlFile", qmlComponent->url()); } #endif } bool rootCreated = getRootItem() != nullptr; // Make sure we will call callback for this codepath // Call this before qmlComponent->completeCreate() otherwise ghost window appears // If we already have a root, just set a couple of flags and the ancestry if (rootCreated) { callback(qmlContext, newItem); if (!parent) { parent = getRootItem(); } // Allow child windows to be destroyed from JS QQmlEngine::setObjectOwnership(newObject, QQmlEngine::JavaScriptOwnership); newObject->setParent(parent); newItem->setParentItem(parent); } else { // The root item is ready. Associate it with the window. _sharedObject->setRootItem(newItem); } qmlComponent->completeCreate(); qmlComponent->deleteLater(); onItemCreated(qmlContext, newItem); if (!rootCreated) { connect(newItem, SIGNAL(sendToScript(QVariant)), this, SIGNAL(fromQml(QVariant))); onRootCreated(); emit rootItemCreated(newItem); // Call this callback after rootitem is set, otherwise VrMenu wont work callback(qmlContext, newItem); } }