Merge pull request #11425 from Atlante45/feat/auto-bake

Asset Browser auto-refresh
This commit is contained in:
Ryan Huffman 2017-09-22 13:17:04 -07:00 committed by GitHub
commit 883bdc6003
4 changed files with 47 additions and 27 deletions

View file

@ -49,10 +49,15 @@ ScrollingWindow {
Component.onCompleted: {
ApplicationInterface.uploadRequest.connect(uploadClicked);
assetMappingsModel.errorGettingMappings.connect(handleGetMappingsError);
assetMappingsModel.autoRefreshEnabled = true;
reload();
}
Component.onDestruction: {
assetMappingsModel.autoRefreshEnabled = false;
}
function doDeleteFile(path) {
console.log("Deleting " + path);
@ -146,7 +151,6 @@ ScrollingWindow {
function reload() {
Assets.mappingModel.refresh();
treeView.selection.clear();
}
function handleGetMappingsError(errorString) {
@ -502,16 +506,6 @@ ScrollingWindow {
onClicked: root.deleteFile()
enabled: treeView.selection.hasSelection
}
HifiControls.GlyphButton {
glyph: hifi.glyphs.reload
color: hifi.buttons.black
colorScheme: root.colorScheme
width: hifi.dimensions.controlLineHeight
onClicked: root.reload()
}
}
}
@ -751,7 +745,7 @@ ScrollingWindow {
var path = assetProxyModel.data(index, 0x100);
mappings.push(path);
}
print("Setting baking enabled:" + mappings + checked);
print("Setting baking enabled:" + mappings + " " + checked);
Assets.setBakingEnabled(mappings, checked, function() {
reload();
});

View file

@ -49,9 +49,15 @@ Rectangle {
isHMD = HMD.active;
ApplicationInterface.uploadRequest.connect(uploadClicked);
assetMappingsModel.errorGettingMappings.connect(handleGetMappingsError);
assetMappingsModel.autoRefreshEnabled = true;
reload();
}
Component.onDestruction: {
assetMappingsModel.autoRefreshEnabled = false;
}
function doDeleteFile(path) {
console.log("Deleting " + path);
@ -145,7 +151,6 @@ Rectangle {
function reload() {
Assets.mappingModel.refresh();
treeView.selection.clear();
}
function handleGetMappingsError(errorString) {
@ -502,16 +507,6 @@ Rectangle {
onClicked: root.deleteFile()
enabled: treeView.selection.hasSelection
}
HifiControls.GlyphButton {
glyph: hifi.glyphs.reload
color: hifi.buttons.black
colorScheme: root.colorScheme
width: hifi.dimensions.controlLineHeight
onClicked: root.reload()
}
}
}
@ -748,7 +743,7 @@ Rectangle {
var path = assetProxyModel.data(index, 0x100);
mappings.push(path);
}
print("Setting baking enabled:" + mappings + checked);
print("Setting baking enabled:" + mappings + " " + checked);
Assets.setBakingEnabled(mappings, checked, function() {
reload();
});

View file

@ -19,8 +19,13 @@
#include <AssetUpload.h>
#include <MappingRequest.h>
#include <NetworkLogging.h>
#include <NodeList.h>
#include <OffscreenUi.h>
static const int AUTO_REFRESH_INTERVAL = 1000;
int assetMappingModelMetatypeId = qRegisterMetaType<AssetMappingModel*>("AssetMappingModel*");
AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() {
_proxyModel.setSourceModel(&_assetMappingModel);
_proxyModel.setSortRole(Qt::DisplayRole);
@ -189,6 +194,29 @@ void AssetMappingsScriptingInterface::setBakingEnabled(QStringList paths, bool e
AssetMappingModel::AssetMappingModel() {
setupRoles();
connect(&_autoRefreshTimer, &QTimer::timeout, this, [this] {
auto nodeList = DependencyManager::get<NodeList>();
auto assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
if (assetServer) {
refresh();
}
});
_autoRefreshTimer.setInterval(AUTO_REFRESH_INTERVAL);
}
bool AssetMappingModel::isAutoRefreshEnabled() {
return _autoRefreshTimer.isActive();
}
void AssetMappingModel::setAutoRefreshEnabled(bool enabled) {
if (enabled != _autoRefreshTimer.isActive()) {
if (enabled) {
_autoRefreshTimer.start();
} else {
_autoRefreshTimer.stop();
}
}
}
bool AssetMappingModel::isKnownFolder(QString path) const {
@ -205,10 +233,7 @@ bool AssetMappingModel::isKnownFolder(QString path) const {
return false;
}
int assetMappingModelMetatypeId = qRegisterMetaType<AssetMappingModel*>("AssetMappingModel*");
void AssetMappingModel::refresh() {
qDebug() << "Refreshing asset mapping model";
auto assetClient = DependencyManager::get<AssetClient>();
auto request = assetClient->createGetAllMappingsRequest();

View file

@ -25,11 +25,16 @@
class AssetMappingModel : public QStandardItemModel {
Q_OBJECT
Q_PROPERTY(bool autoRefreshEnabled READ isAutoRefreshEnabled WRITE setAutoRefreshEnabled)
public:
AssetMappingModel();
Q_INVOKABLE void refresh();
bool isAutoRefreshEnabled();
void setAutoRefreshEnabled(bool enabled);
bool isKnownMapping(QString path) const { return _pathToItemMap.contains(path); }
bool isKnownFolder(QString path) const;
@ -44,6 +49,7 @@ private:
void setupRoles();
QHash<QString, QStandardItem*> _pathToItemMap;
QTimer _autoRefreshTimer;
};
Q_DECLARE_METATYPE(AssetMappingModel*)