From: Dmintriy L. Kruglikov Date: Mon, 30 Jun 2008 16:09:04 +0000 (+0300) Subject: Validator for String fields. Red:Yellow:Green color coding. X-Git-Url: https://gitweb.ananas.su/?a=commitdiff_plain;h=b40248f2e5b54d09a3fe36c0288668c7b8f5ece3;p=projects%2Fananas-labs.git Validator for String fields. Red:Yellow:Green color coding. --- diff --git a/src/designer/deditfield.ui b/src/designer/deditfield.ui index 5fe96fe..9ec82d0 100644 --- a/src/designer/deditfield.ui +++ b/src/designer/deditfield.ui @@ -8,8 +8,8 @@ 0 0 - 478 - 475 + 488 + 490 @@ -724,7 +724,7 @@ - VdcheckBox + efVd Vd @@ -844,10 +844,10 @@ textLabel3 - <font size="-1"><u>Example:</u> RegEx <b><i>[A-C]\d{5}[W-Z]</b></i> for string <i><b>A12345Z</b></i></font> + <u>Example:</u> RegExp <b><i>[A-C]\d{5}[W-Z]</b></i> for string <i><b>A12345Z</b></i> - - WordBreak|AlignCenter + + AutoText @@ -1048,10 +1048,10 @@ tNotBound_stateChanged(int) - VdcheckBox + efVd stateChanged(int) dEditField - VdcheckBox_stateChanged(int) + efVd_stateChanged(int) VdRegEx @@ -1090,7 +1090,7 @@ tNotBound_stateChanged( int ) aUsersList_clicked( QListViewItem * ) setExample() - VdcheckBox_stateChanged( int ) + efVd_stateChanged( int ) VdRegEx_textChanged( const QString & ) Testline_textChanged( const QString & ) diff --git a/src/designer/deditfield.ui.h b/src/designer/deditfield.ui.h index 134edac..75f104a 100644 --- a/src/designer/deditfield.ui.h +++ b/src/designer/deditfield.ui.h @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include "alog.h" #include "acfg.h" #include "acfgrc.h" @@ -73,7 +73,7 @@ void dEditField::init() eType->clear(); otypes.append(" "); lzcheckBox->setText(tr("Add leading zeros")); - VdcheckBox->setText(tr("Validate")); + efVd->setText(tr("Validate")); eType->insertItem(tr("Unknown"), 0); } @@ -124,6 +124,11 @@ void dEditField::setData( aListViewItem *o ) else efPlus->setChecked( false ); if( md->attr( obj, mda_nz ) == "1" ) efNZ->setChecked( true ); else efNZ->setChecked( false ); + if( md->attr( obj, mda_vd ) == "1" ) efVd->setChecked( true ); + else efVd->setChecked( false ); + + VdRegEx->setText( md->attr( obj, mda_validator ) ); + efSum->setChecked(md->attr( obj, mda_sum ) == "1"); QStringList tlist; @@ -291,6 +296,9 @@ void dEditField::updateMD() else md->setAttr( obj, mda_plus, "0" ); if( efNZ->isChecked() ) md->setAttr( obj, mda_nz, "1" ); else md->setAttr( obj, mda_nz, "0" ); + if( efVd->isChecked() ) md->setAttr( obj, mda_vd, "1" ); + else md->setAttr( obj, mda_vd, "0" ); + if (VdRegEx->text() )md->setAttr( obj, mda_validator, VdRegEx->text().stripWhiteSpace() ); if( efSum->isChecked() ) md->setAttr( obj, mda_sum, "1" ); else @@ -327,7 +335,7 @@ void dEditField::typeSelect( int idx ) tSepTriads->show(); comboBox2->setEnabled(false); comboBox2->hide(); - VdcheckBox->show(); + efVd->show(); ValidateGroupBox->show(); DateMask->hide(); saldoTextLabel->hide(); @@ -359,7 +367,7 @@ void dEditField::typeSelect( int idx ) lzcheckBox->hide(); tNotBound->show(); DateMask->show(); - VdcheckBox->show(); + efVd->show(); ValidateGroupBox->show(); efSum->setChecked(false); comboBox2->setEnabled(false); @@ -392,7 +400,7 @@ void dEditField::typeSelect( int idx ) efSum->hide(); tNotBound->hide(); tSepTriads->hide(); - VdcheckBox->hide(); + efVd->hide(); ValidateGroupBox->hide(); // Num_Label->hide(); @@ -422,7 +430,7 @@ void dEditField::typeSelect( int idx ) efSum->hide(); tNotBound->hide(); tSepTriads->hide(); - VdcheckBox->hide(); + efVd->hide(); DateMask->hide(); ValidateGroupBox->hide(); // @@ -508,9 +516,9 @@ void dEditField::setExample() -void dEditField::VdcheckBox_stateChanged( int ) +void dEditField::efVd_stateChanged( int ) { - if (VdcheckBox->isChecked() ) + if (efVd->isChecked() ) { ValidateGroupBox->show(); } else { @@ -546,6 +554,6 @@ void dEditField::Testline_textChanged( const QString & ) if(v.validate(s, pos ) == QValidator::Acceptable) { pal.setColor(QColorGroup::Highlight, Qt::green); - Testline->setPalette(pal); + Testline->setPalette(pal); } } diff --git a/src/lib/acfg.h b/src/lib/acfg.h index f3ae1c1..67e51b9 100644 --- a/src/lib/acfg.h +++ b/src/lib/acfg.h @@ -210,6 +210,9 @@ Metadata attributes. #define mda_format "format" #define mda_stdf "stdf" #define mda_rights "rights" +#define mda_vd "vd" +#define mda_validator "validator" + /*! Actions types diff --git a/src/plugins/wdbfield.cpp b/src/plugins/wdbfield.cpp index a2812a1..24a7929 100644 --- a/src/plugins/wdbfield.cpp +++ b/src/plugins/wdbfield.cpp @@ -324,6 +324,12 @@ wDBField::initObject(aDatabase *adb ) }else{ wField::SetNonZero(false); } + if ( md->attr(o,mda_vd) == "1" && md->attr(o,mda_validator) != "") + { + wField::SetValidator( md->attr(o,mda_validator) ); + } + + //aObject* obj = new aObject(o,adb); //tableInsert( aDatabase::tableDbName( *md, o ), o ); // debug_message("init dbfield \n"); diff --git a/src/plugins/wfield.cpp b/src/plugins/wfield.cpp index 89642d8..4c4a19d 100644 --- a/src/plugins/wfield.cpp +++ b/src/plugins/wfield.cpp @@ -200,14 +200,12 @@ wField::widgetInit() { // set default validator for string lineEdit->setMaxLength(20); - } - else - { + }else{ // set validator for string lineEdit->setMaxLength(n1); } connect( lineEdit, SIGNAL( textChanged( const QString & ) ), - this, SLOT( setValue( const QString & ) ) ); + this, SLOT( setValue( const QString & ) ) ); connect( lineEdit, SIGNAL( lostFocus() ), this, SLOT( focusOutEvent()) ); setFocusProxy(lineEdit); @@ -357,14 +355,58 @@ wField::createEditor( QWidget *parent ) void wField::setValue(const QDate& newDate) { -//CHECK_POINT + //CHECK_POINT vValue = newDate.toString(Qt::ISODate); - vValue+="T00:00:00"; //for correct converting to date-time + vValue+="T00:00:00";//for correct converting to date-time emit valueChanged(vValue); emit valueChanged(QVariant(vValue)); } +/*! + * \en Validate value and paint LineEdit frame. \_en + * \ru Проверяет значение и рисует рамку поля ввода.\_ru + */ +void +wField::Validate(const QString &test) +{ + int p = 0; + QString s = test; + QPalette pal = lineEdit->palette(); + switch ( v->validate(s, p) ) + { + case QValidator::Invalid: + pal.setColor(QColorGroup::Highlight, Qt::red); + lineEdit->setPalette(pal); + emit inputInvalid(); + break; + case QValidator::Intermediate: + pal.setColor(QColorGroup::Highlight, Qt::yellow); + lineEdit->setPalette(pal); + setValue( test ); + break; + case QValidator::Acceptable: + pal.setColor(QColorGroup::Highlight, Qt::green); + lineEdit->setPalette(pal); + setValue( test ); + break; + } +} + +/*! + * \en Set validaror and connect LineEdit to Validator. + * \_en + * \ru Устанавливает валидатор и соединяет LineEdit с Validator. + * \_ru + * \param QString Validator - \en RegExp for QRegExpValidator \_en \ru значение RegExp для установки QRegExpValidator\_ru + */ +void +wField::SetValidator(QString Validator) +{ + QRegExp rx( Validator ); + v = new QRegExpValidator( rx, 0 ); + connect( lineEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( Validate( const QString & ) ) ); +} /*! * \en Sets value. \_en @@ -426,7 +468,6 @@ wField::setValue(const QString &newvalue) } - /*! * \en Gets value. \_en * \ru Возвращает значение виджета. \_ru @@ -440,7 +481,6 @@ wField::value() const } - /*! * \en Gets text value. \_en * \ru Возвращает текстовое значение виджета. \_ru @@ -537,9 +577,6 @@ wField::fieldSelect() } } - - - /*! * \en Handler signal lostFocus. \_en * \ru Обработчик сигнала lostFocus. \ru diff --git a/src/plugins/wfield.h b/src/plugins/wfield.h index edf6b96..c0dffa3 100644 --- a/src/plugins/wfield.h +++ b/src/plugins/wfield.h @@ -42,6 +42,7 @@ #include "adatabase.h" #include "ananas.h" #include "acalendar.h" +#include class wCatButton; class wCheckBox; @@ -80,6 +81,7 @@ public: signals: void valueChanged( const QString & ); void valueChanged( const QVariant & ); + void inputInvalid(); void lostFocus(); public slots: @@ -88,6 +90,7 @@ public slots: virtual QString value() const; QString text() const; virtual void setValue( const QString &fn ); + virtual void Validate( const QString &fn ); void setValue( const QDate& d); virtual QString textValue() {return text();}; void setFieldType( QString n ); @@ -101,6 +104,7 @@ public slots: void selectAll(); virtual void SetReadOnly(bool); virtual void SetNonZero(bool); + virtual void SetValidator(QString Validator); private slots: void on_selected( Q_ULLONG uid ); @@ -113,6 +117,7 @@ protected: QLabel *nzLabel; wCatButton *objButton; wCheckBox *checkBox; + QValidator *v; tEditorType vEditorType; QString vFieldType; QString vValue;