Merge branch 'master' into contact_dialog
[situare] / src / ui / listview.cpp
index bf7190d..d899f09 100644 (file)
@@ -58,6 +58,8 @@ void ListView::addListItemToView(ListItem *item)
 
 void ListView::clearItemSelection()
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     clearSelection();
 
     if (m_currentItem)
@@ -206,20 +208,41 @@ ListItem *ListView::listItemAt(int index)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QHashIterator<QString, ListItem*> itemIterator(m_listItems);
-    ListItem *item = 0;
-    int counter = 0;
+    ListItem *listItem = 0;
 
-    while (itemIterator.hasNext()) {
-        itemIterator.next();
-        if (index == counter) {
-            item = itemIterator.value();
-            break;
-        }
-        counter++;
+    if (index < count())
+        listItem = dynamic_cast<ListItem*>(item(index));
+
+    return listItem;
+}
+
+void ListView::prependListItem(const QString &key, ListItem *item)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (!m_listItems.contains(key)) {
+        insertItem(0, item);
+        m_listItems.insert(key, item);
     }
+}
 
-    return item;
+void ListView::removeLastItem()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    ListItem *item = listItemAt(count() - 1);
+
+    if (item) {
+        if (item) {
+            QString key = m_listItems.key(item);
+            m_listItems.remove(key);
+            takeItem(row(item));
+            if (m_currentItem == item)
+                m_currentItem = 0;
+            delete item;
+            item = 0;
+        }
+    }
 }
 
 QHash<QString, ListItem *> ListView::listItems() const