/*! * Loads elements in group, if then don't loaded. * \param idGroup (in) - id group for load. */ void CatalogForm::loadElements( qulonglong idGroup ) { Q3ListViewItem * item; Q3ListViewItem * p_item; uint i; // printf("load elements\n"); // printf("sel by group id = %lu\n",idGroup); QPixmap pixmap(getElementPixmap()); QPixmap pixmap_mark_deleted(getMarkDeletedPixmap()); cat->selectByGroup(idGroup); // printf("_sel by group\n"); if(cat->First()) { do { //count++; if(map_gr.contains(idGroup) && !map_el.contains(cat->sysValue("id").toULongLong())) { p_item = map_gr[idGroup]; item = new Q3ListViewItem(p_item); if(cat->isElementMarkDeleted()) item->setPixmap(0,pixmap_mark_deleted); else item->setPixmap(0,pixmap); for(i=0; i<fieldList.count(); i++) { // printf("i = %d\n",i); item->setText(i,cat->sysValue(fieldList[i]).toString()); } map_el.insert(cat->sysValue("id").toULongLong(),item); } }while(cat->Next()); } // printf("end load\n"); }
/*! * Function set initial data. Adds one element in each group. * \param catalog (in) - object catalog for edit or select. * \param mg (in) - map of catalog groups. Key - group id. * \param Fname (in) - list of field names of elements. * \param FnameGroup (in) - list of field names of groups. */ void CatalogForm::setData( aCatalogue* catalog, QMap<qulonglong, Q3ListViewItem*> mg, //QMap<Q_ULLONG, bool> map_d, const QStringList & Fname, const QStringList & FnameGroup, qulonglong idElForm, qulonglong idGrForm, const bool toSelect) { ListView->setDestination(toSelect); aLog::print(aLog::Debug, tr("CatalogForm:setData begin")); Q3ListViewItem* item; uint i; QPixmap pixmap(getElementPixmap()); QPixmap pixmap_mark_deleted(getMarkDeletedPixmap()); idElementForm = idElForm; idGroupForm = idGrForm; cat = catalog; fieldName= Fname[0]; fieldList= Fname; fieldListGroup = FnameGroup; map_gr = mg; ListView->setAllColumnsShowFocus ( true ); QMap<qulonglong, Q3ListViewItem *>::Iterator it = map_gr.begin(); cat->Select(); // added one element in each group while(it!=map_gr.end()) { cat->selectByGroup(it.key());// select elements in each group if(cat->First()) // if group have elements { item = new Q3ListViewItem(map_gr[it.key()]); aLog::print(aLog::Debug, tr("CatalogForm add first element in group")); //printf("add first element in group\n"); if(cat->isElementMarkDeleted()) item->setPixmap(0,pixmap_mark_deleted); else item->setPixmap(0,pixmap); for(i=0; i<fieldList.count(); i++) { item->setText(i,cat->sysValue(fieldList[i]).toString()); } map_el.insert(cat->sysValue("id").toULongLong(),item); } ++it; } cat->selectByGroup(0);// select elements without group if(cat->First()) { aLog::print(aLog::Debug, tr("CatalogForm add elements into root")); do { item = new Q3ListViewItem(ListView); if(cat->isElementMarkDeleted()) item->setPixmap(0,pixmap_mark_deleted); else item->setPixmap(0,pixmap); for(i=0; i<fieldList.count(); i++) { item->setText(i,cat->sysValue(fieldList[i]).toString()); } map_el.insert(cat->sysValue("id").toULongLong(),item); }while(cat->Next()); } cat->Select(); setGeometry(aService::loadSizeFromConfig(QString("%1_embedded editor").arg(cat->md->attr( mda_name)))); ListView->setSelected(ListView->firstChild(),true); aLog::print(aLog::Debug, tr("CatalogForm init")); }
void wCatalogEditor::openForm(const bool toSelect) { aLog::print(aLog::MT_DEBUG, tr("wCatalog Editor open form for select=%1 ").arg((int)toSelect)); MainForm *mainform; if(parent()) { mainform = (MainForm*) topLevelWidget(); ws = mainform->ws; } // aWindowsList *wl = mainform->wl; int objid = catId; /* if ( wl->find( objid ) ) { // wl->remove(objid); wl->get( objid )->setFocus(); return; } else { CatalogForm* newform = new CatalogForm(ws,0, WDestructiveClose); wl->insert( objid, newform ); }*/ CatalogForm* newform = new CatalogForm(ws,0, WDestructiveClose); connect( newform, SIGNAL(selected(Q_ULLONG)), this, SLOT(on_selected( Q_ULLONG ))); connect( newform, SIGNAL(destroyed()), this, SLOT(on_destroyed_form())); aCatalogue *cat = new aCatalogue(md->find(catId),db); int count=0; bool est=true; QMap<Q_ULLONG,QListViewItem*> map, map_el; aCfgItem tmp, tmp_f,tmp_el,tmp_group, o; QListViewItem * item; QListViewItem * p_item; Q_ULLONG idGrForm=0, idElForm=0; QStringList listPos, listPosGroup; newform->ListHint->hide(); QPixmap pixmap(newform->getGroupPixmap()); QPixmap pixmap_mark_deleted(newform->getMarkDeletedPixmap()); tmp = md->find(catId); newform->setCaption(md->attr(tmp,mda_name)); o = md->findChild(tmp, md_forms); // get obj forms if(!o.isNull()) { count = md->count(o,md_form); for(int i=0; i<count; i++) { tmp_f = md->findChild(o,md_form,i); if(!tmp_f.isNull() && atoi(md->attr(tmp_f,mda_type).ascii())==md_form_elem) { aLog::print(aLog::MT_DEBUG, tr("wCatalog Editor found element forms")); idElForm = md->id(tmp_f); // continue; } if(!tmp_f.isNull() && atoi(md->attr(tmp_f,mda_type).ascii())==md_form_group) { aLog::print(aLog::MT_DEBUG, tr("wCatalog Editor found group forms")); idGrForm = md->id(tmp_f); } } } else { aLog::print(aLog::MT_ERROR, tr("wCatalog Editor meta object forms not found")); } tmp_el = md->findChild(tmp, md_element); tmp_group = md->findChild(tmp,md_group); tmp = md->findChild(tmp_el, md_field); int count_fields = md->count(tmp_el,md_field); listPosGroup = cat->getGroupUserFields(); int i,level = 0; cat->Select(); while(est) // add group in tree on levels { est = false; ++level; cat->selectByLevel(level-1); if(!cat->FirstInGroupTable()) break; do { if(cat->GroupSysValue("level").toInt()==level-1) //all groups, having this level { est = true; QString displayString; displayString= cat->GroupSysValue(listPosGroup[0]).toString(); if(map.contains(cat->GroupSysValue("idp").toULongLong())) { p_item = map[(cat->GroupSysValue("idp").toULongLong())]; item = new QListViewItem(p_item); } else { item = new QListViewItem(newform->ListView); newform->ListView->insertItem(item); } item->setText(0, displayString); if(cat->isGroupMarkDeleted()) item->setPixmap(0,pixmap_mark_deleted); else item->setPixmap(0,pixmap); map.insert(cat->GroupSysValue("id").toULongLong(),item); //printf("%lu\n",cat->GroupSysValue("id").toULongLong()); } }while(cat->NextInGroupTable()); } listPos = cat->getUserFields(); checkUserFields(listPos); int fid; //sets column name for(uint i=0; i<listPos.count(); i++) { fid = atoi(listPos[i].remove("uf",false).ascii()); if(!fid) { // printf("listPos[]=%s",listPos[i].remove("text_uf",false).ascii()); fid = (listPos[i].remove("text_",false)).toInt(); //tmp = md->find(fid); } if(fid) { tmp = md->find(fid); newform->ListView->addColumn(md->attr(tmp,mda_name)); } } listPos.clear(); listPos = cat->getUserFields(); checkUserFields(listPos); //Q_ULLONG res = 0; // cat deleted in function catalogform::destroy(); newform->setData( cat, map, listPos, cat->getGroupUserFields(), idElForm, idGrForm, toSelect); newform->setId(value().toULongLong()); newform->show(); ((QWidget*)newform->parent())->move(0,0); }