Changed search to retry automatically couple of times before failing.
[jenirok] / src / gui / buttonselector.cpp
index d41ff9e..14534ef 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include <QtGui/QStandardItem>
+#include <QtCore/QDebug>
 #include "buttonselector.h"
 
 ButtonSelector::ButtonSelector(QString const& text, QWidget* parent):
@@ -24,6 +25,7 @@ QMaemo5ValueButton(text, parent), selector_(0), model_(0)
 {
     setValueLayout(QMaemo5ValueButton::ValueBesideText);
     selector_ = new QMaemo5ListPickSelector(this);
+    connect(selector_, SIGNAL(selected(QString const&)), this, SLOT(onSelected(QString const&)));
     model_ = new QStandardItemModel(0, 1);
     selector_->setModel(model_);
     setPickSelector(selector_);
@@ -46,6 +48,7 @@ void ButtonSelector::addItem(QString const& text, QVariant const& value)
     {
         selector_->setCurrentIndex(0);
     }
+
 }
 
 void ButtonSelector::clear()
@@ -53,11 +56,40 @@ void ButtonSelector::clear()
     model_->clear();
 }
 
-void ButtonSelector::setCurrentIndex(int index)
+void ButtonSelector::setCurrentIndex(unsigned int index)
 {
     selector_->setCurrentIndex(index);
 }
 
+int ButtonSelector::indexOfValue(QVariant const& value) const
+{
+    for(int i = 0; i < model_->rowCount(); i++)
+    {
+        QStandardItem* item = model_->item(i);
+
+        if(item && item->data(Qt::UserRole) == value)
+        {
+            return i;
+        }
+    }
+
+    return -1;
+}
+
+bool ButtonSelector::selectByValue(QVariant const& value)
+{
+    int index = indexOfValue(value);
+
+    if(index < 0)
+    {
+        return false;
+    }
+
+    setCurrentIndex(index);
+
+    return true;
+}
+
 int ButtonSelector::currentIndex() const
 {
     return selector_->currentIndex();
@@ -81,3 +113,36 @@ QVariant ButtonSelector::value() const
 
     return item->data(Qt::UserRole);
 }
+
+bool ButtonSelector::changeItem(unsigned int index,
+                                QString const& text)
+{
+    return changeItem(index, text, QVariant(text));
+}
+
+bool ButtonSelector::changeItem(unsigned int index,
+                                QString const& text,
+                                QVariant const& value)
+{
+    QStandardItem* item = model_->item(index);
+
+    if(!item)
+    {
+        return false;
+    }
+
+    item->setText(text);
+    item->setData(value, Qt::UserRole);
+
+    return true;
+}
+
+bool ButtonSelector::removeItem(unsigned int index)
+{
+    return model_->removeRow(index);
+}
+
+void ButtonSelector::onSelected(QString const& text)
+{
+    emit selected(currentIndex(), text, value());
+}