d->ui->rootContext()->setContextProperty("friendModel", &d->friendModel);
d->ui->rootContext()->setContextProperty("engine", this);
- d->ui->rootContext()->setContextProperty("routingModel", &d->routeModel);
- d->ui->rootContext()->setContextProperty("engine", this);
-
d->ui->setSource(QUrl("qrc:/Main.qml"));
d->ui->setResizeMode(QDeclarativeView::SizeRootObjectToView);
d->ui->show();
+ GeoMap* geoMap = qobject_cast<GeoMap*>(d->ui->rootObject()->findChild<QObject*>("geoMap"));
+ Q_ASSERT(geoMap);
+ geoMap->setFriendModel(&d->friendModel);
+
+
connect(d->ui->engine()->networkAccessManager(),
SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)),
m_facebookAuthenticator, SLOT(sslErrors(QNetworkReply*, QList<QSslError>)));
void SituareEngine::imageReady(User *user)
{
qDebug() << __PRETTY_FUNCTION__;
-
+ Q_D(SituareEngine);
if(user->type())
emit userLocationReady(user);
else
emit friendImageReady(user);
+
+ d->friendModel.resetFriends();
}
void SituareEngine::initializeGpsAndAutocentering()
prevMouseY = mouse.y
}
}
+ onClicked: {
+ map.onClicked(mouseX, mouseY)
+ }
}
Image {
#include "geomap.h"
#include <QDebug>
#include <QGeoMapPixmapObject>
+#include "../user/friendmodel.h"
+#include "../coordinates/geocoordinate.h"
+#include <QGraphicsSceneMouseEvent>
using namespace QtMobility;
+class GeoMapPrivate
+{
+public:
+ GeoMapPrivate()
+ : friendModel(0),
+ gpsLocationMapObject(0)
+ {}
+
+ FriendModel* friendModel;
+
+ QGeoMapPixmapObject* gpsLocationMapObject;
+
+ QList<QGeoMapPixmapObject*> friendMapObjects;
+};
+
GeoMap::GeoMap(QGraphicsItem* parent)
: QGraphicsGeoMap(parent),
+ d_ptr(new GeoMapPrivate),
source(0),
prevGpsLocation(0,0),
initialized(false)
setCenter(prevGpsLocation);
goToGpsLocation();
+
+ setObjectName("geoMap");
}
GeoMap::~GeoMap()
return prevGpsLocation.longitude();
}
+void GeoMap::setFriendModel(FriendModel* friendModel)
+{
+ Q_D(GeoMap);
+ if (friendModel) {
+ d->friendModel = friendModel;
+ connect(d->friendModel, SIGNAL(modelReset()), this, SLOT(onFriendModelReset()));
+ }
+}
+
void GeoMap::panned()
{
emit positionChanged();
}
+void GeoMap::onFriendModelReset()
+{
+ Q_D(GeoMap);
+ Q_ASSERT(d->friendModel);
+
+ foreach(QGeoMapPixmapObject* mapObject, d->friendMapObjects)
+ removeMapObject(mapObject);
+
+ for (int i=0; i < d->friendModel->rowCount(); ++i) {
+ const QModelIndex index = d->friendModel->index(i);
+ QPixmap pixmap = d->friendModel->data(index, FriendModel::ImageRole).value<QPixmap>();
+ GeoCoordinate coordinate = d->friendModel->data(index, FriendModel::CoordinateRole).value<GeoCoordinate>();
+
+ if (pixmap.isNull())
+ pixmap = QPixmap(":/res/images/user_info.png");
+
+ Q_ASSERT(!pixmap.isNull());
+
+ if (!pixmap.isNull() && coordinate.isValid()) {
+ QPoint offset(-pixmap.width()/2, -pixmap.height()/2);
+ QGeoMapPixmapObject* object = new QGeoMapPixmapObject(QGeoCoordinate(coordinate.latitude(), coordinate.longitude()),
+ offset,
+ pixmap,
+ 0);
+ object->setProperty("user", d->friendModel->data(index, FriendModel::UserRole));
+ addMapObject(object);
+ d->friendMapObjects << object;
+ }
+ }
+}
+
void GeoMap::goToGpsLocation()
{
qDebug() << "QmlMap::goToGpsLocation";
}
}
+void GeoMap::onClicked(qreal mouseX, qreal mouseY)
+{
+ Q_D(GeoMap);
+ QList<QGeoMapObject*> mapObjects = mapObjectsAtScreenPosition(QPointF(mouseX, mouseY));
+ QList<User*> filter;
+ foreach(QGeoMapObject* mapObject, mapObjects) {
+ User* user = static_cast<User*>(mapObject->property("user").value<void*>());
+ Q_ASSERT(user);
+ filter << user;
+ }
+ // TODO: reset filter only if it contains at least one entry
+ //if (!filter.isEmpty())
+ d->friendModel->filter(filter);
+}
+
void GeoMap::positionUpdated(const QGeoPositionInfo& positionInfo)
{
qDebug() << "QmlMap::positionUpdated: " << positionInfo.coordinate();
prevGpsLocation = positionInfo.coordinate();
+ Q_D(GeoMap);
- if (!initialized) {
- initialized = true;
+ if (!d->gpsLocationMapObject) {
QPixmap image(":/res/gps_position.png");
Q_ASSERT(!image.isNull());
- QGeoMapPixmapObject* pixmap = new QGeoMapPixmapObject(prevGpsLocation, QPoint(-image.width()/2, -image.height()/2), image);
- addMapObject(pixmap);
+ d->gpsLocationMapObject = new QGeoMapPixmapObject(prevGpsLocation, QPoint(-image.width()/2, -image.height()/2), image);
+ addMapObject(d->gpsLocationMapObject);
setCenter(prevGpsLocation);
emit positionChanged();
}
else {
- qobject_cast<QGeoMapPixmapObject*>(mapObjects().at(0))->setCoordinate(prevGpsLocation);
-
+ d->gpsLocationMapObject->setCoordinate(prevGpsLocation);
}
emit gpsLocationChanged();
}
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
#include <QGeoCoordinate>
-#include <QVector3D>
using namespace QtMobility;
+class FriendModel;
+
+class GeoMapPrivate;
class GeoMap : public QGraphicsGeoMap
{
double gpsLocationLatitude() const;
double gpsLocationLongitude() const;
+ void setFriendModel(FriendModel* friendModel);
+
signals:
void positionChanged();
void screenCenterChanged();
public slots:
void goToGpsLocation();
+ void onClicked(qreal mouseX, qreal mouseY);
private slots:
void positionUpdated(const QGeoPositionInfo& positionInfo);
void panned();
+ void onFriendModelReset();
private:
+ Q_DISABLE_COPY(GeoMap);
+ Q_DECLARE_PRIVATE(GeoMap);
+ QScopedPointer<GeoMapPrivate> d_ptr;
+
QGeoPositionInfoSource *source;
QGeoCoordinate prevGpsLocation;
bool initialized;
endInsertRows();
}
-//void RouteModel::setSegments(const QList<RouteSegment>& segments)
+namespace {
+ QList<User *> filtered(const QList<User *>& all_friends, const QList<User *>& filter)
+ {
+ QList<User *> result = all_friends;
+ if (!filter.isEmpty()) {
+ foreach(User* user, all_friends) {
+ if (!filter.contains(user))
+ result.removeAll(user);
+ }
+ }
+ return result;
+ }
+}
+
void FriendModel::setFriends(const QList<User *>& friends)
{
beginResetModel();
- m_friends = friends;
+ m_all_friends = friends;
+ m_friends = filtered(m_all_friends, m_filter);
+ endResetModel();
+}
+
+void FriendModel::resetFriends()
+{
+ beginResetModel();
+ endResetModel();
+}
+
+void FriendModel::filter(const QList<User*>& friends)
+{
+ beginResetModel();
+ m_filter = friends;
+ m_friends = filtered(m_all_friends, m_filter);
+ endResetModel();
+}
+
+void FriendModel::resetFilter()
+{
+ beginResetModel();
+ m_filter.clear();
+ m_friends = m_all_friends;
endResetModel();
}
const User *user = m_friends[index.row()];
switch (role) {
case CoordinateRole:
-// return user->coordinates();
+ return QVariant::fromValue(user->coordinates());
case AddressRole:
return user->address();
case NameRole:
}
case UserIdRole:
return user->userId();
+ case UserRole:
+ return QVariant::fromValue((void*)user);
default:
return QVariant();
}
TimeStampRole,
DistanceRole,
DistanceUnitRole,
- UserIdRole
+ UserIdRole,
+ UserRole
};
explicit FriendModel(QObject *parent = 0);
void addFriend(const User &singleFriend);
void setFriends(const QList<User *>& friends);
+ void resetFriends();
+
+ void filter(const QList<User*>& friends);
+ Q_INVOKABLE void resetFilter();
+
int rowCount(const QModelIndex & parent = QModelIndex()) const;
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
private:
+ QList<User *> m_all_friends;
+ QList<User *> m_filter;
QList<User *> m_friends;
};