|
78 | 78 |
|
79 | 79 | // IWYU pragma: no_forward_declare QRectF |
80 | 80 |
|
| 81 | +#ifdef Q_OS_ANDROID |
| 82 | +#include "core/storage_location.h" |
| 83 | +#endif |
| 84 | + |
81 | 85 |
|
82 | 86 | namespace OpenOrienteering { |
83 | 87 |
|
@@ -694,6 +698,15 @@ bool Map::exportTo(const QString& path, MapView* view, const FileFormat* format) |
694 | 698 | } |
695 | 699 |
|
696 | 700 | success = file.commit(); |
| 701 | +#ifdef Q_OS_ANDROID |
| 702 | + if (success) |
| 703 | + { |
| 704 | + // Make the MediaScanner aware of the *updated* file. This is an |
| 705 | + // attempt to resolve issues with files being transferred |
| 706 | + // incompletely to the PC (#1115). |
| 707 | + Android::mediaScannerScanFile(QFileInfo(path).absolutePath()); |
| 708 | + } |
| 709 | +#endif |
697 | 710 | } |
698 | 711 |
|
699 | 712 | if (!success) |
@@ -2239,96 +2252,45 @@ void Map::setCurrentPartIndex(std::size_t index) |
2239 | 2252 | } |
2240 | 2253 | } |
2241 | 2254 |
|
2242 | | -std::size_t Map::reassignObjectsToMapPart(std::set<Object*>::const_iterator begin, std::set<Object*>::const_iterator end, std::size_t source, std::size_t destination) |
2243 | | -{ |
2244 | | - Q_ASSERT(source < parts.size()); |
2245 | | - Q_ASSERT(destination < parts.size()); |
2246 | | - |
2247 | | - std::size_t count = 0; |
2248 | | - MapPart* const source_part = parts[source]; |
2249 | | - MapPart* const target_part = parts[destination]; |
2250 | | - for (auto it = begin; it != end; ++it) |
2251 | | - { |
2252 | | - Object* const object = *it; |
2253 | | - source_part->deleteObject(object, true); |
2254 | | - |
2255 | | - int index = target_part->getNumObjects(); |
2256 | | - target_part->addObject(object, index); |
2257 | | - |
2258 | | - ++count; |
2259 | | - } |
2260 | | - |
2261 | | - setOtherDirty(); |
2262 | | - |
2263 | | - std::size_t const target_end = target_part->getNumObjects(); |
2264 | | - std::size_t const target_begin = target_end - count; |
2265 | | - |
2266 | | - if (current_part_index == source) |
2267 | | - { |
2268 | | - int const selection_size = getNumSelectedObjects(); |
2269 | | - |
2270 | | - // When modifying the selection we must not use the original iterators |
2271 | | - // because they may be operating on the selection and then become invalid! |
2272 | | - for (std::size_t i = target_begin; i != target_end; ++i) |
2273 | | - { |
2274 | | - Object* const object = target_part->getObject(i); |
2275 | | - if (isObjectSelected(object)) |
2276 | | - removeObjectFromSelection(object, false); |
2277 | | - } |
2278 | | - |
2279 | | - if (selection_size != getNumSelectedObjects()) |
2280 | | - emit objectSelectionChanged(); |
2281 | | - } |
2282 | | - |
2283 | | - return target_begin; |
2284 | | -} |
2285 | | - |
2286 | | -std::size_t Map::reassignObjectsToMapPart(std::vector<int>::const_iterator begin, std::vector<int>::const_iterator end, std::size_t source, std::size_t destination) |
| 2255 | +int Map::reassignObjectsToMapPart(std::vector<int>::const_iterator first, std::vector<int>::const_iterator last, std::size_t source, std::size_t destination) |
2287 | 2256 | { |
2288 | 2257 | Q_ASSERT(source < parts.size()); |
2289 | 2258 | Q_ASSERT(destination < parts.size()); |
2290 | 2259 |
|
2291 | | - bool selection_changed = false; |
2292 | | - |
2293 | | - std::size_t count = 0; |
2294 | 2260 | MapPart* const source_part = parts[source]; |
2295 | 2261 | MapPart* const target_part = parts[destination]; |
2296 | | - for (auto it = begin; it != end; ++it) |
| 2262 | + auto first_object = target_part->getNumObjects(); |
| 2263 | + auto selection_size = getNumSelectedObjects(); |
| 2264 | + for (auto it = first; it != last; ++it) |
2297 | 2265 | { |
| 2266 | + Q_ASSERT(*it < source_part->getNumObjects()); |
2298 | 2267 | Object* const object = source_part->getObject(*it); |
2299 | 2268 |
|
2300 | 2269 | if (current_part_index == source && isObjectSelected(object)) |
2301 | | - { |
2302 | 2270 | removeObjectFromSelection(object, false); |
2303 | | - selection_changed = true; |
2304 | | - } |
2305 | 2271 |
|
2306 | 2272 | source_part->deleteObject(object, true); |
2307 | | - |
2308 | | - int index = target_part->getNumObjects(); |
2309 | | - target_part->addObject(object, index); |
2310 | | - |
2311 | | - ++count; |
| 2273 | + target_part->addObject(object); |
2312 | 2274 | } |
2313 | 2275 |
|
2314 | 2276 | setOtherDirty(); |
2315 | 2277 |
|
2316 | | - if (selection_changed) |
| 2278 | + if (getNumSelectedObjects() != selection_size) |
2317 | 2279 | emit objectSelectionChanged(); |
2318 | 2280 |
|
2319 | | - return target_part->getNumObjects() - count; |
| 2281 | + return first_object; |
2320 | 2282 | } |
2321 | 2283 |
|
2322 | | -std::size_t Map::mergeParts(std::size_t source, std::size_t destination) |
| 2284 | +int Map::mergeParts(std::size_t source, std::size_t destination) |
2323 | 2285 | { |
2324 | 2286 | Q_ASSERT(source < parts.size()); |
2325 | 2287 | Q_ASSERT(destination < parts.size()); |
2326 | 2288 |
|
2327 | | - std::size_t count = 0; |
| 2289 | + int count = 0; |
2328 | 2290 | MapPart* const source_part = parts[source]; |
2329 | 2291 | MapPart* const target_part = parts[destination]; |
2330 | 2292 | // Preserve order (but not efficient) |
2331 | | - for (std::size_t i = source_part->getNumObjects(); i > 0 ; --i) |
| 2293 | + for (auto i = source_part->getNumObjects(); i > 0 ; --i) |
2332 | 2294 | { |
2333 | 2295 | Object* object = source_part->getObject(0); |
2334 | 2296 | source_part->deleteObject(0, true); |
|
0 commit comments