/*! \internal cursors should be filled with Q3SqlFieldInfos... */ void Q3SqlCursor::append(const QSqlField& field) { append(Q3SqlFieldInfo(field)); }
void Q3SqlCursor::remove(int pos) { d->editBuffer.remove(pos); d->infoBuffer[pos] = Q3SqlFieldInfo(); QSqlRecord::remove(pos); }
/*! *\~english * Initialisation the widget on form loaded in engine. *\~russian * Инициализация виджета при загрузке в форму инжина. *\~ */ void wDBTable::init(aDatabase *adb, aEngine *e ) { aLog::print(aLog::Debug, tr("wDBTable init in engine ")); // printf("begin init wdbtable\n"); unsigned int countField,i; aCfgItem o, own; QString str, ctype; QStringList lst,lstHead,lstWidth; int tid; aWidget *container = NULL; t_doc = rcIcon( "t_doc.png" ); t_doc_d = rcIcon( "t_doc_d.png" ); t_doc_t = rcIcon( "t_doc_t.png" ); t_doc_m = rcIcon( "t_doc_m.png" ); t_doc_tm = rcIcon( "t_doc_tm.png" ); t_cat_e = rcIcon( "t_cat_e.png" ); t_cat_ed = rcIcon( "t_cat_ed.png" ); t_cat_g = rcIcon( "t_cat_g.png" ); t_cat_gd = rcIcon( "t_cat_gd.png" ); engine = e; setConfirmDelete(true); db = adb; md = &adb->cfg; tid = property("TableInd").toInt(); container = aWidget::parentContainer( this ); if ( !container ) { aLog::print(aLog::Error, tr("wDBTable not in Ananas object container ")); return; //printf("!no wDBTable parent container\n"); } else { o = md->objTable( container->getId(), tid ); if ( o.isNull() ) { //debug_message("Table not found\n"); aLog::print(aLog::Error, tr("wDBTable init meta object not found ")); } ctype = container->className(); aLog::print(aLog::Info, tr("wDBTable container type is %1 ").arg(ctype)); setContainerType(ctype); } //o = md->find(property("TableInd").toInt()); if ( o.isNull() ) { aLog::print(aLog::Error, tr("wDBTable init meta object not found ")); return; } countField = numCols(); for(i=0; i<countField;i++) { removeColumn(0); } aSQLTable *tbl = NULL; //printf("ctype = %s\n",( const char *) ctype ); if ( containerType() == "wDocument" ) { QString flt; flt = QString("idd=%1").arg(container->uid()); aLog::print(aLog::Info, tr("wDBTable filter is %1 ").arg(flt)); setFilter(flt); //TODO: fix memory leak tbl = new aSQLTable( o, adb ); // printf("new table ok\n"); // tbl->first(); } if ( containerType() == "wCatalogue" ) { tbl = container->table(); //new aSQLTable( o, adb ); setFilter(QString("idg=0")); newDataId(0); tbl->append( Q3SqlFieldInfo("system_icon") ); // tbl->setGenerated( "system_icon", false ); tbl->setCalculated("system_icon", true ); } if ( containerType() == "wJournal" ) { tbl = container->table(); //new aSQLTable( o, adb ); tbl->setMode( 0 ); tbl->append( Q3SqlFieldInfo( "system_icon" ) ); // tbl->setGenerated( "system_icon", false ); tbl->setCalculated( "system_icon", true ); // tbl->append( QSqlFieldInfo( "t1" ) ); // tbl->setGenerated( "t1", false ); // tbl->setCalculated("t1", true ); } refresh(); cur->clear(); setSqlCursor(tbl,true); refresh(RefreshColumns); countField = numCols(); lst = property("DefIdList").toStringList(); lstHead = property("DefHeaders").toStringList(); lstWidth = property("ColWidth").toStringList(); for ( i = 0; i < countField; i++ ) { //remove all columns in wDBTable, not in sql cursor removeColumn( 0 ); QString s = sqlCursor()->fieldName(i); // printf(">>>>s = %s\n",s.ascii()); // if(sqlCursor()->isCalculated(s)) // { // if((s.left(7)=="text_uf" && lst.findIndex(s.mid(7))!=-1) || s == "system_icon") // { // continue; // } // not calculate field, if is not contents in wDBTable // sqlCursor()->setCalculated(sqlCursor()->fieldName(i),false); // } } if ( containerType() == "wJournal" ) { addColumn( "system_icon", "", 20 ); setColumnReadOnly( 0, true ); if (md->objClass(*(container->getMDObject()))==md_journal && !((aDocJournal*) container->dataObject())->type() ) { // we have common journal // Insert journal system columns. addColumn( "ddate", tr("Date"), 100 ); addColumn( "pnum", tr("Prefix"), 200 ); addColumn( "num", tr("Number"), 100 ); } } if ( containerType() == "wCatalogue" ) { addColumn( "system_icon", "", 20 ); // printf("set column ro\n"); setColumnReadOnly( 0, true ); } if ( containerType() == "wDocument" || containerType() == "wCatalogue" ) { // Задаем сортировку по индентификатору в обратном порядке для // табличной части документа // чтобы при добавлении новых позиций в список строки не скакали QSqlIndex pk = sqlCursor()->primaryIndex(); pk.setDescending( 0, false); setSort( pk ); sqlCursor()->select(); sqlCursor()->first(); refresh(); } //refresh(RefreshColumns); if (md->objClass(*(container->getMDObject()))!=md_journal || ((aDocJournal*) container->dataObject())->type() ) { // we have not common journal for(i=0; i<lst.count();i++) { // assemble sql table field names if ( containerType() == "wJournal" ) { // str = journalFieldName(lst[i].toLong()); str = "uf"+QString::number(journalFieldId(lst[i].toLong())); //printf(">>>>>>ss=%s\n",str.ascii()); } else { str = "uf"+lst[i]; } // add defined fields addColumn(str,lstHead[i],lstWidth[i].toInt()); } } refresh(RefreshAll); setWFieldEditor(); aLog::print(aLog::Debug, tr("wDBTable init in engine ok")); }