void ImagePropertiesGPSTab::setGPSInfoList(const GPSImageInfo::List& list)
{
    // Clear info label
    d->altitude->clear();
    d->latitude->clear();
    d->longitude->clear();
    d->date->clear();
    d->gpsInfoList.clear();
    d->itemModel->clear();
    d->gpsInfoList = list;

    setEnabled(!list.isEmpty());

    if (list.isEmpty())
    {
        return;
    }

    if (list.count() == 1)
    {
        const GPSImageInfo info = list.first();
        const KGeoMap::GeoCoordinates& coordinates = info.coordinates;

        if (!coordinates.hasAltitude())
        {
            d->altitude->setText(i18n("Undefined"));
        }
        else
        {
            d->altitude->setText(QString("%1 m").arg(QString::number(coordinates.alt())));
        }

        d->latitude->setText(QString::number(coordinates.lat()));
        d->longitude->setText(QString::number(coordinates.lon()));
        d->date->setText(KGlobal::locale()->formatDateTime(info.dateTime,
                         KLocale::ShortDate, true));
    }

    for (int i=0; i<d->gpsInfoList.count(); ++i)
    {
        QStandardItem* const currentImageGPSItem = new QStandardItem();
        currentImageGPSItem->setData(QVariant::fromValue(d->gpsInfoList.at(i)), RoleGPSImageInfo);
        d->itemModel->appendRow(currentImageGPSItem);
    }

    if (!d->map->getStickyModeState())
    {
        if (!d->map->getActiveState())
        {
            d->boundariesShouldBeAdjusted = true;
        }
        else
        {
            d->boundariesShouldBeAdjusted = false;
            d->map->adjustBoundariesToGroupedMarkers();
        }
    }
}
Esempio n. 2
0
/**
 * @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;
        }
    }