Added unit test for TagsDialog.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 2 Nov 2010 10:46:46 +0000 (12:46 +0200)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 2 Nov 2010 10:46:46 +0000 (12:46 +0200)
27 files changed:
res/images/tag.png
res/images/tag_btn.png
res/images/tag_btn_d.png
res/images/tag_btn_s.png
src/engine/engine.cpp
src/situareservice/database.cpp
src/situareservice/database.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/ui/extendedlistitem.cpp
src/ui/extendedlistitem.h
src/ui/listitem.cpp
src/ui/listitem.h
src/ui/listview.cpp
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/meetpeoplepanel.cpp
src/ui/tagsdialog.cpp
src/ui/tagsdialog.h
src/ui/userinfo.cpp
src/ui/userinfo.h
src/ui/userinfopanel.cpp
src/ui/userinfopanel.h
src/user/user.cpp
src/user/user.h
tests/ui/tagsdialog/tagsdialog.pro [new file with mode: 0644]
tests/ui/tagsdialog/testtagsdialog.cpp [new file with mode: 0644]

index 3f9ace8..43c500e 100644 (file)
Binary files a/res/images/tag.png and b/res/images/tag.png differ
index 60cf753..05512af 100644 (file)
Binary files a/res/images/tag_btn.png and b/res/images/tag_btn.png differ
index b496f8e..0ee1712 100644 (file)
Binary files a/res/images/tag_btn_d.png and b/res/images/tag_btn_d.png differ
index 56d132e..52414c5 100644 (file)
Binary files a/res/images/tag_btn_s.png and b/res/images/tag_btn_s.png differ
index abf5ebc..236485e 100644 (file)
@@ -713,6 +713,12 @@ void SituareEngine::signalsFromMainWindow()
     connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
             this, SLOT(enableAutomaticLocationUpdate(bool, int)));
 
+    connect(m_ui, SIGNAL(addTags(QStringList)),
+            m_situareService, SLOT(addTags(QStringList)));
+
+    connect(m_ui, SIGNAL(removeTags(QStringList)),
+            m_situareService, SLOT(removeTags(QStringList)));
+
     // signals from user info tab
     connect(m_ui, SIGNAL(refreshUserData()),
             this, SLOT(refreshUserData()));
index bca5e91..d97749f 100644 (file)
@@ -167,15 +167,15 @@ QByteArray Database::getInterestingPeople(qulonglong userId,
     QStringList userIds;
     QHashIterator<QString, QString> i(tags);
     while (i.hasNext())
-        userIds.append(i.key());
+        userIds.append(i.next().key());
 
     QSqlQuery userQuery(QString("SELECT user.id, user.name, user.image_url FROM user WHERE "
                                 "user.id IN (") + userIds.join(", ") + QString(") AND "
                                 "user.latitude >= '%1' AND user.latitude < '%2' AND "
-                                "user.longitude >= '%3' AND user.longitude < '%4")
+                                "user.longitude >= '%3' AND user.longitude < '%4'")
                 .arg(southWestCoordinates.latitude()).arg(northEastCoordinates.latitude())
                 .arg(southWestCoordinates.longitude()).arg(northEastCoordinates.longitude()));
-
+    qWarning() << userQuery.lastQuery();
     QString result;
     result.append("{\"people\": [");
 
@@ -229,17 +229,17 @@ QByteArray Database::getNotifications(qulonglong userId)
     return result.toUtf8();
 }
 
-QStringList Database::getTags(qulonglong userId)
+QHash<QString, QString> Database::getTags(qulonglong userId)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QStringList tags;
+    QHash<QString, QString> tags;
 
-    QSqlQuery query(QString("SELECT tag.name FROM usertag, tag WHERE usertag.userid = '%1' "
+    QSqlQuery query(QString("SELECT tag.id, tag.name FROM usertag, tag WHERE usertag.userid = '%1' "
                             "AND usertag.tagid = tag.id").arg(userId));
 
     while (query.next())
-        tags.append(query.value(0).toString());
+        tags.insert(query.value(0).toString(), query.value(1).toString());
 
     return tags;
 }
@@ -258,6 +258,22 @@ bool Database::openDatabase()
     return m_database.open();
 }
 
+bool Database::removeTags(qulonglong userId, const QStringList &tags)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QSqlQuery removeTagsQuery;
+
+    bool val = removeTagsQuery.exec(QString("DELETE FROM usertag WHERE usertag.userid = "
+                                         "'%1' AND usertag.tagid IN (").arg(userId) +
+                                 tags.join(", ") + ")");
+
+    qWarning() << __PRETTY_FUNCTION__ << val;
+    qWarning() << removeTagsQuery.lastQuery();
+
+    return true;
+}
+
 bool Database::sendMessage(qulonglong senderId, qulonglong receiverId, const QString &message)
 {
     qDebug() << __PRETTY_FUNCTION__;
index b929341..fba806e 100644 (file)
@@ -20,7 +20,7 @@ public:
 
     bool addTag(qulonglong userId, const QString &tag);
     QByteArray getNotifications(qulonglong userId);
-    QStringList getTags(qulonglong userId);
+    QHash<QString, QString> getTags(qulonglong userId);
     QByteArray getInterestingPeople(qulonglong userId,
                                      const GeoCoordinate &southWestCoordinates,
                                      const GeoCoordinate &northEastCoordinates);
@@ -30,6 +30,7 @@ public:
     bool createUserTagTable();
     bool createUserTable();
     bool openDatabase();
+    bool removeTags(qulonglong userId, const QStringList &tags);
     bool sendMessage(qulonglong senderId, qulonglong receiverId, const QString &message);
 
 private:
index 6130658..d5fe2f3 100644 (file)
@@ -81,7 +81,7 @@ void SituareService::fetchMessages()
     qDebug() << __PRETTY_FUNCTION__;
 
     //Request sent to server does not need the UID
-    QByteArray arr = m_database->getNotifications(m_user->userId().toULongLong());
+    QByteArray arr = m_database->getNotifications(613374451);
 
     parseMessagesData(arr);
 }
@@ -92,7 +92,7 @@ void SituareService::fetchPeopleWithSimilarInterest(const GeoCoordinate &southWe
     qDebug() << __PRETTY_FUNCTION__;
 
     //Request sent to server does not need the UID
-    QByteArray arr = m_database->getInterestingPeople(m_user->userId().toULongLong(),
+    QByteArray arr = m_database->getInterestingPeople(613374451,
                                                       southWestCoordinates,
                                                       northEastCoordinates);
 
@@ -258,7 +258,7 @@ void SituareService::sendMessage(const QString &receiverId, const QString &messa
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    qWarning() << __PRETTY_FUNCTION__ << m_database->sendMessage(m_user->userId().toULongLong(), receiverId.toULongLong(), message);
+    qWarning() << __PRETTY_FUNCTION__ << m_database->sendMessage(613374451, receiverId.toULongLong(), message);
 }
 
 void SituareService::sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie)
@@ -600,17 +600,24 @@ void SituareService::clearUserData()
     emit userDataChanged(m_user, m_friendsList);
 }
 
-QStringList SituareService::getTags(const QString &userId)
+QHash<QString, QString> SituareService::getTags(const QString &userId)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     return m_database->getTags(userId.toInt());
 }
 
-void SituareService::updateTags(const QString &userId, const QStringList &tags)
+void SituareService::removeTags(const QStringList &tags)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_database->removeTags(613374451, tags);
+}
+
+void SituareService::addTags(const QStringList &tags)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     foreach (QString tag, tags)
-        m_database->addTag(userId.toInt(), tag);
+        m_database->addTag(613374451, tag);
 }
index 92f5a90..78c40bb 100644 (file)
@@ -103,16 +103,15 @@ public:
     */
     void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
 
+public slots:
     /**
-    * @brief Updates tags to the Situare server
+    * @brief Adds tags to the Situare server
     *
     * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
-    * @param userId user ID
     * @param tags list of user's tags
     */
-    void updateTags(const QString &userId, const QStringList &tags);
+    void addTags(const QStringList &tags);
 
-public slots:
     /**
     * @brief Retrieves messages sent to user.
     */
@@ -132,6 +131,13 @@ public slots:
     void credentialsReady(const FacebookCredentials &credentials);
 
     /**
+    * @brief Removes tags.
+    *
+    * @param tags list of tags to remove
+    */
+    void removeTags(const QStringList &tags);
+
+    /**
     * @brief Public slot, which indicates when http request has been completed
     *
     * @param reply storage for http reply
@@ -200,7 +206,7 @@ private:
     * @param userId
     * @return QStringList list of tags
     */
-    QStringList getTags(const QString &userId);
+    QHash<QString, QString> getTags(const QString &userId);
 
     /**
     * @brief Parses interesting people data from JSON string
index 79da1bd..3c8c319 100644 (file)
@@ -30,8 +30,9 @@
 
 #include "extendedlistitem.h"
 
-ExtendedListItem::ExtendedListItem()
-    : m_selected(false),
+ExtendedListItem::ExtendedListItem(QListWidget *parent, int type)
+    : ListItem(parent, type),
+      m_selected(false),
       m_expandedHeight(ITEM_MIN_HEIGHT),
       m_normalHeight(ITEM_MIN_HEIGHT),
       m_subItemTextWidth(SUBITEM_TEXT_MAX_WIDTH)
index 0522c6e..db1318e 100644 (file)
@@ -40,7 +40,7 @@ public:
     *
     * Sets item size and creates sub item store list.
     */
-    ExtendedListItem();
+    ExtendedListItem(QListWidget *parent = 0, int type = Type);
 
     /**
     * @brief Destructor.
index 82127db..d8ab074 100644 (file)
@@ -28,7 +28,8 @@
 
 #include "listitem.h"
 
-ListItem::ListItem()
+ListItem::ListItem(QListWidget *parent, int type)
+    : QListWidgetItem(parent, type)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
index 29600b0..cf59961 100644 (file)
@@ -38,7 +38,7 @@ public:
     /**
     * @brief Constructor.
     */
-    ListItem();
+    ListItem(QListWidget *parent = 0, int type = Type);
 
     /**
     * @brief Defines text size.
index 94be566..e429a74 100644 (file)
@@ -197,7 +197,7 @@ void ListView::listItemClicked(QListWidgetItem *item)
 
     ListItem *currentItem = dynamic_cast<ListItem*>(item);
 
-    if (currentItem)
+    if (currentItem && (currentItem->type() != QListWidgetItem::UserType))
         listItemClicked(currentItem);
 }
 
index a26eace..f5bea55 100644 (file)
@@ -526,6 +526,12 @@ void MainWindow::buildUserInfoPanel()
 
     connect(this, SIGNAL(userImageReady(QString,QPixmap)),
             m_userInfoPanel, SLOT(setImage(QString,QPixmap)));
+
+    connect(m_userInfoPanel, SIGNAL(addTags(QStringList)),
+            this, SIGNAL(addTags(QStringList)));
+
+    connect(m_userInfoPanel, SIGNAL(removeTags(QStringList)),
+            this, SIGNAL(removeTags(QStringList)));
 }
 
 void MainWindow::buildWebView()
index 58edfae..bf43cb0 100644 (file)
@@ -457,6 +457,13 @@ private slots:
  ******************************************************************************/
 signals:
     /**
+    * @brief Signal for adding tags.
+    *
+    * @param tags tags to add
+    */
+    void addTags(const QStringList &tags);
+
+    /**
      * @brief Automatic centering setting changed by user
      *
      * @param enabled True if automatic centering is enabled, otherwise false
@@ -627,6 +634,13 @@ signals:
     void refreshUserData();
 
     /**
+    * @brief Signal for removing tags.
+    *
+    * @param tags tags to add
+    */
+    void removeTags(const QStringList &tags);
+
+    /**
     * @brief Requests contact dialog.
     *
     * @param facebookId contact's facebookId
index 61f7c91..259f59b 100644 (file)
@@ -100,13 +100,13 @@ void MeetPeoplePanel::populateInterestingPeopleListView(QList<User> &interesting
     for (int i = 0; i < interestingPeople.count(); ++i) {
         if (i == 0) {
             m_personListView->setItemDelegateForRow(i, new HeaderListItemDelegate(this));
-            ExtendedListItem *item = new ExtendedListItem();
+            ExtendedListItem *item = new ExtendedListItem(0, QListWidgetItem::UserType);
             item->setTitle(tr("Friends:"));
             m_personListView->addListItem(QString("header") + QString::number(i), item);
         }
         else if (i == 2) {
             m_personListView->setItemDelegateForRow(i+1, new HeaderListItemDelegate(this));
-            ExtendedListItem *item = new ExtendedListItem();
+            ExtendedListItem *item = new ExtendedListItem(0, QListWidgetItem::UserType);
             item->setTitle(tr("Others:"));
             m_personListView->addListItem(QString("header") + QString::number(i), item);
         }
index 15c9351..ec0e2bf 100644 (file)
@@ -8,14 +8,14 @@
 
 #include "tagsdialog.h"
 
-TagsDialog::TagsDialog(const QStringList &tags)
+TagsDialog::TagsDialog(const QHash<QString, QString> &tags)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     setWindowTitle(tr("Edit tags"));
 
     QGridLayout *gridLayout = new QGridLayout;
-    m_addTagEdit = new QLineEdit("sdsds");
+    m_addTagEdit = new QLineEdit("");
     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
 
     QPushButton *addButton = buttonBox->addButton(tr("Add"), QDialogButtonBox::ActionRole);
@@ -40,18 +40,56 @@ TagsDialog::TagsDialog(const QStringList &tags)
 
     connect(cancelButton, SIGNAL(clicked()),
             this, SLOT(reject()));
+
+    connect(addButton, SIGNAL(clicked()),
+            this, SLOT(addTagToList()));
+
+    connect(deleteButton, SIGNAL(clicked()),
+            this, SLOT(deleteTagFromList()));
 }
 
-QStringList TagsDialog::userTags()
+void TagsDialog::addTagToList()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    QStringList tags;
 
-    for (int i = 0; i < m_tagsView->count(); ++i) {
-        QListWidgetItem *tagItem = m_tagsView->item(i);
-        if (tagItem)
-            tags.append(tagItem->text());
+    QList<QListWidgetItem *> findItems = m_tagsView->findItems(m_addTagEdit->text(),
+                                                               Qt::MatchExactly);
+
+    if (findItems.isEmpty()) {
+        m_tagsView->insertItem(0, m_addTagEdit->text());
+        m_newTags.append(m_addTagEdit->text());
     }
 
-    return tags;
+    m_addTagEdit->setText("");
+}
+
+void TagsDialog::deleteTagFromList()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QList<QListWidgetItem *> selectedItems = m_tagsView->selectedItems();
+
+    if (!selectedItems.isEmpty()) {
+        QListWidgetItem *selectedItem = selectedItems.at(0);
+        m_tagsView->takeItem(m_tagsView->row(selectedItem));
+
+        if (m_newTags.contains(selectedItem->text()))
+            m_newTags.removeOne(selectedItem->text());
+        else
+            m_removedTags.append(selectedItem->text());
+    }
+}
+
+QStringList TagsDialog::newTags()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_newTags;
+}
+
+QStringList TagsDialog::removedTags()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_removedTags;
 }
index e389d3f..9550de8 100644 (file)
@@ -23,6 +23,7 @@
 #define TAGSDIALOG_H
 
 #include <QDialog>
+#include <QHash>
 
 class QDialogButtonBox;
 class QLabel;
@@ -42,11 +43,16 @@ class TagsDialog : public QDialog
 public:
 
     /**
+    * @brief Unit test class.
+    */
+    friend class TestTagsDialog;
+
+    /**
     * @brief Default constructor
     *
     * @param parent Instance of parent widget
     */
-    TagsDialog(const QStringList &tags);
+    TagsDialog(const QHash<QString, QString> &tags);
 
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
@@ -54,20 +60,40 @@ public:
 public:
 
     /**
-    * @brief Gets user tags.
+    * @brief Gets new tags.
+    *
+    * @return list of new tags
+    */
+    QStringList newTags();
+
+    /**
+    * @brief Gets removed tags.
     *
-    * @param email Email address
-    * @param password Password
+    * @return list of removed tags
     */
-    QStringList userTags();
+    QStringList removedTags();
+
+private slots:
+    /**
+    * @brief Adds tag to the list.
+    */
+    void addTagToList();
+
+    /**
+    * @brief Deletes tag from the list.
+    */
+    void deleteTagFromList();
 
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    QLineEdit *m_addTagEdit;
+    QLineEdit *m_addTagEdit;    ///< Add tag line edit
+
+    QListWidget *m_tagsView;    ///< Tag list view
 
-    QListWidget *m_tagsView;
+    QStringList m_newTags;      ///< List of new tags
+    QStringList m_removedTags;  ///< Removed tags
 };
 
 #endif // LOGINDIALOG_H
index dc00392..ad6f221 100644 (file)
@@ -123,6 +123,9 @@ UserInfo::UserInfo(QWidget *parent)
     m_backgroundTopImage.load(":/res/images/list_item_top.png");
     m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
     m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
+    m_backgroundTopSelectedImage.load(":/res/images/list_item_top_selected.png");
+    m_backgroundMiddleSelectedImage.load(":/res/images/list_item_middle_selected.png");
+    m_backgroundBottomSelectedImage.load(":/res/images/list_item_bottom_selected.png");
 
     restoreUnsendMessage();
 }
@@ -221,6 +224,7 @@ void UserInfo::mouseReleaseEvent(QMouseEvent *event)
             setExpanded(true);
             m_expanded = true;
         }
+        update();
     }
 }
 
@@ -232,15 +236,21 @@ void UserInfo::paintEvent(QPaintEvent *event)
 
     QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
 
-    QRect middleRect = QRect(topRect.left(), topRect.bottom() + 1, BACKGROUND_WIDTH,
-                             this->height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
+    QRect middleRect = QRect(topRect.left(), topRect.bottom(), BACKGROUND_WIDTH,
+                             height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
 
-    QRect bottomRect = QRect(topRect.left(), middleRect.bottom() + 1, BACKGROUND_WIDTH,
+    QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
                              BACKGROUND_BOTTOM_HEIGHT);
 
-    painter.drawPixmap(topRect, m_backgroundTopImage);
-    painter.drawPixmap(middleRect, m_backgroundMiddleImage);
-    painter.drawPixmap(bottomRect, m_backgroundBottomImage);
+    if (m_expanded) {
+        painter.drawPixmap(topRect, m_backgroundTopSelectedImage);
+        painter.drawPixmap(middleRect, m_backgroundMiddleSelectedImage);
+        painter.drawPixmap(bottomRect, m_backgroundBottomSelectedImage);
+    } else {
+        painter.drawPixmap(topRect, m_backgroundTopImage);
+        painter.drawPixmap(middleRect, m_backgroundMiddleImage);
+        painter.drawPixmap(bottomRect, m_backgroundBottomImage);
+    }
 }
 
 void UserInfo::restoreUnsendMessage()
@@ -298,7 +308,7 @@ void UserInfo::setExpanded(bool expanded)
     emit itemSelectionChanged(expanded);
 }
 
-void UserInfo::setTags(const QStringList &tags)
+void UserInfo::setTags(const QHash<QString, QString> &tags)
 {
 qDebug() << __PRETTY_FUNCTION__;
 
@@ -306,8 +316,11 @@ qDebug() << __PRETTY_FUNCTION__;
 
     QString tagsText;
 
-    foreach (QString tag, tags)
-    tagsText.append("[" + tag + "] ");
+    QHashIterator<QString, QString> tagsIterator(tags);
+    while (tagsIterator.hasNext()) {
+        tagsIterator.next();
+        tagsText.append("[" + tagsIterator.value() + "] ");
+    }
 
     m_tagsTextLabel->setText(tagsText);
 }
@@ -341,13 +354,22 @@ void UserInfo::showTagsDialog()
 
 void UserInfo::tagsDialogFinished(int reason)
 {
-qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
-    if (reason == QDialog::Accepted) {
-        QStringList userTags = m_tagsDialog->userTags();
-    }
+    if (m_tagsDialog) {
+        if (reason == QDialog::Accepted) {
+            QStringList removedTagsIds;
+
+            foreach (QString removedTag, m_tagsDialog->removedTags())
+                removedTagsIds.append(m_userTags.key(removedTag));
 
-    m_tagsDialog->deleteLater();
+            emit removeTags(removedTagsIds);
+            emit addTags(m_tagsDialog->newTags());
+        }
+
+        m_tagsDialog->deleteLater();
+        m_tagsDialog = 0;
+    }
 }
 
 void UserInfo::updateLocationDialogFinished(int reason)
index 4b9e3eb..8d48f7b 100644 (file)
@@ -119,7 +119,7 @@ public:
     *
     * @param tags list of tags
     */
-    void setTags(const QStringList &tags);
+    void setTags(const QHash<QString, QString> &tags);
 
     /**
      * @brief Sets the time of updated message
@@ -206,6 +206,13 @@ private slots:
 ******************************************************************************/
 signals:
     /**
+    * @brief Signal for adding tags.
+    *
+    * @param tags tags to add
+    */
+    void addTags(const QStringList &tags);
+
+    /**
      * @brief Signal for finding user.
      *
      * @param coordinates user geo coordinates
@@ -227,6 +234,13 @@ signals:
     void requestReverseGeo();
 
     /**
+    * @brief Signal for removing tags.
+    *
+    * @param tags tags to add
+    */
+    void removeTags(const QStringList &tags);
+
+    /**
      * @brief Signals, when address data is ready
      *
      * @param address Street address
@@ -264,6 +278,9 @@ private:
     QPixmap m_backgroundBottomImage;        ///< Bottom background image
     QPixmap m_backgroundMiddleImage;        ///< Middle background image
     QPixmap m_backgroundTopImage;           ///< Top background image
+    QPixmap m_backgroundBottomSelectedImage;   ///< Selected bottom background image
+    QPixmap m_backgroundMiddleSelectedImage;   ///< Selected middle background image
+    QPixmap m_backgroundTopSelectedImage;      ///< Selected top background image
 
     QPoint m_mousePosition;                 ///< Current mouse press position
 
@@ -272,7 +289,7 @@ private:
     QString m_messageText;                  ///< User's message
     QString m_userName;                     ///< User's name
 
-    QStringList m_userTags;                 ///< User's tags
+    QHash<QString, QString> m_userTags;                 ///< User's tags
 
     GeoCoordinate m_coordinates;            ///< User current coordinates
     ImageButton *m_avatar;                  ///< User find button
index 94b0774..fc58695 100644 (file)
@@ -85,6 +85,12 @@ UserInfoPanel::UserInfoPanel(QWidget *parent)
     connect(m_userInfo, SIGNAL(itemSelectionChanged(bool)),
             this, SLOT(onUserInfoItemSelected(bool)));
 
+    connect(m_userInfo, SIGNAL(addTags(QStringList)),
+            this, SIGNAL(addTags(QStringList)));
+
+    connect(m_userInfo, SIGNAL(removeTags(QStringList)),
+            this, SIGNAL(removeTags(QStringList)));
+
     ImageButton *updateFriendsButton = new ImageButton(":/res/images/refresh.png",
                                                        ":/res/images/refresh_s.png",
                                                        "", this);
index bb10a2d..5aee4c8 100644 (file)
@@ -71,6 +71,13 @@ public slots:
  ******************************************************************************/
 signals:
     /**
+    * @brief Signal for adding tags.
+    *
+    * @param tags tags to add
+    */
+    void addTags(const QStringList &tags);
+
+    /**
      * @brief Signal for collapse user info
      */
     void collapse();
@@ -98,6 +105,13 @@ signals:
     void refreshUserData();
 
     /**
+    * @brief Signal for removing tags.
+    *
+    * @param tags tags to add
+    */
+    void removeTags(const QStringList &tags);
+
+    /**
      * @brief Signal for requesting reverseGeo from SituareEngine
      */
     void requestReverseGeo();
index fbbc0e8..c4d5537 100644 (file)
 
 User::User(const QString &address, const GeoCoordinate &coordinates, const QString &name,
            const QString &note, const QUrl &imageUrl, const QString &timestamp, const bool &type,
-           const QString &userId, const QString &units, const double &value,
-           const QStringList &tags)
+           const QString &userId, const QString &units, const double &value)
                : m_address(address)
                , m_coordinates(coordinates)
                , m_name(name)
                , m_note(note)
                , m_profileImageUrl(imageUrl)
-               , m_tags(tags)
                , m_timestamp(timestamp)
                , m_type(type)
                , m_units(units)
@@ -94,17 +92,17 @@ void User::setProfileImageUrl(const QUrl &imageUrl)
     m_profileImageUrl = imageUrl;
 }
 
-void User::setTags(const QStringList &tags)
+void User::setTags(const QHash<QString, QString> &tags)
 {
     m_tags = tags;
 }
 
 void User::setTags(const QList<QVariant> &tags)
 {
-    QStringList tagsStrings;
+    QHash<QString, QString> tagsStrings;
 
-    foreach (QVariant tag, tags)
-        tagsStrings.append(tag.toString());
+    for (int i = 0; i < tags.count(); ++i)
+        tagsStrings.insert(QString::number(i), tags.at(i).toString());
 
     m_tags = tagsStrings;
 }
@@ -155,7 +153,7 @@ const QUrl& User::profileImageUrl() const
     return m_profileImageUrl;
 }
 
-const QStringList& User::tags() const
+const QHash<QString, QString>& User::tags() const
 {
     return m_tags;
 }
index 0b0ca2e..cfb45f1 100644 (file)
@@ -45,7 +45,7 @@ public:
     User(const QString &address, const GeoCoordinate &coordinates, const QString &name,
          const QString &note, const QUrl &imageUrl, const QString &timestamp,
          const bool &type, const QString &userId, const QString &units = 0,
-         const double &value = 0, const QStringList &tags = QStringList());
+         const double &value = 0);
 
     /**
     * @brief Default constructor, initializes member data as NULL/0
@@ -112,7 +112,7 @@ public:
     *
     * @param tags user's tags
     */
-    void setTags(const QStringList &tags);
+    void setTags(const QHash<QString, QString> &tags);
 
     /**
     * @brief Sets user's tags.
@@ -190,7 +190,7 @@ public:
     *
     * @return QStringList list of tags
     */
-    const QStringList &tags() const;
+    const QHash<QString, QString> &tags() const;
 
     /**
     * @brief Get timestamp of last status update
@@ -223,7 +223,7 @@ private:
     QString m_name; ///< placeholder for name
     QString m_note; ///< placeholder for note
     QUrl m_profileImageUrl; ///< placeholder for image url
-    QStringList m_tags;     ///< placeholder for tags
+    QHash<QString, QString> m_tags;     ///< placeholder for tags
     QString m_timestamp; ///< placeholer for timestamp
     bool m_type; ///< placeholder for user type
     QString m_units; ///< placeholder for distance unit type
diff --git a/tests/ui/tagsdialog/tagsdialog.pro b/tests/ui/tagsdialog/tagsdialog.pro
new file mode 100644 (file)
index 0000000..c1a0850
--- /dev/null
@@ -0,0 +1,11 @@
+CONFIG += qtestlib
+DEFINES += QT_NO_DEBUG_OUTPUT
+INCLUDEPATH += . \
+    ../../../src/
+
+HEADERS += \
+    ../../../src/ui/tagsdialog.h
+
+SOURCES += \
+    ../../../src/ui/tagsdialog.cpp \
+    testtagsdialog.cpp
diff --git a/tests/ui/tagsdialog/testtagsdialog.cpp b/tests/ui/tagsdialog/testtagsdialog.cpp
new file mode 100644 (file)
index 0000000..16e3eb9
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@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 <QtTest>
+#include <QtGui>
+
+#include "../../../src/ui/tagsdialog.h"
+
+class TestTagsDialog: public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void initTestCase();
+    void cleanup();
+    void init();
+    void addTagToList();
+    void addAndDeleteTag();
+
+private:
+    QHash<QString, QString> m_tags;
+    TagsDialog *m_tagsDialog;
+};
+
+void TestTagsDialog::cleanup()
+{
+    delete m_tagsDialog;
+}
+
+void TestTagsDialog::init()
+{
+    m_tagsDialog = new TagsDialog(m_tags);
+    QVERIFY(m_tagsDialog);
+    QCOMPARE(m_tagsDialog->m_tagsView->count(), 3);
+}
+
+void TestTagsDialog::initTestCase()
+{
+    m_tags.insert("1", "pop");
+    m_tags.insert("2", "rock");
+    m_tags.insert("3", "britney spears");
+}
+
+void TestTagsDialog::addTagToList()
+{
+    m_tagsDialog->m_addTagEdit->setText("new age");
+    m_tagsDialog->addTagToList();
+    QCOMPARE(m_tagsDialog->m_tagsView->count(), 4);
+    QCOMPARE(m_tagsDialog->m_tagsView->item(0)->text(), QString("new age"));
+    QVERIFY(m_tagsDialog->newTags().contains("new age"));
+}
+
+void TestTagsDialog::addAndDeleteTag()
+{
+    addTagToList();
+
+    m_tagsDialog->m_tagsView->setItemSelected(m_tagsDialog->m_tagsView->item(0), true);
+    m_tagsDialog->deleteTagFromList();
+    QCOMPARE(m_tagsDialog->m_tagsView->count(), 3);
+    QVERIFY(m_tags.contains("1"));
+    QVERIFY(m_tags.contains("2"));
+    QVERIFY(m_tags.contains("3"));
+
+    QListWidgetItem *item = m_tagsDialog->m_tagsView->item(0);
+    m_tagsDialog->m_tagsView->setItemSelected(item, true);
+    m_tagsDialog->deleteTagFromList();
+    QCOMPARE(m_tagsDialog->m_tagsView->count(), 2);
+    QVERIFY(m_tagsDialog->removedTags().contains(item->text()));
+}
+
+QTEST_MAIN(TestTagsDialog)
+#include "testtagsdialog.moc"