mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 00:10:52 +02:00
added const to several parameters
This commit is contained in:
parent
01c1032540
commit
a428eb5b75
2 changed files with 34 additions and 32 deletions
|
@ -36,11 +36,11 @@ GooglePolyScriptingInterface::GooglePolyScriptingInterface() {
|
||||||
// nothing to be implemented
|
// nothing to be implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
void GooglePolyScriptingInterface::setAPIKey(QString key) {
|
void GooglePolyScriptingInterface::setAPIKey(const QString& key) {
|
||||||
authCode = key;
|
authCode = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GooglePolyScriptingInterface::getAssetList(QString keyword, QString category, QString format) {
|
QString GooglePolyScriptingInterface::getAssetList(const QString& keyword, const QString& category, const QString& format) {
|
||||||
QUrl url = formatURLQuery(keyword, category, format);
|
QUrl url = formatURLQuery(keyword, category, format);
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
QByteArray json = parseJSON(url, 0).toJsonDocument().toJson();
|
QByteArray json = parseJSON(url, 0).toJsonDocument().toJson();
|
||||||
|
@ -51,42 +51,43 @@ QString GooglePolyScriptingInterface::getAssetList(QString keyword, QString cate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GooglePolyScriptingInterface::getFBX(QString keyword, QString category) {
|
QString GooglePolyScriptingInterface::getFBX(const QString& keyword, const QString& category) {
|
||||||
QUrl url = formatURLQuery(keyword, category, "FBX");
|
QUrl url = formatURLQuery(keyword, category, "FBX");
|
||||||
return getModelURL(url);
|
return getModelURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GooglePolyScriptingInterface::getOBJ(QString keyword, QString category) {
|
QString GooglePolyScriptingInterface::getOBJ(const QString& keyword, const QString& category) {
|
||||||
QUrl url = formatURLQuery(keyword, category, "OBJ");
|
QUrl url = formatURLQuery(keyword, category, "OBJ");
|
||||||
return getModelURL(url);
|
return getModelURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GooglePolyScriptingInterface::getBlocks(QString keyword, QString category) {
|
QString GooglePolyScriptingInterface::getBlocks(const QString& keyword, const QString& category) {
|
||||||
QUrl url = formatURLQuery(keyword, category, "BLOCKS");
|
QUrl url = formatURLQuery(keyword, category, "BLOCKS");
|
||||||
return getModelURL(url);
|
return getModelURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GooglePolyScriptingInterface::getGLTF(QString keyword, QString category) {
|
QString GooglePolyScriptingInterface::getGLTF(const QString& keyword, const QString& category) {
|
||||||
QUrl url = formatURLQuery(keyword, category, "GLTF");
|
QUrl url = formatURLQuery(keyword, category, "GLTF");
|
||||||
return getModelURL(url);
|
return getModelURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GooglePolyScriptingInterface::getGLTF2(QString keyword, QString category) {
|
QString GooglePolyScriptingInterface::getGLTF2(const QString& keyword, const QString& category) {
|
||||||
QUrl url = formatURLQuery(keyword, category, "GLTF2");
|
QUrl url = formatURLQuery(keyword, category, "GLTF2");
|
||||||
return getModelURL(url);
|
return getModelURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method will not be useful until we support Tilt models
|
// This method will not be useful until we support Tilt models
|
||||||
QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) {
|
QString GooglePolyScriptingInterface::getTilt(const QString& keyword, const QString& category) {
|
||||||
QUrl url = formatURLQuery(keyword, category, "TILT");
|
QUrl url = formatURLQuery(keyword, category, "TILT");
|
||||||
return getModelURL(url);
|
return getModelURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can provide asset name or full URL to model
|
// Can provide asset name or full URL to model
|
||||||
QString GooglePolyScriptingInterface::getModelInfo(QString name) {
|
QString GooglePolyScriptingInterface::getModelInfo(const QString& input) {
|
||||||
if (name.contains("poly.googleapis") || name.contains("poly.google.com")) {
|
QString name(input);
|
||||||
QStringList list = name.split("/");
|
if (input.contains("poly.googleapis") || input.contains("poly.google.com")) {
|
||||||
if (name.contains("poly.googleapis")) {
|
QStringList list = input.split("/");
|
||||||
|
if (input.contains("poly.googleapis")) {
|
||||||
name = list[4];
|
name = list[4];
|
||||||
} else {
|
} else {
|
||||||
name = list.last();
|
name = list.last();
|
||||||
|
@ -106,14 +107,15 @@ int GooglePolyScriptingInterface::getRandIntInRange(int length) {
|
||||||
return qrand() % length;
|
return qrand() % length;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString category, QString format) {
|
QUrl GooglePolyScriptingInterface::formatURLQuery(const QString& keyword, const QString& category, const QString& format) {
|
||||||
QString queries;
|
QString queries;
|
||||||
if (!VALID_FORMATS.contains(format, Qt::CaseInsensitive) || !VALID_CATEGORIES.contains(category, Qt::CaseInsensitive)) {
|
if (!VALID_FORMATS.contains(format, Qt::CaseInsensitive) || !VALID_CATEGORIES.contains(category, Qt::CaseInsensitive)) {
|
||||||
return QUrl("");
|
return QUrl("");
|
||||||
} else {
|
} else {
|
||||||
if (!keyword.isEmpty()) {
|
if (!keyword.isEmpty()) {
|
||||||
keyword.replace(" ", "+");
|
QString keywords(keyword);
|
||||||
queries.append("&keywords=" + keyword);
|
keywords.replace(" ", "+");
|
||||||
|
queries.append("&keywords=" + keywords);
|
||||||
}
|
}
|
||||||
if (!category.isEmpty()) {
|
if (!category.isEmpty()) {
|
||||||
queries.append("&category=" + category);
|
queries.append("&category=" + category);
|
||||||
|
@ -121,12 +123,12 @@ QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString categ
|
||||||
if (!format.isEmpty()) {
|
if (!format.isEmpty()) {
|
||||||
queries.append("&format=" + format);
|
queries.append("&format=" + format);
|
||||||
}
|
}
|
||||||
QString urlString = QString(LIST_POLY_URL + "key=" + authCode + queries);
|
QString urlString(LIST_POLY_URL + "key=" + authCode + queries);
|
||||||
return QUrl(urlString);
|
return QUrl(urlString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GooglePolyScriptingInterface::getModelURL(QUrl url) {
|
QString GooglePolyScriptingInterface::getModelURL(const QUrl& url) {
|
||||||
qCDebug(scriptengine) << "Google URL request: " << url;
|
qCDebug(scriptengine) << "Google URL request: " << url;
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
return parseJSON(url, 1).toString();
|
return parseJSON(url, 1).toString();
|
||||||
|
@ -137,7 +139,7 @@ QString GooglePolyScriptingInterface::getModelURL(QUrl url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: synchronous
|
// FIXME: synchronous
|
||||||
QByteArray GooglePolyScriptingInterface::getHTTPRequest(QUrl url) {
|
QByteArray GooglePolyScriptingInterface::getHTTPRequest(const QUrl& url) {
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
QNetworkReply *response = manager.get(QNetworkRequest(url));
|
QNetworkReply *response = manager.get(QNetworkRequest(url));
|
||||||
QEventLoop event;
|
QEventLoop event;
|
||||||
|
@ -148,7 +150,7 @@ QByteArray GooglePolyScriptingInterface::getHTTPRequest(QUrl url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0 = asset list, 1 = model from asset list, 2 = specific model
|
// 0 = asset list, 1 = model from asset list, 2 = specific model
|
||||||
QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) {
|
QVariant GooglePolyScriptingInterface::parseJSON(const QUrl& url, int fileType) {
|
||||||
QByteArray jsonString = getHTTPRequest(url);
|
QByteArray jsonString = getHTTPRequest(url);
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(jsonString);
|
QJsonDocument doc = QJsonDocument::fromJson(jsonString);
|
||||||
QJsonObject obj = doc.object();
|
QJsonObject obj = doc.object();
|
||||||
|
|
|
@ -22,24 +22,24 @@ public:
|
||||||
GooglePolyScriptingInterface();
|
GooglePolyScriptingInterface();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setAPIKey(QString key);
|
void setAPIKey(const QString& key);
|
||||||
|
|
||||||
QString getAssetList(QString keyword, QString category, QString format);
|
QString getAssetList(const QString& keyword, const QString& category, const QString& format);
|
||||||
QString getFBX(QString keyword, QString category);
|
QString getFBX(const QString& keyword, const QString& category);
|
||||||
QString getOBJ(QString keyword, QString category);
|
QString getOBJ(const QString& keyword, const QString& category);
|
||||||
QString getBlocks(QString keyword, QString category);
|
QString getBlocks(const QString& keyword, const QString& categoryy);
|
||||||
QString getGLTF(QString keyword, QString category);
|
QString getGLTF(const QString& keyword, const QString& category);
|
||||||
QString getGLTF2(QString keyword, QString category);
|
QString getGLTF2(const QString& keyword, const QString& category);
|
||||||
QString getTilt(QString keyword, QString category);
|
QString getTilt(const QString& keyword, const QString& category);
|
||||||
QString getModelInfo(QString name);
|
QString getModelInfo(const QString& input);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString authCode;
|
QString authCode;
|
||||||
|
|
||||||
QUrl formatURLQuery(QString keyword, QString category, QString format);
|
QUrl formatURLQuery(const QString& keyword, const QString& category, const QString& format);
|
||||||
QString getModelURL(QUrl url);
|
QString getModelURL(const QUrl& url);
|
||||||
QByteArray getHTTPRequest(QUrl url);
|
QByteArray getHTTPRequest(const QUrl& url);
|
||||||
QVariant parseJSON(QUrl url, int fileType);
|
QVariant parseJSON(const QUrl& url, int fileType);
|
||||||
int getRandIntInRange(int length);
|
int getRandIntInRange(int length);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue