void BackendGoogleMaps::addActionsToConfigurationMenu(QMenu* const configurationMenu)
{
    KGEOMAP_ASSERT(configurationMenu!=0);

    if (!d->isReady)
        return;

    configurationMenu->addSeparator();

    // map type actions:
    const QList<QAction*> mapTypeActions = d->mapTypeActionGroup->actions();

    for (int i = 0; i < mapTypeActions.count(); ++i)
    {
        QAction* const mapTypeAction = mapTypeActions.at(i);
        configurationMenu->addAction(mapTypeAction);
    }

    configurationMenu->addSeparator();

    // float items visibility:
    QMenu* const floatItemsSubMenu = new QMenu(i18n("Float items"), configurationMenu);
    configurationMenu->addMenu(floatItemsSubMenu);

    floatItemsSubMenu->addAction(d->showMapTypeControlAction);
    floatItemsSubMenu->addAction(d->showNavigationControlAction);
    floatItemsSubMenu->addAction(d->showScaleControlAction);

    updateActionAvailability();
}
Exemple #2
0
void BackendOSM::readSettingsFromGroup(const KConfigGroup* const group)
{
    KGEOMAP_ASSERT(group != 0);

    if (!group)
        return;
}
Exemple #3
0
void BackendOSM::saveSettingsToGroup(KConfigGroup* const group)
{
    KGEOMAP_ASSERT(group != 0);

    if (!group)
        return;
}
Exemple #4
0
void BackendOSM::addActionsToConfigurationMenu(QMenu* const configurationMenu)
{
    KGEOMAP_ASSERT(configurationMenu != 0);

    if (!d->isReady)
        return;
}
int BackendGoogleMaps::getMarkerModelLevel()
{
    KGEOMAP_ASSERT(isReady());

    if (!isReady())
    {
        return 0;
    }

    // get the current zoom level:
    const int currentZoom = d->cacheZoom;

    int tileLevel = 0;
         if (currentZoom== 0) { tileLevel = 1; }
    else if (currentZoom== 1) { tileLevel = 1; }
    else if (currentZoom== 2) { tileLevel = 1; }
    else if (currentZoom== 3) { tileLevel = 2; }
    else if (currentZoom== 4) { tileLevel = 2; }
    else if (currentZoom== 5) { tileLevel = 3; }
    else if (currentZoom== 6) { tileLevel = 3; }
    else if (currentZoom== 7) { tileLevel = 3; }
    else if (currentZoom== 8) { tileLevel = 4; }
    else if (currentZoom== 9) { tileLevel = 4; }
    else if (currentZoom==10) { tileLevel = 4; }
    else if (currentZoom==11) { tileLevel = 4; }
    else if (currentZoom==12) { tileLevel = 4; }
    else if (currentZoom==13) { tileLevel = 4; }
    else if (currentZoom==14) { tileLevel = 5; }
    else if (currentZoom==15) { tileLevel = 5; }
    else if (currentZoom==16) { tileLevel = 6; }
    else if (currentZoom==17) { tileLevel = 7; }
    else if (currentZoom==18) { tileLevel = 7; }
    else if (currentZoom==19) { tileLevel = 8; }
    else if (currentZoom==20) { tileLevel = 9; }
    else if (currentZoom==21) { tileLevel = 9; }
    else if (currentZoom==22) { tileLevel = 9; }
    else
    {
        tileLevel = TileIndex::MaxLevel-1;
    }

    KGEOMAP_ASSERT(tileLevel <= TileIndex::MaxLevel-1);

    return tileLevel;
}
Exemple #6
0
/**
 * @brief Wrapper around executeScript to catch more errors
 */
QVariant HTMLWidget::runScript(const QString& scriptCode)
{
    KGEOMAP_ASSERT(d->isReady);

    if (!d->isReady)
        return QVariant();

//     qCDebug(LIBKGEOMAP_LOG) << scriptCode;
    return page()->mainFrame()->evaluateJavaScript(scriptCode);
}
void BackendGoogleMaps::saveSettingsToGroup(KConfigGroup* const group)
{
    KGEOMAP_ASSERT(group != 0);

    if (!group)
        return;

    group->writeEntry("GoogleMaps Map Type", getMapType());
    group->writeEntry("GoogleMaps Show Map Type Control", d->cacheShowMapTypeControl);
    group->writeEntry("GoogleMaps Show Navigation Control", d->cacheShowNavigationControl);
    group->writeEntry("GoogleMaps Show Scale Control", d->cacheShowScaleControl);
}
void BackendGoogleMaps::readSettingsFromGroup(const KConfigGroup* const group)
{
    KGEOMAP_ASSERT(group != 0);

    if (!group)
        return;

    const QString mapType = group->readEntry("GoogleMaps Map Type", "ROADMAP");
    setMapType(mapType);
    setShowMapTypeControl(group->readEntry("GoogleMaps Show Map Type Control", true));
    setShowNavigationControl(group->readEntry("GoogleMaps Show Navigation Control", true));
    setShowScaleControl(group->readEntry("GoogleMaps Show Scale Control", true));
}
void BackendGoogleMaps::setZoom(const QString& newZoom)
{
    const QString myZoomString = s->worldMapWidget->convertZoomToBackendZoom(newZoom, QLatin1String("googlemaps"));
    KGEOMAP_ASSERT(myZoomString.startsWith(QLatin1String("googlemaps:")));

    const int myZoom           = myZoomString.mid(QString::fromLatin1("googlemaps:").length()).toInt();
    kDebug() << myZoom;

    d->cacheZoom               = myZoom;

    if (isReady())
    {
        d->htmlWidget->runScript(QString::fromLatin1("kgeomapSetZoom(%1);").arg(d->cacheZoom));
    }
}
Exemple #10
0
void BackendOSM::setZoom(const QString& newZoom)
{
    // zoom settings for OSM are basically the same as for Google Maps, so just re-use the prefix
    const QString myZoomString = s->worldMapWidget->convertZoomToBackendZoom(newZoom, "googlemaps");
    KGEOMAP_ASSERT(myZoomString.startsWith(QLatin1String("googlemaps:")));

    const int myZoom = myZoomString.mid(QLatin1String("googlemaps:").length()).toInt();
    qCDebug(LIBKGEOMAP_LOG) << myZoom;

    d->cacheZoom = myZoom;

    if (isReady())
    {
        d->htmlWidget->runScript(QString::fromLatin1("kgeomapSetZoom(%1);").arg(d->cacheZoom));
    }
}
void BackendGoogleMaps::updateClusters()
{
    kDebug() << "start updateclusters";
    // re-transfer the clusters to the map:
    KGEOMAP_ASSERT(isReady());

    if (!isReady())
        return;

    // TODO: only update clusters that have actually changed!

    // re-transfer all markers to the javascript-part:
    const bool canMoveItems = s->modificationsAllowed && s->markerModel->tilerFlags().testFlag(AbstractMarkerTiler::FlagMovable) && !s->showThumbnails;
    d->htmlWidget->runScript(QLatin1String("kgeomapClearClusters();"));
    d->htmlWidget->runScript(QString::fromLatin1("kgeomapSetIsInEditMode(%1);").arg(s->showThumbnails?QLatin1String("false" ):QLatin1String("true" )));

    for (int currentIndex = 0; currentIndex < s->clusterList.size(); ++currentIndex)
    {
        const KGeoMapCluster& currentCluster = s->clusterList.at(currentIndex);

        d->htmlWidget->runScript(QString::fromLatin1("kgeomapAddCluster(%1, %2, %3, %4, %5, %6);")
                .arg(currentIndex)
                .arg(currentCluster.coordinates.latString())
                .arg(currentCluster.coordinates.lonString())
                .arg(canMoveItems ? QLatin1String("true") : QLatin1String("false"))
                .arg(currentCluster.markerCount)
                .arg(currentCluster.markerSelectedCount)
            );

        // TODO: for now, only set generated pixmaps when not in edit mode
        // this can be changed once we figure out how to appropriately handle
        // the selection state changes when a marker is dragged
        if (s->showThumbnails)
        {
            QPoint clusterCenterPoint;
            // TODO: who calculates the override values?
            const QPixmap clusterPixmap = s->worldMapWidget->getDecoratedPixmapForCluster(currentIndex, 0, 0, &clusterCenterPoint);

            setClusterPixmap(currentIndex, clusterCenterPoint, clusterPixmap);
        }
    }
    kDebug()<<"end updateclusters";
}
Exemple #12
0
void BackendOSM::updateClusters()
{
    qCDebug(LIBKGEOMAP_LOG) << "start updateclusters";
    // re-transfer the clusters to the map:
    KGEOMAP_ASSERT(isReady());

    if (!isReady())
        return;

    // TODO: only update clusters that have actually changed!

    // re-transfer all markers to the javascript-part:
    d->htmlWidget->runScript(QLatin1String("kgeomapClearClusters();"));

    for (int currentIndex = 0; currentIndex < s->clusterList.size(); ++currentIndex)
    {
        const KGeoMapCluster& currentCluster = s->clusterList.at(currentIndex);

        // determine the colors:
        QColor       fillColor;
        QColor       strokeColor;
        Qt::PenStyle strokeStyle;
        QColor       labelColor;
        QString      labelText;
        s->worldMapWidget->getColorInfos(currentIndex, &fillColor, &strokeColor,
                                         &strokeStyle, &labelText, &labelColor);

        const QString fillColorName = fillColor.name();

        d->htmlWidget->runScript(QLatin1String("kgeomapAddCluster(%1, %2, %3, %4, '%5', '%6');")
                                 .arg(currentIndex)
                                 .arg(currentCluster.coordinates.latString())
                                 .arg(currentCluster.coordinates.lonString())
                                 .arg(true?"true":"false")
                                 .arg(fillColorName.mid(1))
                                 .arg(labelText)
                                );
    }

    qCDebug(LIBKGEOMAP_LOG) << "end updateclusters";
}
Exemple #13
0
void BackendOSM::updateMarkers()
{
    KGEOMAP_ASSERT(isReady());

    if (!isReady())
        return;

    // re-transfer all markers to the javascript-part:
    d->htmlWidget->runScript(QLatin1String("kgeomapClearMarkers();"));

    for (int row = 0; row < s->specialMarkersModel->rowCount(); ++row)
    {
        const QModelIndex currentIndex          = s->specialMarkersModel->index(row, 0);
        const GeoCoordinates currentCoordinates = s->specialMarkersModel->data(currentIndex, s->specialMarkersCoordinatesRole).value<GeoCoordinates>();

        d->htmlWidget->runScript(QLatin1String("kgeomapAddMarker(%1, %2, %3, %4);")
                                 .arg(row)
                                 .arg(currentCoordinates.latString())
                                 .arg(currentCoordinates.lonString())
                                 .arg(/*currentMarker.isDraggable()?*/"true"/*:"false"*/)
                                );
    }
}
QSize BackendGoogleMaps::mapSize() const
{
    KGEOMAP_ASSERT(d->htmlWidgetWrapper != 0);

    return d->htmlWidgetWrapper->size();
}
void BackendGoogleMaps::slotHTMLEvents(const QStringList& events)
{
    // for some events, we just note that they appeared and then process them later on:
    bool centerProbablyChanged    = false;
    bool mapTypeChanged           = false;
    bool zoomProbablyChanged      = false;
    bool mapBoundsProbablyChanged = false;
    QIntList movedClusters;
    QList<QPersistentModelIndex> movedMarkers;
    QIntList clickedClusters;

    // TODO: verify that the order of the events is still okay
    //       or that the order does not matter
    for (QStringList::const_iterator it = events.constBegin(); it != events.constEnd(); ++it)
    {
        const QString eventCode           = it->left(2);
        const QString eventParameter      = it->mid(2);
        const QStringList eventParameters = eventParameter.split(QLatin1Char( '/' ));

        if (eventCode == QLatin1String("MT"))
        {
            // map type changed
            mapTypeChanged  = true;
            d->cacheMapType = eventParameter;
        }
        else if (eventCode == QLatin1String("MB"))
        {   // NOTE: event currently disabled in javascript part
            // map bounds changed
            centerProbablyChanged    = true;
            zoomProbablyChanged      = true;
            mapBoundsProbablyChanged = true;
        }
        else if (eventCode == QLatin1String("ZC"))
        {   // NOTE: event currently disabled in javascript part
            // zoom changed
            zoomProbablyChanged      = true;
            mapBoundsProbablyChanged = true;
        }
        else if (eventCode == QLatin1String("id"))
        {
            // idle after drastic map changes
            centerProbablyChanged    = true;
            zoomProbablyChanged      = true;
            mapBoundsProbablyChanged = true;
        }
        else if (eventCode == QLatin1String("cm"))
        {
            /// @todo buffer this event type!
            // cluster moved
            bool okay              = false;
            const int clusterIndex = eventParameter.toInt(&okay);
            KGEOMAP_ASSERT(okay);

            if (!okay)
                continue;

            KGEOMAP_ASSERT(clusterIndex >= 0);
            KGEOMAP_ASSERT(clusterIndex<s->clusterList.size());

            if ((clusterIndex<0)||(clusterIndex>s->clusterList.size()))
                continue;

            // re-read the marker position:
            GeoCoordinates clusterCoordinates;
            const bool isValid = d->htmlWidget->runScript2Coordinates(
                    QString::fromLatin1("kgeomapGetClusterPosition(%1);").arg(clusterIndex),
                    &clusterCoordinates
                );

            KGEOMAP_ASSERT(isValid);

            if (!isValid)
                continue;

            /// @todo this discards the altitude!
            /// @todo is this really necessary? clusters should be regenerated anyway...
            s->clusterList[clusterIndex].coordinates = clusterCoordinates;

            movedClusters << clusterIndex;
        }
        else if (eventCode == QLatin1String("cs"))
        {
            /// @todo buffer this event type!
            // cluster snapped
            bool okay = false;
            const int clusterIndex = eventParameters.first().toInt(&okay);
            KGEOMAP_ASSERT(okay);

            if (!okay)
                continue;

            KGEOMAP_ASSERT(clusterIndex >= 0);
            KGEOMAP_ASSERT(clusterIndex<s->clusterList.size());

            if ((clusterIndex<0)||(clusterIndex>s->clusterList.size()))
                continue;

            // determine to which marker we snapped:
            okay                  = false;
            const int snapModelId = eventParameters.at(1).toInt(&okay);
            KGEOMAP_ASSERT(okay);

            if (!okay)
                continue;

            okay                   = false;
            const int snapMarkerId = eventParameters.at(2).toInt(&okay);
            KGEOMAP_ASSERT(okay);

            if (!okay)
                continue;

            /// @todo emit signal here or later?
            ModelHelper* const modelHelper  = s->ungroupedModels.at(snapModelId);
            QAbstractItemModel* const model = modelHelper->model();
            QPair<int, QModelIndex> snapTargetIndex(snapModelId, model->index(snapMarkerId, 0));
            emit(signalClustersMoved(QIntList()<<clusterIndex, snapTargetIndex));
        }
        else if (eventCode == QLatin1String("cc"))
        {
            /// @todo buffer this event type!
            // cluster clicked
            bool okay              = false;
            const int clusterIndex = eventParameter.toInt(&okay);
            KGEOMAP_ASSERT(okay);

            if (!okay)
                continue;

            KGEOMAP_ASSERT(clusterIndex>=0);
            KGEOMAP_ASSERT(clusterIndex<s->clusterList.size());

            if ((clusterIndex<0)||(clusterIndex>s->clusterList.size()))
                continue;

            clickedClusters << clusterIndex;
        }
        else if (eventCode == QLatin1String("mm"))
        {
//             // TODO: buffer this event type!
//             // marker moved
//             bool okay           = false;
//             const int markerRow = eventParameter.toInt(&okay);
//             KGEOMAP_ASSERT(okay);
//
//             if (!okay)
//                 continue;
//
//             KGEOMAP_ASSERT(markerRow >= 0);
//             KGEOMAP_ASSERT(markerRow<s->specialMarkersModel->rowCount());
//
//             if ((markerRow<0)||(markerRow>=s->specialMarkersModel->rowCount()))
//                 continue;
//
//             // re-read the marker position:
//             GeoCoordinates markerCoordinates;
//             const bool isValid = d->htmlWidget->runScript2Coordinates(
//                     QString::fromLatin1("kgeomapGetMarkerPosition(%1);").arg(markerRow),
//                     &markerCoordinates
//                 );
//
//             KGEOMAP_ASSERT(isValid);
//
//             if (!isValid)
//                 continue;
//
//             // TODO: this discards the altitude!
//             const QModelIndex markerIndex = s->specialMarkersModel->index(markerRow, 0);
//             s->specialMarkersModel->setData(markerIndex, QVariant::fromValue(markerCoordinates), s->specialMarkersCoordinatesRole);
//
//             movedMarkers << QPersistentModelIndex(markerIndex);
        }
        else if (eventCode == QLatin1String("do"))
        {
            // debug output:
            kDebug() << QString::fromLatin1("javascript:%1").arg(eventParameter);
        }
    }

    if (!movedClusters.isEmpty())
    {
        kDebug()<<movedClusters;
        emit(signalClustersMoved(movedClusters, QPair<int, QModelIndex>(-1, QModelIndex())));
    }

    if (!movedMarkers.isEmpty())
    {
        kDebug()<<movedMarkers;
//         emit(signalSpecialMarkersMoved(movedMarkers));
    }

    if (!clickedClusters.isEmpty())
    {
        kDebug()<<clickedClusters;
        emit(signalClustersClicked(clickedClusters));
    }

    // now process the buffered events:
    if (mapTypeChanged)
    {
        updateZoomMinMaxCache();
    }

    if (zoomProbablyChanged)
    {
        d->cacheZoom = d->htmlWidget->runScript(QLatin1String("kgeomapGetZoom();")).toInt();
        emit(signalZoomChanged(QString::fromLatin1("googlemaps:%1").arg(d->cacheZoom)));
    }

    if (centerProbablyChanged)
    {
        // there is nothing we can do if the coordinates are invalid
        /*const bool isValid = */d->htmlWidget->runScript2Coordinates(QLatin1String("kgeomapGetCenter();"), &(d->cacheCenter));
    }

    // update the actions if necessary:
    if (zoomProbablyChanged || mapTypeChanged || centerProbablyChanged)
    {
        updateActionAvailability();
    }

    if (mapBoundsProbablyChanged)
    {
        const QString mapBoundsString = d->htmlWidget->runScript(QLatin1String("kgeomapGetBounds();")).toString();
        KGeoMapHelperParseBoundsString(mapBoundsString, &d->cacheBounds);
    }

    if (mapBoundsProbablyChanged||!movedClusters.isEmpty())
    {
        s->worldMapWidget->markClustersAsDirty();
        s->worldMapWidget->updateClusters();
    }
}
void BackendGoogleMaps::slotUngroupedModelChanged(const int mindex)
{
    KGEOMAP_ASSERT(isReady());

    if (!isReady())
        return;

    d->htmlWidget->runScript(QString::fromLatin1("kgeomapClearMarkers(%1);").arg(mindex));

    // this can happen when a model was removed and we are simply asked to remove its markers
    if (mindex>s->ungroupedModels.count())
        return;

    ModelHelper* const modelHelper = s->ungroupedModels.at(mindex);

    if (!modelHelper)
        return;

    if (!modelHelper->modelFlags().testFlag(ModelHelper::FlagVisible))
        return;

    QAbstractItemModel* const model = modelHelper->model();

    for (int row = 0; row < model->rowCount(); ++row)
    {
        const QModelIndex currentIndex     = model->index(row, 0);
        const ModelHelper::Flags itemFlags = modelHelper->itemFlags(currentIndex);

        // TODO: this is untested! We need to make sure the indices stay correct inside the JavaScript part!
        if (!itemFlags.testFlag(ModelHelper::FlagVisible))
            continue;

        GeoCoordinates currentCoordinates;
        if (!modelHelper->itemCoordinates(currentIndex, &currentCoordinates))
            continue;

        // TODO: use the pixmap supplied by the modelHelper
        d->htmlWidget->runScript(QString::fromLatin1("kgeomapAddMarker(%1, %2, %3, %4, %5, %6);")
                .arg(mindex)
                .arg(row)
                .arg(currentCoordinates.latString())
                .arg(currentCoordinates.lonString())
                .arg(itemFlags.testFlag(ModelHelper::FlagMovable)?QLatin1String("true" ):QLatin1String("false"))
                .arg(itemFlags.testFlag(ModelHelper::FlagSnaps)?QLatin1String("true" ):QLatin1String("false"))
            );

        QPoint     markerCenterPoint;
        QSize      markerSize;
        QPixmap    markerPixmap;
        KUrl       markerUrl;
        const bool markerHasIcon = modelHelper->itemIcon(currentIndex, &markerCenterPoint,
                                                         &markerSize, &markerPixmap, &markerUrl);

        if (markerHasIcon)
        {
            if (!markerUrl.isEmpty())
            {
                setMarkerPixmap(mindex, row, markerCenterPoint, markerSize, markerUrl);
            }
            else
            {
                setMarkerPixmap(mindex, row, markerCenterPoint, markerPixmap);
            }
        }
    }

}