mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01: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 }
|
HifiConstants { id: hifi }
|
||||||
|
|
||||||
property var scripts: ScriptDiscoveryService;
|
property var scripts: ScriptDiscoveryService;
|
||||||
property var scriptsModel: scripts.scriptsModelFilter
|
property var scriptsModel: Assets.getAssetMappingModel()
|
||||||
property var currentDirectory;
|
property var currentDirectory;
|
||||||
|
|
||||||
Settings {
|
Settings {
|
||||||
|
@ -45,6 +45,7 @@ Window {
|
||||||
|
|
||||||
function reload() {
|
function reload() {
|
||||||
print("reload");
|
print("reload");
|
||||||
|
scriptsModel.refresh();
|
||||||
}
|
}
|
||||||
function addToWorld() {
|
function addToWorld() {
|
||||||
print("addToWorld");
|
print("addToWorld");
|
||||||
|
|
|
@ -792,8 +792,11 @@ void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callb
|
||||||
assetRequest->start();
|
assetRequest->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int standardItemModelMetaTypeId = qRegisterMetaType<AssetMappingModel*>("AssetMappingModel*");
|
||||||
|
|
||||||
AssetMappingsScriptingInterface::AssetMappingsScriptingInterface(QJSEngine* engine) :
|
AssetMappingsScriptingInterface::AssetMappingsScriptingInterface(QJSEngine* engine) :
|
||||||
_engine(engine)
|
_engine(engine),
|
||||||
|
_assetMappingModel(this)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -867,3 +870,97 @@ void AssetMappingsScriptingInterface::getAllMappings(QJSValue callback) {
|
||||||
|
|
||||||
request->start();
|
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
|
#ifndef hifi_AssetClient_h
|
||||||
#define hifi_AssetClient_h
|
#define hifi_AssetClient_h
|
||||||
|
|
||||||
|
#include <QStandardItemModel>
|
||||||
#include <QtQml/QJSEngine>
|
#include <QtQml/QJSEngine>
|
||||||
#include <QString>
|
#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 {
|
class AssetMappingsScriptingInterface : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(AssetMappingModel* mappingModel READ getAssetMappingModel CONSTANT)
|
||||||
public:
|
public:
|
||||||
AssetMappingsScriptingInterface(QJSEngine* engine);
|
AssetMappingsScriptingInterface(QJSEngine* engine);
|
||||||
|
|
||||||
|
Q_INVOKABLE AssetMappingModel* getAssetMappingModel() { return &_assetMappingModel; };
|
||||||
|
|
||||||
Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback);
|
Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback);
|
||||||
Q_INVOKABLE void getMapping(QString path, QJSValue callback);
|
Q_INVOKABLE void getMapping(QString path, QJSValue callback);
|
||||||
Q_INVOKABLE void deleteMappings(QStringList paths, QJSValue callback);
|
Q_INVOKABLE void deleteMappings(QStringList paths, QJSValue callback);
|
||||||
|
@ -137,7 +158,6 @@ public:
|
||||||
protected:
|
protected:
|
||||||
QSet<AssetRequest*> _pendingRequests;
|
QSet<AssetRequest*> _pendingRequests;
|
||||||
QJSEngine* _engine;
|
QJSEngine* _engine;
|
||||||
|
AssetMappingModel _assetMappingModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue