Added possibility to control items checking in SelectView from outside.
Change-Id: I583939d512f9a86e8bcf7e0eacd7c5312495a369
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
*/
void setSelectMode(SelectMode selectMode);
- protected:
/**
* @return Selection result associated with the item.
*/
- virtual SelectResult getSelectResult() const = 0;
+ SelectResult getSelectResult() const;
+
+ /**
+ * @brief Set custom selection result to override the default result.
+ */
+ void setCustomResult(SelectResult result);
+
+ /**
+ * @brief Unset custom selection result to use default result.
+ */
+ void unsetCustomResult();
+
+ protected:
+ /**
+ * @return Default selection result associated with the item.
+ */
+ virtual SelectResult getDefaultResult() const = 0;
/**
* @see GenlistItem::getContent()
friend class SelectView;
SelectMode m_SelectMode;
+ SelectResult m_CustomResult;
+ bool m_HasCustomResult;
};
}
/**
* @brief Range of consecutive selection results.
*/
- typedef Utils::Range<const SelectResult *> SelectResults;
+ typedef Utils::Range<SelectResult *> SelectResults;
/**
* @brief Callback to be called when selection is done.
class EXPORT_API SelectView : public Ui::View
{
public:
+ /**
+ * @brief Called when item's "checked" state changed in #SelectMulti mode.
+ * @remark Use SelectView::setCheckCallback() to properly change item's state
+ * if necessary.
+ * @param[in] Changed item
+ * @param[in] Whether item is checked
+ */
+ typedef std::function<bool(SelectItem *, bool)> CheckCallback;
+
SelectView();
/**
*/
void setSelectCallback(SelectCallback callback);
+ /**
+ * @brief Set item check callback.
+ * @param[in] callback Check callback
+ */
+ void setCheckCallback(CheckCallback callback);
+
+ /**
+ * @brief Set item's "checked" state.
+ * @remark Item "checked" state should always be changed via this function,
+ * otherwise SelectView wouldn't know to update the select count.
+ * @param[in] item Item to change state for
+ * @param[in] isChecked Whether item should be checked
+ */
+ void setCheckedItem(SelectItem *item, bool isChecked);
+
protected:
/**
* @return View selection mode.
SelectMode getSelectMode() const;
/**
- * @return Current seleciton limit.
+ * @return Current selection limit.
*/
size_t getSelectLimit() const;
SelectMode m_SelectMode;
SelectCallback m_OnSelected;
+ CheckCallback m_OnChecked;
};
}
using namespace Contacts;
SelectItem::SelectItem()
- : m_SelectMode(SelectNone)
+ : m_SelectMode(SelectNone), m_CustomResult{ 0, 0 }, m_HasCustomResult(false)
{
}
onSelectModeChanged(m_SelectMode);
}
+SelectResult SelectItem::getSelectResult() const
+{
+ return m_HasCustomResult ? m_CustomResult : getDefaultResult();
+}
+
+void SelectItem::setCustomResult(SelectResult result)
+{
+ m_CustomResult = result;
+ m_HasCustomResult = true;
+}
+
+void SelectItem::unsetCustomResult()
+{
+ m_HasCustomResult = false;
+}
+
Evas_Object *SelectItem::getContent(Evas_Object *parent, const char *part)
{
if (m_SelectMode == SelectMulti) {
m_OnSelected = std::move(callback);
}
+void SelectView::setCheckCallback(CheckCallback callback)
+{
+ m_OnChecked = std::move(callback);
+}
+
+void SelectView::setCheckedItem(SelectItem *item, bool isChecked)
+{
+ item->setChecked(isChecked);
+ updateSelectCount(isChecked ? CountIncrement : CountDecrement);
+}
+
SelectMode SelectView::getSelectMode() const
{
return m_SelectMode;
return false;
}
+ if (m_OnChecked && !m_OnChecked(item, isChecked)) {
+ return false;
+ }
+
updateSelectCount(isChecked ? CountIncrement : CountDecrement);
return true;
}
/**
* @see SelectItem::getSelectResult()
*/
- virtual SelectResult getSelectResult() const override;
+ virtual SelectResult getDefaultResult() const override;
/**
* @see ContactField::UpdatedCallback
private:
virtual char *getText(Evas_Object *parent, const char *part) override;
virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override;
- virtual SelectResult getSelectResult() const override;
+ virtual SelectResult getDefaultResult() const override;
Model::Person &m_Person;
};
return nullptr;
}
-SelectResult FieldItem::getSelectResult() const
+SelectResult FieldItem::getDefaultResult() const
{
return { m_Object.getSubType(), m_Object.getRecordId() };
}
return nullptr;
}
-SelectResult PersonItem::getSelectResult() const
+SelectResult PersonItem::getDefaultResult() const
{
return { ResultPerson, m_Person.getId() };
}
virtual char *getText(Evas_Object *parent, const char *part) override;
virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override;
virtual void onSelectModeChanged(Contacts::SelectMode selectMode) override;
- virtual Contacts::SelectResult getSelectResult() const override;
+ virtual Contacts::SelectResult getDefaultResult() const override;
static Evas_Object *createIcon(Evas_Object *parent, const char *path);
static const char *getImagePath(int type);
private:
virtual char *getText(Evas_Object *parent, const char *part) override;
virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override;
- virtual Contacts::SelectResult getSelectResult() const override;
+ virtual Contacts::SelectResult getDefaultResult() const override;
Evas_Object *createThumbnail(Evas_Object *parent);
Evas_Object *createLayout(Evas_Object *parent, const char *layoutName);
}
}
-SelectResult LogDetailItem::getSelectResult() const
+SelectResult LogDetailItem::getDefaultResult() const
{
return { 0, m_Log };
}
return nullptr;
}
-SelectResult LogItem::getSelectResult() const
+SelectResult LogItem::getDefaultResult() const
{
return { 0, m_Group };
}