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

void FLFieldDB::initEditor (  )  [slot]

Crea e inicia el editor apropiado para editar el tipo de datos contenido en el campo (p.e: si el campoe contiene una fecha crea e inicia un QDataEdit)

Definition at line 253 of file FLFieldDB.cpp.

References FLFieldMetaData::alias(), cursor_, editor_, FLTableMetaData::field(), fieldName_, FLTableMetaData::fieldNameToAlias(), FLRelationMetaData::foreignTable(), FLFieldMetaData::length(), FLSqlCursor::metadata(), FLFieldMetaData::partDecimal(), FLFieldMetaData::partInteger(), FLFieldMetaData::relationM1(), FLFieldMetaData::Serial, FLFieldMetaData::type(), and updateValue().

Referenced by setFieldName(), setFieldRelation(), setForeignField(), and setTableName().

{
  if (!cursor_)
      return;

  if (editor_)
      return;

  FLTableMetaData *tMD = cursor_->metadata ();

  if (!tMD)
      return;

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

  if (!field)
    return;

  int type = field->type();
  int len = field->length();
  int partInteger = field->partInteger();
  int partDecimal = field->partDecimal();

  QString rt;

  if (field->relationM1())
    rt = field->relationM1()->foreignTable();
  bool hasPushButtonDB = false;

  if (rt.isEmpty () && type != QVariant::Pixmap)
      {
        pushButtonDB->close ();
        if (type != QVariant::Bool)
            textLabelDB->setText (field->alias());
        textLabelDB->setFont (qApp->font ());
      }
  else
      {
        textLabelDB->close ();
        pushButtonDB->setText (field->alias());
        pushButtonDB->setFont (qApp->font ());
        hasPushButtonDB = true;
      }

  switch (type)
      {
      case QVariant::Double:
      case QVariant::String:
        componentDB->close ();
        editor_ = new FLLineEdit (this, "editor");

        ((FLLineEdit *) editor_)->setFrameShape (QLineEdit::Box);
        ((FLLineEdit *) editor_)->setFrameShadow (QLineEdit::Plain);
        ((FLLineEdit *) editor_)->setFont (qApp->font ());
        ((FLLineEdit *) editor_)->setLineWidth (1);

        if (type == QVariant::Double)
            {
              ((FLLineEdit *) editor_)->setValidator (new FLDoubleValidator (0, pow (10, partInteger) - 1, partDecimal, editor_));
              ((FLLineEdit *) editor_)->setAlignment (Qt::AlignRight);
            }
        else
            ((FLLineEdit *) editor_)->setMaxLength (len);

        editor_->setSizePolicy (QSizePolicy ((QSizePolicy::SizeType) 7, (QSizePolicy::SizeType) 0, editor_->sizePolicy ().hasHeightForWidth ()));
        FLWidgetFieldDBLayout->addWidget (editor_);

        connect (editor_, SIGNAL (textChanged (const QString &)), this, SLOT (updateValue (const QString &)));
        if (hasPushButtonDB)
            connect ((FLLineEdit *) editor_, SIGNAL (key_F2_Pressed ()), pushButtonDB, SLOT (animateClick ()));
        break;

      case QVariant::UInt:
      case QVariant::Int:
      case FLFieldMetaData::Serial:
        componentDB->close ();
        editor_ = new QSpinBox (this, "editor");

        ((QSpinBox *) editor_)->setFont (qApp->font ());

        editor_->setSizePolicy (QSizePolicy ((QSizePolicy::SizeType) 7, (QSizePolicy::SizeType) 0, editor_->sizePolicy ().hasHeightForWidth ()));
        FLWidgetFieldDBLayout->addWidget (editor_);

        connect (editor_, SIGNAL (valueChanged (const QString &)), this, SLOT (updateValue (const QString &)));
        break;

      case QVariant::Pixmap:
        break;

      case QVariant::Date:
        componentDB->close ();
        editor_ = new QDateEdit (this, "editor");

        ((QDateEdit *) editor_)->setFont (qApp->font ());

        editor_->setSizePolicy (QSizePolicy ((QSizePolicy::SizeType) 7, (QSizePolicy::SizeType) 0, editor_->sizePolicy ().hasHeightForWidth ()));
        FLWidgetFieldDBLayout->addWidget (editor_);

        ((QDateEdit *) editor_)->setOrder (QDateEdit::DMY);

        connect (editor_, SIGNAL (valueChanged (const QDate &)), this, SLOT (updateValue (const QDate &)));
        {
            QDate d;

            ((QDateEdit *) editor_)->setDate (d.currentDate ());
        }
     break;

      case QVariant::Time:
    {
        componentDB->close ();
     QTime timeNow = QTime::currentTime();
        
        editor_ = new QTimeEdit (this, "editor");

        ((QTimeEdit *) editor_)->setFont (qApp->font ());
          
        editor_->setSizePolicy (QSizePolicy ((QSizePolicy::SizeType) 7, (QSizePolicy::SizeType) 0, editor_->sizePolicy ().hasHeightForWidth ()));
        FLWidgetFieldDBLayout->addWidget (editor_);

        connect (editor_, SIGNAL (valueChanged (const QTime &)), this, SLOT (updateValue (const QTime &)));

      ((QTimeEdit *) editor_)->setTime( timeNow );
     ((QTimeEdit *) editor_)->setRange( timeNow, timeNow.addSecs( 60 * 60 ) );
    }
        break;

      case QVariant::StringList:
        componentDB->close ();
        editor_ = new QTextEdit (this, "editor");

        ((QTextEdit *) editor_)->setFrameShape (QLineEdit::Box);
        ((QTextEdit *) editor_)->setFrameShadow (QLineEdit::Plain);
        ((QTextEdit *) editor_)->setFont (qApp->font ());
        ((QTextEdit *) editor_)->setLineWidth (1);

        editor_->setSizePolicy (QSizePolicy ((QSizePolicy::SizeType) 7, (QSizePolicy::SizeType) 0, editor_->sizePolicy ().hasHeightForWidth ()));
        FLWidgetFieldDBLayout->addWidget (editor_);

        connect (editor_, SIGNAL (textChanged ()), this, SLOT (updateValue ()));
        break;

      case QVariant::Bool:
        componentDB->close ();
        textLabelDB->close ();
        editor_ = new QCheckBox (this, "editor");

        ((QCheckBox *) editor_)->setText (tMD->fieldNameToAlias (fieldName_));
        ((QCheckBox *) editor_)->setFont (qApp->font ());

        editor_->setSizePolicy (QSizePolicy ((QSizePolicy::SizeType) 7, (QSizePolicy::SizeType) 0, editor_->sizePolicy ().hasHeightForWidth ()));
        FLWidgetFieldDBLayout->addWidget (editor_);

        connect (editor_, SIGNAL (toggled (bool)), this, SLOT (updateValue (bool)));
        break;
      }

  QPalette pal;
  QColorGroup cg;

  cg.setColor (QColorGroup::Foreground, black);
  cg.setColor (QColorGroup::Button, QColor (220, 220, 220));
  cg.setColor (QColorGroup::Light, white);
  cg.setColor (QColorGroup::Midlight, QColor (242, 242, 242));
  cg.setColor (QColorGroup::Dark, QColor (78, 78, 78));
  cg.setColor (QColorGroup::Mid, QColor (183, 183, 183));
  cg.setColor (QColorGroup::Text, black);
  cg.setColor (QColorGroup::BrightText, white);
  cg.setColor (QColorGroup::ButtonText, black);
  cg.setColor (QColorGroup::Base, white);
  cg.setColor (QColorGroup::Background, QColor (220, 220, 220));
  cg.setColor (QColorGroup::Shadow, black);
  cg.setColor (QColorGroup::Highlight, QColor (84, 112, 152));
  cg.setColor (QColorGroup::HighlightedText, white);
  cg.setColor (QColorGroup::Link, QColor (0, 0, 255));
  cg.setColor (QColorGroup::LinkVisited, QColor (255, 0, 255));
  pal.setActive (cg);
  cg.setColor (QColorGroup::Foreground, black);
  cg.setColor (QColorGroup::Button, QColor (220, 220, 220));
  cg.setColor (QColorGroup::Light, white);
  cg.setColor (QColorGroup::Midlight, QColor (242, 242, 242));
  cg.setColor (QColorGroup::Dark, QColor (78, 78, 78));
  cg.setColor (QColorGroup::Mid, QColor (183, 183, 183));
  cg.setColor (QColorGroup::Text, black);
  cg.setColor (QColorGroup::BrightText, white);
  cg.setColor (QColorGroup::ButtonText, black);
  cg.setColor (QColorGroup::Base, white);
  cg.setColor (QColorGroup::Background, QColor (220, 220, 220));
  cg.setColor (QColorGroup::Shadow, black);
  cg.setColor (QColorGroup::Highlight, QColor (84, 112, 152));
  cg.setColor (QColorGroup::HighlightedText, white);
  cg.setColor (QColorGroup::Link, QColor (0, 0, 255));
  cg.setColor (QColorGroup::LinkVisited, QColor (255, 0, 255));
  pal.setInactive (cg);
  cg.setColor (QColorGroup::Foreground, QColor (128, 128, 128));
  cg.setColor (QColorGroup::Button, QColor (220, 220, 220));
  cg.setColor (QColorGroup::Light, white);
  cg.setColor (QColorGroup::Midlight, QColor (253, 253, 253));
  cg.setColor (QColorGroup::Dark, QColor (110, 110, 110));
  cg.setColor (QColorGroup::Mid, QColor (146, 146, 146));
  cg.setColor (QColorGroup::Text, black);
  cg.setColor (QColorGroup::BrightText, white);
  cg.setColor (QColorGroup::ButtonText, black);
  cg.setColor (QColorGroup::Base, white);
  cg.setColor (QColorGroup::Background, QColor (220, 220, 220));
  cg.setColor (QColorGroup::Shadow, black);
  cg.setColor (QColorGroup::Highlight, QColor (0, 0, 128));
  cg.setColor (QColorGroup::HighlightedText, white);
  cg.setColor (QColorGroup::Link, QColor (0, 0, 255));
  cg.setColor (QColorGroup::LinkVisited, QColor (255, 0, 255));
  pal.setDisabled (cg);

  if (editor_)
      {
        editor_->setPalette (pal);
        editor_->setFocusPolicy (QWidget::StrongFocus);
        setFocusProxy (editor_);
        if (hasPushButtonDB)
            pushButtonDB->setFocusPolicy (QWidget::NoFocus);
      }
  else
      {
        componentDB->setPalette (pal);
        componentDB->setFocusPolicy (QWidget::NoFocus);
        if (hasPushButtonDB)
            setFocusProxy (pushButtonDB);
      }

  if (hasPushButtonDB)
      pushButtonDB->setPalette (pal);
  else
      textLabelDB->setPalette (pal);
}


Generated by  Doxygen 1.6.0   Back to index