Added filtering by name in ListView.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 3 Aug 2010 06:22:14 +0000 (09:22 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 3 Aug 2010 06:22:14 +0000 (09:22 +0300)
src/ui/friendlistpanel.cpp
src/ui/listitem.cpp
src/ui/listitem.h
src/ui/listview.cpp
src/ui/listview.h

index ac7cf36..fbaa696 100644 (file)
@@ -49,7 +49,7 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     QPalette labelPalette = m_friendListHeaderWidget->palette();
     labelPalette.setColor(QPalette::Background, Qt::black);
     m_friendListHeaderWidget->setPalette(labelPalette);
-    m_friendListHeaderWidget->hide();
+    //m_friendListHeaderWidget->hide();
     m_friendListLabel = new QLabel(this);
     m_clearFilterButton = new QPushButton(tr("Show all"));
     filterLayout->addWidget(m_friendListLabel);
@@ -68,10 +68,10 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     m_locationListView = new LocationListView(this);
     m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
     //REMOVE
-    //m_locationListView->hide();
+    m_locationListView->hide();
 
     friendListLayout->addWidget(m_friendListView);
-    friendListLayout->addWidget(m_locationListView);
+    //friendListLayout->addWidget(m_locationListView);
     m_panelVBox->addLayout(friendListLayout);
 
     connect(m_friendListView, SIGNAL(friendItemClicked(GeoCoordinate)),
@@ -129,8 +129,10 @@ void FriendListPanel::clearFriendListFilter()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_friendListHeaderWidget->hide();
-    m_friendListView->clearFilter();
+//    m_friendListHeaderWidget->hide();
+//    m_friendListView->clearFilter();
+
+    m_friendListView->filter("pek");
 }
 
 void FriendListPanel::locationDataReady(QList<Location> &result)
index 27ba308..6ca1b99 100644 (file)
@@ -33,6 +33,13 @@ ListItem::ListItem()
     setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
 }
 
+QString ListItem::name() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return data(NAME_DISPLAY_INDEX).toString();
+}
+
 void ListItem::setImage(const QPixmap &image)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 6cdcda9..653687a 100644 (file)
@@ -57,6 +57,13 @@ public:
     virtual QString id() const = 0;
 
     /**
+    * @brief Returns item's name.
+    *
+    * @return item's name
+    */
+    QString name() const;
+
+    /**
     * @brief Sets item's image.
     *
     * @param image QPixmap
index d4459b2..6e100c4 100644 (file)
@@ -110,6 +110,18 @@ void ListView::filter(const QList<QString> &userIDs)
     }
 }
 
+void ListView::filter(const QString &pattern)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    foreach (ListItem *item, m_listItems) {
+        if (item->name().contains(pattern, Qt::CaseInsensitive))
+            setItemHidden(item, false);
+        else
+            setItemHidden(item, true);
+    }
+}
+
 ListItem *ListView::takeListItemFromView(const QString &userID)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 73cc81e..a6ceb64 100644 (file)
@@ -106,6 +106,8 @@ public:
     */
     void filter(const QList<QString> &userIDs);
 
+    void filter(const QString &pattern);
+
     /**
     * @brief Takes item from view.
     *
@@ -124,6 +126,8 @@ public:
     */
     ListItem *listItem(const QString &userID);
 
+private:
+
 protected slots:
     /**
     * @brief Slot for list item clicked.
@@ -136,8 +140,10 @@ protected slots:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    ListItem *m_previousItem;               ///< Previously selected item
     QHash<QString, ListItem *> m_listItems; ///< List of items in this view. Key = user ID
+    ListItem *m_previousItem;               ///< Previously selected item
+    QVector<int> m_filteredIndices;
+    QVector<int> m_shownIndices;
 };
 
 #endif // LISTVIEW_H