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

void FLFieldDB::searchValue (  )  [protected, slot]

Abre un dialogo para buscar en una tabla o en ficheros el valor del campo

Definition at line 488 of file FLFieldDB.cpp.

References FLManager::action(), actionName(), actionName_, FLFieldMetaData::alias(), FLFieldMetaData::associatedField(), FLFieldMetaData::associatedFieldFilterTo(), FLFormDB::cursor(), cursor_, FLFormSearchDB::exec(), FLTableMetaData::field(), fieldName_, FLRelationMetaData::foreignField(), FLRelationMetaData::foreignTable(), FLAction::form(), FLManager::formatValue(), FLInterface::getReceiver(), FLAction::masterProcess(), FLSqlCursor::metadata(), FLTableMetaData::name(), FLFieldMetaData::name(), FLSqlCursor::next(), refresh(), FLFieldMetaData::relationM1(), FLSqlCursor::select(), FLSqlCursor::setAction(), FLFormSearchDB::setMainWidget(), FLSqlCursor::setValueBuffer(), FLFieldMetaData::type(), updateValue(), and FLSqlCursor::valueBuffer().

{
  if (!cursor_)
      return;

  if (fieldName_.isEmpty ())
      return;

  FLTableMetaData *tMD = cursor_->metadata ();

  if (!tMD)
      return;

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

  if (!field)
    return;

  int type = field->type();

  if (type == QVariant::Pixmap)
      {

        PixmapView *p = new PixmapView;
        QFileDialog *fd = new QFileDialog (this);

        fd->setContentsPreviewEnabled (TRUE);
        fd->setContentsPreview (p, p);
        fd->setPreviewMode (QFileDialog::Contents);
        fd->setCaption (tr ("Elegir archivo"));
        fd->setFilter ("*.xpm");

        QString filename;

        if (fd->exec () == QDialog::Accepted)
            filename = fd->selectedFile ();

        if (filename.isEmpty ())
            {
              componentDB->clear ();
              updateValue ("");
              return;
            }

         QFile f(filename);
         QByteArray ba;
         if ( f.open(IO_ReadOnly) )
            ba = f.readAll();
         f.close();

         QPixmap pix;
         QString s(ba);

         if (s.isEmpty())
            {
              componentDB->clear ();
              updateValue ("");
              return;
            }

        if (!QPixmapCache::find (s.left(100), pix))
            {
              pix.loadFromData (ba);
              QPixmapCache::insert (s.left(100), pix);
            }

        if (!pix.isNull ())
            {
              componentDB->resize (pix.size ());
              componentDB->setPixmap (pix);
              componentDB->repaint ();
            }
        else
            componentDB->clear ();

        updateValue (s);
        return;
      }

  if (!field->relationM1())
    {
        qWarning("FLFieldDB : " + tr ("El campo de busqueda debe tener una relación M1"));
        return;
    }

  FLFormSearchDB *f = 0;
  FLSqlCursor *c = 0;
  FLFieldMetaData *fMD = field->associatedField ();
  FLAction *a;
  FLReceiver *r=0;
  
  if (fMD)
      {
      if (!fMD->relationM1())
        {
            qWarning("FLFieldDB : " + tr ("El campo asociado debe tener una relación M1"));
            return;
        }

        c = new FLSqlCursor (fMD->relationM1()->foreignTable());
        QString s = cursor_->valueBuffer (fMD->name ()).toString ();

        if (s.isEmpty ())
            {
              QMessageBox::warning (qApp->mainWidget (), tr ("Aviso"), tr ("Debe indicar un valor para ") + fMD->alias (), QMessageBox::Ok, 0, 0);
              return;
            }
        c->select ("upper(" + fMD->relationM1 ()->foreignField () + ")=" + FLManager::formatValue (fMD, QVariant (s.upper ())));
        c->next ();

         if (actionName().isEmpty())
            a = FLManager::action (c->metadata ()->name ());
         else
            a = FLManager::action (actionName());

         r = FLInterface::getReceiver (a->masterProcess ());
              f = new FLFormSearchDB (c, qApp->mainWidget(),r);
      }
  else
       {
         if (actionName().isEmpty())
            a = FLManager::action (field->relationM1()->foreignTable());
         else
            a = FLManager::action (actionName_);

         r = FLInterface::getReceiver (a->masterProcess ());
         f = new FLFormSearchDB (field->relationM1()->foreignTable(), qApp->mainWidget(),r);
       }
  
  f->cursor()->setAction(a);

  QWidget *w = 0;

  if (r)
    w = QWidgetFactory::create (a->form (), r, f);
  else
    w = QWidgetFactory::create (a->form (), f, f);     

  if (fMD && w)
      {
        QObject *obj = w->child ("tableDBRecords");

        if (obj)
            {
              ((FLTableDB *) obj)->setTableName ((const char *)field->relationM1()->foreignTable());
              ((FLTableDB *) obj)->setFieldRelation ((const char *)field->associatedFieldFilterTo ());
              ((FLTableDB *) obj)->setForeignField ((const char *)fMD->relationM1 ()->foreignField ());
            }
      }

  if (!w)
      {
        qWarning (tr ("FLFieldDB : No se ha podido cargar ") + a->form () + tr ("'. Ejecute 'make install' despues de compilar la aplicación."));
        return;
      }

  f->setMainWidget (w);
  f->setFocus();
  f->exec ();

  if (((FLFormSearchDB *) f)->accepted ())
      {
        cursor_->setValueBuffer (fieldName_, f->cursor ()->valueBuffer (field->relationM1()->foreignField()));
        refresh ();
      }
    
  if (f)
      f->close ();

  if (c)
      delete c;
}


Generated by  Doxygen 1.6.0   Back to index