Пример #1
0
/*!
 *\ru
 *	Слот обрабатывает ситуацию смены/установки идентификатора документа, запоминая новое значение.
 *	Для смены фильта следует вызывать слот newFilter.
 *	\param id - идентификатор документа, который следует запомнить.
 *\_ru
 */
void
wDBTable::newDataId(const qulonglong id)
{
	if(containerType() == "wDocument")
	{
		setId(id);
	}
	if(containerType() == "wCatalogue")
	{
		cat_group_id = id;
	}
}
Пример #2
0
/*!
 *	\~english
 *	Key press handler.
 *	\~russian
 *	Обрабатывает события при нажатии кнопок клавиатуры.
 *	\~
 */
void
wDBTable::keyPressEvent ( QKeyEvent *e )
{
	qulonglong id;

	aWidget *container = NULL;
	if ( searchMode == FALSE && e->text().at( 0 ).isPrint() )
	{
		searchOpen( e->text() );
	}
	else
	{
		searchClose();
	}

	if(containerType() =="wJournal")
	{
		e->ignore();
	}
	if(containerType() =="wCatalogue")
	{
		switch ( e->key() )
		{
		case Qt::Key_Escape:
			e->ignore();
			break;
		case Qt::Key_Return:
			if(currentRecord())
			{
				id = currentRecord()->value(0).toLongLong();
				if ( e->state() == Qt::ShiftModifier )
				{
					//printf("Shift+Return pressed %Ld\n", id);
					EditElement();
				} else
				{
					//printf("Return pressed %Ld\n", id );
					emit( selected( id ) );
				}
				e->accept();
			}
			else
			{
				aLog::print(aLog::Info, tr("wDBTable: current record not setted"));
			}
			break;
		default:
			e->ignore();
			break;
		}
	}
	Q3DataTable::keyPressEvent( e );
}
Пример #3
0
void
wDBTable::doubleClickEventHandler(int /*rol*/, int /*col*/, int /*button*/, const QPoint &/*mousePos*/)
{
	if(containerType() =="wCatalogue" || containerType() == "wJournal")
	{
		if(currentRecord())
		{
			qulonglong id = currentRecord()->value(0).toLongLong();
			emit( selected( id ) );
		}
	}

}
Пример #4
0
/*!
 *\ru
 *	Устанавливает значение системного поля idd во вновь добавляемую запись табличной части документа.
 *\_ru
 */
void
wDBTable::lineInsert(QSqlRecord* rec){

	if (containerType() == "wDocument")
	{
		if(rec->contains("idd")) rec->setValue("idd",QVariant(doc_id));
		if(rec->contains("ln")) rec->setValue("ln",numRows()-1);
	}
	if(containerType() == "wCatalogue")
	{
		if(rec->contains("idg")) rec->setValue("idg",QVariant(cat_group_id));
	}
}
Пример #5
0
Operator Container::firstOperator() const
{
	Operator ret(Object::onone);
	bool found=false;
	for(int i=0; i<m_params.count() && !found; i++) {
		if(m_params[i]->type()==Object::oper) {
			ret = m_params[i];
			found = true;
		} else if(i==0 && containerType()==apply && m_params[i]->type()==Object::variable) {
			ret = function;
			found=true;
		}
	}
	
	return ret;
}
Пример #6
0
QString Container::toString() const
{
	QStringList ret;
	bool func=false;
	
	Operator *op=0;
	for(int i=0; i<m_params.count(); i++) {
		if(m_params[i]==0) {
			qDebug() << "kkk";
			return "<<kk>>";
		}
		
		if(m_params[i]->type() == Object::oper)
			op = (Operator*) m_params[i];
		else if(m_params[i]->type() == Object::variable) {
			Ci *b = (Ci*) m_params[i];
			if(b->isFunction())
				func=true;
			ret << b->toString();
		} else if(m_params[i]->type() == Object::container) {
			Container *c = (Container*) m_params[i];
			QString s = c->toString();
			Operator child_op = c->firstOperator();
			if(op!=0 && op->weight()>child_op.weight() && child_op.nparams()!=1)
				s=QString("(%1)").arg(s);
			
			if(c->containerType() == Object::bvar) {
				Container *ul = ulimit(), *dl = dlimit();
				if(ul!=0 || dl!=0) {
					if(dl!=0)
						s += dl->toString();
					s += "..";
					if(ul!=0)
						s += ul->toString();
				}
			}
			
			if(c->containerType()!=Object::uplimit && c->containerType()!=Object::downlimit)
				ret << s;
		} else 
			ret << m_params[i]->toString();
	}
	
	QString toret;
	switch(containerType()) {
		case Object::declare:
			toret += ret.join(":=");
			break;
		case Object::lambda:
			toret += ret.join("");
			break;
		case Object::math:
			toret += ret.join("; ");
			break;
		case Object::apply:
			if(func){
				QString n = ret.takeFirst();
				toret += QString("%1(%2)").arg(n).arg(ret.join(", "));
			} else if(op==0)
				toret += ret.join(" ");
			else switch(op->operatorType()) {
				case Object::plus:
					toret += ret.join("+");
					break;
				case Object::times:
					toret += ret.join("*");
					break;
				case Object::divide:
					toret += ret.join("/");
					break;
				case Object::minus:
					if(ret.count()==1)
						toret += "-"+ret[0];
					else
						toret += ret.join("-");
					break;
				case Object::power:
					toret += ret.join("^");
					break;
				default:
					toret += QString("%1(%2)").arg(op->toString()).arg(ret.join(", "));
					break;
			}
			break;
		case Object::uplimit: //x->(n1..n2) is put at the same time
		case Object::downlimit:
			break;
		case Object::bvar:
			toret += ret.join("->")+"->";
			break;
		default:
			toret += ret.join(" ?? ");
			break;
	}
	return toret;
}
Пример #7
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"));
}
Пример #8
0
/*!
 *	\~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();

}