mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 04:08:13 +02:00
Merge pull request #7498 from Atlante45/fix/import-entities
Make svo loading use ResourceManager
This commit is contained in:
commit
830d08c385
2 changed files with 18 additions and 35 deletions
|
@ -2893,14 +2893,7 @@ void Application::saveSettings() {
|
||||||
bool Application::importEntities(const QString& urlOrFilename) {
|
bool Application::importEntities(const QString& urlOrFilename) {
|
||||||
_entityClipboard->eraseAllOctreeElements();
|
_entityClipboard->eraseAllOctreeElements();
|
||||||
|
|
||||||
QUrl url(urlOrFilename);
|
bool success = _entityClipboard->readFromURL(urlOrFilename);
|
||||||
|
|
||||||
// if the URL appears to be invalid or relative, then it is probably a local file
|
|
||||||
if (!url.isValid() || url.isRelative()) {
|
|
||||||
url = QUrl::fromLocalFile(urlOrFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool success = _entityClipboard->readFromURL(url.toString());
|
|
||||||
if (success) {
|
if (success) {
|
||||||
_entityClipboard->remapIDs();
|
_entityClipboard->remapIDs();
|
||||||
_entityClipboard->reaverageOctreeElements();
|
_entityClipboard->reaverageOctreeElements();
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <NetworkAccessManager.h>
|
#include <NetworkAccessManager.h>
|
||||||
#include <OctalCode.h>
|
#include <OctalCode.h>
|
||||||
#include <udt/PacketHeaders.h>
|
#include <udt/PacketHeaders.h>
|
||||||
|
#include <ResourceManager.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
#include <PathUtils.h>
|
#include <PathUtils.h>
|
||||||
#include <Gzip.h>
|
#include <Gzip.h>
|
||||||
|
@ -1674,35 +1675,24 @@ bool Octree::readJSONFromGzippedFile(QString qFileName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Octree::readFromURL(const QString& urlString) {
|
bool Octree::readFromURL(const QString& urlString) {
|
||||||
bool readOk = false;
|
auto request = std::unique_ptr<ResourceRequest>(ResourceManager::createResourceRequest(this, urlString));
|
||||||
|
|
||||||
// determine if this is a local file or a network resource
|
if (!request) {
|
||||||
QUrl url(urlString);
|
return false;
|
||||||
|
|
||||||
if (url.isLocalFile()) {
|
|
||||||
readOk = readFromFile(qPrintable(url.toLocalFile()));
|
|
||||||
} else {
|
|
||||||
QNetworkRequest request;
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
|
||||||
request.setUrl(url);
|
|
||||||
|
|
||||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
|
||||||
QNetworkReply* reply = networkAccessManager.get(request);
|
|
||||||
|
|
||||||
qCDebug(octree) << "Downloading svo at" << qPrintable(urlString);
|
|
||||||
|
|
||||||
QEventLoop loop;
|
|
||||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
|
||||||
loop.exec();
|
|
||||||
|
|
||||||
if (reply->error() == QNetworkReply::NoError) {
|
|
||||||
int resourceSize = reply->bytesAvailable();
|
|
||||||
QDataStream inputStream(reply);
|
|
||||||
readOk = readFromStream(resourceSize, inputStream);
|
|
||||||
}
|
|
||||||
delete reply;
|
|
||||||
}
|
}
|
||||||
return readOk;
|
|
||||||
|
QEventLoop loop;
|
||||||
|
connect(request.get(), &ResourceRequest::finished, &loop, &QEventLoop::quit);
|
||||||
|
request->send();
|
||||||
|
loop.exec();
|
||||||
|
|
||||||
|
if (request->getResult() != ResourceRequest::Success) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto data = request->getData();
|
||||||
|
QDataStream inputStream(data);
|
||||||
|
return readFromStream(data.size(), inputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue