/*! * \~english * Function paint field in table. * \~russian * Переопределенная функция рисования поля таблицы. * В типе DateTime не отображает время. * Поддерживает вычисляемые поля. * \~ */ void wDBTable::paintField ( QPainter * p, const QSqlField * field, const QRect & cr, bool selected ) { if(field->name().left(5)=="text_") return; if ( sqlCursor()->isCalculated( field->name() ) ){ if ( field->name()=="system_icon" ) p->drawPixmap( QRect( 0, 0, cr.width(), cr.height() ), systemIcon() ); return; } if ( sqlCursor()->contains( "text_"+field->name() ) ) { QSqlField f(*field); f.setValue(((aDataTable*)sqlCursor())->sysValue("text_"+f.name())); Q3DataTable::paintField( p, &f, cr, selected ); return; // f = * sqlCursor()->field( "text_"+f.name() ); } if(field->type() == QVariant::DateTime) { QSqlField f(*field); f.setValue(field->value().toDate());// don't show time Q3DataTable::paintField( p, &f, cr, selected ); return; } Q3DataTable::paintField( p, field, cr, selected ); }
bool wDBTable::beginInsert() { if ( !sqlCursor() || isReadOnly() || !numCols() ) return FALSE; if ( !sqlCursor()->canInsert() ) return FALSE; bool result = Q3DataTable::beginInsert(); endEdit( currentRow(), currentColumn(), false, false); setCurrentCell( numRows(), 0 ); return result; }
bool wDBTable::searchColumn( const QString & text, bool FromCurrent, bool Forward ) { QString s; uint curr = currentRow(), curc=currentColumn(), row = 0, idx; bool found = FALSE; aSQLTable *t = ( aSQLTable *) sqlCursor(); if ( FromCurrent ) row = curr; if ( Forward ) row++; else row--; idx = indexOf( curc ); while ( t->seek( row ) ){ s = t->value( idx ).toString(); if ( s.left( text.length() ) == text ) { found = TRUE; break; } if ( Forward ) row++; else row--; } if ( found ) { setCurrentCell( row, curc ); }; return found; }
void Q3DataBrowser::insert() { QSqlRecord* buf = d->frm.record(); Q3SqlCursor* cur = d->cur.cursor(); if (!buf || !cur) return; bool doIns = true; QSql::Confirm conf = QSql::Yes; switch (d->dat.mode()) { case QSql::Insert: if (autoEdit()) { if (confirmInsert()) conf = confirmEdit(QSql::Insert); switch (conf) { case QSql::Yes: insertCurrent(); break; case QSql::No: break; case QSql::Cancel: doIns = false; break; } } break; default: if (autoEdit() && currentEdited()) { if (confirmUpdate()) conf = confirmEdit(QSql::Update); switch (conf) { case QSql::Yes: updateCurrent(); break; case QSql::No: break; case QSql::Cancel: doIns = false; break; } } break; } if (doIns) { d->dat.setMode(QSql::Insert); sqlCursor()->primeInsert(); emit primeInsert(d->frm.record()); readFields(); } }
/*! * \en Handler line current change signal. \_en * \ru Обработчик сигнала изменения строки. Генерирует сигналы * deleteLine и saveLine. \_ru */ void wDBTable::lineUpdate( QSql::Op mode) { QSqlRecord *rec = sqlCursor()->editBuffer();//currentRecord(); switch(mode) { case QSql::Update: // rec = currentRecord(); break; case QSql::Insert: break; case QSql::Delete: //printf("emit del line\n"); emit(deleteLine(rec)); return; default: break; } //if(!rec) return; //printf(" emit saveLine\n"); emit(saveLine(rec)); }
int wDBTable::Select( ANANAS_UID db_uid ) { aSQLTable *t = ( aSQLTable *) sqlCursor(); // printf("id = %Li\n",db_uid); ANANAS_UID cur_id = 0; uint curr = currentRow(), curc=currentColumn(), row = 0; bool found = FALSE; while ( t->seek( row ) ){ cur_id = t->sysValue( "id" ).toULongLong(); if ( cur_id == db_uid ) { found = TRUE; break; } row++; } if ( found ) { setCurrentCell( row, curc ); } else setCurrentCell( curr, curc ); return 0; }
/*! *\~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")); }
/*! * \~english * Return system icon for display object record state. * \russian * Возвращает иконку для отображения состояния строки. * \~ */ QPixmap wDBTable::systemIcon() { aWidget *container = aWidget::parentContainer( this ); QString ctype=""; QPixmap pm; Q3SqlCursor *r = sqlCursor(); int df=0, cf=0, mf=0; if ( container ) ctype = container->className(); if ( r ) { if ( r->contains("df") ) df = r->field("df").value().toInt(); if ( r->contains("cf") ) cf = r->field("cf").value().toInt(); else { if(ctype=="wJournal") { aDocJournal* sysObj = new aDocJournal(db); if(sysObj) { //for(int i=0; i<r->count(); i++) // printf("f[%d]=%s, %s\n",i, r->fieldName(i).ascii(), r->field(i)->value().toString().ascii()); if(sysObj->findDocument(r->field("id").value().toULongLong())) { aDocument *doc = sysObj->CurrentDocument(); cf = doc->IsConducted(); delete doc; } else { printf(">>doc select failed!\n"); } //doc = 0; //cf = sysObj->sysValue("cf").toInt(); } delete sysObj; } //>>>>>>> 1.71.2.13 } if ( r->contains("mf") ) mf = r->field("mf").value().toInt(); if(ctype=="wJournal") { pm = t_doc; if ( df ) pm = t_doc_d; if ( cf && !df ) pm = t_doc_t; if ( mf && !df ) pm = t_doc_m; if ( cf && mf && !df ) pm = t_doc_tm; } else if(ctype=="wCatalogue") { pm = t_cat_e; if ( df ) pm = t_cat_ed; } else if(ctype=="wCatGroupe") { pm = t_cat_g; if ( df ) pm = t_cat_gd; } } return pm; }
/*! * \~english * Reimplemented QDataTable function. * \~russian * Переопределяет функцию QDataTable. Если контейнер wJournal, может испускаеть сигналы insertRequest(), updateRequest(), deleteRequest(), viewRequest() * \~ */ void wDBTable::contentsContextMenuEvent ( QContextMenuEvent * e ) { Q3Table::contentsContextMenuEvent( e ); QString str, ctype; if ( containerType() == "wDocument" || containerType() == "wCatalogue" ) { // Переопределяем всплывающее по правой кнопке мыши меню для табличной части документа // Во-первых, для его локализации // Во-вторых, чтобы добавляемая в табличную часть строка всегда вставлялась самой последней. enum { IdInsert=0, IdUpdate, IdDelete, }; QPointer<Q3PopupMenu> popupForDoc = new Q3PopupMenu( this ); int id[ 3 ]; id[ IdInsert ] = popupForDoc->insertItem( tr( "New" ) ); id[ IdUpdate ] = popupForDoc->insertItem( tr( "Edit" ) ); id[ IdDelete ] = popupForDoc->insertItem( tr( "Delete" ) ); if ( !sqlCursor() || isReadOnly() || !numCols() ) { popupForDoc->setItemEnabled(id[ IdInsert ], false ); popupForDoc->setItemEnabled(id[ IdUpdate ], false ); popupForDoc->setItemEnabled(id[ IdDelete ], false ); } int r = popupForDoc->exec( e->globalPos() ); delete (Q3PopupMenu*) popupForDoc; if(r==id[IdInsert]) { beginInsert(); } else if(r==id[IdUpdate]) { keyPressEvent( new QKeyEvent( QEvent::KeyPress, Qt::Key_F2, 0, Qt::NoButton)); } else if(r==id[IdDelete]) { Q3DataTable::deleteCurrent(); } } if ( containerType() == "wJournal" ) { //id = currentRecord()->value(0).toLongLong(); enum { IdInsert=0, IdUpdate, IdDelete, IdView, IdRefresh }; QPointer<Q3PopupMenu> popup = new Q3PopupMenu( this ); int id[ 5 ]; id[ IdInsert ] = popup->insertItem( tr( "New" ) ); id[ IdUpdate ] = popup->insertItem( tr( "Edit" ) ); id[ IdDelete ] = popup->insertItem( tr( "Delete" ) ); id[ IdView ] = popup->insertItem( tr( "View" ) ); id[ IdRefresh ] = popup->insertItem( tr( "Refresh" ) ); int r = popup->exec( e->globalPos() ); delete (Q3PopupMenu*) popup; if(r==id[IdInsert]) emit(insertRequest()); else if(r==id[IdUpdate]) emit(updateRequest()); else if(r==id[IdDelete]) emit(deleteRequest()); else if(r==id[IdView]) emit(viewRequest()); if(r==id[IdRefresh]) { //recalculate(); refresh(); } } e->accept(); }