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
3636 // nothing to be implemented
3737 }
3838
39−void GooglePolyScriptingInterface::setAPIKey(QString key) {
39+void GooglePolyScriptingInterface::setAPIKey(const QString& key) {
4040 authCode = key;
4141 }
4242
43−QString GooglePolyScriptingInterface::getAssetList(QString keyword, QString category, QString format) {
43+QString GooglePolyScriptingInterface::getAssetList(const QString& keyword, const QString& category, const QString& format) {
4444 QUrl url = formatURLQuery(keyword, category, format);
4545 if (!url.isEmpty()) {
4646 QByteArray json = parseJSON(url, 0).toJsonDocument().toJson();
@@ -51,42 +51,43 @@ QString GooglePolyScriptingInterface::getAssetList(QString keyword, QString cate · 4 unmodified lines
5151 }
5252 }
5353
54−QString GooglePolyScriptingInterface::getFBX(QString keyword, QString category) {
54+QString GooglePolyScriptingInterface::getFBX(const QString& keyword, const QString& category) {
5555 QUrl url = formatURLQuery(keyword, category, "FBX");
5656 return getModelURL(url);
5757 }
5858
59−QString GooglePolyScriptingInterface::getOBJ(QString keyword, QString category) {
59+QString GooglePolyScriptingInterface::getOBJ(const QString& keyword, const QString& category) {
6060 QUrl url = formatURLQuery(keyword, category, "OBJ");
6161 return getModelURL(url);
6262 }
6363
64−QString GooglePolyScriptingInterface::getBlocks(QString keyword, QString category) {
64+QString GooglePolyScriptingInterface::getBlocks(const QString& keyword, const QString& category) {
6565 QUrl url = formatURLQuery(keyword, category, "BLOCKS");
6666 return getModelURL(url);
6767 }
6868
69−QString GooglePolyScriptingInterface::getGLTF(QString keyword, QString category) {
69+QString GooglePolyScriptingInterface::getGLTF(const QString& keyword, const QString& category) {
7070 QUrl url = formatURLQuery(keyword, category, "GLTF");
7171 return getModelURL(url);
7272 }
7373
74−QString GooglePolyScriptingInterface::getGLTF2(QString keyword, QString category) {
74+QString GooglePolyScriptingInterface::getGLTF2(const QString& keyword, const QString& category) {
7575 QUrl url = formatURLQuery(keyword, category, "GLTF2");
7676 return getModelURL(url);
7777 }
7878
7979 // This method will not be useful until we support Tilt models
80−QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) {
80+QString GooglePolyScriptingInterface::getTilt(const QString& keyword, const QString& category) {
8181 QUrl url = formatURLQuery(keyword, category, "TILT");
8282 return getModelURL(url);
8383 }
8484
8585 // Can provide asset name or full URL to model
86−QString GooglePolyScriptingInterface::getModelInfo(QString name) {
87− if (name.contains("poly.googleapis") || name.contains("poly.google.com")) {
88− QStringList list = name.split("/");
89− if (name.contains("poly.googleapis")) {
86+QString GooglePolyScriptingInterface::getModelInfo(const QString& input) {
87+ QString name(input);
88+ if (input.contains("poly.googleapis") || input.contains("poly.google.com")) {
89+ QStringList list = input.split("/");
90+ if (input.contains("poly.googleapis")) {
9091 name = list[4];
9192 } else {
9293 name = list.last();
@@ -106,14 +107,15 @@ int GooglePolyScriptingInterface::getRandIntInRange(int length) { · 13 unmodified lines
106107 return qrand() % length;
107108 }
108109
109−QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString category, QString format) {
110+QUrl GooglePolyScriptingInterface::formatURLQuery(const QString& keyword, const QString& category, const QString& format) {
110111 QString queries;
111112 if (!VALID_FORMATS.contains(format, Qt::CaseInsensitive) || !VALID_CATEGORIES.contains(category, Qt::CaseInsensitive)) {
112113 return QUrl("");
113114 } else {
114115 if (!keyword.isEmpty()) {
115− keyword.replace(" ", "+");
116− queries.append("&keywords=" + keyword);
116+ QString keywords(keyword);
117+ keywords.replace(" ", "+");
118+ queries.append("&keywords=" + keywords);
117119 }
118120 if (!category.isEmpty()) {
119121 queries.append("&category=" + category);
@@ -121,12 +123,12 @@ QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString categ · 1 unmodified line
121123 if (!format.isEmpty()) {
122124 queries.append("&format=" + format);
123125 }
124− QString urlString = QString(LIST_POLY_URL + "key=" + authCode + queries);
126+ QString urlString(LIST_POLY_URL + "key=" + authCode + queries);
125127 return QUrl(urlString);
126128 }
127129 }
128130
129−QString GooglePolyScriptingInterface::getModelURL(QUrl url) {
131+QString GooglePolyScriptingInterface::getModelURL(const QUrl& url) {
130132 qCDebug(scriptengine) << "Google URL request: " << url;
131133 if (!url.isEmpty()) {
132134 return parseJSON(url, 1).toString();
@@ -137,7 +139,7 @@ QString GooglePolyScriptingInterface::getModelURL(QUrl url) { · 4 unmodified lines
137139 }
138140
139141 // FIXME: synchronous
140−QByteArray GooglePolyScriptingInterface::getHTTPRequest(QUrl url) {
142+QByteArray GooglePolyScriptingInterface::getHTTPRequest(const QUrl& url) {
141143 QNetworkAccessManager manager;
142144 QNetworkReply *response = manager.get(QNetworkRequest(url));
143145 QEventLoop event;
@@ -148,7 +150,7 @@ QByteArray GooglePolyScriptingInterface::getHTTPRequest(QUrl url) { · 4 unmodified lines
148150 }
149151
150152 // 0 = asset list, 1 = model from asset list, 2 = specific model
151−QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) {
153+QVariant GooglePolyScriptingInterface::parseJSON(const QUrl& url, int fileType) {
152154 QByteArray jsonString = getHTTPRequest(url);
153155 QJsonDocument doc = QJsonDocument::fromJson(jsonString);
154156 QJsonObject obj = doc.object();