mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 00:13:29 +02:00
remove nullptr check in AssetMappingsScriptingInterface
This commit is contained in:
parent
2bbeac6597
commit
9c53f40fbe
2 changed files with 85 additions and 91 deletions
|
@ -38,7 +38,7 @@ void AssetRequest::start() {
|
||||||
|
|
||||||
// in case we haven't parsed a valid hash, return an error now
|
// in case we haven't parsed a valid hash, return an error now
|
||||||
if (isValidHash(_hash)) {
|
if (isValidHash(_hash)) {
|
||||||
_result = InvalidHash;
|
_error = InvalidHash;
|
||||||
_state = Finished;
|
_state = Finished;
|
||||||
|
|
||||||
emit finished(this);
|
emit finished(this);
|
||||||
|
|
|
@ -140,102 +140,96 @@ void AssetMappingModel::refresh() {
|
||||||
auto assetClient = DependencyManager::get<AssetClient>();
|
auto assetClient = DependencyManager::get<AssetClient>();
|
||||||
auto request = assetClient->createGetAllMappingsRequest();
|
auto request = assetClient->createGetAllMappingsRequest();
|
||||||
|
|
||||||
if (request) {
|
connect(request, &GetAllMappingsRequest::finished, this, [this](GetAllMappingsRequest* request) mutable {
|
||||||
connect(request, &GetAllMappingsRequest::finished, this, [this](GetAllMappingsRequest* request) mutable {
|
if (request->getError() == MappingRequest::NoError) {
|
||||||
if (request->getError() == MappingRequest::NoError) {
|
auto mappings = request->getMappings();
|
||||||
auto mappings = request->getMappings();
|
auto existingPaths = _pathToItemMap.keys();
|
||||||
auto existingPaths = _pathToItemMap.keys();
|
for (auto& mapping : mappings) {
|
||||||
for (auto& mapping : mappings) {
|
auto& path = mapping.first;
|
||||||
auto& path = mapping.first;
|
auto parts = path.split("/");
|
||||||
auto parts = path.split("/");
|
auto length = parts.length();
|
||||||
auto length = parts.length();
|
|
||||||
|
|
||||||
existingPaths.removeOne(mapping.first);
|
existingPaths.removeOne(mapping.first);
|
||||||
|
|
||||||
QString fullPath = "/";
|
QString fullPath = "/";
|
||||||
|
|
||||||
QStandardItem* lastItem = nullptr;
|
QStandardItem* lastItem = nullptr;
|
||||||
|
|
||||||
// start index at 1 to avoid empty string from leading slash
|
// start index at 1 to avoid empty string from leading slash
|
||||||
for (int i = 1; i < length; ++i) {
|
for (int i = 1; i < length; ++i) {
|
||||||
fullPath += (i == 1 ? "" : "/") + parts[i];
|
fullPath += (i == 1 ? "" : "/") + parts[i];
|
||||||
|
|
||||||
auto it = _pathToItemMap.find(fullPath);
|
auto it = _pathToItemMap.find(fullPath);
|
||||||
if (it == _pathToItemMap.end()) {
|
if (it == _pathToItemMap.end()) {
|
||||||
qDebug() << "prefix not found: " << fullPath;
|
qDebug() << "prefix not found: " << fullPath;
|
||||||
auto item = new QStandardItem(parts[i]);
|
auto item = new QStandardItem(parts[i]);
|
||||||
bool isFolder = i < length - 1;
|
bool isFolder = i < length - 1;
|
||||||
item->setData(isFolder ? fullPath + "/" : fullPath, Qt::UserRole);
|
item->setData(isFolder ? fullPath + "/" : fullPath, Qt::UserRole);
|
||||||
item->setData(isFolder, Qt::UserRole + 1);
|
item->setData(isFolder, Qt::UserRole + 1);
|
||||||
item->setData(parts[i], Qt::UserRole + 2);
|
item->setData(parts[i], Qt::UserRole + 2);
|
||||||
item->setData("atp:" + fullPath, Qt::UserRole + 3);
|
item->setData("atp:" + fullPath, Qt::UserRole + 3);
|
||||||
if (lastItem) {
|
if (lastItem) {
|
||||||
lastItem->setChild(lastItem->rowCount(), 0, item);
|
lastItem->setChild(lastItem->rowCount(), 0, item);
|
||||||
} else {
|
|
||||||
appendRow(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
lastItem = item;
|
|
||||||
_pathToItemMap[fullPath] = lastItem;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lastItem = it.value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(fullPath == path);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove folders from list
|
|
||||||
auto it = existingPaths.begin();
|
|
||||||
while (it != existingPaths.end()) {
|
|
||||||
auto item = _pathToItemMap[*it];
|
|
||||||
if (item->data(Qt::UserRole + 1).toBool()) {
|
|
||||||
it = existingPaths.erase(it);
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& path : existingPaths) {
|
|
||||||
Q_ASSERT(_pathToItemMap.contains(path));
|
|
||||||
qDebug() << "removing existing: " << path;
|
|
||||||
|
|
||||||
auto item = _pathToItemMap[path];
|
|
||||||
|
|
||||||
while (item) {
|
|
||||||
// During each iteration, delete item
|
|
||||||
QStandardItem* nextItem = nullptr;
|
|
||||||
|
|
||||||
auto parent = item->parent();
|
|
||||||
if (parent) {
|
|
||||||
parent->removeRow(item->row());
|
|
||||||
if (parent->rowCount() > 0) {
|
|
||||||
// The parent still contains children, set the nextItem to null so we stop processing
|
|
||||||
nextItem = nullptr;
|
|
||||||
} else {
|
|
||||||
nextItem = parent;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
removeRow(item->row());
|
appendRow(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
_pathToItemMap.remove(path);
|
lastItem = item;
|
||||||
//delete item;
|
_pathToItemMap[fullPath] = lastItem;
|
||||||
|
}
|
||||||
item = nextItem;
|
else {
|
||||||
|
lastItem = it.value();
|
||||||
}
|
}
|
||||||
//removeitem->index();
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
emit errorGettingMappings(uint8_t(request->getError()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
request->start();
|
Q_ASSERT(fullPath == path);
|
||||||
} else {
|
}
|
||||||
qDebug() << "NO CONNECTED ASSET SERVER";
|
|
||||||
// not connected to an Asset Server, emit network error
|
// Remove folders from list
|
||||||
emit errorGettingMappings(uint8_t(MappingRequest::NetworkError));
|
auto it = existingPaths.begin();
|
||||||
}
|
while (it != existingPaths.end()) {
|
||||||
|
auto item = _pathToItemMap[*it];
|
||||||
|
if (item->data(Qt::UserRole + 1).toBool()) {
|
||||||
|
it = existingPaths.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& path : existingPaths) {
|
||||||
|
Q_ASSERT(_pathToItemMap.contains(path));
|
||||||
|
qDebug() << "removing existing: " << path;
|
||||||
|
|
||||||
|
auto item = _pathToItemMap[path];
|
||||||
|
|
||||||
|
while (item) {
|
||||||
|
// During each iteration, delete item
|
||||||
|
QStandardItem* nextItem = nullptr;
|
||||||
|
|
||||||
|
auto parent = item->parent();
|
||||||
|
if (parent) {
|
||||||
|
parent->removeRow(item->row());
|
||||||
|
if (parent->rowCount() > 0) {
|
||||||
|
// The parent still contains children, set the nextItem to null so we stop processing
|
||||||
|
nextItem = nullptr;
|
||||||
|
} else {
|
||||||
|
nextItem = parent;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
removeRow(item->row());
|
||||||
|
}
|
||||||
|
|
||||||
|
_pathToItemMap.remove(path);
|
||||||
|
//delete item;
|
||||||
|
|
||||||
|
item = nextItem;
|
||||||
|
}
|
||||||
|
//removeitem->index();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emit errorGettingMappings(uint8_t(request->getError()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
request->start();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue