Logo Search packages:      
Sourcecode: facturalux version File versions  Download package

void FLSqlCursor::refreshBuffer (  )  [slot]

Refresca el buffer segun el modo de acceso establecido.

Lleva informacion del cursor al buffer para editar o navegar, o prepara el buffer para insertar o borrar.

Definition at line 108 of file FLSqlCursor.cpp.

References action_, BROWSE, buffer_, FLReceiver::calculateCounter(), cursorRelation, FLFieldMetaData::defaultValue(), DEL, EDIT, FLRelationMetaData::field(), FLTableMetaData::fieldList(), FLRelationMetaData::foreignField(), FLInterface::getReceiver(), INSERT, FLFieldMetaData::isCounter(), metadata_, modeAccess_, FLTableMetaData::name(), FLFieldMetaData::name(), newBuffer(), FLAction::process(), relation, FLFieldMetaData::Serial, FLReceiver::setCursor(), setValueBuffer(), FLFieldMetaData::type(), updateBufferCopy(), and valueBuffer().

Referenced by FLFormRecordDB::acceptContinue(), first(), FLFormRecordDB::init(), last(), next(), openFormInMode(), prev(), and seek().

{
  if (!metadata_)
      return;

  if (!isValid () && modeAccess_ != INSERT)
      {
        buffer_ = 0;
        emit newBuffer ();

        return;
      }
 
  switch (modeAccess_)
      {
      case INSERT:
        {
            buffer_ = primeInsert ();
            
            FLTableMetaData::FLFieldMetaDataList * fieldList = metadata_->fieldList ();
            FLFieldMetaData *field;

            for (unsigned int i = 0; i < fieldList->count (); i++)
              {
                  field = fieldList->at (i);

                  if ( field->defaultValue().isValid() )
                        {
                        if ( (field->type() == QVariant::Bool) || (field->type()==FLFieldMetaData::Unlock))
                        {
                                    if ( field->defaultValue().toString()=="true" )
                                    buffer_->setValue(field->name(), QVariant(true));
                                    else
                                    buffer_->setValue(field->name(), QVariant(false));
                        }
                        else
                        buffer_->setValue(field->name(), field->defaultValue());
                        }
          
                  if (field->type () == FLFieldMetaData::Serial)
                    {
                        QString seq = metadata_->name () + "_" + field->name () + "_seq";
                        QSqlQuery query ("SELECT nextval('" + seq + "');");

                        query.next ();
                        buffer_->setValue (field->name (), query.value (0));
                    }
                  //Código para rellenar el campo contador, por Andrés Otón Urbano
                  if (field->isCounter ())
                    {
                        FLReceiver *r = FLInterface::getReceiver (action_->process ());
                        QVariant siguiente;
                        if (r)
                          {
                              r->setCursor (this);
                              siguiente = r->calculateCounter (field->name ());
                          }
                        if (siguiente.isValid ())
                          {
                              buffer_->setValue (field->name (), siguiente);
                          }
                    }
              }

      if (cursorRelation && relation)
              setValueBuffer (relation->field (), cursorRelation->valueBuffer (relation->foreignField ()).toString ());

            updateBufferCopy();
            emit newBuffer ();
        }
        break;

      case EDIT:
            {
                  buffer_ = primeUpdate ();

                  FLTableMetaData::FLFieldMetaDataList * fieldList = metadata_->fieldList ();
                  FLFieldMetaData *field;

                  if (fieldList)
                        {
                              for (unsigned int i = 0; i < fieldList->count (); i++)
                                    {
                                          field = fieldList->at (i);
                                          if (field->type () == FLFieldMetaData::Unlock)
                                          if (!valueBuffer (field->name ()).toBool ())
                                                {
                                                      modeAccess_ = BROWSE;
                                                      refreshBuffer();
                                                      return;
                                                }
                                    }
                        }

                  updateBufferCopy();
                  emit newBuffer ();
            }

        break;

      case DEL:
        buffer_ = primeDelete ();
        break;

      case BROWSE:
        buffer_ = editBuffer (true);
        emit newBuffer ();

        break;
      }
}


Generated by  Doxygen 1.6.0   Back to index