Added FriendGroupItem and FriendItemsHandler classes
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 6 May 2010 09:11:09 +0000 (12:11 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 6 May 2010 09:11:09 +0000 (12:11 +0300)
 - Added FriendGroupItem & FriendItemsHandler classes
   and some basic functionality for grouping friend items

 - Added friend_group.png

 - Modified SituareService to read some debug data from file

 - Moved ItemIgnoresTransformations flag to BaseLocationItem
   constructor

15 files changed:
images.qrc
res/images/friend_group.png [new file with mode: 0644]
src/engine/engine.cpp
src/map/baselocationitem.cpp
src/map/baselocationitem.h
src/map/frienditemshandler.cpp [new file with mode: 0644]
src/map/frienditemshandler.h [new file with mode: 0644]
src/map/friendlocationitem.cpp
src/map/friendlocationitem.h
src/map/mapengine.cpp
src/map/mapengine.h
src/map/ownlocationitem.cpp
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/src.pro

index 9837038..25c1ec6 100644 (file)
@@ -19,5 +19,6 @@
         <file>res/images/led_red_g.png</file>
         <file>res/images/led_red_h.png</file>
         <file>res/images/led_red_s.png</file>
+        <file>res/images/friend_group.png</file>
     </qresource>
 </RCC>
diff --git a/res/images/friend_group.png b/res/images/friend_group.png
new file mode 100644 (file)
index 0000000..9b8aec7
Binary files /dev/null and b/res/images/friend_group.png differ
index 605bc33..62ce97f 100644 (file)
@@ -74,6 +74,8 @@ void SituareEngine::loginOk()
     m_facebookAuthenticator->hide();
     m_ui->show();
     m_situareService->fetchLocations(); // request user locations
+
+    m_situareService->debugData();
 }
 
 void SituareEngine::requestAddress()
index 6ded2bb..bce6209 100644 (file)
@@ -20,6 +20,7 @@
 */
 
 #include <QDebug>
+
 #include "mapengine.h"
 #include "baselocationitem.h"
 
@@ -27,6 +28,19 @@ BaseLocationItem::BaseLocationItem(QObject *parent)
     : QObject(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
+
+    setFlag(QGraphicsItem::ItemIgnoresTransformations);
+}
+
+QRect BaseLocationItem::sceneTransformedBoundingRect(int zoomLevel) const
+{
+    QRect rect = sceneBoundingRect().toRect();
+    int multiplier = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
+
+    int heightDelta = (rect.height() * multiplier - rect.height()) / 2;
+    int widthDelta = (rect.width() * multiplier - rect.width()) / 2;
+
+    return rect.adjusted(-widthDelta, -heightDelta, widthDelta, heightDelta);
 }
 
 void BaseLocationItem::setPosition(const QPointF & newPosition)
index 9e9354f..537b29c 100644 (file)
@@ -63,6 +63,8 @@ public:
     */
     QPoint position() const;
 
+    QRect sceneTransformedBoundingRect(int zoomLevel) const;
+
     /**
     * @brief sets position of item as specified in parameter.
     *        Parameter can be given in georaphical coordinates
diff --git a/src/map/frienditemshandler.cpp b/src/map/frienditemshandler.cpp
new file mode 100644 (file)
index 0000000..bed3192
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+
+#include <QDebug>
+
+#include "frienditemshandler.h"
+
+FriendItemsHandler::FriendItemsHandler(QObject *parent)
+    : QObject(parent)
+{
+}
+
+void FriendItemsHandler::checkFriendsForCollisions()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+//    foreach(FriendGroupItem *item, m_friendGroupItems) {
+//        m_friendGroupItems.removeAll(item);
+//        m_mapScene->removeItem(item);
+//    }
+
+    int lastItem = m_friendsLocations.size() - 1;
+    for (int checking = 0; checking <= lastItem; checking++) {
+        QRect beginItemRect = m_friendsLocations.at(checking)->sceneTransformedBoundingRect(m_zoomLevel);
+
+        // don't check items which are already part of a group (and thus unvisible)
+        if (m_friendsLocations.at(checking)->isPartOfGroup())
+            continue;
+
+        // check all other items
+        for (int another = 0; another <= lastItem; another++)
+        {
+            // don't check against itself
+            if (checking == another)
+                continue;
+
+            // don't check against items which are already part of a group (and thus unvisible)
+            if (m_friendsLocations.at(another)->isPartOfGroup())
+                continue;
+
+            // does items collide
+            QRect iterItemRect = m_friendsLocations.at(another)->sceneTransformedBoundingRect(m_zoomLevel);
+            if (beginItemRect.intersects(iterItemRect)) {
+                qWarning() << __PRETTY_FUNCTION__ << "collision found" << checking << another;
+                FriendGroupItem *group = new FriendGroupItem();
+                m_friendGroupItems.append(group);
+                group->setPos(m_friendsLocations.at(checking)->pos());
+                group->joinFriend(m_friendsLocations.at(checking));
+                group->joinFriend(m_friendsLocations.at(another));
+                m_mapScene->addItem(group);
+                break;
+            }
+        }
+    }
+}
+
+void FriendItemsHandler::checkGroupsForCollisions()
+{
+
+}
+
+void FriendItemsHandler::dropOutOfGroupFriends()
+{
+
+}
+
+void FriendItemsHandler::refactorFriendItems()
+{
+    dropOutOfGroupFriends();
+    checkGroupsForCollisions();
+    checkFriendsForCollisions();
+}
diff --git a/src/map/frienditemshandler.h b/src/map/frienditemshandler.h
new file mode 100644 (file)
index 0000000..ad4a65b
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+
+#ifndef FRIENDITEMSHANDLER_H
+#define FRIENDITEMSHANDLER_H
+
+#include <QList>
+#include <QObject>
+
+class FriendGroupItem;
+
+class FriendItemsHandler : public QObject
+{
+    Q_OBJECT
+
+public:
+    FriendItemsHandler(QObject *parent = 0);
+
+    void checkFriendsForCollisions();
+
+    void checkGroupsForCollisions();
+
+    void dropOutOfGroupFriends();
+
+    void refactorFriendItems();
+
+private:
+    QList<FriendGroupItem *> m_friendGroupItems;
+};
+
+#endif // FRIENDITEMSHANDLER_H
index 39027ce..ef8ae5e 100644 (file)
 FriendLocationItem::FriendLocationItem(const QPixmap &icon,
                                        const QPointF &friendsLocation,
                                        QObject *parent)
-                                           : BaseLocationItem(parent)
+    : BaseLocationItem(parent),
+      m_partOfGroup(false)
 
 {
-    //Q_UNUSED(parent);
     qDebug() << __PRETTY_FUNCTION__;
 
     setPixmap(icon);
     setPosition(QPointF( friendsLocation.x(), friendsLocation.y() ));
     setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
     setOffset(-icon.width()/2, -icon.height()/2);
-    setFlag(QGraphicsItem::ItemIgnoresTransformations);       
 }
 
+bool FriendLocationItem::isPartOfGroup() const
+{
+    return m_partOfGroup;
+}
 
 void FriendLocationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
@@ -50,6 +53,11 @@ void FriendLocationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
     emit iconClicked(m_userId);
 }
 
+void FriendLocationItem::setPartOfGroup(bool value)
+{
+    m_partOfGroup = value;
+}
+
 QString FriendLocationItem::userId() const
 {
     return m_userId;
index c4a6b15..67a0836 100644 (file)
@@ -55,6 +55,8 @@ public:
     */
     FriendLocationItem(const QPixmap &icon, const QPointF &friendsLocation, QObject *parent = 0);    
 
+    bool isPartOfGroup() const;
+
     /**
     * @brief getter for m_userId
     *
@@ -62,6 +64,8 @@ public:
     */
     QString userId() const;
 
+    void setPartOfGroup(bool value);
+
     /**
     * @brief sets name for friend.
     *
@@ -88,6 +92,7 @@ protected:
     void mousePressEvent(QGraphicsSceneMouseEvent *event);    
 
 private:
+    bool m_partOfGroup;
     QString m_userId; ///< Friends user ID
 };
 
index 4b68360..95bfceb 100644 (file)
@@ -30,6 +30,7 @@
 #include <QHashIterator>
 #include <QRect>
 
+#include "frienditemshandler.h"
 #include "mapengine.h"
 #include "maptile.h"
 
@@ -55,7 +56,11 @@ MapEngine::MapEngine(QObject *parent)
     connect(m_mapZoomPanel, SIGNAL(zoomInPressed()), this, SLOT(zoomIn()));
     connect(m_mapZoomPanel, SIGNAL(zoomOutPressed()), this, SLOT(zoomOut()));
 
-   m_ownLocation = new OwnLocationItem(QPointF());
+    /// @todo VILLE: m_ownLocation ei poisteta mikäli ei koskaan saa tietoa sijainnista jolloin vasta
+    /// lisätään sceneen
+    m_ownLocation = new OwnLocationItem(QPointF());
+
+    m_friendItemsHandler = new FriendItemsHandler(this);
 }
 
 MapEngine::~MapEngine()
@@ -333,5 +338,11 @@ void MapEngine::receiveFriendLocations(QList<User *> &friendsList)
         friendLocation->setUserId(friendsList.at(i)->userId());
         m_friendsLocations.append(friendLocation);
         m_mapScene->addItem(friendLocation);
+
+        m_friendItemsHandler->refactorFriendItems();
     }
 }
+
+
+
+
index 15bb3ef..304c1e2 100644 (file)
@@ -35,6 +35,8 @@
 #include "friendlocationitem.h"
 #include "user/user.h"
 
+class FriendItemsHandler;
+
 /**
 * @brief Map engine
 *
@@ -265,6 +267,7 @@ signals:
  ******************************************************************************/
 private:
     QPoint m_centerTile; ///< Current center tile
+    FriendItemsHandler *m_friendItemsHandler;
     MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
     MapScene *m_mapScene; ///< Scene for map tiles
     MapZoomPanel *m_mapZoomPanel; ///< Toolbar for zoom buttons
index f95e692..6cf5bb7 100644 (file)
@@ -34,5 +34,4 @@ OwnLocationItem::OwnLocationItem(const QPointF & ownPosition)
     setPosition(ownPosition);
     setZValue(OWN_LOCATION_ICON_Z_LEVEL);
     setOffset(-ownLocationIcon.width()/2, -ownLocationIcon.height()/2);
-    setFlag(QGraphicsItem::ItemIgnoresTransformations);
 }
index fdd9714..9e81150 100644 (file)
@@ -22,6 +22,7 @@
 #include <QtAlgorithms>
 #include <QDebug>
 #include <QtGlobal>
+#include <QString>
 #include <QStringList>
 #include <QPixmap>
 #include <QNetworkReply>
@@ -64,6 +65,17 @@ SituareService::~SituareService()
     m_friendsList.clear();
 }
 
+void SituareService::debugData()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+    QFile file("/home/ramosam-local/situare_debug_data.txt");
+    qWarning() << __PRETTY_FUNCTION__ << "file size: " << file.size();
+    qWarning() << __PRETTY_FUNCTION__ << "file open success?" << file.open(QIODevice::ReadOnly);
+    QByteArray debugReplyArray = file.readAll();
+    qWarning() << __PRETTY_FUNCTION__ << "did read" << debugReplyArray.size();
+    parseUserData(debugReplyArray);
+}
+
 void SituareService::fetchLocations()
 {
     qDebug() << __PRETTY_FUNCTION__;
index 605dfe9..2594877 100644 (file)
@@ -63,6 +63,8 @@ public:
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 
+    void debugData();
+
     /**
     * @brief Retrieves location user and friends information from Situare server
     *
@@ -111,7 +113,7 @@ private:
     * @param urlParameters optional parameters for url
     * @return QUrl formed url
     */
-    QUrl formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters = 0);
+    QUrl formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters = QString());
 
     /**
     * @brief Forms url parameters
@@ -121,7 +123,7 @@ private:
     * @param publish optional publish location on Facebook wall (true/false)
     * @return QString
     */
-    QString formUrlParameters(const QPointF &coordinates, QString status = 0, QString publish = 0);
+    QString formUrlParameters(const QPointF &coordinates, QString status = QString(), QString publish = QString());
 
     /**
     * @brief Parses user and friend data from JSON string
index 62e816c..9637e9a 100644 (file)
@@ -36,7 +36,9 @@ SOURCES += main.cpp \
     ui/situareuser.cpp \
     engine/engine.cpp \
     ui/settingsdialog.cpp \
-    map/maptilerequest.cpp
+    map/maptilerequest.cpp \
+    map/friendgroupitem.cpp \
+    map/frienditemshandler.cpp
 HEADERS += ui/mainwindow.h \
     ui/mapviewscreen.h \
     ui/listviewscreen.h \
@@ -69,7 +71,9 @@ HEADERS += ui/mainwindow.h \
     ui/situareuser.h \
     engine/engine.h \
     ui/settingsdialog.h \
-    map/maptilerequest.h
+    map/maptilerequest.h \
+    map/friendgroupitem.h \
+    map/frienditemshandler.h
 QT += network \
     webkit
 DEFINES += QT_NO_DEBUG_OUTPUT
@@ -78,7 +82,7 @@ DEFINES += QT_NO_DEBUG_OUTPUT
     message(Make sure you have QJson development headers installed)
     message(install headers with: sudo apt-get install libqjson-dev)
 }
-maemo5 {
+maemo5 { 
     message(QJson built in)
     message(Make sure you have QJson development headers installed)
     message(add: deb http://repository.maemo.org/extras-devel fremantle free non-free)