bool BackendOSM::screenCoordinates(const GeoCoordinates& coordinates, QPoint* const point) { if (!d->isReady) return false; const bool isValid = KGeoMapHelperParseXYStringToPoint( d->htmlWidget->runScript(QLatin1String("kgeomapLatLngToPixel(%1, %2);") .arg(coordinates.latString()) .arg(coordinates.lonString())) .toString(), point); // TODO: apparently, even points outside the visible area are returned as valid // check whether they are actually visible return isValid; }
void GPSSyncDialog::slotImageActivated(const QModelIndex& index) { d->detailsWidget->slotSetCurrentImage(index); if (!index.isValid()) return; KipiImageItem* const item = d->imageModel->itemFromIndex(index); if (!item) return; const GeoCoordinates imageCoordinates = item->coordinates(); if (imageCoordinates.hasCoordinates()) { d->mapWidget->setCenter(imageCoordinates); } }
void BackendOSM::setCenter(const GeoCoordinates& coordinate) { qCDebug(LIBKGEOMAP_LOG) << isReady() << coordinate.geoUrl(); d->cacheCenter = coordinate; if (isReady()) { d->htmlWidget->runScript(QString::fromLatin1("kgeomapSetCenter(%1, %2);").arg(d->cacheCenter.latString()) .arg(d->cacheCenter.lonString())); } }
void BackendOSM::updateMarkers() { KMAP_ASSERT(isReady()); if (!isReady()) return; // re-transfer all markers to the javascript-part: d->htmlWidget->runScript(QLatin1String("kmapClearMarkers();")); 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("kmapAddMarker(%1, %2, %3, %4);") .arg(row) .arg(currentCoordinates.latString()) .arg(currentCoordinates.lonString()) .arg(/*currentMarker.isDraggable()?*/"true"/*:"false"*/) ); } }
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, ¤tCoordinates)) 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); } } } }