void CustomOrderedListEdit::slotEditButtonClicked() { OListEditForm *d = new OListEditForm( this ); d->setWindowTitle( _FU8( m_custom->label ) ); initPtrList(); /* * Adding Enabled Items */ foreach( const struct uim_custom_choice *item, m_itemList ) { d->addCheckItem( true, _FU8(item->label) ); }
void CustomOrderedListEdit::slotEditButtonClicked() { OListEditForm *d = new OListEditForm( this ); initPtrList(); /* * Adding Enabled Items */ for( struct uim_custom_choice *item = m_itemList.first(); item; item = m_itemList.next() ) { d->addCheckItem( true, _FU8(item->label) ); } /* * Adding Disabled Items */ for( struct uim_custom_choice *valid_item = m_validItemList.first(); valid_item; valid_item = m_validItemList.next() ) { /* Exclude Enabled Item */ bool isActive = false; for( struct uim_custom_choice *item = m_itemList.first(); item; item = m_itemList.next() ) { if( QString::compare( valid_item->symbol, item->symbol ) == 0 ) { isActive = true; break; } } if( isActive == false ) { d->addCheckItem( false, _FU8(valid_item->label) ); } } /* Exec Dialog */ if( d->exec() == OListEditForm::Accepted ) { /* search active item's ptr, realloc it, and store in activeItemList */ QPtrList<struct uim_custom_choice> activeItemList; activeItemList.setAutoDelete( false ); QStringList activeItemLabelList = d->activeItemLabels(); for( unsigned int i = 0; i < activeItemLabelList.count(); i++ ) { struct uim_custom_choice *item = NULL; int j = 0; for( item = m_custom->range->as_olist.valid_items[0], j = 0; item; item = m_custom->range->as_olist.valid_items[++j] ) { if( QString::compare( activeItemLabelList[i], _FU8(item->label) ) == 0 ) { /* allocate new struct because we will free the old struct */ struct uim_custom_choice *activeItem = (struct uim_custom_choice *)malloc(sizeof(struct uim_custom_choice)); activeItem->symbol = item->symbol ? strdup(item->symbol) : NULL; activeItem->label = item->label ? strdup(item->label) : NULL; activeItem->desc = item->desc ? strdup(item->desc) : NULL; activeItemList.append( activeItem ); break; } } } /* free old items */ for( unsigned int i = 0; i < m_itemList.count(); i++ ) { free( m_custom->value->as_olist[i]->symbol ); free( m_custom->value->as_olist[i]->label ); free( m_custom->value->as_olist[i]->desc ); free( m_custom->value->as_olist[i] ); } /* create null-terminated new olist */ m_custom->value->as_olist = (struct uim_custom_choice **)realloc( m_custom->value->as_olist, sizeof(struct uim_custom_choice *) * (activeItemList.count() + 1) ); for( unsigned int i = 0; i < activeItemList.count(); i++ ) { m_custom->value->as_olist[i] = activeItemList.at(i); } m_custom->value->as_olist[activeItemList.count()] = NULL; /* save */ setCustom( m_custom ); /* reload */ update(); } delete d; }