mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:50:06 +00:00 
			
		
		
		
	Modify usage of get_marker for updated interface, and update checks for lat/lon input
This commit is contained in:
		
							parent
							
								
									0ec81e5832
								
							
						
					
					
						commit
						0cfad82933
					
				
					 2 changed files with 30 additions and 34 deletions
				
			
		|  | @ -57,10 +57,14 @@ void MarkerLayer::Impl::ReloadMarkers() | |||
| 
 | ||||
|    for (size_t i = 0; i < markerManager->marker_count(); i++) | ||||
|    { | ||||
|       const types::MarkerInfo& marker = markerManager->get_marker(i); | ||||
|       std::optional<types::MarkerInfo> marker = markerManager->get_marker(i); | ||||
|       if (!marker) | ||||
|       { | ||||
|          break; | ||||
|       } | ||||
|       std::shared_ptr<gl::draw::GeoIconDrawItem> icon = geoIcons_->AddIcon(); | ||||
|       geoIcons_->SetIconTexture(icon, markerIconName_, 0); | ||||
|       geoIcons_->SetIconLocation(icon, marker.latitude, marker.longitude); | ||||
|       geoIcons_->SetIconLocation(icon, marker->latitude, marker->longitude); | ||||
|    } | ||||
| 
 | ||||
|    geoIcons_->FinishIcons(); | ||||
|  |  | |||
|  | @ -87,15 +87,17 @@ QVariant MarkerModel::data(const QModelIndex& index, int role) const | |||
|    static const char COORDINATE_FORMAT    = 'g'; | ||||
|    static const int  COORDINATE_PRECISION = 6; | ||||
| 
 | ||||
|    if (!index.isValid() || index.row() < 0 || | ||||
|        static_cast<std::size_t>(index.row()) >= | ||||
|           p->markerManager_->marker_count()) | ||||
|    if (!index.isValid() || index.row() < 0) | ||||
|    { | ||||
|       return QVariant(); | ||||
|    } | ||||
| 
 | ||||
|    const types::MarkerInfo markerInfo = | ||||
|    std::optional<types::MarkerInfo> markerInfo = | ||||
|       p->markerManager_->get_marker(index.row()); | ||||
|    if (!markerInfo) | ||||
|    { | ||||
|       return QVariant(); | ||||
|    } | ||||
| 
 | ||||
|    switch(index.column()) | ||||
|    { | ||||
|  | @ -104,7 +106,7 @@ QVariant MarkerModel::data(const QModelIndex& index, int role) const | |||
|           role == Qt::ItemDataRole::ToolTipRole || | ||||
|           role == Qt::ItemDataRole::EditRole) | ||||
|       { | ||||
|          return QString::fromStdString(markerInfo.name); | ||||
|          return QString::fromStdString(markerInfo->name); | ||||
|       } | ||||
|       break; | ||||
| 
 | ||||
|  | @ -114,7 +116,7 @@ QVariant MarkerModel::data(const QModelIndex& index, int role) const | |||
|           role == Qt::ItemDataRole::EditRole) | ||||
|       { | ||||
|          return QString::number( | ||||
|             markerInfo.latitude, COORDINATE_FORMAT, COORDINATE_PRECISION); | ||||
|             markerInfo->latitude, COORDINATE_FORMAT, COORDINATE_PRECISION); | ||||
|       } | ||||
|       break; | ||||
| 
 | ||||
|  | @ -124,7 +126,7 @@ QVariant MarkerModel::data(const QModelIndex& index, int role) const | |||
|           role == Qt::ItemDataRole::EditRole) | ||||
|       { | ||||
|          return QString::number( | ||||
|             markerInfo.longitude, COORDINATE_FORMAT, COORDINATE_PRECISION); | ||||
|             markerInfo->longitude, COORDINATE_FORMAT, COORDINATE_PRECISION); | ||||
|       } | ||||
|       break; | ||||
| 
 | ||||
|  | @ -167,14 +169,16 @@ bool MarkerModel::setData(const QModelIndex& index, | |||
|                           const QVariant&    value, | ||||
|                           int                role) | ||||
| { | ||||
|    if (!index.isValid() || index.row() < 0 || | ||||
|        static_cast<std::size_t>(index.row()) >= | ||||
|           p->markerManager_->marker_count()) | ||||
|    if (!index.isValid() || index.row() < 0) | ||||
|    { | ||||
|       return false; | ||||
|    } | ||||
|    std::optional<types::MarkerInfo> markerInfo = | ||||
|       p->markerManager_->get_marker(index.row()); | ||||
|    if (!markerInfo) | ||||
|    { | ||||
|       return false; | ||||
|    } | ||||
| 
 | ||||
|    types::MarkerInfo markerInfo = p->markerManager_->get_marker(index.row()); | ||||
|    bool result = false; | ||||
| 
 | ||||
|    switch(index.column()) | ||||
|  | @ -183,8 +187,8 @@ bool MarkerModel::setData(const QModelIndex& index, | |||
|       if (role == Qt::ItemDataRole::EditRole) | ||||
|       { | ||||
|          QString str = value.toString(); | ||||
|          markerInfo.name = str.toStdString(); | ||||
|          p->markerManager_->set_marker(index.row(), markerInfo); | ||||
|          markerInfo->name = str.toStdString(); | ||||
|          p->markerManager_->set_marker(index.row(), *markerInfo); | ||||
|          result = true; | ||||
|       } | ||||
|       break; | ||||
|  | @ -195,16 +199,10 @@ bool MarkerModel::setData(const QModelIndex& index, | |||
|          QString str = value.toString(); | ||||
|          bool ok; | ||||
|          double latitude = str.toDouble(&ok); | ||||
|          if (str.isEmpty()) | ||||
|          if (ok && str.isEmpty() && -90 <= latitude && latitude <= 90) | ||||
|          { | ||||
|             markerInfo.latitude = 0; | ||||
|             p->markerManager_->set_marker(index.row(), markerInfo); | ||||
|             result = true; | ||||
|          } | ||||
|          else if (ok) | ||||
|          { | ||||
|             markerInfo.latitude = latitude; | ||||
|             p->markerManager_->set_marker(index.row(), markerInfo); | ||||
|             markerInfo->latitude = latitude; | ||||
|             p->markerManager_->set_marker(index.row(), *markerInfo); | ||||
|             result = true; | ||||
|          } | ||||
|       } | ||||
|  | @ -216,16 +214,10 @@ bool MarkerModel::setData(const QModelIndex& index, | |||
|          QString str = value.toString(); | ||||
|          bool ok; | ||||
|          double longitude = str.toDouble(&ok); | ||||
|          if (str.isEmpty()) | ||||
|          if (str.isEmpty() && ok && -180 <= longitude && longitude <= 180) | ||||
|          { | ||||
|             markerInfo.longitude = 0; | ||||
|             p->markerManager_->set_marker(index.row(), markerInfo); | ||||
|             result = true; | ||||
|          } | ||||
|          else if (ok) | ||||
|          { | ||||
|             markerInfo.longitude = longitude; | ||||
|             p->markerManager_->set_marker(index.row(), markerInfo); | ||||
|             markerInfo->longitude = longitude; | ||||
|             p->markerManager_->set_marker(index.row(), *markerInfo); | ||||
|             result = true; | ||||
|          } | ||||
|       } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AdenKoperczak
						AdenKoperczak