mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 02:54:46 -04:00
Format code using clang-format
This commit is contained in:
@ -3,8 +3,8 @@
|
||||
#include <QtScript>
|
||||
#include <QDebug>
|
||||
|
||||
ResponseParser::ResponseParser(QObject *parent) :
|
||||
QObject(parent),error(false),errorTxt("None"),numResults(-1),currentPage(-1),totalPages(-1)
|
||||
ResponseParser::ResponseParser(QObject *parent)
|
||||
: QObject(parent), error(false), errorTxt("None"), numResults(-1), currentPage(-1), totalPages(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -20,12 +20,12 @@ QString ResponseParser::errorDescription()
|
||||
|
||||
qint32 ResponseParser::getNumResults()
|
||||
{
|
||||
return numResults;
|
||||
return numResults;
|
||||
}
|
||||
|
||||
qint32 ResponseParser::getCurrentPage()
|
||||
{
|
||||
return currentPage;
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
qint32 ResponseParser::getTotalPages()
|
||||
@ -35,49 +35,43 @@ qint32 ResponseParser::getTotalPages()
|
||||
|
||||
bool ResponseParser::isError(qint32 error)
|
||||
{
|
||||
switch(error)
|
||||
{
|
||||
case 100:
|
||||
return true;
|
||||
switch (error) {
|
||||
case 100:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ResponseParser::loadJSONResponse(const QString &response)
|
||||
{
|
||||
QScriptEngine engine;
|
||||
QScriptValue sc;
|
||||
sc = engine.evaluate("(" + response + ")");
|
||||
QScriptEngine engine;
|
||||
QScriptValue sc;
|
||||
sc = engine.evaluate("(" + response + ")");
|
||||
|
||||
errorTxt = "None";
|
||||
|
||||
if (!sc.property("status_code").isValid() || isError(sc.property("status_code").toInt32()))
|
||||
{
|
||||
error = true;
|
||||
if(sc.property("error").isValid())
|
||||
if (!sc.property("status_code").isValid() || isError(sc.property("status_code").toInt32())) {
|
||||
error = true;
|
||||
if (sc.property("error").isValid())
|
||||
errorTxt = sc.property("error").toString();
|
||||
else
|
||||
errorTxt = "Unknown error";
|
||||
}
|
||||
else
|
||||
{
|
||||
error = false;
|
||||
if(sc.property("number_of_total_results").isValid())
|
||||
numResults = sc.property("number_of_total_results").toString().toInt();// sc.property("number_of_total_results").toInt32();
|
||||
else
|
||||
qDebug() << sc.property("oops").toString();
|
||||
} else {
|
||||
error = false;
|
||||
if (sc.property("number_of_total_results").isValid())
|
||||
numResults = sc.property("number_of_total_results").toString().toInt(); // sc.property("number_of_total_results").toInt32();
|
||||
else
|
||||
qDebug() << sc.property("oops").toString();
|
||||
|
||||
int limit = sc.property("limit").toInt32();
|
||||
int offset = sc.property("offset").toInt32();
|
||||
int total = sc.property("number_of_total_results").toInt32();
|
||||
if(limit > 0)
|
||||
{
|
||||
totalPages = (total / limit) + (total%limit>0?1:0);
|
||||
currentPage = (offset / limit) + 1;
|
||||
}
|
||||
else
|
||||
totalPages = currentPage = 1;
|
||||
}
|
||||
int limit = sc.property("limit").toInt32();
|
||||
int offset = sc.property("offset").toInt32();
|
||||
int total = sc.property("number_of_total_results").toInt32();
|
||||
if (limit > 0) {
|
||||
totalPages = (total / limit) + (total % limit > 0 ? 1 : 0);
|
||||
currentPage = (offset / limit) + 1;
|
||||
} else
|
||||
totalPages = currentPage = 1;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user