mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:50:05 +00:00 
			
		
		
		
	Position manager updates for tracking
This commit is contained in:
		
							parent
							
								
									400db66f09
								
							
						
					
					
						commit
						18f500fe5f
					
				
					 3 changed files with 29 additions and 17 deletions
				
			
		|  | @ -35,7 +35,6 @@ | |||
| 
 | ||||
| #include <boost/asio/post.hpp> | ||||
| #include <boost/asio/thread_pool.hpp> | ||||
| #include <boost/uuid/random_generator.hpp> | ||||
| #include <QDesktopServices> | ||||
| #include <QFileDialog> | ||||
| #include <QMessageBox> | ||||
|  | @ -63,7 +62,6 @@ class MainWindowImpl : public QObject | |||
| 
 | ||||
| public: | ||||
|    explicit MainWindowImpl(MainWindow* mainWindow) : | ||||
|        uuid_ {boost::uuids::random_generator()()}, | ||||
|        mainWindow_ {mainWindow}, | ||||
|        settings_ {}, | ||||
|        activeMap_ {nullptr}, | ||||
|  | @ -124,7 +122,7 @@ public: | |||
| 
 | ||||
|       if (settings::GeneralSettings::Instance().track_location().GetValue()) | ||||
|       { | ||||
|          positionManager_->TrackLocation(uuid_, true); | ||||
|          positionManager_->TrackLocation(true); | ||||
|       } | ||||
|    } | ||||
|    ~MainWindowImpl() { threadPool_.join(); } | ||||
|  | @ -155,8 +153,6 @@ public: | |||
| 
 | ||||
|    boost::asio::thread_pool threadPool_ {1u}; | ||||
| 
 | ||||
|    boost::uuids::uuid uuid_; | ||||
| 
 | ||||
|    MainWindow*           mainWindow_; | ||||
|    QMapLibreGL::Settings settings_; | ||||
|    map::MapProvider      mapProvider_; | ||||
|  | @ -872,13 +868,8 @@ void MainWindowImpl::ConnectOtherSignals() | |||
|               settings::GeneralSettings::Instance().track_location().StageValue( | ||||
|                  trackingEnabled); | ||||
| 
 | ||||
|               for (std::size_t i = 0; i < maps_.size(); ++i) | ||||
|               { | ||||
|                  // maps_[i]->SetTrackLocation(trackingEnabled);
 | ||||
|               } | ||||
| 
 | ||||
|               // Turn on location tracking (location manager)
 | ||||
|               positionManager_->TrackLocation(uuid_, trackingEnabled); | ||||
|               // Turn on location tracking
 | ||||
|               positionManager_->TrackLocation(trackingEnabled); | ||||
|            }); | ||||
|    connect(level2ProductsWidget_, | ||||
|            &ui::Level2ProductsWidget::RadarProductSelected, | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| 
 | ||||
| #include <set> | ||||
| 
 | ||||
| #include <boost/uuid/random_generator.hpp> | ||||
| #include <QGeoPositionInfoSource> | ||||
| 
 | ||||
| namespace scwx | ||||
|  | @ -19,7 +20,8 @@ static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | |||
| class PositionManager::Impl | ||||
| { | ||||
| public: | ||||
|    explicit Impl(PositionManager* self) : self_ {self} | ||||
|    explicit Impl(PositionManager* self) : | ||||
|        self_ {self}, trackingUuid_ {boost::uuids::random_generator()()} | ||||
|    { | ||||
|       // TODO: macOS requires permission
 | ||||
|       geoPositionInfoSource_ = | ||||
|  | @ -55,6 +57,9 @@ public: | |||
| 
 | ||||
|    PositionManager* self_; | ||||
| 
 | ||||
|    boost::uuids::uuid trackingUuid_; | ||||
|    bool               trackingEnabled_ {false}; | ||||
| 
 | ||||
|    std::set<boost::uuids::uuid> uuids_ {}; | ||||
| 
 | ||||
|    QGeoPositionInfoSource* geoPositionInfoSource_ {}; | ||||
|  | @ -69,15 +74,20 @@ QGeoPositionInfo PositionManager::position() const | |||
|    return p->position_; | ||||
| } | ||||
| 
 | ||||
| void PositionManager::TrackLocation(boost::uuids::uuid uuid, | ||||
|                                     bool               trackingEnabled) | ||||
| bool PositionManager::IsLocationTracked() | ||||
| { | ||||
|    return p->trackingEnabled_; | ||||
| } | ||||
| 
 | ||||
| void PositionManager::EnablePositionUpdates(boost::uuids::uuid uuid, | ||||
|                                             bool               enabled) | ||||
| { | ||||
|    if (p->geoPositionInfoSource_ == nullptr) | ||||
|    { | ||||
|       return; | ||||
|    } | ||||
| 
 | ||||
|    if (trackingEnabled) | ||||
|    if (enabled) | ||||
|    { | ||||
|       if (p->uuids_.empty()) | ||||
|       { | ||||
|  | @ -97,6 +107,13 @@ void PositionManager::TrackLocation(boost::uuids::uuid uuid, | |||
|    } | ||||
| } | ||||
| 
 | ||||
| void PositionManager::TrackLocation(bool trackingEnabled) | ||||
| { | ||||
|    p->trackingEnabled_ = trackingEnabled; | ||||
|    EnablePositionUpdates(p->trackingUuid_, trackingEnabled); | ||||
|    Q_EMIT LocationTrackingChanged(trackingEnabled); | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<PositionManager> PositionManager::Instance() | ||||
| { | ||||
|    static std::weak_ptr<PositionManager> positionManagerReference_ {}; | ||||
|  |  | |||
|  | @ -25,11 +25,15 @@ public: | |||
| 
 | ||||
|    QGeoPositionInfo position() const; | ||||
| 
 | ||||
|    void TrackLocation(boost::uuids::uuid uuid, bool trackingEnabled); | ||||
|    bool IsLocationTracked(); | ||||
| 
 | ||||
|    void EnablePositionUpdates(boost::uuids::uuid uuid, bool enabled); | ||||
|    void TrackLocation(bool trackingEnabled); | ||||
| 
 | ||||
|    static std::shared_ptr<PositionManager> Instance(); | ||||
| 
 | ||||
| signals: | ||||
|    void LocationTrackingChanged(bool trackingEnabled); | ||||
|    void PositionUpdated(const QGeoPositionInfo& info); | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat