{
qDebug() << __PRETTY_FUNCTION__;
- connect(m_geocodingService, SIGNAL(locationDataParsed(QList<Location>&)),
- m_ui, SIGNAL(locationDataParsed(QList<Location>&)));
+ connect(m_geocodingService, SIGNAL(locationDataParsed(const QList<Location>&)),
+ m_ui, SIGNAL(locationDataParsed(const QList<Location>&)));
}
void SituareEngine::signalsFromGPS()
m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
// signals from routing tab
- connect(m_ui, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
- m_mapEngine, SLOT(showMapArea(GeoCoordinate&,GeoCoordinate&)));
+ connect(m_ui,
+ SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
+ m_mapEngine,
+ SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&)));
// signals from distence indicator button
connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
m_tilesGridSize.setWidth(gridWidth);
}
-void MapEngine::showMapArea(GeoCoordinate &swBound, GeoCoordinate &neBound)
+void MapEngine::showMapArea(const GeoCoordinate &swBound, const GeoCoordinate &neBound)
{
qDebug() << __PRETTY_FUNCTION__;
* @param swBound south-west bound of location item
* @param neBound north-east bound of location item
*/
- void showMapArea(GeoCoordinate &swBound, GeoCoordinate &neBound);
+ void showMapArea(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
/**
* @brief Slot for actions after view zoom is finished
*
* @param result List of Location items
*/
- void locationDataParsed(QList<Location> &result);
+ void locationDataParsed(const QList<Location> &result);
/*******************************************************************************
* DATA MEMBERS
}
QRect iconRect = QRect(itemRect.left() + MARGIN * 3,
- previousSubItemTextRectBottom + ICON_MARGIN,
- ICON_WIDTH, ICON_HEIGHT);
+ previousSubItemTextRectBottom + ICON_MARGIN,
+ ICON_WIDTH, ICON_HEIGHT);
if (itemHasImage)
iconRect.translate(IMAGE_WIDTH, 0);
qDebug() << __PRETTY_FUNCTION__;
}
-void ExtendedListItemStore::setIcon(const QPixmap &icon)
+QPixmap ExtendedListItemStore::icon() const
{
qDebug() << __PRETTY_FUNCTION__;
- m_icon = icon;
+ return m_icon;
}
-void ExtendedListItemStore::setShortenedText(const QString &shortenedText)
+void ExtendedListItemStore::setIcon(const QPixmap &icon)
{
qDebug() << __PRETTY_FUNCTION__;
- m_shortenedText = shortenedText;
+ m_icon = icon;
}
-void ExtendedListItemStore::setTextRect(const QRect &textRect)
+void ExtendedListItemStore::setShortenedText(const QString &shortenedText)
{
qDebug() << __PRETTY_FUNCTION__;
- m_textRect = textRect;
+ m_shortenedText = shortenedText;
}
-QPixmap ExtendedListItemStore::icon() const
+QString ExtendedListItemStore::shortenedText() const
{
qDebug() << __PRETTY_FUNCTION__;
- return m_icon;
+ return m_shortenedText;
}
-QString ExtendedListItemStore::shortenedText() const
+void ExtendedListItemStore::setTextRect(const QRect &textRect)
{
qDebug() << __PRETTY_FUNCTION__;
- return m_shortenedText;
+ m_textRect = textRect;
}
QString ExtendedListItemStore::text() const
******************************************************************************/
public:
/**
- * @brief Sets shortended text.
+ * @brief Returns icon.
*
- * @param shortenedText shortened text
+ * @return QPixmap
*/
- void setShortenedText(const QString &shortenedText);
+ QPixmap icon() const;
/**
* @brief Sets icon.
void setIcon(const QPixmap &icon);
/**
- * @brief Sets text rect.
+ * @brief Sets shortended text.
*
- * @param textRect text rect
+ * @param shortenedText shortened text
*/
- void setTextRect(const QRect &textRect);
+ void setShortenedText(const QString &shortenedText);
/**
- * @brief Returns icon.
+ * @brief Returns shortened text.
*
- * @return QPixmap
+ * @return QString
*/
- QPixmap icon() const;
+ QString shortenedText() const;
/**
- * @brief Returns text rect.
+ * @brief Sets text rect.
*
- * @return QRect
+ * @param textRect text rect
*/
- QRect textRect() const;
+ void setTextRect(const QRect &textRect);
/**
* @brief Returns text
QString text() const;
/**
- * @brief Returns shortened text.
+ * @brief Returns text rect.
*
- * @return QString
+ * @return QRect
*/
- QString shortenedText() const;
+ QRect textRect() const;
/******************************************************************************
* DATA MEMBERS
#include "friendlistitem.h"
-const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
-const int CAR_DISTANCE = 500; ///< Car distance limit for distance icon
-const int WALK_DISTANCE = 5; ///< Walk distance limit for distance icon
-
FriendListItem::FriendListItem()
{
qDebug() << __PRETTY_FUNCTION__;
setSubitemTextWidth(SUBITEM_TEXT_MAX_WIDTH);
}
-GeoCoordinate FriendListItem::coordinates()
+GeoCoordinate FriendListItem::coordinates() const
{
qDebug() << __PRETTY_FUNCTION__;
{
qDebug() << __PRETTY_FUNCTION__;
- if(user) {
-
- QString unit;
- double value;
- user->distance(value, unit);
- QString distanceText = QString::number(value) + " " + unit;
- setData(DISTANCE_TEXT_DISPLAY_INDEX, distanceText);
- setDistanceIcon(value, unit);
-
- //Dummy value to get painter font metrics.
- QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
- QPainter painter(&p);
- painter.setFont(NOKIA_FONT_SMALL);
- QFontMetrics distanceTextFontMetrics = painter.fontMetrics();
- QRect distanceRect = distanceTextFontMetrics.boundingRect(distanceText);
-
- setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
- setName(shortenText(user->name(), NAME_TEXT_MAX_WIDTH - distanceRect.width() + MARGIN,
- ListItem::TEXT_SIZE_NORMAL));
- setCoordinates(user->coordinates());
-
- if (!user->profileImage().isNull())
- setImage(user->profileImage());
-
- clearSubItems();
-
- addSubItem(user->note(), QPixmap(":/res/images/envelope.png"));
- addSubItem(user->address(), QPixmap(":/res/images/compass.png"));
- addSubItem(user->timestamp(), QPixmap(":/res/images/clock.png"));
- }
+ QString unit;
+ double value;
+ user->distance(value, unit);
+ QString distanceText = QString::number(value) + " " + unit;
+ setData(DISTANCE_TEXT_DISPLAY_INDEX, distanceText);
+ setDistanceIcon(value, unit);
+
+ //Dummy value to get painter font metrics.
+ QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
+ QPainter painter(&p);
+ painter.setFont(NOKIA_FONT_SMALL);
+ QFontMetrics distanceTextFontMetrics = painter.fontMetrics();
+ QRect distanceRect = distanceTextFontMetrics.boundingRect(distanceText);
+
+ setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
+ setTitle(shortenText(user->name(), NAME_TEXT_MAX_WIDTH - distanceRect.width() + MARGIN,
+ ListItem::TEXT_SIZE_NORMAL));
+ setCoordinates(user->coordinates());
+
+ if (!user->profileImage().isNull())
+ setImage(user->profileImage());
+
+ clearSubItems();
+
+ addSubItem(user->note(), QPixmap(":/res/images/envelope.png"));
+ addSubItem(user->address(), QPixmap(":/res/images/compass.png"));
+ addSubItem(user->timestamp(), QPixmap(":/res/images/clock.png"));
}
void FriendListItem::setAvatarImage(const QPixmap &image)
{
qDebug() << __PRETTY_FUNCTION__;
+ const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
+ const int CAR_DISTANCE = 500; ///< Car distance limit for distance icon
+ const int WALK_DISTANCE = 5; ///< Walk distance limit for distance icon
+
QPixmap distanceImage;
if ((unit == "m") || (value < WALK_DISTANCE))
*
* @return item's coordinates
*/
- GeoCoordinate coordinates();
+ GeoCoordinate coordinates() const;
/**
* @brief Sets item's coordinates.
QRect itemRect = option.rect;
- QPoint distanceIconPoint = QPoint(ITEM_WIDTH - ICON_WIDTH - 3*MARGIN, itemRect.top() + MARGIN);
+ QPoint distanceIconPoint = QPoint(ITEM_WIDTH - ICON_WIDTH - 3 * MARGIN,
+ itemRect.top() + MARGIN);
+
QRect distanceRect = index.data(DISTANCE_SIZE_HINT_INDEX).toRect();
- distanceRect.translate(ITEM_WIDTH - distanceRect.width() - 2*MARGIN,
- itemRect.top() + ICON_HEIGHT + 3*MARGIN);
+ distanceRect.translate(ITEM_WIDTH - distanceRect.width() - 2 * MARGIN,
+ itemRect.top() + ICON_HEIGHT + 3 * MARGIN);
painter->drawPixmap(distanceIconPoint, distanceIcon);
painter->drawText(distanceRect, Qt::TextSingleLine, distance);
Situare - A location system for Facebook
Copyright (C) 2010 Ixonos Plc. Authors:
- Kaj Wallin - kaj.wallin@ixonos.com
- Henri Lampela - henri.lampela@ixonos.com
- Pekka Nissinen - pekka.nissinen@ixonos.com
+ 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
const int SUBITEM_TEXT_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH
- MARGIN * 2;
-const int NAME_DISPLAY_INDEX = Qt::DisplayRole;
+const int TITLE_DISPLAY_INDEX = Qt::DisplayRole;
const int AVATAR_IMAGE_INDEX = Qt::DecorationRole;
const int ITEM_SIZE_HINT_INDEX = Qt::SizeHintRole;
setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
}
-QString ListItem::name() const
+QString ListItem::title() const
{
qDebug() << __PRETTY_FUNCTION__;
- return data(NAME_DISPLAY_INDEX).toString();
+ return data(TITLE_DISPLAY_INDEX).toString();
}
void ListItem::setImage(const QPixmap &image)
}
-void ListItem::setName(const QString &name)
+void ListItem::setTitle(const QString &title)
{
qDebug() << __PRETTY_FUNCTION__;
- setData(NAME_DISPLAY_INDEX, name);
+ setData(TITLE_DISPLAY_INDEX, title);
}
void ListItem::setSize(const QSize &size)
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
/**
- * @brief Returns item's name.
+ * @brief Returns item's title.
*
- * @return item's name
+ * @return item's title
*/
- QString name() const;
+ QString title() const;
/**
* @brief Sets item's image.
void setImage(const QPixmap &image);
/**
- * @brief Sets item's name.
+ * @brief Sets item's title.
*
- * @param name item's name
+ * @param name item's title
*/
- void setName(const QString &name);
+ void setTitle(const QString &name);
/**
* @brief Sets item selected.
qDebug() << __PRETTY_FUNCTION__;
QPixmap image = QPixmap(qvariant_cast<QPixmap>(index.data(AVATAR_IMAGE_INDEX)));
- QString name = index.data(NAME_DISPLAY_INDEX).toString();
+ QString name = index.data(TITLE_DISPLAY_INDEX).toString();
QSize size = index.data(ITEM_SIZE_HINT_INDEX).toSize();
QRect itemRect = option.rect;
private:
QPixmap m_backgroundBottomImage; ///< Bottom background image
QPixmap m_backgroundMiddleImage; ///< Middle background image
- QPixmap m_backgroundTopImage; ///< Top background image
+ QPixmap m_backgroundTopImage; ///< Top background image
};
#endif // LISTITEMDELEGATE_H
qDebug() << __PRETTY_FUNCTION__;
foreach (ListItem *item, m_listItems) {
- if (item->name().contains(pattern, Qt::CaseInsensitive))
+ if (item->title().contains(pattern, Qt::CaseInsensitive))
setItemHidden(item, false);
else
setItemHidden(item, true);
setSubitemTextWidth(LOCATION_SUBITEM_TEXT_MAX_WIDTH);
}
-GeoCoordinate LocationListItem::coordinates()
+void LocationListItem::bounds(GeoCoordinate &swBound, GeoCoordinate &neBound)
{
qDebug() << __PRETTY_FUNCTION__;
- return m_location.coordinates();
+ m_location.viewport(swBound, neBound);
}
-QString LocationListItem::id() const
+GeoCoordinate LocationListItem::coordinates() const
{
qDebug() << __PRETTY_FUNCTION__;
- return QString();
+ return m_location.coordinates();
}
void LocationListItem::setLocationData(const Location &location)
QStringList addressComponents = m_location.addressComponents();
- if (addressComponents.count() > 0)
- setName(shortenText(addressComponents.at(0), ITEM_WIDTH - 3*MARGIN,
- ListItem::TEXT_SIZE_NORMAL));
+ if (addressComponents.isEmpty())
+ return;
- QString addressTail;
+ setTitle(shortenText(addressComponents.at(0), ITEM_WIDTH - 3 * MARGIN,
+ ListItem::TEXT_SIZE_NORMAL));
- for (int i = 1; i < addressComponents.count(); ++i) {
- addressTail.append(addressComponents.at(i));
+ addressComponents.removeFirst();
- if (i < (addressComponents.count() - 1))
- addressTail.append(", ");
+ if (!addressComponents.isEmpty()) {
+ clearSubItems();
+ addSubItem(addressComponents.join(", "), QPixmap(":/res/images/compass.png"));
}
- clearSubItems();
- addSubItem(addressTail, QPixmap(":/res/images/compass.png"));
-
-}
-
-void LocationListItem::bounds(GeoCoordinate &swBound, GeoCoordinate &neBound)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_location.viewport(swBound, neBound);
}
LocationListItem::~LocationListItem()
*
* @return item's coordinates
*/
- GeoCoordinate coordinates();
-
- /**
- * @brief Returns item's ID.
- *
- * @return item's ID
- */
- QString id() const;
+ GeoCoordinate coordinates() const;
/******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
+/*
+ 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 "locationlistitem.h"
#include "locationlistview.h"
* @param swBound south-west bound in GeoCoorinate
* @param neBound north-east bound in GeoCoordinate
*/
- void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+ void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
};
#endif // LOCATIONLISTVIEW_H
m_routingPanel = new RoutingPanel(this);
- connect(this, SIGNAL(locationDataParsed(QList<Location>&)),
- m_routingPanel, SLOT(populateLocationListView(QList<Location>&)));
+ connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
+ m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
- connect(m_routingPanel, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
- this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
+ connect(m_routingPanel,
+ SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
+ this,
+ SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
}
void MainWindow::buildUserInfoPanel()
*
* @param result List of Location items
*/
- void locationDataParsed(QList<Location> &result);
+ void locationDataParsed(const QList<Location> &result);
/**
* @brief Signal is emitted when location item is clicked on map.
* @param swBound south-west bound in GeoCoorinate
* @param neBound north-east bound in GeoCoordinate
*/
- void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+ void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
/**
* @brief Signals when Login/Logout action is pressed
routingLayout->addWidget(m_locationListHeaderWidget);
routingLayout->addLayout(listViewLayout);
- connect(m_locationListView, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
- this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
+ connect(m_locationListView,
+ SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
+ this,
+ SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
}
-void RoutingPanel::populateLocationListView(QList<Location> &locations)
+void RoutingPanel::populateLocationListView(const QList<Location> &locations)
{
qDebug() << __PRETTY_FUNCTION__;
//openPanel();
- if (locations.size() == 1) {
- ListItem *item = m_locationListView->listItemAt(0);
+ const int FIRST_LOCATION_ITEM_INDEX = 0;
+ const int ONE_LOCATION_ITEM = 1;
+
+ if (locations.size() == ONE_LOCATION_ITEM) {
+ ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
if (item)
m_locationListView->listItemClicked(item);
/**
* @brief Populates location list view.
*
- * @param result list of Location objects
+ * @param locations list of Location objects
*/
- void populateLocationListView(QList<Location> &locations);
+ void populateLocationListView(const QList<Location> &locations);
/*******************************************************************************
* SIGNALS
* @param swBound south-west bound GeoCoordinate
* @param neBound north-east bound GeoCoordinate
*/
- void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+ void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
/*******************************************************************************
* DATA MEMBERS
QCOMPARE(subItems->at(2)->textRect(), QRect(0, 0, 250, 48));
friendListItem->toggleSelection();
- QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 142 + 3*24));
+ QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 142 + 3 * 24));
QCOMPARE(friendListItem->data(ITEM_EXPANDED_INDEX).toBool(), true);
friendListItem->toggleSelection();
+++ /dev/null
-CONFIG += qtestlib
-DEFINES += QT_NO_DEBUG_OUTPUT
-INCLUDEPATH += . \
- ../../../src/
-HEADERS += ../../../src/ui/listview.h \
- ../../../src/ui/listitem.h \
- ../../../src/ui/extendedlistitem.h \
- ../../../src/ui/extendedlistitemstore.h \
- ../../../src/ui/friendlistitem.h \
- ../../../src/user/user.h \
- ../../../src/coordinates/scenecoordinate.h \
- ../../../src/coordinates/geocoordinate.h \
- ../../../src/ui/friendlistview.h
-SOURCES += ../../../src/ui/listview.cpp \
- ../../../src/ui/listitem.cpp \
- ../../../src/ui/extendedlistitem.cpp \
- ../../../src/ui/extendedlistitemstore.cpp \
- ../../../src/ui/friendlistitem.cpp \
- ../../../src/user/user.cpp \
- testlistview.cpp \
- ../../../src/coordinates/scenecoordinate.cpp \
- ../../../src/coordinates/geocoordinate.cpp \
- ../../../src/ui/friendlistview.cpp
-RESOURCES += ../../../images.qrc
+++ /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/friendlistitem.h"
-#include "../../../src/ui/friendlistview.h"
-#include "../../../src/user/user.h"
-
-class TestListView: public QObject
-{
- Q_OBJECT
-
-private slots:
- void cleanupTestCase();
- void initTestCase();
- void addListItem();
- void addItemToView();
- void clearUnused();
- void filterListByID();
- void filterListByName();
- void takeListItemFromView();
-
-private:
- int hiddenItemCount();
-
-private:
- FriendListView *friendListView;
- User *user1;
- User *user2;
- User *user3;
- User *user4;
-};
-
-void TestListView::cleanupTestCase()
-{
- delete friendListView;
- delete user1;
- delete user2;
- delete user3;
- delete user4;
-}
-
-void TestListView::initTestCase()
-{
- friendListView = new FriendListView();
- QVERIFY(friendListView != 0);
-
- user1 = new User(QString("Address address address address address"),
- GeoCoordinate(12.22, 23.33), QString("John Doe"),
- QString("Note note note note note note note note"),
- QUrl("http://image.url"), QString("Timestamp timestamp timestamp tim"),
- true, QString("key1"), QString("km"), 44.12);
- user1->setProfileImage(QPixmap(":/res/images/profile_pic_border.png"));
- user2 = new User(QString("Address address"),
- GeoCoordinate(12.1, 44.33), QString("Jane Doe"),
- QString("Note note note note note note note note"),
- QUrl("http://image.url"), QString("Timestamp timestamp timestamp tim"),
- true, QString("key2"), QString("km"), 144.12);
- user2->setProfileImage(QPixmap(":/res/images/profile_pic_border.png"));
- user3 = new User(QString("Address address address address address"),
- GeoCoordinate(12.22, 23.33), QString("Kate Nameless"),
- QString("Note note note note note note note note"),
- QUrl("http://image.url"), QString("Timestamp timestamp timestamp tim"),
- true, QString("key3"), QString("km"), 44.12);
- user3->setProfileImage(QPixmap(":/res/images/profile_pic_border.png"));
- user4 = new User(QString("Address address"),
- GeoCoordinate(12.1, 44.33), QString("Jay Nameless"),
- QString("Note note note note note note note note"),
- QUrl("http://image.url"), QString("Timestamp timestamp timestamp tim"),
- true, QString("key4"), QString("km"), 144.12);
- user4->setProfileImage(QPixmap(":/res/images/profile_pic_border.png"));
-
- QVERIFY(user1 != 0);
- QVERIFY(user2 != 0);
- QVERIFY(user3 != 0);
- QVERIFY(user4 != 0);
-}
-
-void TestListView::addListItem()
-{
- friendListView->addListItem("key1", new FriendListItem());
- QCOMPARE(friendListView->count(), 1);
-
- friendListView->addListItem("key1", new FriendListItem());
- QCOMPARE(friendListView->count(), 1);
-
- friendListView->addListItem("key2", new FriendListItem());
- QCOMPARE(friendListView->count(), 2);
-}
-
-void TestListView::addItemToView()
-{
- friendListView->addListItemToView(new FriendListItem());
- QCOMPARE(friendListView->count(), 3);
-
- friendListView->addListItemToView(new FriendListItem());
- QCOMPARE(friendListView->count(), 4);
-
- friendListView->clearList();
- QCOMPARE(friendListView->count(), 0);
-}
-
-void TestListView::clearUnused()
-{
- friendListView->addListItem("key1", new FriendListItem());
- friendListView->addListItem("key2", new FriendListItem());
- friendListView->addListItem("key3", new FriendListItem());
- friendListView->addListItem("key4", new FriendListItem());
- QCOMPARE(friendListView->count(), 4);
-
- QStringList newUserIDs;
- newUserIDs.append("key2");
- newUserIDs.append("key3");
- friendListView->clearUnused(newUserIDs);
- QCOMPARE(friendListView->count(), 2);
- QVERIFY(friendListView->listItem("key1") == 0);
- QVERIFY(friendListView->listItem("key2") != 0);
- QVERIFY(friendListView->listItem("key3") != 0);
- QVERIFY(friendListView->listItem("key4") == 0);
-}
-
-void TestListView::filterListByID()
-{
- friendListView->clearList();
- QCOMPARE(friendListView->count(), 0);
-
- FriendListItem *item1 = new FriendListItem();
- FriendListItem *item2 = new FriendListItem();
- FriendListItem *item3 = new FriendListItem();;
- FriendListItem *item4 = new FriendListItem();
-
- item1->setUserData(user1);
- item2->setUserData(user2);
- item3->setUserData(user3);
- item4->setUserData(user4);
-
- friendListView->addListItem("key1", item1);
- friendListView->addListItem("key2", item2);
- friendListView->addListItem("key3", item3);
- friendListView->addListItem("key4", item4);
- QCOMPARE(friendListView->count(), 4);
-
- QList<QString> userIDs;
- userIDs.append("key1");
- friendListView->filter(userIDs);
- QCOMPARE(friendListView->count(), 4);
- QCOMPARE(hiddenItemCount(), 3);
-
- userIDs.append("key2");
- friendListView->filter(userIDs);
- QCOMPARE(friendListView->count(), 4);
- QCOMPARE(hiddenItemCount(), 2);
-
- friendListView->clearFilter();
- QCOMPARE(hiddenItemCount(), 0);
-}
-
-void TestListView::filterListByName()
-{
- friendListView->clearList();
- QCOMPARE(friendListView->count(), 0);
-
- FriendListItem *item1 = new FriendListItem();
- FriendListItem *item2 = new FriendListItem();
- FriendListItem *item3 = new FriendListItem();;
- FriendListItem *item4 = new FriendListItem();
-
- item1->setUserData(user1);
- item2->setUserData(user2);
- item3->setUserData(user3);
- item4->setUserData(user4);
-
- friendListView->addListItem("key1", item1);
- friendListView->addListItem("key2", item2);
- friendListView->addListItem("key3", item3);
- friendListView->addListItem("key4", item4);
- QCOMPARE(friendListView->count(), 4);
-
- friendListView->filter("doe");
- QCOMPARE(hiddenItemCount(), 2);
-
- friendListView->filter("j");
- QCOMPARE(hiddenItemCount(), 1);
-
- friendListView->filter("john");
- QCOMPARE(hiddenItemCount(), 3);
-
- friendListView->clearFilter();
- QCOMPARE(hiddenItemCount(), 0);
-}
-
-void TestListView::takeListItemFromView()
-{
- QCOMPARE(friendListView->count(), 4);
-
- ListItem *item = friendListView->takeListItemFromView("key3");
- QVERIFY(item != 0);
- QCOMPARE(friendListView->count(), 3);
-
- friendListView->addListItemToView(item);
- QCOMPARE(friendListView->count(), 4);
-}
-
-int TestListView::hiddenItemCount()
-{
- int hiddenCounter = 0;
-
- for (int i = 0; i < friendListView->count(); ++i) {
- if (friendListView->item(i)->isHidden())
- hiddenCounter++;
- }
-
- return hiddenCounter;
-}
-
-QTEST_MAIN(TestListView)
-#include "testlistview.moc"