mirror of
https://github.com/overte-org/overte.git
synced 2025-04-24 03:33:35 +02:00
Add AssetMappingModel
This commit is contained in:
parent
38edfe0557
commit
4da4fd889a
3 changed files with 122 additions and 4 deletions
|
@ -33,7 +33,7 @@ Window {
|
|||
HifiConstants { id: hifi }
|
||||
|
||||
property var scripts: ScriptDiscoveryService;
|
||||
property var scriptsModel: scripts.scriptsModelFilter
|
||||
property var scriptsModel: Assets.getAssetMappingModel()
|
||||
property var currentDirectory;
|
||||
|
||||
Settings {
|
||||
|
@ -45,6 +45,7 @@ Window {
|
|||
|
||||
function reload() {
|
||||
print("reload");
|
||||
scriptsModel.refresh();
|
||||
}
|
||||
function addToWorld() {
|
||||
print("addToWorld");
|
||||
|
|
|
@ -792,8 +792,11 @@ void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callb
|
|||
assetRequest->start();
|
||||
}
|
||||
|
||||
static int standardItemModelMetaTypeId = qRegisterMetaType<AssetMappingModel*>("AssetMappingModel*");
|
||||
|
||||
AssetMappingsScriptingInterface::AssetMappingsScriptingInterface(QJSEngine* engine) :
|
||||
_engine(engine)
|
||||
_engine(engine),
|
||||
_assetMappingModel(this)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -867,3 +870,97 @@ void AssetMappingsScriptingInterface::getAllMappings(QJSValue callback) {
|
|||
|
||||
request->start();
|
||||
}
|
||||
|
||||
AssetMappingModel::AssetMappingModel(QObject* parent) {
|
||||
}
|
||||
|
||||
void AssetMappingModel::refresh() {
|
||||
qDebug() << "Refreshing asset mapping model";
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
auto request = assetClient->createGetAllMappingsRequest();
|
||||
|
||||
connect(request, &GetAllMappingsRequest::finished, this, [this](GetAllMappingsRequest* request) mutable {
|
||||
qDebug() << "Got response";
|
||||
auto mappings = request->getMappings();
|
||||
// clear();
|
||||
for (auto& mapping : mappings) {
|
||||
auto& path = mapping.first;
|
||||
auto parts = path.split("/");
|
||||
auto length = parts.length();
|
||||
|
||||
QString prefix = parts[0];
|
||||
|
||||
QStandardItem* lastItem = nullptr;
|
||||
|
||||
auto it = _pathToItemMap.find(prefix);
|
||||
if (it == _pathToItemMap.end()) {
|
||||
lastItem = new QStandardItem(parts[0]);
|
||||
_pathToItemMap[prefix] = lastItem;
|
||||
appendRow(lastItem);
|
||||
} else {
|
||||
lastItem = it.value();
|
||||
}
|
||||
|
||||
if (length > 1) {
|
||||
for (int i = 1; i < length; ++i) {
|
||||
prefix += "/" + parts[i];
|
||||
|
||||
auto it = _pathToItemMap.find(prefix);
|
||||
if (it == _pathToItemMap.end()) {
|
||||
qDebug() << "prefix not found: " << prefix;
|
||||
auto item = new QStandardItem(parts[i]);
|
||||
lastItem->setChild(lastItem->rowCount(), 0, item);
|
||||
lastItem = item;
|
||||
_pathToItemMap[prefix] = lastItem;
|
||||
} else {
|
||||
lastItem = it.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Q_ASSERT(prefix == path);
|
||||
}
|
||||
});
|
||||
|
||||
request->start();
|
||||
}
|
||||
|
||||
|
||||
// QModelIndex AssetMappingModel::index(int row, int column, const QModelIndex& parent) const {
|
||||
// if (row < 0 || column < 0) {
|
||||
// return QModelIndex();
|
||||
// }
|
||||
|
||||
// if (parent.isValid()) {
|
||||
// auto item = static_cast<AssetMappingItem*>(parent.internalPointer());
|
||||
// return createIndex(row, column, )
|
||||
// }
|
||||
// return createIndex(row, column, getFolderNodes(
|
||||
// static_cast<AssetMappingItem*>(getTreeNodeFromIndex(parent))).at(row));
|
||||
// }
|
||||
|
||||
// QModelIndex AssetMappingModel::parent(const QModelIndex& child) const {
|
||||
// AssetMappingItem* parent = (static_cast<AssetMappingItem*>(child.internalPointer()))->getParent();
|
||||
// if (!parent) {
|
||||
// return QModelIndex();
|
||||
// }
|
||||
// AssetMappingItem* grandParent = parent->getParent();
|
||||
// int row = getFolderNodes(grandParent).indexOf(parent);
|
||||
// return createIndex(row, 0, parent);
|
||||
// }
|
||||
|
||||
// QVariant AssetMappingModel::data(const QModelIndex& index, int role) const {
|
||||
// TreeNodeBase* node = getTreeNodeFromIndex(index);
|
||||
// if (!node) {
|
||||
// return QVariant();
|
||||
// }
|
||||
// return QVariant();
|
||||
// }
|
||||
|
||||
// int AssetMappingModel::rowCount(const QModelIndex& parent) const {
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
// int AssetMappingModel::columnCount(const QModelIndex& parent) const {
|
||||
// return 1;
|
||||
// }
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#ifndef hifi_AssetClient_h
|
||||
#define hifi_AssetClient_h
|
||||
|
||||
#include <QStandardItemModel>
|
||||
#include <QtQml/QJSEngine>
|
||||
#include <QString>
|
||||
|
||||
|
@ -125,11 +126,31 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
class AssetMappingModel : public QStandardItemModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AssetMappingModel(QObject* parent = nullptr);
|
||||
|
||||
Q_INVOKABLE void refresh();
|
||||
private:
|
||||
QHash<QString, QStandardItem*> _pathToItemMap;
|
||||
};
|
||||
|
||||
//class AssetMappingItem : public QStandardItem {
|
||||
//Q_OBJECT
|
||||
//public:
|
||||
//AssetMappingItem();
|
||||
//};
|
||||
|
||||
|
||||
class AssetMappingsScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(AssetMappingModel* mappingModel READ getAssetMappingModel CONSTANT)
|
||||
public:
|
||||
AssetMappingsScriptingInterface(QJSEngine* engine);
|
||||
|
||||
Q_INVOKABLE AssetMappingModel* getAssetMappingModel() { return &_assetMappingModel; };
|
||||
|
||||
Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback);
|
||||
Q_INVOKABLE void getMapping(QString path, QJSValue callback);
|
||||
Q_INVOKABLE void deleteMappings(QStringList paths, QJSValue callback);
|
||||
|
@ -137,7 +158,6 @@ public:
|
|||
protected:
|
||||
QSet<AssetRequest*> _pendingRequests;
|
||||
QJSEngine* _engine;
|
||||
AssetMappingModel _assetMappingModel;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue