void ImagePropertiesGPSTab::setMetadata(const DMetadata& meta, const KUrl& url) { double lat, lng; const bool haveCoordinates = meta.getGPSLatitudeNumber(&lat) && meta.getGPSLongitudeNumber(&lng); if (haveCoordinates) { double alt; const bool haveAlt = meta.getGPSAltitude(&alt); KGeoMap::GeoCoordinates coordinates(lat, lng); if (haveAlt) { coordinates.setAlt(alt); } GPSImageInfo gpsInfo; gpsInfo.coordinates = coordinates; gpsInfo.dateTime = meta.getImageDateTime(); gpsInfo.rating = meta.getImageRating(); gpsInfo.url = url; setGPSInfoList(GPSImageInfo::List() << gpsInfo); } else { clearGPSInfo(); } }
/** * @brief Gets the coordinates of a marker found at current model index. * @param index Current model index. * @param coordinates Here will be returned the coordinates of the current marker. * @return True, if the marker has coordinates. */ bool MapViewModelHelper::itemCoordinates(const QModelIndex& index, GeoIface::GeoCoordinates* const coordinates) const { switch (d->application) { case MapWidgetView::ApplicationDigikam: { const ImageInfo info = d->model->imageInfo(index); if (info.isNull() || !info.hasCoordinates()) { return false; } *coordinates = GeoIface::GeoCoordinates(info.latitudeNumber(), info.longitudeNumber()); break; } case MapWidgetView::ApplicationImportUI: { const CamItemInfo info = d->importModel->camItemInfo(index); if (info.isNull()) { return false; } const DMetadata meta(info.url().toLocalFile()); double lat, lng; const bool haveCoordinates = meta.getGPSLatitudeNumber(&lat) && meta.getGPSLongitudeNumber(&lng); if (!haveCoordinates) { return false; } GeoIface::GeoCoordinates tmpCoordinates(lat, lng); double alt; const bool haveAlt = meta.getGPSAltitude(&alt); if (haveAlt) { tmpCoordinates.setAlt(alt); } *coordinates = tmpCoordinates; break; } } return true; }
/** * @brief This function finds the best representative marker from a group of markers. This is needed to display a thumbnail for a marker group. * @param indices A list containing markers. * @param sortKey Determines the sorting options and is actually of type GPSImageInfoSorter::SortOptions * @return Returns the index of the marker. */ QPersistentModelIndex MapViewModelHelper::bestRepresentativeIndexFromList(const QList<QPersistentModelIndex>& list, const int sortKey) { if (list.isEmpty()) { return QPersistentModelIndex(); } // first convert from QPersistentModelIndex to QModelIndex QList<QModelIndex> indexList; QModelIndex bestIndex; for (int i=0; i < list.count(); ++i) { const QModelIndex newIndex(list.at(i)); indexList.append(newIndex); } switch (d->application) { case MapWidgetView::ApplicationDigikam: { // now get the ImageInfos and convert them to GPSImageInfos const QList<ImageInfo> imageInfoList = d->model->imageInfos(indexList); GPSImageInfo::List gpsImageInfoList; foreach(const ImageInfo& imageInfo, imageInfoList) { GPSImageInfo gpsImageInfo; if (ImagePropertiesSideBarDB::GPSImageInfofromImageInfo(imageInfo, &gpsImageInfo)) { gpsImageInfoList << gpsImageInfo; } } if (gpsImageInfoList.size()!=indexList.size()) { // this is a problem, and unexpected return indexList.first(); } // now determine the best available index bestIndex = indexList.first(); GPSImageInfo bestGPSImageInfo = gpsImageInfoList.first(); for (int i=1; i < gpsImageInfoList.count(); ++i) { const GPSImageInfo& currentInfo = gpsImageInfoList.at(i); if (GPSImageInfoSorter::fitsBetter(bestGPSImageInfo, GeoIface::SelectedNone, currentInfo, GeoIface::SelectedNone, GeoIface::SelectedNone, GPSImageInfoSorter::SortOptions(sortKey))) { bestIndex = indexList.at(i); bestGPSImageInfo = currentInfo; } } break; } case MapWidgetView::ApplicationImportUI: { // now get the CamItemInfo and convert them to GPSImageInfos const QList<CamItemInfo> imageInfoList = d->importModel->camItemInfos(indexList); GPSImageInfo::List gpsImageInfoList; foreach(const CamItemInfo& imageInfo, imageInfoList) { const DMetadata meta(imageInfo.url().toLocalFile()); double lat, lng; const bool hasCoordinates = meta.getGPSLatitudeNumber(&lat) && meta.getGPSLongitudeNumber(&lng); if (!hasCoordinates) { continue; } GeoIface::GeoCoordinates coordinates(lat, lng); double alt; const bool haveAlt = meta.getGPSAltitude(&alt); if (haveAlt) { coordinates.setAlt(alt); } GPSImageInfo gpsImageInfo; gpsImageInfo.coordinates = coordinates; gpsImageInfo.dateTime = meta.getImageDateTime(); gpsImageInfo.rating = meta.getImageRating(); gpsImageInfo.url = imageInfo.url(); gpsImageInfoList << gpsImageInfo; } if (gpsImageInfoList.size()!=indexList.size()) { // this is a problem, and unexpected return indexList.first(); } // now determine the best available index bestIndex = indexList.first(); GPSImageInfo bestGPSImageInfo = gpsImageInfoList.first(); for (int i=1; i < gpsImageInfoList.count(); ++i) { const GPSImageInfo& currentInfo = gpsImageInfoList.at(i); if (GPSImageInfoSorter::fitsBetter(bestGPSImageInfo, GeoIface::SelectedNone, currentInfo, GeoIface::SelectedNone, GeoIface::SelectedNone, GPSImageInfoSorter::SortOptions(sortKey))) { bestIndex = indexList.at(i); bestGPSImageInfo = currentInfo; } } break; } }