Go to the documentation of this file. 1 #ifndef CNOID_BASE_TARGET_ITEM_PICKER_H
2 #define CNOID_BASE_TARGET_ITEM_PICKER_H
6 #include "exportdecl.h"
18 void setEnabled(
bool on);
19 void clearTargetItem();
21 void storeTargetItem(
Archive& archive,
const std::string& key);
22 void restoreTargetItem(
const Archive& archive,
const std::string& key);
23 void restoreTargetItemLater(
const Archive& archive,
const std::string& key);
26 Item* getTargetItem();
27 virtual Item* extractTargetItemCandidates(
ItemList<>& io_items,
Item* preferred,
bool selectionChanged) = 0;
28 virtual bool targetPredicate(
Item* item) = 0;
29 virtual void onTargetItemSpecified(
Item* item,
bool isChanged) = 0;
30 virtual void onDeactivated() = 0;
38 template<
class ItemType>
47 void setTargetPredicate(std::function<
bool(ItemType* item)> predicate){ targetPredicate_ = predicate; }
49 template<
class Interface>
51 targetPredicate_ = [](ItemType* item)->
bool {
return dynamic_cast<Interface*
>(item) !=
nullptr; };
58 return sigTargetItemSpecified_;
61 return sigTargetItemChanged_;
64 return sigSelectedItemsChanged_;
71 Item* candidate =
nullptr;
73 auto iter = io_items.begin();
74 while(iter != io_items.end()){
75 auto item =
dynamic_cast<ItemType*
>(iter->get());
76 if(item && targetPredicate_){
77 if(!targetPredicate_(item)){
82 iter = io_items.erase(iter);
86 }
else if(item == preferred){
87 candidate = preferred;
94 if(io_items != selectedItems_){
95 selectedItems_ = io_items;
96 sigSelectedItemsChanged_(selectedItems_);
105 if(targetPredicate_){
106 return targetPredicate_(
static_cast<ItemType*
>(item));
113 auto targetItem =
static_cast<ItemType*
>(item);
114 sigTargetItemSpecified_(targetItem);
116 sigTargetItemChanged_(targetItem);
122 selectedItems_.clear();
126 std::function<bool(ItemType* item)> targetPredicate_;
127 Signal<void(ItemType* targetItem)> sigTargetItemSpecified_;
128 Signal<void(ItemType* targetItem)> sigTargetItemChanged_;
ref_ptr< ItemType > ItemTypePtr
Definition: TargetItemPicker.h:42
virtual void onDeactivated() override
Definition: TargetItemPicker.h:120
SignalProxy< void(ItemType *targetItem)> sigTargetItemSpecified()
Definition: TargetItemPicker.h:57
void setTargetInterface()
Definition: TargetItemPicker.h:50
Definition: Referenced.h:103
SignalProxy< void(ItemType *targetItem)> sigTargetItemChanged()
Definition: TargetItemPicker.h:60
SignalProxy< void(const ItemList< ItemType > &selected)> sigSelectedItemsChanged()
Definition: TargetItemPicker.h:63
virtual void onTargetItemSpecified(Item *item, bool isChanged) override
Definition: TargetItemPicker.h:111
virtual Item * extractTargetItemCandidates(ItemList<> &io_items, Item *preferred, bool selectionChanged) override
Definition: TargetItemPicker.h:69
Definition: AbstractSceneLoader.h:11
Definition: TargetItemPicker.h:39
void setTargetPredicate(std::function< bool(ItemType *item)> predicate)
Definition: TargetItemPicker.h:47
const ItemList< ItemType > & selectedItems()
Definition: TargetItemPicker.h:55
virtual bool targetPredicate(Item *item) override
Definition: TargetItemPicker.h:103
ItemType * currentItem()
Definition: TargetItemPicker.h:54
TargetItemPicker(View *view)
Definition: TargetItemPicker.h:45
TargetItemPicker()
Definition: TargetItemPicker.h:44
Definition: TargetItemPicker.h:12
Item * getTargetItem()
Definition: TargetItemPicker.cpp:136