在qml映射的位移/缩放稳定后启动filterAcceptsRow

问题描述 投票:0回答:1

在QML地图上,使用“onCenterChanged”捕获用户激活的移动,一旦移动开始,就会显示要显示的点的过滤过程。

鉴于在此操作期间要处理的数据量很大,我希望它仅在Map完全稳定后停止(停止滑动/缩放,释放鼠标左键并且鼠标滚轮无效)。

这是QML地图的片段

Map {
    id: mainMap
    anchors.centerIn: parent;
    anchors.fill: parent
    plugin: Plugin {name: "osm"}
    center: startingPoint
    zoomLevel: 4.5

    onCenterChanged: {
        updateBoundingBox()
    }

    MapItemView {
        id:viewPointOnMap
        model: navaidsFilter
        delegate: Marker{}
    }

    onMapReadyChanged: {
        updateBoundingBox()
    }

    function updateBoundingBox(){
        navaidsFilter.bBox = mainMap.visibleRegion.boundingGeoRectangle() //boundingBox
    }

}//Map

和过滤器片段:

void NavaidsFilter::setBBox(const QGeoRectangle &bbox)
{
    if(m_processedZone.isEmpty()|| !m_processedZone.contains(bbox)){  //First bbox or displacement/zoom out of the previous box
        m_processedZone = bbox;
        m_boundaryZone = bbox;
        invalidateFilter();
    }
}

bool NavaidsFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
    if(!m_boundaryZone.isValid()){
        return false;
    }

    QModelIndex ix = sourceModel()->index(sourceRow, 0, sourceParent);
    QGeoCoordinate pos = ix.data(NavaidsModel::PositionRole).value<QGeoCoordinate>();
    return m_boundaryZone.contains(pos);
}

我们怎样才能做到这一点?

感谢帮助

qt location qml
1个回答
0
投票

我从未与Map合作过,所以我不知道具体的解决方案。以下是两种在许多情况下都有效的通用解决方案:

  1. 引入聚合所有相关状态的属性 readonly property bool moving: mainMap.gesture.rotationActive | mainMap.gesture.tiltingActive | ...` 一旦这个属性改为false做必要的事情。 (onMovingChanged

  1. 无论什么时候发生变化,都要使用重启的Timer。如果对于某些ms没有任何改变,让它触发并执行必要的操作。
© www.soinside.com 2019 - 2024. All rights reserved.