diff --git a/Map/GeoCoordinates.cpp b/Map/GeoCoordinates.cpp index eb3c2078..79ec1eee 100644 --- a/Map/GeoCoordinates.cpp +++ b/Map/GeoCoordinates.cpp @@ -1,71 +1,70 @@ /* Copyright (C) 2018 Tobias Leupold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "GeoCoordinates.h" bool Map::GeoCoordinates::hasCoordinates() const { - return m_kgeomapCoordinates.hasCoordinates(); + return m_hasCoordinates; } double Map::GeoCoordinates::lon() const { - return m_kgeomapCoordinates.lon(); + return m_lon; } double Map::GeoCoordinates::lat() const { - return m_kgeomapCoordinates.lat(); + return m_lat; } double Map::GeoCoordinates::alt() const { - return m_kgeomapCoordinates.alt(); + return m_alt; } bool Map::GeoCoordinates::hasAltitude() const { - return m_kgeomapCoordinates.hasAltitude(); -} - -KGeoMap::GeoCoordinates Map::GeoCoordinates::kgeomapCoordinates() const -{ - return m_kgeomapCoordinates; + return m_hasAlt; } void Map::GeoCoordinates::setLatLon(const double lat, const double lon) { - m_kgeomapCoordinates.setLatLon( lat, lon ); + m_lat = lat; + m_lon = lon; + m_hasCoordinates = true; } void Map::GeoCoordinates::setAlt(const double alt) { - m_kgeomapCoordinates.setAlt( alt ); + m_alt = alt; + m_hasAlt = true; } -Map::GeoCoordinates::Pair Map::GeoCoordinates::makePair( const qreal lat1, const qreal lon1, const qreal lat2, const qreal lon2 ) +Map::GeoCoordinates::Pair Map::GeoCoordinates::makePair(const double lat1, const double lon1, + const double lat2, const double lon2) { Map::GeoCoordinates coordinates1; coordinates1.setLatLon(lat1, lon1); Map::GeoCoordinates coordinates2; coordinates2.setLatLon(lat2, lon2); return Pair(coordinates1, coordinates2); } // vi:expandtab:tabstop=4 shiftwidth=4: diff --git a/Map/GeoCoordinates.h b/Map/GeoCoordinates.h index 2395ca1e..05aeefbf 100644 --- a/Map/GeoCoordinates.h +++ b/Map/GeoCoordinates.h @@ -1,54 +1,58 @@ /* Copyright (C) 2018 Tobias Leupold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef GEOCOORDINATES_H #define GEOCOORDINATES_H -// Libkgeomap includes #include namespace Map { class GeoCoordinates { public: bool hasCoordinates() const; double lon() const; double lat() const; double alt() const; bool hasAltitude() const; - KGeoMap::GeoCoordinates kgeomapCoordinates() const; void setLatLon(const double lat, const double lon); void setAlt(const double alt); + typedef QPair Pair; - static Pair makePair( const qreal lat1, const qreal lon1, const qreal lat2, const qreal lon2 ); + static Pair makePair(const double lat1, const double lon1, + const double lat2, const double lon2); private: // Variables - KGeoMap::GeoCoordinates m_kgeomapCoordinates; + double m_lat; + double m_lon; + double m_alt; + bool m_hasCoordinates; + bool m_hasAlt; }; } Q_DECLARE_METATYPE(Map::GeoCoordinates::Pair) #endif // GEOCOORDINATES_H // vi:expandtab:tabstop=4 shiftwidth=4: diff --git a/Map/MapMarkerModelHelper.cpp b/Map/MapMarkerModelHelper.cpp index ebf5c583..86198f6f 100644 --- a/Map/MapMarkerModelHelper.cpp +++ b/Map/MapMarkerModelHelper.cpp @@ -1,132 +1,136 @@ /* Copyright (C) 2014-2018 Johannes Zarl-Zierl This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "MapMarkerModelHelper.h" #include "Logging.h" // Qt includes #include #include #include // Local includes #include +// libkgeomap includes +#include + const int FileNameRole = Qt::UserRole + 1; Map::MapMarkerModelHelper::MapMarkerModelHelper() : m_itemModel(0) , m_itemSelectionModel(0) { m_itemModel = new QStandardItemModel(1, 1); m_itemSelectionModel = new QItemSelectionModel(m_itemModel); connect(m_itemModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(slotDataChanged(QModelIndex, QModelIndex))); } Map::MapMarkerModelHelper::~MapMarkerModelHelper() { delete m_itemSelectionModel; delete m_itemModel; } void Map::MapMarkerModelHelper::clearItems() { m_itemModel->clear(); } void Map::MapMarkerModelHelper::addImage(const DB::ImageInfo &image) { qCDebug(MapLog) << "Adding marker for image " << image.label(); QStandardItem *const newItem = new QStandardItem(image.label()); newItem->setToolTip( image.label() ); newItem->setData( QVariant::fromValue( image.fileName() ), FileNameRole ); m_itemModel->appendRow( newItem ); } void Map::MapMarkerModelHelper::addImage( const DB::ImageInfoPtr image ) { addImage( *image ); } void Map::MapMarkerModelHelper::slotDataChanged(const QModelIndex &, const QModelIndex &) { emit( signalModelChangedDrastically() ); } bool Map::MapMarkerModelHelper::itemCoordinates(const QModelIndex &index, KGeoMap::GeoCoordinates *const coordinates) const { if (!index.data(FileNameRole).canConvert()) { return false; } if ( coordinates ) { const DB::FileName filename = index.data( FileNameRole ).value(); - *coordinates = filename.info()->coordinates().kgeomapCoordinates(); + *coordinates = KGeoMap::GeoCoordinates( filename.info()->coordinates().lat(), + filename.info()->coordinates().lon() ); } return true; } QAbstractItemModel *Map::MapMarkerModelHelper::model() const { return m_itemModel; } QItemSelectionModel *Map::MapMarkerModelHelper::selectionModel() const { return m_itemSelectionModel; } KGeoMap::ModelHelper::Flags Map::MapMarkerModelHelper::modelFlags() const { return FlagVisible; } KGeoMap::ModelHelper::Flags Map::MapMarkerModelHelper::itemFlags( const QModelIndex& index ) const { if (!index.data(FileNameRole).canConvert()) { return FlagNull; } return FlagVisible; } // FIXME: for some reason, itemIcon is never called -> no thumbnails bool Map::MapMarkerModelHelper::itemIcon(const QModelIndex &index, QPoint *const offset, QSize *const, QPixmap *const pixmap, QUrl *const) const { if (!index.data(FileNameRole).canConvert()) { return false; } const DB::FileName filename = index.data(FileNameRole).value(); *pixmap = ImageManager::ThumbnailCache::instance()->lookup(filename); *offset = QPoint(pixmap->width() / 2, pixmap->height() / 2); qCDebug(MapLog) << "Map icon for " << filename.relative() << (pixmap->isNull() ? " missing." : " found."); return !pixmap->isNull(); } // vi:expandtab:tabstop=4 shiftwidth=4: diff --git a/Map/MapView.cpp b/Map/MapView.cpp index 2d8bee0d..50138f55 100644 --- a/Map/MapView.cpp +++ b/Map/MapView.cpp @@ -1,244 +1,245 @@ /* Copyright (C) 2014-2018 Tobias Leupold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "MapView.h" #include "Logging.h" // Qt includes #include #include #include #include #include // KDE includes #include #include #include #include #include // Libkgeomap includes +#include #include // Local includes #include "MapMarkerModelHelper.h" #include "SearchMarkerTiler.h" Map::MapView::MapView(QWidget *parent, UsageType type) : QWidget(parent) { if (type == MapViewWindow) { setWindowFlags(Qt::Window); setAttribute(Qt::WA_DeleteOnClose); } QVBoxLayout *layout = new QVBoxLayout(this); m_statusLabel = new QLabel; m_statusLabel->setAlignment(Qt::AlignCenter); m_statusLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); m_statusLabel->hide(); layout->addWidget(m_statusLabel); m_mapWidget = new KGeoMap::MapWidget( this ); layout->addWidget(m_mapWidget); QWidget *controlWidget = m_mapWidget->getControlWidget(); controlWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); layout->addWidget(controlWidget); m_mapWidget->setActive(true); QPushButton *saveButton = new QPushButton; saveButton->setIcon(QPixmap(SmallIcon(QString::fromUtf8("media-floppy")))); saveButton->setToolTip(i18n("Save the current map settings")); m_mapWidget->addWidgetToControlWidget( saveButton ); connect(saveButton, &QPushButton::clicked, this, &MapView::saveSettings); m_setLastCenterButton = new QPushButton; m_setLastCenterButton->setIcon( QPixmap( SmallIcon( QString::fromUtf8( "go-first" ) ) ) ); m_setLastCenterButton->setToolTip(i18n("Go to last map position")); m_mapWidget->addWidgetToControlWidget( m_setLastCenterButton ); connect(m_setLastCenterButton, &QPushButton::clicked, this, &MapView::setLastCenter); // We first try set the default backend "marble" or the first one available ... const QString defaultBackend = QString::fromUtf8( "marble" ); auto backends = m_mapWidget->availableBackends(); if ( backends.contains( defaultBackend ) ) { m_mapWidget->setBackend( defaultBackend ); } else { qCDebug( MapLog ) << "AnnotationMap: using backend " << backends[0]; m_mapWidget->setBackend( backends[0] ); } // ... then we try to set the (probably) saved settings KConfigGroup configGroup = KSharedConfig::openConfig()->group(QString::fromUtf8("MapView")); m_mapWidget->readSettingsFromGroup(&configGroup); // Add the item model for the coordinates display m_modelHelper = new MapMarkerModelHelper(); m_itemMarkerTiler = new SearchMarkerTiler( m_modelHelper, this ); m_mapWidget->setGroupedModel( m_itemMarkerTiler ); connect( m_mapWidget, &KGeoMap::MapWidget::signalRegionSelectionChanged, this, &MapView::signalRegionSelectionChanged ); } Map::MapView::~MapView() { delete m_modelHelper; delete m_itemMarkerTiler; } void Map::MapView::clear() { m_modelHelper->clearItems(); } void Map::MapView::addImage(const DB::ImageInfo &image) { m_modelHelper->addImage( image ); } void Map::MapView::addImage( const DB::ImageInfoPtr image ) { m_modelHelper->addImage( image ); } void Map::MapView::zoomToMarkers() { if (m_modelHelper->model()->rowCount() > 0) { m_mapWidget->adjustBoundariesToGroupedMarkers(); } KGeoMap::GeoCoordinates kgeomapCenter = m_mapWidget->getCenter(); Map::GeoCoordinates center; center.setLatLon( kgeomapCenter.lat(), kgeomapCenter.lon() ); m_lastCenter = center; } void Map::MapView::setCenter(const DB::ImageInfo &image) { m_lastCenter = image.coordinates(); - m_mapWidget->setCenter( m_lastCenter.kgeomapCoordinates() ); + m_mapWidget->setCenter( KGeoMap::GeoCoordinates( m_lastCenter.lat(), m_lastCenter.lon() ) ); } void Map::MapView::setCenter(const DB::ImageInfoPtr image) { m_lastCenter = image->coordinates(); - m_mapWidget->setCenter( m_lastCenter.kgeomapCoordinates() ); + m_mapWidget->setCenter( KGeoMap::GeoCoordinates( m_lastCenter.lat(), m_lastCenter.lon() ) ); } void Map::MapView::saveSettings() { KSharedConfigPtr config = KSharedConfig::openConfig(); KConfigGroup configGroup = config->group( QString::fromUtf8( "MapView" ) ); m_mapWidget->saveSettingsToGroup( &configGroup ); config->sync(); KMessageBox::information( this, i18n( "Settings saved" ), i18n( "Map view" ) ); } void Map::MapView::setShowThumbnails(bool state) { m_mapWidget->setShowThumbnails( state ); } void Map::MapView::displayStatus(MapStatus status) { switch (status) { case MapStatus::Loading: m_statusLabel->setText(i18n("Loading coordinates from the images ...")); m_statusLabel->show(); m_mapWidget->hide(); m_mapWidget->clearRegionSelection(); m_setLastCenterButton->setEnabled(false); break; case MapStatus::ImageHasCoordinates: m_statusLabel->hide(); m_mapWidget->setAvailableMouseModes( KGeoMap::MouseModePan ); m_mapWidget->setVisibleMouseModes( 0 ); m_mapWidget->setMouseMode( KGeoMap::MouseModePan ); m_mapWidget->clearRegionSelection(); m_mapWidget->show(); m_setLastCenterButton->show(); m_setLastCenterButton->setEnabled(true); break; case MapStatus::ImageHasNoCoordinates: m_statusLabel->setText(i18n("This image does not contain geographic coordinates.")); m_statusLabel->show(); m_mapWidget->hide(); m_setLastCenterButton->show(); m_setLastCenterButton->setEnabled(false); break; case MapStatus::SomeImagesHaveNoCoordinates: m_statusLabel->setText(i18n("Some of the selected images do not contain geographic " "coordinates.")); m_statusLabel->show(); m_mapWidget->setAvailableMouseModes( KGeoMap::MouseModePan ); m_mapWidget->setVisibleMouseModes( 0 ); m_mapWidget->setMouseMode( KGeoMap::MouseModePan ); m_mapWidget->clearRegionSelection(); m_mapWidget->show(); m_setLastCenterButton->show(); m_setLastCenterButton->setEnabled(true); break; case MapStatus::SearchCoordinates: m_statusLabel->setText(i18n("Search for geographic coordinates.")); m_statusLabel->show(); m_mapWidget->setAvailableMouseModes( KGeoMap::MouseModePan | KGeoMap::MouseModeRegionSelectionFromIcon | KGeoMap::MouseModeRegionSelection ); m_mapWidget->setVisibleMouseModes( KGeoMap::MouseModePan | KGeoMap::MouseModeRegionSelectionFromIcon | KGeoMap::MouseModeRegionSelection ); m_mapWidget->setMouseMode( KGeoMap::MouseModeRegionSelectionFromIcon ); m_mapWidget->show(); m_mapWidget->setCenter( KGeoMap::GeoCoordinates() ); m_setLastCenterButton->hide(); break; case MapStatus::NoImagesHaveNoCoordinates: m_statusLabel->setText(i18n("None of the selected images contain geographic " "coordinates.")); m_statusLabel->show(); m_mapWidget->hide(); m_setLastCenterButton->show(); m_setLastCenterButton->setEnabled(false); break; } emit displayStatusChanged(status); } void Map::MapView::setLastCenter() { - m_mapWidget->setCenter( m_lastCenter.kgeomapCoordinates() ); + m_mapWidget->setCenter( KGeoMap::GeoCoordinates( m_lastCenter.lat(), m_lastCenter.lon() ) ); } Map::GeoCoordinates::Pair Map::MapView::getRegionSelection() const { KGeoMap::GeoCoordinates::Pair kgeomapCoordinates = m_mapWidget->getRegionSelection(); return GeoCoordinates::makePair( kgeomapCoordinates.first.lon(), kgeomapCoordinates.first.lat(), kgeomapCoordinates.second.lon(), kgeomapCoordinates.second.lat() ); } bool Map::MapView::regionSelected() const { return m_mapWidget->getRegionSelection().first.hasCoordinates() && m_mapWidget->getRegionSelection().second.hasCoordinates(); } // vi:expandtab:tabstop=4 shiftwidth=4: