Skip to content

Commit

Permalink
Aggiunta distanza massima per nearby spots
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Jun 18, 2015
1 parent 85cf7f4 commit 141743b
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions MobileClient/QtProject/src/Panel_NearbySpots.qml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Item {
width: parent.width
height: parent.height
model: wa_NearbySpotModel
maxDistance_km: 150
onSpotClicked: {
stackView.push({item: Qt.resolvedUrl("pages-spot/Page_Spot.qml"),
properties:{width:stackView.width,
Expand Down
12 changes: 7 additions & 5 deletions MobileClient/QtProject/src/cpp/WebApi/NearbySpotsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ QHash<int, QByteArray> NearbySpotsModel::roleNames() const

//-----------------------------------------------------------------------------------------------------------------------------

void NearbySpotsModel::setLocation(float latitude,
float longitude)
void NearbySpotsModel::setLocation(double latitude,
double longitude,
double maxDistance_km)
{
QList<QueryItem> qList_QueryItems;
qList_QueryItems.append(QueryItem(WebApi::R_PARAM_LATITUDE, QString::number(latitude)));
qList_QueryItems.append(QueryItem(WebApi::R_PARAM_LONGITUDE, QString::number(longitude)));
qList_QueryItems.append(QueryItem(WebApi::R_PARAM_LATITUDE, QString::number(latitude)));
qList_QueryItems.append(QueryItem(WebApi::R_PARAM_LONGITUDE, QString::number(longitude)));
qList_QueryItems.append(QueryItem(WebApi::R_PARAM_MAX_DISTANCE_KM, QString::number(maxDistance_km)));

// TODO check post return type
m_Command_GetNearbySpots.postRequest(qList_QueryItems);
Expand Down Expand Up @@ -99,7 +101,7 @@ void NearbySpotsModel::slot_CommandGetNearbySpots_Finished(const WebApiError &er
qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_DESCRIPTION).toString(),
qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_LATITUDE).toNumber(),
qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_LONGITUDE).toNumber(),
qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_DISTANCE).toNumber(),
qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_DISTANCE_KM).toNumber(),
qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_1).toString(),
qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_2).toString()));
}
Expand Down
5 changes: 3 additions & 2 deletions MobileClient/QtProject/src/cpp/WebApi/NearbySpotsModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class NearbySpotsModel : public QAbstractListModel

public slots:

void setLocation(float latitude,
float longitude);
void setLocation(double latitude,
double longitude,
double maxDistance_km);

private slots:
void slot_CommandGetNearbySpots_Finished (const WebApiError &error);
Expand Down
8 changes: 4 additions & 4 deletions MobileClient/QtProject/src/cpp/WebApi/Spot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Spot::Spot(int id,
QString description,
qreal latitude,
qreal longitude,
qreal distance,
qreal distance_km,
QString pictureUrl1,
QString pictureUrl2,
QObject *parent)
Expand All @@ -39,13 +39,13 @@ Spot::Spot(int id,
m_PictureUrl1 (pictureUrl1),
m_PictureUrl2 (pictureUrl2)
{
if(distance >= 2)
if(distance_km >= 2)
{
m_Distance = QString("%1 km").arg((int) distance);
m_Distance = QString("%1 km").arg((int) distance_km);
}
else
{
m_Distance = QString("%1 m").arg((int) (distance*1000));
m_Distance = QString("%1 m").arg((int) (distance_km*1000));
}

if(m_PictureUrl1.isEmpty() == false)
Expand Down
2 changes: 1 addition & 1 deletion MobileClient/QtProject/src/cpp/WebApi/Spot.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Spot : public QObject
QString description,
qreal latitude,
qreal longitude,
qreal distance,
qreal distance_km,
QString pictureUrl1,
QString pictureUrl2,
QObject *parent = 0);
Expand Down
7 changes: 4 additions & 3 deletions MobileClient/QtProject/src/cpp/WebApi/WebApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ const QString WebApi::R_PARAM_EMAIL ("email");

const QString WebApi::R_PARAM_SPOT_ID ("id_spot");

const QString WebApi::R_PARAM_LATITUDE ("latitude");
const QString WebApi::R_PARAM_LONGITUDE ("longitude");
const QString WebApi::R_PARAM_LATITUDE ("latitude");
const QString WebApi::R_PARAM_LONGITUDE ("longitude");
const QString WebApi::R_PARAM_MAX_DISTANCE_KM("maxDistance_km");

const QString WebApi::A_PARAM_AUTHENTICATION ("authentication");
const QString WebApi::A_PARAM_REGISTERED ("registered");
Expand All @@ -65,7 +66,7 @@ const QString WebApi::A_ARRAY_SPOTS_ELEMENT_NAME ("name");
const QString WebApi::A_ARRAY_SPOTS_ELEMENT_DESCRIPTION ("description");
const QString WebApi::A_ARRAY_SPOTS_ELEMENT_LATITUDE ("latitude");
const QString WebApi::A_ARRAY_SPOTS_ELEMENT_LONGITUDE ("longitude");
const QString WebApi::A_ARRAY_SPOTS_ELEMENT_DISTANCE ("distance");
const QString WebApi::A_ARRAY_SPOTS_ELEMENT_DISTANCE_KM ("distance_km");
const QString WebApi::A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_1 ("pictureUrl1");
const QString WebApi::A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_2 ("pictureUrl2");

Expand Down
3 changes: 2 additions & 1 deletion MobileClient/QtProject/src/cpp/WebApi/WebApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class WebApi : public QObject

static const QString R_PARAM_LATITUDE;
static const QString R_PARAM_LONGITUDE;
static const QString R_PARAM_MAX_DISTANCE_KM;

static const QString A_PARAM_AUTHENTICATION;
static const QString A_PARAM_REGISTERED;
Expand All @@ -80,7 +81,7 @@ class WebApi : public QObject
static const QString A_ARRAY_SPOTS_ELEMENT_DESCRIPTION;
static const QString A_ARRAY_SPOTS_ELEMENT_LATITUDE;
static const QString A_ARRAY_SPOTS_ELEMENT_LONGITUDE;
static const QString A_ARRAY_SPOTS_ELEMENT_DISTANCE;
static const QString A_ARRAY_SPOTS_ELEMENT_DISTANCE_KM;
static const QString A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_1;
static const QString A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_2;

Expand Down
9 changes: 8 additions & 1 deletion MobileClient/QtProject/src/pages-spot/Page_SpotsList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,27 @@ BasicPage{
continueButtonVisible: false
menuButtonVisible: false

// Properties --------------------------
property double maxDistance_km: 150

// Bind properties ---------------------
property alias model: listView.model

// Signals -----------------------------
signal spotClicked(int spotId, string spotName, string spotDescription)

// Connections -------------------------
onVisibleChanged: {
if(visible == false)
{
return;
}

console.log("wa_NearbySpotModel.setLocation")

wa_NearbySpotModel.setLocation(hc_LocationManager.latitude(),
hc_LocationManager.longitude());
hc_LocationManager.longitude(),
maxDistance_km);
}

// Gui ---------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ BasicPage{
anchors.top: button_AddNewSpot.bottom
anchors.bottom: parent.bottom
model: wa_NearbySpotModel
maxDistance_km: 4
onSpotClicked: {
wa_PictureUploader.setNewSpot(false);
wa_PictureUploader.setExistingSpotId(spotId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public function webserviceAction(Request $request)

case "getNearbySpots":
$this->getNearbySpots($response,
$request->get('latitude' ),
$request->get('longitude'));
$request->get('latitude' ),
$request->get('longitude'),
$request->get('maxDistance_km'));
break;

default:
Expand Down Expand Up @@ -435,7 +436,7 @@ private function getPictures( &$response,
private function getNearbySpots( &$response,
$latitude,
$longitude,
$distance_km = 150)
$maxDistance_km)
{
$repository = $this->getDoctrine()
->getManager()
Expand All @@ -444,7 +445,7 @@ private function getNearbySpots( &$response,
$jSpots = array();
foreach($repository->getArrayByDistance($latitude,
$longitude,
$distance_km)
$maxDistance_km)
as &$spot)
{
$jSpot = array();
Expand All @@ -454,7 +455,7 @@ private function getNearbySpots( &$response,
$jSpot['description'] = $spot[0]['description'];
$jSpot['latitude'] = $spot[0]['latitude'];
$jSpot['longitude'] = $spot[0]['longitude'];
$jSpot['distance'] = $spot['distance'];
$jSpot['distance_km'] = $spot['distance'];

$picture1 = new Picture();
$picture1->setId ($spot[0]['picture1']['id']);
Expand Down

0 comments on commit 141743b

Please sign in to comment.