CComponentsForm: add new member genIndex()

This commit is contained in:
2013-06-23 22:20:42 +02:00
parent c66c778326
commit a8721fa72a
3 changed files with 14 additions and 6 deletions

View File

@@ -267,7 +267,8 @@ class CComponentsItem : public CComponents
///get current index of item, see also attribut cc_item_index ///get current index of item, see also attribut cc_item_index
virtual int getIndex(){return 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;}; virtual void setIndex(const int& index){cc_item_index = index;};
}; };

View File

@@ -143,11 +143,7 @@ void CComponentsForm::addCCItem(CComponentsItem* cc_Item)
#endif #endif
//assign item index //assign item index
int count = v_cc_items.size(); int new_index = genIndex();
char buf[64];
snprintf(buf, sizeof(buf), "%d%d", cc_item_index, count);
buf[63] = '\0';
int new_index = atoi(buf);
cc_Item->setIndex(new_index); cc_Item->setIndex(new_index);
#ifdef DEBUG_CC #ifdef DEBUG_CC
printf(" %s-%d parent index = %d, assigned index ======> %d\n", __FUNCTION__, __LINE__, cc_item_index, new_index); 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; 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) CComponentsItem* CComponentsForm::getCCItem(const uint& cc_item_id)
{ {

View File

@@ -41,6 +41,8 @@ class CComponentsForm : public CComponentsItem
std::vector<CComponentsItem*> v_cc_items; std::vector<CComponentsItem*> v_cc_items;
void initVarForm(); void initVarForm();
void paintForm(bool do_save_bg); 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_h_offset;
int append_v_offset; int append_v_offset;