connect(m_situareService, SIGNAL(updateWasSuccessful(SituareService::SuccessfulMethod)),
m_ui, SIGNAL(clearUpdateLocationDialogData()));
- connect(m_situareService, SIGNAL(interestingPeopleReceived(QList<User>&)),
- m_ui, SIGNAL(interestingPeopleReceived(QList<User>&)));
+ connect(m_situareService, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)),
+ m_ui, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)));
connect(m_situareService, SIGNAL(messagesReceived(QList<Message>&, QList<Message> &)),
m_ui, SIGNAL(messagesReceived(QList<Message>&, QList<Message>&)));
if (m_database.isOpen()) {
QSqlQuery tagQuery;
- ret = tagQuery.exec(QString("SELECT id FROM tag WHERE name = '%1'")
+ ret = tagQuery.exec(QString("SELECT id, count FROM tag WHERE name = '%1'")
.arg(tag));
//Tag already exists
if (ret && tagQuery.next()) {
+ qWarning() << tagQuery.value(1).toInt();
+ int count = tagQuery.value(1).toInt() + 1;
+ qWarning() << count;
+ QSqlQuery tagUpdateQuery;
+ tagUpdateQuery.exec(QString("UPDATE tag SET count = '%1' WHERE id = '%2'")
+ .arg(count).arg(tagQuery.value(0).toString()));
tagId = tagQuery.value(0).toULongLong();
+ qWarning() << tagUpdateQuery.lastQuery();
}
else {
QSqlQuery tagInsertQuery;
{
qDebug() << __PRETTY_FUNCTION__;
+ //People start
+ QString result;
+ result.append("{\"people\": {");
+
QHash<QString, QString> tags;
+ //Get tags
QSqlQuery tagQuery(QString("SELECT DISTINCT usertag.userid, tag.name FROM usertag, tag WHERE "
- "usertag.tagid = tag.id AND usertag.userid != '%1' AND "
- "tag.name LIKE '%2'").arg(userId).arg(tag));
+ "usertag.tagid = tag.id AND usertag.userid != '%1' AND "
+ "tag.name LIKE '\%%2\%'").arg(userId).arg(tag));
while (tagQuery.next()) {
QString userId = tagQuery.value(0).toString();
while (i.hasNext())
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(")"));
- QString result;
- result.append("{\"people\": [");
+ //Get friends
+ result.append("\"friends\": [");
+
+ QSqlQuery friendQuery(QString("SELECT user.id, user.name, user.image_url, user.latitude, "
+ "user.longitude FROM user WHERE "
+ "user.id IN (") + userIds.join(", ") + QString(") AND "
+ "user.id IN "
+ "(SELECT friend.uid2 FROM friend WHERE friend.uid1 = '%1' "
+ "UNION "
+ "SELECT friend.uid1 FROM friend WHERE friend.uid2 = '%1')")
+ .arg(userId));
+
+ bool friendRemoveLast = false;
- while (userQuery.next()) {
+ while (friendQuery.next()) {
+ friendRemoveLast = true;
result.append("{");
- result.append("\"uid\": \"" + userQuery.value(0).toString() + "\",");
- result.append("\"name\": \"" + userQuery.value(1).toString() + "\",");
- result.append("\"image_url\": \"" + userQuery.value(2).toString() + "\",");
- result.append("\"tags\": [" + tags.value(userQuery.value(0).toString()) + "]");
+ result.append("\"uid\": \"" + friendQuery.value(0).toString() + "\",");
+ result.append("\"name\": \"" + friendQuery.value(1).toString() + "\",");
+ result.append("\"image_url\": \"" + friendQuery.value(2).toString() + "\",");
+ result.append("\"latitude\": \"" + friendQuery.value(3).toString() + "\",");
+ result.append("\"longitude\": \"" + friendQuery.value(4).toString() + "\",");
+ result.append("\"tags\": [" + tags.value(friendQuery.value(0).toString()) + "]");
result.append("},");
}
- int lastComma = result.lastIndexOf(",");
- if (lastComma != -1)
- result.remove(result.lastIndexOf(","), 1);
+ if (friendRemoveLast) {
+ int friendLastComma = result.lastIndexOf(",");
+ if (friendLastComma != -1)
+ result.remove(result.lastIndexOf(","), 1);
+ }
+
+ result.append("],");
+
+ //Get others
+ result.append("\"others\": [");
+
+ QSqlQuery otherQuery(QString("SELECT user.id, user.name, user.image_url FROM user WHERE "
+ "user.id IN (") + userIds.join(", ") + QString(") AND "
+ "user.id NOT IN "
+ "(SELECT friend.uid2 FROM friend WHERE friend.uid1 = '%1' "
+ "UNION "
+ "SELECT friend.uid1 FROM friend WHERE friend.uid2 = '%1')")
+ .arg(userId));
- result.append("]}");
+ bool otherRemoveLast = false;
+
+ while (otherQuery.next()) {
+ otherRemoveLast = true;
+ result.append("{");
+ result.append("\"uid\": \"" + otherQuery.value(0).toString() + "\",");
+ result.append("\"name\": \"" + otherQuery.value(1).toString() + "\",");
+ result.append("\"image_url\": \"" + otherQuery.value(2).toString() + "\",");;
+ result.append("\"tags\": [" + tags.value(otherQuery.value(0).toString()) + "]");
+ result.append("},");
+ }
+
+ if (otherRemoveLast) {
+ int otherLastComma = result.lastIndexOf(",");
+ if (otherLastComma != -1)
+ result.remove(result.lastIndexOf(","), 1);
+ }
+
+ result.append("]");
+
+ result.append("}}");
return result.toUtf8();
}
QHash<QString, QString> tags;
- //Get all
+ //Get tags
QSqlQuery tagQuery(QString("SELECT usertag.userid, tag.name FROM usertag, tag WHERE "
"usertag.tagid IN (SELECT usertag.tagid FROM usertag WHERE "
"usertag.userid = '%1') AND usertag.userid != '%2' "
}
}
- QStringList friendIds;
+ QStringList userIds;
QHashIterator<QString, QString> i(tags);
while (i.hasNext())
- friendIds.append(i.next().key());
+ userIds.append(i.next().key());
+ //Get friends
result.append("\"friends\": [");
- //Get friends
- //(SELECT friend.uid2 FROM friend WHERE friend.uid1 = 613374451
- //UNION
- //SELECT friend.uid1 FROM friend WHERE friend.uid2 = 613374451)
-
- QSqlQuery friendQuery(QString("SELECT user.id, user.name, user.image_url FROM user WHERE "
- "user.id IN (") + friendIds.join(", ") + QString(") AND "
- "user.latitude >= '%1' AND user.latitude < '%2' AND "
- "user.longitude >= '%3' AND user.longitude < '%4'")
+ QSqlQuery friendQuery(QString("SELECT user.id, user.name, user.image_url, user.latitude, "
+ "user.longitude 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' AND user.id IN "
+ "(SELECT friend.uid2 FROM friend WHERE friend.uid1 = '%5' "
+ "UNION "
+ "SELECT friend.uid1 FROM friend WHERE friend.uid2 = '%5')")
.arg(southWestCoordinates.latitude()).arg(northEastCoordinates.latitude())
- .arg(southWestCoordinates.longitude()).arg(northEastCoordinates.longitude()));
+ .arg(southWestCoordinates.longitude()).arg(northEastCoordinates.longitude())
+ .arg(userId));
+
+ bool friendRemoveLast = false;
while (friendQuery.next()) {
+ friendRemoveLast = true;
result.append("{");
result.append("\"uid\": \"" + friendQuery.value(0).toString() + "\",");
result.append("\"name\": \"" + friendQuery.value(1).toString() + "\",");
result.append("\"image_url\": \"" + friendQuery.value(2).toString() + "\",");
+ result.append("\"latitude\": \"" + friendQuery.value(3).toString() + "\",");
+ result.append("\"longitude\": \"" + friendQuery.value(4).toString() + "\",");
result.append("\"tags\": [" + tags.value(friendQuery.value(0).toString()) + "]");
result.append("},");
}
- int friendLastComma = result.lastIndexOf(",");
- if (friendLastComma != -1)
- result.remove(result.lastIndexOf(","), 1);
+ if (friendRemoveLast) {
+ int friendLastComma = result.lastIndexOf(",");
+ if (friendLastComma != -1)
+ result.remove(result.lastIndexOf(","), 1);
+ }
result.append("],");
- QSqlQuery othersQuery(QString("SELECT user.id, user.name, user.image_url FROM user WHERE "
- "user.id IN (") + friendIds.join(", ") + QString(") AND "
- "user.latitude >= '%1' AND user.latitude < '%2' AND "
- "user.longitude >= '%3' AND user.longitude < '%4'")
+ //Get others
+ result.append("\"others\": [");
+
+ QSqlQuery otherQuery(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' AND user.id "
+ "NOT IN "
+ "(SELECT friend.uid2 FROM friend WHERE friend.uid1 = '%5' "
+ "UNION "
+ "SELECT friend.uid1 FROM friend WHERE friend.uid2 = '%5')")
.arg(southWestCoordinates.latitude()).arg(northEastCoordinates.latitude())
- .arg(southWestCoordinates.longitude()).arg(northEastCoordinates.longitude()));
+ .arg(southWestCoordinates.longitude()).arg(northEastCoordinates.longitude())
+ .arg(userId));
- while (othersQuery.next()) {
+ bool otherRemoveLast = false;
+
+ while (otherQuery.next()) {
+ otherRemoveLast = true;
result.append("{");
- result.append("\"uid\": \"" + othersQuery.value(0).toString() + "\",");
- result.append("\"name\": \"" + othersQuery.value(1).toString() + "\",");
- result.append("\"image_url\": \"" + othersQuery.value(2).toString() + "\",");
- result.append("\"tags\": [" + tags.value(othersQuery.value(0).toString()) + "]");
+ result.append("\"uid\": \"" + otherQuery.value(0).toString() + "\",");
+ result.append("\"name\": \"" + otherQuery.value(1).toString() + "\",");
+ result.append("\"image_url\": \"" + otherQuery.value(2).toString() + "\",");;
+ result.append("\"tags\": [" + tags.value(otherQuery.value(0).toString()) + "]");
result.append("},");
}
- int friendLastComma = result.lastIndexOf(",");
- if (friendLastComma != -1)
- result.remove(result.lastIndexOf(","), 1);
+ if (otherRemoveLast) {
+ int otherLastComma = result.lastIndexOf(",");
+ if (otherLastComma != -1)
+ result.remove(result.lastIndexOf(","), 1);
+ }
result.append("]");
- //People end
result.append("}}");
return result.toUtf8();
result.append("\"received\": [");
+ bool receivedRemoveLast = false;
+
while (receivedQuery.next()) {
+ receivedRemoveLast = true;
result.append("{");
result.append("\"id\": \"" + receivedQuery.value(0).toString() + "\",");
result.append("\"sender_id\": \"" + receivedQuery.value(1).toString() + "\",");
result.append("\"image_url\": \"" + receivedQuery.value(4).toString() + "\",");
result.append("\"timestamp\": \"" + receivedQuery.value(5).toString() + "\",");
result.append("\"text\": \"" + receivedQuery.value(6).toString() + "\",");
+ result.append("\"address\": \"" + QString("Address 13, Oulu") + "\",");
result.append("\"latitude\": \"" + receivedQuery.value(7).toString() + "\",");
result.append("\"longitude\": \"" + receivedQuery.value(8).toString() + "\"");
result.append("},");
}
- int receivedLastComma = result.lastIndexOf(",");
- if (receivedLastComma != -1)
- result.remove(result.lastIndexOf(","), 1);
+ if (receivedRemoveLast) {
+ int receivedLastComma = result.lastIndexOf(",");
+ if (receivedLastComma != -1)
+ result.remove(result.lastIndexOf(","), 1);
+ }
result.append("],");
result.append("\"sent\": [");
+ bool sentRemoveLast = false;
+
while (sentQuery.next()) {
+ sentRemoveLast = true;
result.append("{");
result.append("\"id\": \"" + sentQuery.value(0).toString() + "\",");
result.append("\"sender_id\": \"" + sentQuery.value(1).toString() + "\",");
result.append("\"image_url\": \"" + sentQuery.value(4).toString() + "\",");
result.append("\"timestamp\": \"" + sentQuery.value(5).toString() + "\",");
result.append("\"text\": \"" + sentQuery.value(6).toString() + "\",");
+ result.append("\"address\": \"" + QString("Address 13, Oulu") + "\",");
result.append("\"latitude\": \"" + sentQuery.value(7).toString() + "\",");
result.append("\"longitude\": \"" + sentQuery.value(8).toString() + "\"");
result.append("},");
}
+ if (sentRemoveLast) {
+ int lastComma = result.lastIndexOf(",");
+ if (lastComma != -1)
+ result.remove(result.lastIndexOf(","), 1);
+ }
+
+ result.append("]");
+
+ result.append("}}");
+
+ return result.toUtf8();
+}
+
+QByteArray Database::getPopularTags()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QSqlQuery query(QString("SELECT tag.id, tag.name FROM tag ORDER BY count DESC LIMIT 10"));
+
+ QString result;
+ result.append("{\"popular_tags\": [");
+
+ while (query.next()) {
+ result.append("{");
+ result.append("\"id\": \"" + query.value(0).toString() + "\",");
+ result.append("\"name\": \"" + query.value(1).toString() + "\"");
+ result.append("},");
+ }
+
int lastComma = result.lastIndexOf(",");
if (lastComma != -1)
result.remove(result.lastIndexOf(","), 1);
result.append("]");
- result.append("}}");
-
return result.toUtf8();
}
bool addTag(qulonglong userId, const QString &tag);
QByteArray getNotifications(qulonglong userId);
+ QByteArray getPopularTags();
QHash<QString, QString> getTags(qulonglong userId);
QByteArray getInterestingPeople(qulonglong userId,
const GeoCoordinate &southWestCoordinates,
Message::Message(const Type type)
: m_timestamp(QDateTime()),
+ m_address(QString()),
m_id(QString()),
m_image(QPixmap()),
m_receiverId(QString()),
qDebug() << __PRETTY_FUNCTION__;
}
+const QString &Message::address() const
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_address;
+}
+
const GeoCoordinate &Message::coordinates() const
{
qDebug() << __PRETTY_FUNCTION__;
return m_senderName;
}
+void Message::setAddress(const QString &address)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_address = address;
+}
+
void Message::setCoordinates(const GeoCoordinate &coordinates)
{
qDebug() << __PRETTY_FUNCTION__;
******************************************************************************/
public:
/**
+ * @brief Returns message's address
+ *
+ * @return message's address
+ */
+ const QString &address() const;
+
+ /**
* @brief Returns message's coordinates
*
* @return message's coordinates as GeoCoordinate
const QString &senderName() const;
/**
+ * @brief Sets message's address
+ *
+ * @param address message's address
+ */
+ void setAddress(const QString &address);
+
+ /**
* @brief Sets message's coordinates
*
* @param coordinates message's coordinates
******************************************************************************/
private:
QDateTime m_timestamp; ///< message's timestamp
+ QString m_address; ///< message's address
QString m_id; ///< message's ID
QPixmap m_image; ///< message's image
QString m_receiverId; ///< message receiver's ID
parseInterestingPeopleData(arr);
}
+void SituareService::fetchPopularTags()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QByteArray arr = m_database->getPopularTags();
+
+ parsePopularTagsData(arr);
+}
+
void SituareService::fetchLocations()
{
qDebug() << __PRETTY_FUNCTION__;
emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
return;
} else {
- QList<User> interestingPeople;
+ QVariant people = result["people"];
+
+ QList<User> friends;
+ QList<User> others;
- foreach (QVariant personVariant, result["people"].toList()) {
+ foreach (QVariant personVariant, people.toMap().value("friends").toList()) {
User user;
QMap<QString, QVariant> person = personVariant.toMap();
user.setUserId(person["uid"].toString());
QPixmap(":/res/images/empty_avatar.png"), AvatarImage::Small));
user.setProfileImageUrl(person["image_url"].toUrl());
user.setTags(person["tags"].toList());
- interestingPeople.append(user);
+
+ bool latOk;
+ qreal latitude = person["latitude"].toReal(&latOk);
+ bool lonOk;
+ qreal longitude = person["longitude"].toReal(&lonOk);
+
+ if (latOk && lonOk)
+ user.setCoordinates(GeoCoordinate(latitude, longitude));
+
+ friends.append(user);
//Remove comment when the actual server is used
//emit fetchImage(user.userId(), user.profileImageUrl());
}
- emit interestingPeopleReceived(interestingPeople);
+ foreach (QVariant personVariant, people.toMap().value("others").toList()) {
+ User user;
+ QMap<QString, QVariant> person = personVariant.toMap();
+ user.setUserId(person["uid"].toString());
+ user.setName(person["name"].toString());
+ user.setProfileImage(AvatarImage::create(
+ QPixmap(":/res/images/empty_avatar.png"), AvatarImage::Small));
+ user.setProfileImageUrl(person["image_url"].toUrl());
+ user.setTags(person["tags"].toList());
+
+ others.append(user);
+
+ //Remove comment when the actual server is used
+ //emit fetchImage(user.userId(), user.profileImageUrl());
+ }
+
+ emit interestingPeopleReceived(friends, others);
}
}
bool lonOk;
qreal longitude = messageMap["longitude"].toReal(&lonOk);
- if (latOk && lonOk)
+ if (latOk && lonOk) {
+ message.setAddress(messageMap["address"].toString());
message.setCoordinates(GeoCoordinate(latitude, longitude));
+ }
received.append(message);
bool lonOk;
qreal longitude = messageMap["longitude"].toReal(&lonOk);
- if (latOk && lonOk)
+ if (latOk && lonOk) {
+ message.setAddress(messageMap["address"].toString());
message.setCoordinates(GeoCoordinate(latitude, longitude));
+ }
sent.append(message);
}
}
+void SituareService::parsePopularTagsData(const QByteArray &jsonReply)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QJson::Parser parser;
+ bool ok;
+
+ QVariantMap result = parser.parse(jsonReply, &ok).toMap();
+
+ if (!ok) {
+ emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
+ return;
+ } else {
+ QHash<QString, QString> popularTags;
+
+ foreach (QVariant tagVariant, result["popular_tags"].toList()) {
+ QMap<QString, QVariant> tag = tagVariant.toMap();
+ popularTags.insert(tag["id"].toString(), tag["name"].toString());
+ }
+
+ emit interestingPeopleReceived(friends, others);
+ }
+}
+
+
void SituareService::parseUserData(const QByteArray &jsonReply)
{
qDebug() << __PRETTY_FUNCTION__;
{
qDebug() << __PRETTY_FUNCTION__;
- bool retVal = false;
-
foreach (QString tag, tags)
- retVal = m_database->addTag(613374451, tag);
+ m_database->addTag(613374451, tag);
- if (retVal)
- emit updateWasSuccessful(SituareService::SuccessfulAddTags);
+ emit updateWasSuccessful(SituareService::SuccessfulAddTags);
}
void SituareService::searchPeopleByTag(const QString &tag)
void fetchMessages();
/**
+ * @brief Retrieves popular tags.
+ *
+ * Tags are fetch from local database instead of Situare server.
+ */
+ void fetchPopularTags();
+
+ /**
* @brief Public slot, to clear user data
*
*/
*/
void parseMessagesData(const QByteArray &jsonReply);
+ /**
+ * @brief Parses popular tags data from JSON string
+ *
+ * @param jsonReply JSON string
+ */
+ void parsePopularTagsData(const QByteArray &jsonReply);
/**
* @brief Parses user and friend data from JSON string
/**
* @brief Signal when fetchPeopleWithSimilarInterest request is finished
*
- * @param interestingPeople list of interesting people
+ * @param friends list of friends
+ * @param others list of other people
*/
- void interestingPeopleReceived(QList<User> &interestingPeople);
+ void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
/**
* @brief Signal when fetchMessages request is finished
situareservice/message.cpp \
ui/personlistitem.cpp \
ui/personlistview.cpp \
- ui/messagedialog.cpp
+ ui/messagedialog.cpp \
+ ui/tagcompletion.cpp
HEADERS += application.h \
common.h \
coordinates/geocoordinate.h \
situareservice/message.h \
ui/personlistitem.h \
ui/personlistview.h \
- ui/messagedialog.h
+ ui/messagedialog.h \
+ ui/tagcompletion.h
QT += network \
webkit \
sql
setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
}
-QString ListItem::title() const
+QString ListItem::title()
{
qDebug() << __PRETTY_FUNCTION__;
*
* @return item's title
*/
- QString title() const;
+ QString title();
/**
* @brief Toggles selection.
#include "listitem.h"
#include "listview.h"
-#include "friendlistitem.h"
ListView::ListView(QWidget *parent)
: QListWidget(parent),
public:
/**
+ * @brief Unit test class
+ */
+ friend class TestListView;
+
+ /**
* @brief Constructor.
*
* @param parent QWidget
connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
m_meetPeoplePanel, SLOT(setImage(QString,QPixmap)));
- connect(this, SIGNAL(interestingPeopleReceived(QList<User>&)),
- m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User>&)));
+ connect(this, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)),
+ m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User>&,QList<User>&)));
connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeople()),
this, SIGNAL(requestInterestingPeople()));
/**
* @brief Signal when fetchPeopleWithSimilarInterest request is finished
*
- * @param interestingPeople list of interesting people
+ * @param friends list of friends
+ * @param others list of other people
*/
- void interestingPeopleReceived(QList<User> &interestingPeople);
+ void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
/**
* @brief Signal for friend location ready.
#include "meetpeoplepanel.h"
MeetPeoplePanel::MeetPeoplePanel(QWidget *parent)
- : PanelBase(parent)
+ : PanelBase(parent),
+ m_headerListItemDelegate(0)
{
qDebug() << __PRETTY_FUNCTION__;
setLayout(meetPeopleLayout);
m_personListView = new PersonListView(this);
- m_personListView->setItemDelegate(new ExtendedListItemDelegate(this));
+ m_personListItemDelegate = new ExtendedListItemDelegate(this);
+ initItemDelegates();
connect(m_personListView, SIGNAL(listItemSelectionChanged()),
- this, SLOT(onListItemSelectionChanged()));
+ this, SLOT(listItemSelectionHandler()));
connect(m_personListView, SIGNAL(personItemClicked(GeoCoordinate)),
this, SIGNAL(findPerson(GeoCoordinate)));
connect(searchPeopleButton, SIGNAL(clicked()),
this, SIGNAL(requestInterestingPeopleSearch()));
- ImageButton *friendListButton = new ImageButton(":/res/images/friend_list_btn.png",
+ m_friendListButton = new ImageButton(":/res/images/friend_list_btn.png",
":/res/images/friend_list_btn_s.png",
":/res/images/friend_list_btn_d.png", this);
- connect(friendListButton, SIGNAL(clicked()),
+ connect(m_friendListButton, SIGNAL(clicked()),
this, SLOT(showFriend()));
ImageButton *messageButton = new ImageButton(":/res/images/chat_btn.png",
m_genericButtonsLayout->addWidget(refreshInterestingPeopleButton);
m_genericButtonsLayout->addWidget(searchPeopleButton);
- m_itemButtonsLayout->addWidget(friendListButton);
+ m_itemButtonsLayout->addWidget(m_friendListButton);
m_itemButtonsLayout->addWidget(messageButton);
}
m_personListView->clearItemSelection();
}
+void MeetPeoplePanel::initItemDelegates()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_personListView->setItemDelegate(m_personListItemDelegate);
+
+ if (m_headerListItemDelegate)
+ delete m_headerListItemDelegate;
+ m_headerListItemDelegate = new HeaderListItemDelegate(this);
+}
+
+void MeetPeoplePanel::listItemSelectionHandler()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ PersonListItem *personItem = dynamic_cast<PersonListItem*>(m_personListView->selectedItem());
+
+ if (personItem && !personItem->isFriend())
+ m_friendListButton->setDisabled(true);
+ else
+ m_friendListButton->setEnabled(true);
+
+ onListItemSelectionChanged();
+}
+
void MeetPeoplePanel::messageButtonPressed()
{
qDebug() << __PRETTY_FUNCTION__;
PersonListItem *personItem = dynamic_cast<PersonListItem*>(m_personListView->selectedItem());
- if (personItem)
+
+ if (personItem) {
+ m_personListView->clearItemSelection();
emit requestMessageDialog(QPair<QString, QString>(personItem->facebookId(),
personItem->title()));
+ }
}
void MeetPeoplePanel::setImage(const QString &id, const QPixmap &image)
PersonListItem *personItem = dynamic_cast<PersonListItem*>(m_personListView->selectedItem());
if (personItem) {
+ m_personListView->clearItemSelection();
QList<QString> userIds;
userIds.append(personItem->facebookId());
emit requestShowFriend(userIds);
}
}
-void MeetPeoplePanel::populateInterestingPeopleListView(QList<User> &interestingPeople)
+void MeetPeoplePanel::populateInterestingPeopleListView(QList<User> &friends, QList<User> &others)
{
qDebug() << __PRETTY_FUNCTION__ ;
m_personListView->clearList();
-
- for (int i = 0; i < interestingPeople.count(); ++i) {
- if (i == 0) {
- m_personListView->setItemDelegateForRow(i, new HeaderListItemDelegate(this));
- ExtendedListItem *item = new ExtendedListItem(0, QListWidgetItem::UserType);
- item->setTitle(tr("Friends:"));
- m_personListView->addListItem(QString("header") + QString::number(i), item);
+ initItemDelegates();
+
+ if (friends.count() > 0) {
+ m_personListView->setItemDelegateForRow(0, m_headerListItemDelegate);
+ ExtendedListItem *friendsHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
+ friendsHeaderItem->setTitle(tr("Friends:"));
+ m_personListView->addListItem(QString("friendsHeader"), friendsHeaderItem);
+
+ foreach (User user, friends) {
+ PersonListItem *item = new PersonListItem();
+ item->setPersonData(user, true);
+ m_personListView->addListItem(user.userId(), item);
}
- else if (i == 2) {
- m_personListView->setItemDelegateForRow(i+1, new HeaderListItemDelegate(this));
- ExtendedListItem *item = new ExtendedListItem(0, QListWidgetItem::UserType);
- item->setTitle(tr("Others:"));
- m_personListView->addListItem(QString("header") + QString::number(i), item);
+ }
+
+ if (others.count() > 0) {
+ m_personListView->setItemDelegateForRow(m_personListView->count(),
+ m_headerListItemDelegate);
+ ExtendedListItem *othersHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
+ othersHeaderItem->setTitle(tr("Others:"));
+ m_personListView->addListItem(QString("othersHeader"), othersHeaderItem);
+
+ foreach (User user, others) {
+ PersonListItem *item = new PersonListItem();
+ item->setPersonData(user, false);
+ m_personListView->addListItem(user.userId(), item);
}
- PersonListItem *item = new PersonListItem();
- item->setPersonData(interestingPeople.at(i));
- m_personListView->addListItem(interestingPeople.at(i).userId(), item);
}
m_personListView->scrollToTop();
class QUrl;
+class ExtendedListItemDelegate;
class GeoCoordinate;
+class HeaderListItemDelegate;
class ImageButton;
class PersonListView;
class User;
void anyPanelClosed();
/**
+ * @brief Handles list item selection.
+ *
+ * Sets item releated buttons enabled
+ */
+ void listItemSelectionHandler();
+
+ /**
* @brief Called when message button is pressed.
*
* Calls requestMessageDialog with message receiver's ID and name
/**
* @brief Populates interesting people list view.
*
- * @param interestingPeople list of interesting people
+ * @param friends list of friends
+ * @param others list of other people
+ */
+ void populateInterestingPeopleListView(QList<User> &friends, QList<User> &others);
+
+private:
+ /**
+ * @brief Inits item delegates for message list view.
*/
- void populateInterestingPeopleListView(QList<User> &interestingPeople);
+ void initItemDelegates();
signals:
/**
void requestShowFriend(const QList<QString> &userIDs);
private:
- PersonListView *m_personListView; ///< Interesting people list view
- ImageButton *m_chatButton; ///< Chat button
+ ExtendedListItemDelegate *m_personListItemDelegate; ///< Person list item delegate
+ HeaderListItemDelegate *m_headerListItemDelegate; ///< Header list item delegate
+ ImageButton *m_chatButton; ///< Chat button
+ ImageButton *m_friendListButton; ///< Friend list button
+ PersonListView *m_personListView; ///< Interesting people list view
};
#endif // MEETPEOPLEPANEL_H
icon.load(":/res/images/chat.png");
addSubItem(message.text(), icon);
addSubItem(message.timestamp().toString(), QPixmap(":/res/images/calendar.png"));
+
+ if (m_coordinates.isValid())
+ addSubItem(message.address(), QPixmap(":/res/images/compass.png"));
}
#include "messagepanel.h"
MessagePanel::MessagePanel(QWidget *parent)
- : PanelBase(parent)
+ : PanelBase(parent),
+ m_headerListItemDelegate(0)
{
qDebug() << __PRETTY_FUNCTION__;
qDebug() << __PRETTY_FUNCTION__;
m_messageListView->setItemDelegate(m_messageListItemDelegate);
- delete m_headerListItemDelegate;
+
+ if (m_headerListItemDelegate)
+ delete m_headerListItemDelegate;
m_headerListItemDelegate = new HeaderListItemDelegate(this);
}
MessageListItem *messageItem = dynamic_cast<MessageListItem*>(
m_messageListView->selectedItem());
- if (messageItem)
+ if (messageItem) {
+ m_messageListView->clearItemSelection();
emit requestMessageDialog(QPair<QString, QString>(messageItem->receiverId(),
messageItem->title()));
+ }
}
void MessagePanel::populateMessageListView(QList<Message> &received, QList<Message> &sent)
#include "personlistitem.h"
PersonListItem::PersonListItem()
+ : m_isFriend(false)
{
qDebug() << __PRETTY_FUNCTION__;
QString PersonListItem::facebookId() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_facebookId;
}
+bool PersonListItem::isFriend() const
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_isFriend;
+}
+
void PersonListItem::setAvatarImage(const QPixmap &image)
{
qDebug() << __PRETTY_FUNCTION__;
m_facebookId = facebookId;
}
-void PersonListItem::setPersonData(const User &user)
+void PersonListItem::setIsFriend(bool isFriend)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_isFriend = isFriend;
+}
+
+void PersonListItem::setPersonData(const User &user, bool isFriend)
{
qDebug() << __PRETTY_FUNCTION__;
+ setIsFriend(isFriend);
setFacebookId(user.userId());
setTitle(shortenText(user.name(), NAME_TEXT_MAX_WIDTH - MARGIN * 3,
QString facebookId() const;
/**
+ * @brief Returns is this item friend.
+ *
+ * @return true if friend, false otherwise
+ */
+ bool isFriend() const;
+
+ /**
* @brief Sets avatar image for this item.
*
* @param image image
void setCoordinates(const GeoCoordinate &coordinates);
/**
+ * @brief Sets is friend flag.
+ *
+ * @param isFriend true if friend, false otherwise
+ */
+ void setIsFriend(bool isFriend);
+
+ /**
* @brief Set person data for this item.
*
* @param user User
*/
- void setPersonData(const User &user);
+ void setPersonData(const User &user, bool isFriend = true);
private:
/**
* DATA MEMBERS
******************************************************************************/
private:
+ bool m_isFriend; ///< Is friend flag
+
QString m_facebookId; ///< User's Facebook ID
GeoCoordinate m_coordinates; ///< User coordinates
--- /dev/null
+#include <QDebug>
+#include <QEvent>
+#include <QKeyEvent>
+#include <QTreeWidget>
+#include <QLineEdit>
+#include <QHeaderView>
+#include <QTimer>
+
+#include "tagcompletion.h"
+
+TagCompletion::TagCompletion(QLineEdit *parent) :
+ QObject(parent), m_parentLineEdit(parent)
+{
+ m_popup = new QTreeWidget;
+ m_popup->setWindowFlags(Qt::Popup);
+ m_popup->setFocusPolicy(Qt::NoFocus);
+ m_popup->setFocusProxy(parent);
+ m_popup->setColumnCount(2);
+ m_popup->setUniformRowHeights(true);
+ m_popup->setRootIsDecorated(false);
+ m_popup->setEditTriggers(QTreeWidget::NoEditTriggers);
+ m_popup->setSelectionBehavior(QTreeWidget::SelectRows);
+ m_popup->setFrameStyle(QFrame::Box | QFrame::Plain);
+ m_popup->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ m_popup->header()->hide();
+
+ m_popup->installEventFilter(this);
+
+ connect(m_popup, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
+ this, SLOT(doneCompletion()));
+
+ connect(m_parentLineEdit, SIGNAL(textEdited(QString)),
+ this, SLOT(requestChoices(QString)));
+}
+
+TagCompletion::~TagCompletion()
+{
+ delete m_popup;
+}
+
+void TagCompletion::doneCompletion()
+{
+ m_popup->hide();
+ m_parentLineEdit->setFocus();
+ QTreeWidgetItem *item = m_popup->currentItem();
+ if (item) {
+ m_parentLineEdit->setText(item->text(0));
+ QMetaObject::invokeMethod(m_parentLineEdit, "returnPressed");
+ }
+
+}
+
+bool TagCompletion::eventFilter(QObject *obj, QEvent *ev)
+{
+ if (obj != m_popup)
+ return false;
+
+ if (ev->type() == QEvent::MouseButtonPress) {
+ m_popup->hide();
+ m_parentLineEdit->setFocus();
+ return true;
+ }
+
+ if (ev->type() == QEvent::KeyPress) {
+ bool consumed = false;
+ int key = static_cast<QKeyEvent*>(ev)->key();
+ switch (key) {
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ doneCompletion();
+ consumed = true;
+
+ case Qt::Key_Escape:
+ m_parentLineEdit->setFocus();
+ m_popup->hide();
+ consumed = true;
+
+ case Qt::Key_Up:
+ case Qt::Key_Down:
+ case Qt::Key_Home:
+ case Qt::Key_End:
+ case Qt::Key_PageUp:
+ case Qt::Key_PageDown:
+ break;
+
+ default:
+ m_parentLineEdit->setFocus();
+ m_parentLineEdit->event(ev);
+ //m_popup->hide();
+ break;
+ }
+
+ return consumed;
+ }
+
+ return false;
+}
+
+void TagCompletion::requestChoices(const QString &text)
+{
+ qWarning() << __PRETTY_FUNCTION__ << text;
+
+ QStringList choices;
+ choices.append("aaa");
+ choices.append("bbb");
+ choices.append("ccc");
+
+ showCompletion(choices);
+}
+
+void TagCompletion::showCompletion(const QStringList &choices)
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ m_popup->setUpdatesEnabled(false);
+ m_popup->clear();
+ for (int i = 0; i < choices.count(); ++i) {
+ QTreeWidgetItem * item;
+ item = new QTreeWidgetItem(m_popup);
+ item->setText(0, choices[i]);
+ item->setText(1, "123");
+ item->setTextAlignment(1, Qt::AlignRight);
+ }
+ m_popup->setCurrentItem(m_popup->topLevelItem(0));
+ m_popup->resizeColumnToContents(0);
+ m_popup->resizeColumnToContents(1);
+ m_popup->adjustSize();
+ m_popup->setUpdatesEnabled(true);
+
+ int h = m_popup->sizeHintForRow(0) * qMin(7, choices.count()) + 3;
+ m_popup->resize(m_popup->width(), h);
+
+ m_popup->move(m_parentLineEdit->mapToGlobal(
+ QPoint(0, m_parentLineEdit->height())));
+ m_popup->setFocus();
+ m_popup->show();
+
+}
--- /dev/null
+#ifndef TAGCOMPLETION_H
+#define TAGCOMPLETION_H
+
+#include <QObject>
+
+class QLineEdit;
+class QTimer;
+class QTreeWidget;
+
+class TagCompletion : public QObject
+{
+ Q_OBJECT
+public:
+ TagCompletion(QLineEdit *parent = 0);
+ ~TagCompletion();
+
+ bool eventFilter(QObject *obj, QEvent *ev);
+ void showCompletion(const QStringList &choices);
+
+public slots:
+ void requestChoices(const QString &text);
+ void doneCompletion();
+
+private:
+ QLineEdit *m_parentLineEdit;
+ QTimer *timer;
+ QTreeWidget *m_popup;
+};
+
+#endif // TAGCOMPLETION_H
#include <QListWidget>
#include <QListWidgetItem>
#include <QPushButton>
+#include <QLabel>
+
+#include "tagcompletion.h"
#include "tagsdialog.h"
-TagsDialog::TagsDialog(const QHash<QString, QString> &tags)
+TagsDialog::TagsDialog(const QHash<QString, QString> &tags, QWidget *parent)
+ : QDialog(parent)
{
qDebug() << __PRETTY_FUNCTION__;
setWindowTitle(tr("Edit tags"));
- QGridLayout *gridLayout = new QGridLayout;
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5StackedWindow);
+ setWindowFlags(Qt::Window);
+#endif
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ QHBoxLayout *lineEditLayout = new QHBoxLayout;
+ QGridLayout *listLayout = new QGridLayout;
+
m_addTagEdit = new QLineEdit("");
- QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
+ QPushButton *addButton = new QPushButton(tr("Add"));
+ lineEditLayout->addWidget(m_addTagEdit);
+ lineEditLayout->addWidget(addButton);
- QPushButton *addButton = buttonBox->addButton(tr("Add"), QDialogButtonBox::ActionRole);
- QPushButton *deleteButton = buttonBox->addButton(tr("Delete"),
- QDialogButtonBox::ActionRole);
- QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
- QPushButton *okButton = buttonBox->addButton(tr("Ok"), QDialogButtonBox::AcceptRole);
+ QPushButton *deleteButton = new QPushButton(tr("Delete"));
+ QPushButton *cancelButton = new QPushButton(tr("Cancel"));
+ QPushButton *okButton = new QPushButton(tr("Update"));
- m_tagsView = new QListWidget(this);
+ QLabel *yourTagsLabel = new QLabel(tr("Your tags:"));
+ yourTagsLabel->setAlignment(Qt::AlignCenter);
+ QLabel *popularTagsLabel = new QLabel(tr("Popular tags:"));
+ popularTagsLabel->setAlignment(Qt::AlignCenter);
+ m_userTagsView = new QListWidget();
+ m_popularTagsView = new QListWidget();
- gridLayout->addWidget(m_addTagEdit, 0, 0, 1, 1);
- gridLayout->addWidget(m_tagsView, 1, 0, 2, 1);
- gridLayout->addWidget(buttonBox, 0, 1, 2, 1);
+ listLayout->addWidget(yourTagsLabel, 0, 0);
+ listLayout->addWidget(popularTagsLabel, 0, 1);
+ listLayout->addWidget(m_userTagsView, 1, 0);
+ listLayout->addWidget(m_userTagsView, 1, 1);
- foreach (QString tag, tags)
- m_tagsView->addItem(tag);
+ mainLayout->addLayout(lineEditLayout);
+ mainLayout->addLayout(listLayout);
- setLayout(gridLayout);
+ setLayout(mainLayout);
connect(okButton, SIGNAL(clicked()),
this, SLOT(accept()));
connect(deleteButton, SIGNAL(clicked()),
this, SLOT(deleteTagFromList()));
+
+ populateUserTags(tags);
}
void TagsDialog::addTagToList()
{
qDebug() << __PRETTY_FUNCTION__;
- QList<QListWidgetItem *> findItems = m_tagsView->findItems(m_addTagEdit->text(),
+ QList<QListWidgetItem *> findItems = m_userTagsView->findItems(m_addTagEdit->text(),
Qt::MatchExactly);
if (findItems.isEmpty()) {
- m_tagsView->insertItem(0, m_addTagEdit->text());
+ m_userTagsView->insertItem(0, m_addTagEdit->text());
m_newTags.append(m_addTagEdit->text());
}
{
qDebug() << __PRETTY_FUNCTION__;
- QList<QListWidgetItem *> selectedItems = m_tagsView->selectedItems();
+ QList<QListWidgetItem *> selectedItems = m_userTagsView->selectedItems();
if (!selectedItems.isEmpty()) {
QListWidgetItem *selectedItem = selectedItems.at(0);
- m_tagsView->takeItem(m_tagsView->row(selectedItem));
+ m_userTagsView->takeItem(m_userTagsView->row(selectedItem));
if (m_newTags.contains(selectedItem->text()))
m_newTags.removeOne(selectedItem->text());
return m_removedTags;
}
+
+void TagsDialog::populatePopularTags(const QHash<QString, QString> &popularTags)
+{
+ m_popularTagsView->clear();
+
+ foreach (QString tag, popularTags)
+ m_popularTagsView->addItem(tag);
+}
+
+void TagsDialog::populateUserTags(const QHash<QString, QString> &userTags)
+{
+ m_userTagsView->clear();
+
+ foreach (QString tag, m_newTags) {
+ if (!userTags.values().contains(tag))
+ m_userTagsView->addItem(tag);
+ }
+
+ foreach (QString tag, userTags)
+ m_userTagsView->addItem(tag);
+}
*
* @param parent Instance of parent widget
*/
- TagsDialog(const QHash<QString, QString> &tags);
+ TagsDialog(const QHash<QString, QString> &tags, QWidget *parent = 0);
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
*/
QStringList removedTags();
+public slots:
+ void populateUserTags(const QHash<QString, QString> &userTags);
+
+ void populatePopularTags(const QHash<QString, QString> &popularTags);
+
private slots:
/**
* @brief Adds tag to the list.
* DATA MEMBERS
******************************************************************************/
private:
- QLineEdit *m_addTagEdit; ///< Add tag line edit
+ QLineEdit *m_addTagEdit; ///< Add tag line edit
- QListWidget *m_tagsView; ///< Tag list view
+ QListWidget *m_userTagsView; ///< User tag list view
+ QListWidget *m_popularTagsView; ///< Popular tag list view
- QStringList m_newTags; ///< List of new tags
- QStringList m_removedTags; ///< Removed tags
+ QStringList m_newTags; ///< List of new tags
+ QStringList m_removedTags; ///< Removed tags
};
#endif // LOGINDIALOG_H
void UserInfo::setTags(const QHash<QString, QString> &tags)
{
-qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
m_userTags = tags;
}
m_tagsTextLabel->setText(tagsText);
+
+ if (m_tagsDialog)
+ m_tagsDialog->populateUserTags(m_userTags);
}
void UserInfo::setTime(const QString &time)
{
qDebug() << __PRETTY_FUNCTION__;
- m_tagsDialog = new TagsDialog(m_userTags);
+ m_tagsDialog = new TagsDialog(m_userTags, this);
connect(m_tagsDialog, SIGNAL(finished(int)),
this, SLOT(tagsDialogFinished(int)));
m_tagsDialog->show();
virtual void setSelected(bool selected);
virtual void setSubitemTextWidth(int width);
virtual bool toggleSelection();
-
};
void ExtendedListItemStub::ExtendedListItemConstructor(QListWidget *parent, int type)
stubMethodEntered("setSubitemTextWidth", params);
}
-QString ExtendedListItemStub::toggleSelection()
+bool ExtendedListItemStub::toggleSelection()
{
stubMethodEntered("toggleSelection");
+
+ return stubReturnValue<bool>("toggleSelection");
}
//Create a stub instance
extendedListItemStub->ExtendedListItemConstructor(parent, type);
}
-void ExtendedListItemStub::addSubItem(const QString &text, const QPixmap &icon)
+ExtendedListItem::~ExtendedListItem()
+{
+
+}
+
+void ExtendedListItem::addSubItem(const QString &text, const QPixmap &icon)
{
extendedListItemStub->addSubItem(text, icon);
}
-void ExtendedListItemStub::clearSubItems()
+void ExtendedListItem::clearSubItems()
{
extendedListItemStub->clearSubItems();
}
-void ExtendedListItemStub::setSelected(bool selected)
+void ExtendedListItem::setSelected(bool selected)
{
extendedListItemStub->setSelected(selected);
}
-void ExtendedListItemStub::setSubitemTextWidth(int width)
+void ExtendedListItem::setSubitemTextWidth(int width)
{
extendedListItemStub->setSubitemTextWidth(width);
}
-void ExtendedListItemStub::toggleSelection()
+bool ExtendedListItem::toggleSelection()
{
- extendedListItemStub->toggleSelection();
+ return extendedListItemStub->toggleSelection();
}
#endif // EXTENDEDLISTITEMSTUB_H
-
#include "../../src/coordinates/geocoordinate.h"
#include "stubbase.h"
-class ListViewStub : public StubBase
+class ListItemStub : public StubBase
{
public:
- virtual void ListItemConstructor(QListWidget *parent = 0, int type = Type);
+ virtual void ListItemConstructor(QListWidget *parent = 0,
+ int type = QListWidgetItem::Type);
enum TextSize{TEXT_SIZE_NORMAL, TEXT_SIZE_SMALL};
virtual void setImage(const QPixmap &image);
virtual void setTitle(const QString &name);
- virtual void setSelected(bool selected) = 0;
virtual void setSize(const QSize &size);
- virtual QString shortenText(const QString &text, int textWidth, TextSize textSize);
- virtual QString title() const;
- virtual bool toggleSelection() = 0;
+ virtual QString shortenText(const QString &text, int textWidth, ListItem::TextSize textSize);
+ virtual QString title();
};
-void ListViewStub::ListItemConstructor(QListWidget *parent, int type)
+void ListItemStub::ListItemConstructor(QListWidget *parent, int type)
{
Q_UNUSED(parent)
Q_UNUSED(type)
}
-void ListViewStub::setImage(const QPixmap &image)
+void ListItemStub::setImage(const QPixmap &image)
{
QList<ParameterBase *> params;
- params.append(new Parameter<const QPixmap *>(image));
+ params.append(new Parameter<const QPixmap &>(image));
stubMethodEntered("setImage", params);
}
-void ListViewStub::setTitle(const QString &name)
+void ListItemStub::setTitle(const QString &name)
{
QList<ParameterBase *> params;
params.append(new Parameter<const QString &>(name));
stubMethodEntered("setTitle", params);
}
-void ListViewStub::setSize(const QSize &size)
+void ListItemStub::setSize(const QSize &size)
{
QList<ParameterBase *> params;
params.append(new Parameter<const QSize &>(size));
stubMethodEntered("setSize", params);
}
-QString ListViewStub::shortenText(const QString &text, int textWidth, TextSize textSize)
+QString ListItemStub::shortenText(const QString &text, int textWidth, ListItem::TextSize textSize)
{
QList<ParameterBase *> params;
params.append(new Parameter<const QString &>(text));
params.append(new Parameter<int>(textWidth));
- params.append(new Parameter<TextSize>(textSize));
+ params.append(new Parameter<ListItem::TextSize>(textSize));
stubMethodEntered("shortenText", params);
return stubReturnValue<QString>("shortenText");
}
-QString ListViewStub::title() const
+QString ListItemStub::title()
{
return stubReturnValue<QString>("title");
}
//Create a stub instance
-ListViewStub defaultListItemStub;
-ListViewStub *listItemStub = &defaultListItemStub;
+ListItemStub defaultListItemStub;
+ListItemStub *listItemStub = &defaultListItemStub;
ListItem::ListItem(QListWidget *parent, int type)
: QListWidgetItem(parent, type)
listItemStub->ListItemConstructor(parent, type);
}
-void ListViewStub::setImage(const QPixmap &image)
+void ListItem::setImage(const QPixmap &image)
{
listItemStub->setImage(image);
}
-void ListViewStub::setTitle(const QString &name)
+void ListItem::setTitle(const QString &name)
{
listItemStub->setTitle(name);
}
-void ListViewStub::setSize(const QSize &size)
+void ListItem::setSize(const QSize &size)
{
listItemStub->setSize(size);
}
-QString ListViewStub::shortenText(const QString &text, int textWidth, TextSize textSize)
+QString ListItem::shortenText(const QString &text, int textWidth, ListItem::TextSize textSize)
{
return listItemStub->shortenText(text, textWidth, textSize);
}
-QString ListViewStub::title()
+QString ListItem::title()
{
return listItemStub->title();
}
#ifndef LISTVIEWSTUB_H
#define LISTVIEWSTUB_H
+#include <QListWidget>
+
#include "../../src/ui/personlistview.h"
#include "listitem.h"
#include "stubbase.h"
virtual void removeLastItem();
virtual ListItem *selectedItem();
virtual void setSelectedItem(ListItem *item);
-
-protected:
virtual bool listItemClicked(ListItem *clickedItem);
+ virtual void listItemClicked(QListWidgetItem *item);
};
-ListViewStub::ListViewConstructor(QWidget *parent)
+void ListViewStub::ListViewConstructor(QWidget *parent)
{
Q_UNUSED(parent)
}
return stubReturnValue<bool>("listItemClicked");
}
+void ListViewStub::listItemClicked(QListWidgetItem *item)
+{
+ QList<ParameterBase *> params;
+ params.append(new Parameter<QListWidgetItem *>(item));
+ stubMethodEntered("listItemClicked", params);
+}
+
ListViewStub defaultListViewStub;
ListViewStub *listViewStub = &defaultListViewStub;
listViewStub->ListViewConstructor(parent);
}
+ListView::~ListView()
+{
+
+}
+
void ListView::addListItem(const QString &key, ListItem *item)
{
listViewStub->addListItem(key, item);
listViewStub->clearList();
}
-void ListView::contains(const QString &userID)
+bool ListView::contains(const QString &userID)
{
- listViewStub->contains(userID);
+ return listViewStub->contains(userID);
}
void ListView::filter(const QList<QString> &itemIDs)
bool ListView::listItemClicked(ListItem *clickedItem)
{
- listViewStub->listItemClicked(clickedItem);
+ return listViewStub->listItemClicked(clickedItem);
+}
+
+void ListView::listItemClicked(QListWidgetItem *item)
+{
+ listViewStub->listItemClicked(item);
}
#endif // LISTVIEWSTUB_H
#include "../../src/ui/personlistitem.h"
#include "../../src/coordinates/geocoordinate.h"
+#include "extendedlistitem.h"
#include "stubbase.h"
class PersonListItemStub : public StubBase
void PersonListItemStub::setAvatarImage(const QPixmap &image)
{
QList<ParameterBase *> params;
- params.append(new Parameter<const QPixmap *>(image));
+ params.append(new Parameter<const QPixmap &>(image));
stubMethodEntered("setAvatarImage", params);
}
personListItemStub->PersonListItemConstructor();
}
+PersonListItem::~PersonListItem()
+{
+
+}
+
GeoCoordinate PersonListItem::coordinates() const
{
return personListItemStub->coordinates();
}
-GeoCoordinate PersonListItem::facebookId() const
+QString PersonListItem::facebookId() const
{
return personListItemStub->facebookId();
}
bool PersonListView::listItemClicked(ListItem *item)
{
- personListViewStub->listItemClicked(item);
+ return personListViewStub->listItemClicked(item);
}
#endif // PERSONLISTVIEWSTUB_H
--- /dev/null
+CONFIG += qtestlib
+DEFINES += QT_NO_DEBUG_OUTPUT
+
+INCLUDEPATH += /home/jupe/Desktop/sbhome/projects/situare/tests/stubs/
+
+HEADERS += \
+ ../../stubs/stubbase.h \
+ ../../stubs/listitem.h \
+ ../../../src/ui/listview.h
+
+SOURCES += \
+ ../../stubs/stubbase.cpp \
+ ../../../src/ui/listview.cpp \
+ testlistview.cpp
--- /dev/null
+/*
+ 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/listview.h"
+
+class TestListView: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void cleanup();
+ void init();
+
+private:
+ ListView *m_listView;
+};
+
+void TestListView::cleanup()
+{
+ delete m_listView;
+}
+
+void TestListView::init()
+{
+ m_listView = new ListView();
+ QVERIFY(m_listView);
+}
+
+QTEST_MAIN(TestListView)
+#include "testlistview.moc"
+
INCLUDEPATH += ../../stubs/
HEADERS += \
+ ../../stubs/stubbase.h \
../../stubs/personlistview.h \
../../stubs/personlistitem.h \
../../stubs/listview.h \
../../stubs/listitem.h \
../../stubs/extendedlistitem.h \
../../../src/ui/extendedlistitemdelegate.h \
+ ../../../src/ui/headerlistitemdelegate.h \
../../../src/ui/listitemdelegate.h \
../../../src/ui/meetpeoplepanel.h \
../../../src/coordinates/geocoordinate.h \
../../../src/user/user.h
SOURCES += \
+ ../../stubs/stubbase.cpp \
../../../src/ui/meetpeoplepanel.cpp \
../../../src/user/user.cpp \
../../../src/ui/extendedlistitemdelegate.cpp \
+ ../../../src/ui/headerlistitemdelegate.cpp \
../../../src/ui/listitemdelegate.cpp \
../../../src/ui/imagebutton.cpp \
../../../src/ui/panelbase.cpp \