PizzeriaSearcher.cpp Example File
callapizza/src/PizzeriaSearcher.cpp
#include "PizzeriaSearcher.hpp"
using namespace bb::cascades;
using namespace bb::data;
static QUrl assembleSearchUrl(const QString &zipCode)
{
QUrl url;
url.setScheme(QLatin1String("http"));
url.setHost(QLatin1String("local.yahooapis.com"));
url.setPath(QLatin1String("/LocalSearchService/V3/localSearch"));
url.addQueryItem(QLatin1String("appid"), QLatin1String("H.A4m8fV34HyNuOXZKbEnrjRDfMQJhA65jnhTej8vPBMWFzN0Kya5LgpRtXoNQ--"));
url.addQueryItem(QLatin1String("query"), QLatin1String("pizza"));
url.addQueryItem(QLatin1String("zip"), zipCode);
url.addQueryItem(QLatin1String("results"), QLatin1String("10"));
return url;
}
PizzeriaSearcher::PizzeriaSearcher(QObject *parent)
: QObject(parent)
, m_model(new GroupDataModel(this))
, m_dataSource(new DataSource(this))
{
m_model->setGrouping(ItemGrouping::None);
m_dataSource->setQuery(QLatin1String("/ResultSet/Result"));
bool ok = connect(m_dataSource, SIGNAL(dataLoaded(QVariant)), this, SLOT(dataLoaded(QVariant)));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
void PizzeriaSearcher::dataLoaded(const QVariant &data)
{
m_model->clear();
m_model->insertList(data.toList());
}
GroupDataModel* PizzeriaSearcher::model() const
{
return m_model;
}
QString PizzeriaSearcher::zipCode() const
{
return m_zipCode;
}
void PizzeriaSearcher::setZipCode(const QString &zipCode)
{
if (m_zipCode == zipCode)
return;
m_zipCode = zipCode;
emit zipCodeChanged();
m_dataSource->setSource(assembleSearchUrl(m_zipCode));
m_dataSource->load();
}