1

All events mouse protected. I tried to do it via eventFilter and using QObject :: connect, but the result false. How do I catch a click event on Graphic? What I tried:

...
    void ViewshedGeoElement::graphic3dMouseClicked()
    {
        qDebug()<<"m_graphic3d";
    }

    bool ViewshedGeoElement::eventFilter(QObject *obj, QEvent *event)
    {
        qDebug()<<obj<<event;
        if (event->type() == QEvent::MouseButtonPress)
        {
            graphic3dMouseClicked();
            return true;
        }
        return false;
    }
...

Esri::ArcGISRuntime::Graphic* m_graphic3d = nullptr;
m_model3d = new ModelSceneSymbol(QUrl(dataPath + PathModel), 1.0f, this);
m_model3d->setAnchorPosition(SceneSymbolAnchorPosition::Bottom);
m_model3d->setHeading(180.0f);
m_graphic3d = new Graphic(dp.m_pos, m_model3d, this);

m_graphic3d->attributes()->insertAttribute(HEADING, dp.m_heading);
m_graphic3d->attributes()->insertAttribute(PITCH, dp.m_pitch);
m_graphic3d->attributes()->insertAttribute(ROLL, dp.m_roll);

m_sceneView->graphicsOverlays()->at(0)->graphics()->installEventFilter(m_graphic3d);

...

the second way doesn't work either:

...
void ViewshedGeoElement::graphic3dMouseClicked()
{
    qDebug()<<"m_graphic3d";
}
...
QObject::connect(m_graphic3d,SIGNAL(mousePressEvent()),this,SLOT(graphic3dMouseClicked()));
0

My code selects one Graphic and highlights it:

...
    QObjectList m_PointLogLag;
...
void ViewshedGeoElement::connectSignals()
{
    // handle the identifyLayerCompleted signal
    QObject::connect(m_sceneView, &SceneQuickView::identifyGraphicsOverlayCompleted, this, [this](QUuid, IdentifyGraphicsOverlayResult* result)
    {
        if (result->graphicsOverlay()->graphics()->isEmpty())
            return;
        // get the results
        GraphicListModel* graphicElements = result->graphicsOverlay()->graphics();
        for(int i=0;i<graphicElements->size();i++)
        {
            Point loaction = graphicElements->at(i)->geometry();
            qDebug()<<floor(loaction.x()*10000 )/10000<<floor(m_PointLogLag.last()->property("latitude").toDouble()*10000 )/10000;
            qDebug()<<floor(loaction.y()*10000 )/10000<<floor(m_PointLogLag.last()->property("longitude").toDouble()*10000 )/10000;
            if (floor(loaction.x()*10000 )/10000==floor(m_PointLogLag.last()->property("latitude").toDouble()*10000 )/10000,
                floor(loaction.y()*10000 )/10000==floor(m_PointLogLag.last()->property("longitude").toDouble()*10000 )/10000)
            {
               graphicElements->at(i)->setSelected(true);
               return;
            }
        }
    });

    //     when the scene is clicked, identify the clicked feature and select it
    QObject::connect(m_sceneView, &SceneQuickView::mousePressed, this, [this](QMouseEvent& mouseEvent)
    {
        //     clear any previous selection
        m_sceneView->graphicsOverlays()->at(0)->clearSelection();

        Point clickedPoint = m_sceneView->screenToBaseSurface(mouseEvent.x(), mouseEvent.y());
        m_PointLogLag.append(new Coordinates(clickedPoint.x(),clickedPoint.y()));

        //     identify from the click
        m_sceneView->identifyGraphicsOverlay(m_sceneView->graphicsOverlays()->at(0), mouseEvent.x(), mouseEvent.y(), 10, false);
    });
}
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.