File indexing completed on 2024-04-28 03:49:28

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #ifndef MARBLE_ROUTINGINPUTWIDGET_H
0007 #define MARBLE_ROUTINGINPUTWIDGET_H
0008 
0009 #include "PositionProviderPluginInterface.h"
0010 
0011 #include <QWidget>
0012 
0013 class QAbstractItemModel;
0014 
0015 namespace Marble
0016 {
0017 
0018 class RoutingInputWidgetPrivate;
0019 class GeoDataCoordinates;
0020 class GeoDataPlacemark;
0021 class MarbleModel;
0022 class MarblePlacemarkModel;
0023 
0024 /**
0025   * Combines a line edit for input and a couple of buttons to let
0026   * the user type in a search term, find according placemarks using
0027   * the marble runner manager and store one of them as the current
0028   * selection (target position)
0029   */
0030 class RoutingInputWidget : public QWidget
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035 
0036     /** Constructor */
0037     explicit RoutingInputWidget( MarbleModel* model, int index, QWidget *parent = nullptr );
0038 
0039     /** Destructor */
0040     ~RoutingInputWidget() override;
0041 
0042     /**
0043       * Returns true if the user has selected a valid geo position
0044       * @see targetPosition
0045       */
0046     bool hasTargetPosition() const;
0047 
0048     /**
0049       * Returns the geoposition selected by the user, or a default
0050       * constructed geoposition if hasTargetPosition returns false
0051       * @see hasTargetPosition selectPlacemark
0052       */
0053     GeoDataCoordinates targetPosition() const;
0054 
0055     /**
0056       * Returns the placemark model that contains search results
0057       */
0058     MarblePlacemarkModel *searchResultModel();
0059 
0060     /**
0061       * Returns false iff the input text is empty
0062       */
0063     bool hasInput() const;
0064 
0065     /**
0066       * Change the data index in the route request model
0067       */
0068     void setIndex( int index );
0069 
0070     /**
0071       * Remove target position and user input, if any
0072       */
0073     void clear();
0074 
0075 public Q_SLOTS:
0076     /**
0077       * Search for placemarks matching the current input text. Does nothing
0078       * if input is empty
0079       */
0080     void findPlacemarks();
0081 
0082     /** Set the target position to the given coordinates,
0083       * eliminating any previously set positions
0084       * @see selectPlacemark hasTargetPosition
0085       */
0086     void setTargetPosition( const GeoDataCoordinates &position, const QString &name = QString() );
0087 
0088     /** Cancel a started input request from the map */
0089     void abortMapInputRequest();
0090 
0091     /** Reload the bookmarks menu */
0092     void reloadBookmarks();
0093 
0094 Q_SIGNALS:
0095     /** All runners are finished */
0096     void searchFinished( RoutingInputWidget * );
0097 
0098     /** User requests to remove this widget */
0099     void removalRequest( RoutingInputWidget * );
0100 
0101     /** User requests to activate this widget */
0102     void activityRequest( RoutingInputWidget * );
0103 
0104     /** User requests position input from the map */
0105     void mapInputModeEnabled( RoutingInputWidget *, bool enabled );
0106 
0107     /** hasTargetPosition changed because of selecting a placemark or changing the search term */
0108     void targetValidityChanged( bool targetValid );
0109 
0110 private Q_SLOTS:
0111     /** Runner progress */
0112     void setPlacemarkModel( QAbstractItemModel * );
0113 
0114     /** Handle click on the goto target button */
0115     void requestActivity();
0116 
0117     /** Handle click on the remove widget button */
0118     void requestRemoval();
0119 
0120     /** Handle click on the map input button */
0121     void setMapInputModeEnabled( bool enabled );
0122 
0123     /** All runners have completed */
0124     void finishSearch();
0125 
0126     /** Mark ourselves dirty (no target) */
0127     void setInvalid();
0128 
0129     /** Set the target position (dragging) */
0130     void updatePosition( int index, const GeoDataCoordinates &position );
0131 
0132     void reverseGeocoding();
0133 
0134     void retrieveReverseGeocodingResult( const GeoDataCoordinates &coordinates, const GeoDataPlacemark &placemark );
0135 
0136     void setHomePosition();
0137 
0138     void setCurrentLocation();
0139 
0140     void updateCurrentLocationButton( PositionProviderStatus status );
0141 
0142     void updateCenterButton( bool hasPosition );
0143 
0144     void setBookmarkPosition( QAction* bookmark );
0145 
0146     void openTargetSelectionDialog();
0147 
0148     void showMenu();
0149 
0150 private:
0151     RoutingInputWidgetPrivate *const d;
0152 };
0153 
0154 } // namespace Marble
0155 
0156 #endif