diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index 3d01723d9..e86b43799 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -267,7 +267,8 @@ class CComponentsItem : public CComponents ///get current index of item, see also attribut cc_item_index virtual int getIndex(){return cc_item_index;}; - ///set index to item, see also attribut cc_item_index + ///set an index to item, see also attribut cc_item_index. + ///To generate an index, use genIndex() virtual void setIndex(const int& index){cc_item_index = index;}; }; diff --git a/src/gui/components/cc_frm.cpp b/src/gui/components/cc_frm.cpp index 46313ba2e..ebc65a028 100644 --- a/src/gui/components/cc_frm.cpp +++ b/src/gui/components/cc_frm.cpp @@ -143,11 +143,7 @@ void CComponentsForm::addCCItem(CComponentsItem* cc_Item) #endif //assign item index - int count = v_cc_items.size(); - char buf[64]; - snprintf(buf, sizeof(buf), "%d%d", cc_item_index, count); - buf[63] = '\0'; - int new_index = atoi(buf); + int new_index = genIndex(); cc_Item->setIndex(new_index); #ifdef DEBUG_CC printf(" %s-%d parent index = %d, assigned index ======> %d\n", __FUNCTION__, __LINE__, cc_item_index, new_index); @@ -177,6 +173,15 @@ bool CComponentsForm::isAdded(CComponentsItem* cc_item) return ret; } +int CComponentsForm::genIndex() +{ + int count = v_cc_items.size(); + char buf[64]; + snprintf(buf, sizeof(buf), "%d%d", cc_item_index, count); + buf[63] = '\0'; + int ret = atoi(buf); + return ret; +} CComponentsItem* CComponentsForm::getCCItem(const uint& cc_item_id) { diff --git a/src/gui/components/cc_frm.h b/src/gui/components/cc_frm.h index 38a2bd348..d9cd09e7c 100644 --- a/src/gui/components/cc_frm.h +++ b/src/gui/components/cc_frm.h @@ -41,6 +41,8 @@ class CComponentsForm : public CComponentsItem std::vector v_cc_items; void initVarForm(); void paintForm(bool do_save_bg); + ///generates next possible index for an item, see also cc_item_index, getIndex(), setIndex() + int genIndex(); int append_h_offset; int append_v_offset;