History

added const to several parameters

Elisa Lupin-Jimenez committed 8 years ago

Commit a428eb51 parent 01c10322 files · +34 −32Browse files

Showing the changes to interface/src/scripting/GooglePolyScriptingInterface.cpp (1 of 2 files). Show all

Unified · Split

interface/src/scripting/GooglePolyScriptingInterface.cpp+21−19
@@ -36,11 +36,11 @@ GooglePolyScriptingInterface::GooglePolyScriptingInterface() { · 35 unmodified lines
36 // nothing to be implemented36 // nothing to be implemented
37}37}
38 38
39void GooglePolyScriptingInterface::setAPIKey(QString key) {39void GooglePolyScriptingInterface::setAPIKey(const QString& key) {
40 authCode = key;40 authCode = key;
41}41}
42 42
43QString GooglePolyScriptingInterface::getAssetList(QString keyword, QString category, QString format) {43QString GooglePolyScriptingInterface::getAssetList(const QString& keyword, const QString& category, const QString& format) {
44 QUrl url = formatURLQuery(keyword, category, format);44 QUrl url = formatURLQuery(keyword, category, format);
45 if (!url.isEmpty()) {45 if (!url.isEmpty()) {
46 QByteArray json = parseJSON(url, 0).toJsonDocument().toJson();46 QByteArray json = parseJSON(url, 0).toJsonDocument().toJson();
@@ -51,42 +51,43 @@ QString GooglePolyScriptingInterface::getAssetList(QString keyword, QString cate · 4 unmodified lines
51 }51 }
52}52}
53 53
54QString GooglePolyScriptingInterface::getFBX(QString keyword, QString category) {54QString GooglePolyScriptingInterface::getFBX(const QString& keyword, const QString& category) {
55 QUrl url = formatURLQuery(keyword, category, "FBX");55 QUrl url = formatURLQuery(keyword, category, "FBX");
56 return getModelURL(url);56 return getModelURL(url);
57}57}
58 58
59QString GooglePolyScriptingInterface::getOBJ(QString keyword, QString category) {59QString GooglePolyScriptingInterface::getOBJ(const QString& keyword, const QString& category) {
60 QUrl url = formatURLQuery(keyword, category, "OBJ");60 QUrl url = formatURLQuery(keyword, category, "OBJ");
61 return getModelURL(url);61 return getModelURL(url);
62}62}
63 63
64QString GooglePolyScriptingInterface::getBlocks(QString keyword, QString category) {64QString GooglePolyScriptingInterface::getBlocks(const QString& keyword, const QString& category) {
65 QUrl url = formatURLQuery(keyword, category, "BLOCKS");65 QUrl url = formatURLQuery(keyword, category, "BLOCKS");
66 return getModelURL(url);66 return getModelURL(url);
67}67}
68 68
69QString GooglePolyScriptingInterface::getGLTF(QString keyword, QString category) {69QString GooglePolyScriptingInterface::getGLTF(const QString& keyword, const QString& category) {
70 QUrl url = formatURLQuery(keyword, category, "GLTF");70 QUrl url = formatURLQuery(keyword, category, "GLTF");
71 return getModelURL(url);71 return getModelURL(url);
72}72}
73 73
74QString GooglePolyScriptingInterface::getGLTF2(QString keyword, QString category) {74QString GooglePolyScriptingInterface::getGLTF2(const QString& keyword, const QString& category) {
75 QUrl url = formatURLQuery(keyword, category, "GLTF2");75 QUrl url = formatURLQuery(keyword, category, "GLTF2");
76 return getModelURL(url);76 return getModelURL(url);
77}77}
78 78
79// This method will not be useful until we support Tilt models79// This method will not be useful until we support Tilt models
80QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) {80QString GooglePolyScriptingInterface::getTilt(const QString& keyword, const QString& category) {
81 QUrl url = formatURLQuery(keyword, category, "TILT");81 QUrl url = formatURLQuery(keyword, category, "TILT");
82 return getModelURL(url);82 return getModelURL(url);
83}83}
84 84
85// Can provide asset name or full URL to model85// Can provide asset name or full URL to model
86QString GooglePolyScriptingInterface::getModelInfo(QString name) {86QString GooglePolyScriptingInterface::getModelInfo(const QString& input) {
87 if (name.contains("poly.googleapis") || name.contains("poly.google.com")) {87 QString name(input);
88 QStringList list = name.split("/");88 if (input.contains("poly.googleapis") || input.contains("poly.google.com")) {
89 if (name.contains("poly.googleapis")) {89 QStringList list = input.split("/");
90 if (input.contains("poly.googleapis")) {
90 name = list[4];91 name = list[4];
91 } else {92 } else {
92 name = list.last();93 name = list.last();
@@ -106,14 +107,15 @@ int GooglePolyScriptingInterface::getRandIntInRange(int length) { · 13 unmodified lines
106 return qrand() % length;107 return qrand() % length;
107}108}
108 109
109QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString category, QString format) {110QUrl GooglePolyScriptingInterface::formatURLQuery(const QString& keyword, const QString& category, const QString& format) {
110 QString queries;111 QString queries;
111 if (!VALID_FORMATS.contains(format, Qt::CaseInsensitive) || !VALID_CATEGORIES.contains(category, Qt::CaseInsensitive)) {112 if (!VALID_FORMATS.contains(format, Qt::CaseInsensitive) || !VALID_CATEGORIES.contains(category, Qt::CaseInsensitive)) {
112 return QUrl("");113 return QUrl("");
113 } else {114 } else {
114 if (!keyword.isEmpty()) {115 if (!keyword.isEmpty()) {
115 keyword.replace(" ", "+");116 QString keywords(keyword);
116 queries.append("&keywords=" + keyword);117 keywords.replace(" ", "+");
118 queries.append("&keywords=" + keywords);
117 }119 }
118 if (!category.isEmpty()) {120 if (!category.isEmpty()) {
119 queries.append("&category=" + category);121 queries.append("&category=" + category);
@@ -121,12 +123,12 @@ QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString categ · 1 unmodified line
121 if (!format.isEmpty()) {123 if (!format.isEmpty()) {
122 queries.append("&format=" + format);124 queries.append("&format=" + format);
123 }125 }
124 QString urlString = QString(LIST_POLY_URL + "key=" + authCode + queries);126 QString urlString(LIST_POLY_URL + "key=" + authCode + queries);
125 return QUrl(urlString);127 return QUrl(urlString);
126 }128 }
127}129}
128 130
129QString GooglePolyScriptingInterface::getModelURL(QUrl url) {131QString GooglePolyScriptingInterface::getModelURL(const QUrl& url) {
130 qCDebug(scriptengine) << "Google URL request: " << url;132 qCDebug(scriptengine) << "Google URL request: " << url;
131 if (!url.isEmpty()) {133 if (!url.isEmpty()) {
132 return parseJSON(url, 1).toString();134 return parseJSON(url, 1).toString();
@@ -137,7 +139,7 @@ QString GooglePolyScriptingInterface::getModelURL(QUrl url) { · 4 unmodified lines
137}139}
138 140
139// FIXME: synchronous141// FIXME: synchronous
140QByteArray GooglePolyScriptingInterface::getHTTPRequest(QUrl url) {142QByteArray GooglePolyScriptingInterface::getHTTPRequest(const QUrl& url) {
141 QNetworkAccessManager manager;143 QNetworkAccessManager manager;
142 QNetworkReply *response = manager.get(QNetworkRequest(url));144 QNetworkReply *response = manager.get(QNetworkRequest(url));
143 QEventLoop event;145 QEventLoop event;
@@ -148,7 +150,7 @@ QByteArray GooglePolyScriptingInterface::getHTTPRequest(QUrl url) { · 4 unmodified lines
148}150}
149 151
150// 0 = asset list, 1 = model from asset list, 2 = specific model152// 0 = asset list, 1 = model from asset list, 2 = specific model
151QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) {153QVariant GooglePolyScriptingInterface::parseJSON(const QUrl& url, int fileType) {
152 QByteArray jsonString = getHTTPRequest(url);154 QByteArray jsonString = getHTTPRequest(url);
153 QJsonDocument doc = QJsonDocument::fromJson(jsonString);155 QJsonDocument doc = QJsonDocument::fromJson(jsonString);
154 QJsonObject obj = doc.object();156 QJsonObject obj = doc.object();