Added possibility to store additional selection result in SelectItem. 42/62642/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Thu, 17 Mar 2016 07:43:31 +0000 (09:43 +0200)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Thu, 17 Mar 2016 09:28:29 +0000 (11:28 +0200)
Added possibility to control items checking in SelectView from outside.

Change-Id: I583939d512f9a86e8bcf7e0eacd7c5312495a369
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
13 files changed:
lib-common/inc/Contacts/SelectItem.h
lib-common/inc/Contacts/SelectTypes.h
lib-common/inc/Contacts/SelectView.h
lib-common/src/Contacts/SelectItem.cpp
lib-common/src/Contacts/SelectView.cpp
lib-contact/inc/Contacts/Details/FieldItem.h
lib-contact/inc/Contacts/List/PersonItem.h
lib-contact/src/Contacts/Details/FieldItem.cpp
lib-contact/src/Contacts/List/PersonItem.cpp
lib-logs/inc/Logs/Details/LogDetailItem.h
lib-logs/inc/Logs/List/LogItem.h
lib-logs/src/Logs/Details/LogDetailItem.cpp
lib-logs/src/Logs/List/LogItem.cpp

index ec8d332..198e267 100644 (file)
@@ -41,11 +41,26 @@ namespace Contacts
                 */
                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()
@@ -67,6 +82,8 @@ namespace Contacts
                friend class SelectView;
 
                SelectMode m_SelectMode;
+               SelectResult m_CustomResult;
+               bool m_HasCustomResult;
        };
 }
 
index caeabc7..e3d7273 100644 (file)
@@ -51,7 +51,7 @@ namespace Contacts
        /**
         * @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.
index b27b67d..8c28f83 100644 (file)
@@ -40,6 +40,15 @@ namespace Contacts
        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();
 
                /**
@@ -60,6 +69,21 @@ namespace Contacts
                 */
                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.
@@ -67,7 +91,7 @@ namespace Contacts
                SelectMode getSelectMode() const;
 
                /**
-                * @return Current seleciton limit.
+                * @return Current selection limit.
                 */
                size_t getSelectLimit() const;
 
@@ -167,6 +191,7 @@ namespace Contacts
 
                SelectMode m_SelectMode;
                SelectCallback m_OnSelected;
+               CheckCallback m_OnChecked;
        };
 }
 
index 70a25ec..a9bf36f 100644 (file)
@@ -20,7 +20,7 @@
 using namespace Contacts;
 
 SelectItem::SelectItem()
-       : m_SelectMode(SelectNone)
+       : m_SelectMode(SelectNone), m_CustomResult{ 0, 0 }, m_HasCustomResult(false)
 {
 }
 
@@ -37,6 +37,22 @@ void SelectItem::setSelectMode(SelectMode selectMode)
        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) {
index 871f013..dd8c051 100644 (file)
@@ -78,6 +78,17 @@ void SelectView::setSelectCallback(SelectCallback callback)
        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;
@@ -290,6 +301,10 @@ bool SelectView::onItemChecked(SelectItem *item, bool isChecked)
                return false;
        }
 
+       if (m_OnChecked && !m_OnChecked(item, isChecked)) {
+               return false;
+       }
+
        updateSelectCount(isChecked ? CountIncrement : CountDecrement);
        return true;
 }
index 8c3153b..c0784eb 100644 (file)
@@ -74,7 +74,7 @@ namespace Contacts
                        /**
                         * @see SelectItem::getSelectResult()
                         */
-                       virtual SelectResult getSelectResult() const override;
+                       virtual SelectResult getDefaultResult() const override;
 
                        /**
                         * @see ContactField::UpdatedCallback
index d97f043..da9c533 100644 (file)
@@ -53,7 +53,7 @@ namespace Contacts
                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;
                };
index 78f3b60..f81c4b4 100644 (file)
@@ -89,7 +89,7 @@ Evas_Object *FieldItem::getContent(Evas_Object *parent, const char *part)
        return nullptr;
 }
 
-SelectResult FieldItem::getSelectResult() const
+SelectResult FieldItem::getDefaultResult() const
 {
        return { m_Object.getSubType(), m_Object.getRecordId() };
 }
index df4dc45..e045f0f 100644 (file)
@@ -60,7 +60,7 @@ Evas_Object *PersonItem::getContent(Evas_Object *parent, const char *part)
        return nullptr;
 }
 
-SelectResult PersonItem::getSelectResult() const
+SelectResult PersonItem::getDefaultResult() const
 {
        return { ResultPerson, m_Person.getId() };
 }
index 08752c6..535e249 100644 (file)
@@ -43,7 +43,7 @@ namespace Logs
                        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);
index bf081af..964b181 100644 (file)
@@ -70,7 +70,7 @@ namespace Logs
                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);
index f971ce6..c7a182d 100644 (file)
@@ -81,7 +81,7 @@ void LogDetailItem::onSelectModeChanged(SelectMode selectMode)
        }
 }
 
-SelectResult LogDetailItem::getSelectResult() const
+SelectResult LogDetailItem::getDefaultResult() const
 {
        return { 0, m_Log };
 }
index c9ee5d1..0232d20 100644 (file)
@@ -133,7 +133,7 @@ Evas_Object *LogItem::getContent(Evas_Object *parent, const char *part)
        return nullptr;
 }
 
-SelectResult LogItem::getSelectResult() const
+SelectResult LogItem::getDefaultResult() const
 {
        return { 0, m_Group };
 }