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

void FLFieldDB::refresh ( QString  fN = QString::null  )  [slot]

Refresca el contenido del campo con los valores del cursor de la tabla origen.

Si se indica el nombre de un campo sólo "refresca" si el campo indicado coincide con la propiedad fieldRelation, tomando como filtro el valor del campo fieldRelation de la tabla relacionada. Si no se indica nigún nombre de campo el refresco es llevado a cabo siempre.

Parameters:
fN Nombre de un campo

Definition at line 692 of file FLFieldDB.cpp.

References FLSqlCursor::BROWSE, cursor_, cursorAux, FLSqlCursor::EDIT, editor_, FLTableMetaData::field(), FLSqlCursor::fieldDisabled(), fieldName_, fieldRelation_, FLRelationMetaData::foreignField(), foreignField_, FLRelationMetaData::foreignTable(), FLManager::formatValue(), FLFieldMetaData::isPrimaryKey(), FLSqlCursor::metadata(), FLSqlCursor::modeAccess(), FLFieldMetaData::partDecimal(), refreshOne, FLFieldMetaData::relationM1(), FLFieldMetaData::Serial, FLFieldMetaData::type(), FLSqlCursor::valueBuffer(), and FLFieldMetaData::visible().

Referenced by initCursor(), searchValue(), and ~FLFieldDB().

{
  if (!cursor_)
      return;

  FLTableMetaData * tMD = cursor_->metadata();

  if (!tMD)
    return;

  QVariant v;

  if (fN.isEmpty ())
      v = cursor_->valueBuffer (fieldName_);
  else
      {
        if (!cursorAux && fN.lower () == fieldRelation_.lower () && refreshOne)
            {
              FLFieldMetaData * field = tMD->field(fieldRelation_);

          if (!field)
            return;

          if (!field->relationM1())
            {
                qWarning ("FLFieldDB : " + tr ("El campo de la relación debe estar relacionado en M1"));
                return;
            }
          FLSqlCursor c (field->relationM1()->foreignTable());
              QString s = cursor_->valueBuffer (fieldRelation_).toString ();

              c.select ("upper(" + field->relationM1()->foreignField() + ")=" +
                              FLManager::formatValue (field, QVariant (s.upper ())));
              if (c.next ())
                  v = c.valueBuffer (foreignField_);
              else
                  return;
            }
        else
            {
              if (!cursorAux && fN.lower () == fieldRelation_.lower ())
                  refreshOne = true;
              return;
            }
      }

  int modeAccess = cursor_->modeAccess ();

  FLFieldMetaData * field = tMD->field(fieldName_);

  if (!field)
    return;

  int type = field->type();
  int partDecimal = field->partDecimal();

  if (!field->visible())
        close();

  setDisabled (cursor_->fieldDisabled (fieldName_)
                    || (modeAccess == FLSqlCursor::EDIT && field->isPrimaryKey() ));

  switch (type)
      {
      case QVariant::Double:
        if (modeAccess == FLSqlCursor::BROWSE)
            setDisabled (true);

        if (!editor_)
            return;

        if (v.isValid ())
            {
              QString s;

              s.setNum (v.toDouble (), 'f', partDecimal);
              ((FLLineEdit *) editor_)->setText (s);
            }
        else
            ((FLLineEdit *) editor_)->setText (QString::null);
        break;

      case QVariant::String:
        if (modeAccess == FLSqlCursor::BROWSE)
            setDisabled (true);

        if (!editor_)
            return;

        if (v.isValid ())
            ((FLLineEdit *) editor_)->setText (v.toString ());
        else
            ((FLLineEdit *) editor_)->setText (QString::null);
        break;

      case QVariant::UInt:
      case QVariant::Int:
      case FLFieldMetaData::Serial:
        if (modeAccess == FLSqlCursor::BROWSE)
            setDisabled (true);

        if (!editor_)
            return;

       if (v.isValid ())
            ((QSpinBox *) editor_)->setValue (v.toInt ());
       else
            ((QSpinBox *) editor_)->setValue (0);
        break;

      case QVariant::Pixmap:
        {
            QCString cs;

            if (v.isValid ())
              cs = v.toCString ();

            if (cs.isEmpty ())
              {
                  componentDB->clear ();
                  return;
              }

            QPixmap pix;

            if (!QPixmapCache::find (cs.left(100), pix))
              {
                  pix.loadFromData (cs);
                  QPixmapCache::insert (cs.left(100), pix);
              }
            if (!pix.isNull ())
              {
                  componentDB->resize (pix.size ());
                  componentDB->setPixmap (pix);
                  componentDB->repaint ();
              }
            else
              componentDB->clear ();
        }

        if (modeAccess == FLSqlCursor::BROWSE)
            pushButtonDB->setDisabled (true);
        break;

      case QVariant::Date:
        if (!editor_)
            {
              qWarning ("FLFieldDB : No se ha podido crear el editor para el campo " + fieldName_);
              return;
            }
        if (modeAccess == FLSqlCursor::BROWSE)
            setDisabled (true);

        {
            QDate d = v.toDate ();

            if (!d.isValid ())
              d = QDate::currentDate ();
            ((QDateEdit *) editor_)->setDate (d);
        }
        break;

      case QVariant::Time:
        if (!editor_)
            return;

        if (modeAccess == FLSqlCursor::BROWSE)
            setDisabled (true);

        {
            QTime t = v.toTime ();

            if (!t.isValid ())
              t = QTime::currentTime ();
            ((QTimeEdit *) editor_)->setTime (t);
        }
        break;

      case QVariant::StringList:
        if (modeAccess == FLSqlCursor::BROWSE)
            setDisabled (true);

        if (!editor_)
            return;

        ((QTextEdit *) editor_)->setText (v.toString ());
        break;

      case QVariant::Bool:
        if (!editor_)
            return;

        if (modeAccess == FLSqlCursor::BROWSE)
            setDisabled (true);

        ((QCheckBox *) editor_)->setChecked (v.toBool ());
        break;
      }
}


Generated by  Doxygen 1.6.0   Back to index