From: Dmintriy L. Kruglikov Date: Wed, 2 Jul 2008 09:50:19 +0000 (+0300) Subject: New: InputMask for String field and managed Validator X-Git-Url: https://gitweb.ananas.su/?a=commitdiff_plain;h=a583674a9bfce7c9ceb58be045c473767a00b2ce;p=projects%2Fananas-labs.git New: InputMask for String field and managed Validator --- diff --git a/src/designer/deditfield.ui b/src/designer/deditfield.ui index 9ec82d0..2d4084b 100644 --- a/src/designer/deditfield.ui +++ b/src/designer/deditfield.ui @@ -8,8 +8,8 @@ 0 0 - 488 - 490 + 585 + 478 @@ -42,7 +42,7 @@ unnamed - + textLabel1 @@ -68,7 +68,7 @@ Name - + textLabel4 @@ -100,7 +100,7 @@ Type - + textLabel1_2_2 @@ -126,7 +126,7 @@ Comment - + eComment @@ -135,7 +135,7 @@ - + eType @@ -155,7 +155,7 @@ false - + eCname @@ -172,7 +172,7 @@ - + textLabel1_2 @@ -192,7 +192,7 @@ Cname - + eName @@ -209,7 +209,7 @@ - + tWidth @@ -221,177 +221,7 @@ Width - - - Num_Label - - - Numerator - - - - - exLabel - - - <u><i>Example</i>:</u> - - - - - layout27 - - - - unnamed - - - - spacer20 - - - Horizontal - - - Expanding - - - - 144 - 16 - - - - - - eXample - - - ___ - - - - - spacer19 - - - Horizontal - - - Expanding - - - - 135 - 16 - - - - - - - - layout19 - - - - 7 - 0 - 0 - 0 - - - - - unnamed - - - - MinLabel - - - Min: - - - - - eMin - - - - 7 - 0 - 2 - 0 - - - - - - MaxLabel - - - Max: - - - - - eMax - - - - 7 - 0 - 2 - 0 - - - - - - PrLabel - - - Prefix: - - - - - ePrefix - - - - 7 - 0 - 1 - 0 - - - - - - SfLabel - - - Suffix: - - - - - eSuffix - - - - 7 - 0 - 1 - 0 - - - - - - + PropBox @@ -485,7 +315,7 @@ - + layout19 @@ -536,18 +366,12 @@ - + - DateMask + NumeratorGroupBox - Use Date with Mask - - - true - - - true + Numeranor @@ -559,93 +383,256 @@ 3 - + - textLabel1_3 + exLabel - Date format + <u><i>Example</i>:</u> - - - - yyyyMMdd - - - - - yyMMdd - - - - - dd MMMM yyyy - - + - aDFormatBox + Num_Label - - - 1 - 0 - 2 - 0 - + + Numerator - + - textLabel2 + DateFormat - or + and date - - - spacer21 - - - Horizontal - - - Expanding - - - - 20 - 16 - - - - + - eOwnFormat + layout19 7 0 - 1 + 0 0 + + + unnamed + + + + MinLabel + + + Min: + + + + + eMin + + + + 7 + 0 + 2 + 0 + + + + + + MaxLabel + + + Max: + + + + + eMax + + + + 7 + 0 + 2 + 0 + + + + + + PrLabel + + + Prefix: + + + + + ePrefix + + + + 7 + 0 + 1 + 0 + + + + + + SfLabel + + + Suffix: + + + + + eSuffix + + + + 7 + 0 + 1 + 0 + + + + - + - useOwnFofmat + layout27 - - use own format + + + unnamed + + + + spacer20 + + + Horizontal + + + Expanding + + + + 144 + 16 + + + + + + eXample + + + ___ + + + + + spacer19 + + + Horizontal + + + Expanding + + + + 135 + 16 + + + + + + + + layout9 + + + unnamed + + + + + yyyyMMdd + + + + + yyMMdd + + + + + dd MMMM yyyy + + + + aDFormatBox + + + + 1 + 0 + 2 + 0 + + + + + + textLabel2 + + + or + + + + + useOwnFofmat + + + use own format + + + + + eOwnFormat + + + + 7 + 0 + 1 + 0 + + + + - + - layout6 + layout7 @@ -733,6 +720,14 @@ true + + + efNumerator + + + Num + + spacer7 @@ -745,31 +740,14 @@ - 15 + 45 20 - - - spacer13 - - - Vertical - - - Expanding - - - - 16 - 40 - - - - + ValidateGroupBox @@ -783,9 +761,60 @@ unnamed - + - layout8 + textLabel3 + + + <u>Example:</u> RegExp <b><i>[A-C]\d{5}[W-Z]</b></i> for string <i><b>A12345Z</b></i> + + + AutoText + + + + + textLabel1_5 + + + RegExp + + + + + two_state + + + Intermediate == Invalid + + + + + textLabel1_4 + + + Input Mask + + + + + VdRegEx + + + [ABCD], will match an A or a B or a C or a D. + + + + + inputMask + + + [ABCD], will match an A or a B or a C or a D. + + + + + layout7 @@ -793,39 +822,6 @@ - textLabel1_5 - - - RegExp - - - - - VdRegEx - - - [ABCD], will match an A or a B or a C or a D. - - - - - spacer7_2 - - - Horizontal - - - Expanding - - - - 20 - 21 - - - - - textLabel2_3 @@ -839,19 +835,25 @@ - - - textLabel3 - - - <u>Example:</u> RegExp <b><i>[A-C]\d{5}[W-Z]</b></i> for string <i><b>A12345Z</b></i> - - - AutoText - - + + + spacer13 + + + Vertical + + + Expanding + + + + 16 + 80 + + + @@ -1000,12 +1002,6 @@ setExample() - DateMask - toggled(bool) - dEditField - setExample() - - ePrefix textChanged(const QString&) dEditField @@ -1054,16 +1050,28 @@ efVd_stateChanged(int) - VdRegEx + Testline textChanged(const QString&) dEditField - VdRegEx_textChanged(const QString&) + Testline_textChanged(const QString&) - Testline + inputMask textChanged(const QString&) dEditField - Testline_textChanged(const QString&) + inputMask_textChanged(const QString&) + + + efNumerator + stateChanged(int) + dEditField + efNumerator_stateChanged(int) + + + DateFormat + stateChanged(int) + dEditField + DateFormat_stateChanged(int) @@ -1091,8 +1099,10 @@ aUsersList_clicked( QListViewItem * ) setExample() efVd_stateChanged( int ) - VdRegEx_textChanged( const QString & ) Testline_textChanged( const QString & ) + inputMask_textChanged( const QString & ) + efNumerator_stateChanged( int ) + DateFormat_stateChanged( int ) destroy() diff --git a/src/designer/deditfield.ui.h b/src/designer/deditfield.ui.h index 75f104a..3b35c0d 100644 --- a/src/designer/deditfield.ui.h +++ b/src/designer/deditfield.ui.h @@ -74,6 +74,7 @@ void dEditField::init() otypes.append(" "); lzcheckBox->setText(tr("Add leading zeros")); efVd->setText(tr("Validate")); + efNumerator->setText(tr("Numerator")); eType->insertItem(tr("Unknown"), 0); } @@ -126,8 +127,10 @@ void dEditField::setData( aListViewItem *o ) else efNZ->setChecked( false ); if( md->attr( obj, mda_vd ) == "1" ) efVd->setChecked( true ); else efVd->setChecked( false ); - + if( md->attr( obj, mda_twostate ) == "1" ) two_state->setChecked( true ); + else two_state->setChecked( false ); VdRegEx->setText( md->attr( obj, mda_validator ) ); + inputMask->setText( md->attr( obj, mda_inputmask ) ); efSum->setChecked(md->attr( obj, mda_sum ) == "1"); @@ -299,6 +302,9 @@ void dEditField::updateMD() 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 (inputMask->text() )md->setAttr( obj, mda_inputmask, inputMask->text().stripWhiteSpace() ); + if (two_state->isChecked() ) md->setAttr( obj, mda_twostate, "1" ); + else md->setAttr( obj, mda_twostate, "0" ); if( efSum->isChecked() ) md->setAttr( obj, mda_sum, "1" ); else @@ -337,21 +343,8 @@ void dEditField::typeSelect( int idx ) comboBox2->hide(); efVd->show(); ValidateGroupBox->show(); - DateMask->hide(); + NumeratorGroupBox->hide(); saldoTextLabel->hide(); - // - Num_Label->hide(); - MinLabel->hide(); - eMin->hide(); - MaxLabel->hide(); - eMax->hide(); - PrLabel->hide(); - ePrefix->hide(); - SfLabel->hide(); - eSuffix->hide(); - exLabel->hide(); - eXample->hide(); - // } else { @@ -366,24 +359,13 @@ void dEditField::typeSelect( int idx ) tSepTriads->hide(); lzcheckBox->hide(); tNotBound->show(); - DateMask->show(); + NumeratorGroupBox->show(); efVd->show(); ValidateGroupBox->show(); efSum->setChecked(false); comboBox2->setEnabled(false); comboBox2->hide(); saldoTextLabel->hide(); - Num_Label->show(); - MinLabel->show(); - eMin->show(); - MaxLabel->show(); - eMax->show(); - PrLabel->show(); - ePrefix->show(); - SfLabel->show(); - eSuffix->show(); - exLabel->show(); - eXample->show(); } else { @@ -402,19 +384,7 @@ void dEditField::typeSelect( int idx ) tSepTriads->hide(); efVd->hide(); ValidateGroupBox->hide(); - // - Num_Label->hide(); - MinLabel->hide(); - eMin->hide(); - MaxLabel->hide(); - eMax->hide(); - PrLabel->hide(); - ePrefix->hide(); - SfLabel->hide(); - eSuffix->hide(); - exLabel->hide(); - eXample->hide(); - // + NumeratorGroupBox->hide(); efSum->setChecked(false); } else @@ -431,21 +401,8 @@ void dEditField::typeSelect( int idx ) tNotBound->hide(); tSepTriads->hide(); efVd->hide(); - DateMask->hide(); + NumeratorGroupBox->hide(); ValidateGroupBox->hide(); - // - Num_Label->hide(); - MinLabel->hide(); - eMin->hide(); - MaxLabel->hide(); - eMax->hide(); - PrLabel->hide(); - ePrefix->hide(); - SfLabel->hide(); - eSuffix->hide(); - exLabel->hide(); - eXample->hide(); - // efSum->setChecked(false); // comboBox2->setEnabled(false); } @@ -488,16 +445,13 @@ void dEditField::setExample() { QDate date = QDate::currentDate(); QString curdate, dateformat, numerator; - if (DateMask->isChecked() ) + + if (DateFormat->isChecked() ) { if (useOwnFofmat->isChecked() ) { - aDFormatBox->setEnabled(FALSE); - eOwnFormat->setEnabled(TRUE); dateformat =eOwnFormat->text(); }else{ - aDFormatBox->setEnabled(TRUE); - eOwnFormat->setEnabled(FALSE); dateformat =aDFormatBox->currentText(); } curdate = date.toString(dateformat); @@ -514,8 +468,6 @@ void dEditField::setExample() } - - void dEditField::efVd_stateChanged( int ) { if (efVd->isChecked() ) @@ -527,12 +479,6 @@ void dEditField::efVd_stateChanged( int ) } -void dEditField::VdRegEx_textChanged( const QString & ) -{ - -} - - void dEditField::Testline_textChanged( const QString & ) { QRegExp rx( VdRegEx->text() ); @@ -548,7 +494,11 @@ void dEditField::Testline_textChanged( const QString & ) } if(v.validate(s, pos ) == QValidator::Intermediate) { - pal.setColor(QColorGroup::Highlight, Qt::red); + if (two_state->isChecked() ) { + pal.setColor(QColorGroup::Highlight, Qt::red); + }else{ + pal.setColor(QColorGroup::Highlight, Qt::yellow); + } Testline->setPalette(pal); } if(v.validate(s, pos ) == QValidator::Acceptable) @@ -557,3 +507,36 @@ void dEditField::Testline_textChanged( const QString & ) Testline->setPalette(pal); } } + +void dEditField::inputMask_textChanged( const QString & ) +{ + Testline->setInputMask(inputMask->text()); +} + + +void dEditField::efNumerator_stateChanged( int ) +{ + if (efNumerator->isChecked() ) + { + NumeratorGroupBox->show(); + } else { + NumeratorGroupBox->hide(); + } +} + + +void dEditField::DateFormat_stateChanged( int ) +{ + if (DateFormat->isChecked() ) + { + aDFormatBox->setEnabled(TRUE); + textLabel2->setEnabled(TRUE); + useOwnFofmat->setEnabled(TRUE); + eOwnFormat->setEnabled(TRUE); + } else { + aDFormatBox->setEnabled(FALSE); + textLabel2->setEnabled(FALSE); + useOwnFofmat->setEnabled(FALSE); + eOwnFormat->setEnabled(FALSE); + } +} diff --git a/src/lib/acfg.h b/src/lib/acfg.h index 67e51b9..d16f174 100644 --- a/src/lib/acfg.h +++ b/src/lib/acfg.h @@ -211,13 +211,14 @@ Metadata attributes. #define mda_stdf "stdf" #define mda_rights "rights" #define mda_vd "vd" +#define mda_twostate "twostate" #define mda_validator "validator" +#define mda_inputmask "inputmask" /*! Actions types */ - #define md_action_new 0 #define md_action_edit 1 #define md_action_view 2 diff --git a/src/plugins/wdbfield.cpp b/src/plugins/wdbfield.cpp index 24a7929..9790dab 100644 --- a/src/plugins/wdbfield.cpp +++ b/src/plugins/wdbfield.cpp @@ -326,7 +326,11 @@ wDBField::initObject(aDatabase *adb ) } if ( md->attr(o,mda_vd) == "1" && md->attr(o,mda_validator) != "") { - wField::SetValidator( md->attr(o,mda_validator) ); + wField::SetValidator( md->attr(o,mda_validator), md->attr(o,mda_twostate).toInt() ); + } + if (md->attr(o,mda_inputmask) != "" ) + { + wField::SetMask(md->attr(o,mda_inputmask)); } diff --git a/src/plugins/wfield.cpp b/src/plugins/wfield.cpp index 4c4a19d..f05ddc1 100644 --- a/src/plugins/wfield.cpp +++ b/src/plugins/wfield.cpp @@ -380,7 +380,11 @@ wField::Validate(const QString &test) emit inputInvalid(); break; case QValidator::Intermediate: - pal.setColor(QColorGroup::Highlight, Qt::yellow); + if (two_state == 0) { + pal.setColor(QColorGroup::Highlight, Qt::yellow); + }else{ + pal.setColor(QColorGroup::Highlight, Qt::red); + } lineEdit->setPalette(pal); setValue( test ); break; @@ -401,14 +405,29 @@ wField::Validate(const QString &test) * \param QString Validator - \en RegExp for QRegExpValidator \_en \ru значение RegExp для установки QRegExpValidator\_ru */ void -wField::SetValidator(QString Validator) +wField::SetValidator(QString Validator, int twostate) { + two_state = twostate; QRegExp rx( Validator ); v = new QRegExpValidator( rx, 0 ); connect( lineEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( Validate( const QString & ) ) ); } /*! + * \en Set input Mask to LineEdit. + * \_en + * \ru Устанавливает маску ввода в LineEdit. + * \_ru + * \param QString inputMas - \en inputMas for LineEdit. \_en + * \ru inputMas для LineEdit.\_ru + */ +void +wField::SetMask(QString inputMask) +{ + if (inputMask != "") lineEdit->setInputMask(inputMask); +} + +/*! * \en Sets value. \_en * \ru Устанавливает значение виджета. \_ru * \param newvalue (in) - \en value for set \_en \ru значение для установки \_ru diff --git a/src/plugins/wfield.h b/src/plugins/wfield.h index c0dffa3..edf58e8 100644 --- a/src/plugins/wfield.h +++ b/src/plugins/wfield.h @@ -104,7 +104,8 @@ public slots: void selectAll(); virtual void SetReadOnly(bool); virtual void SetNonZero(bool); - virtual void SetValidator(QString Validator); + virtual void SetMask(QString); + virtual void SetValidator(QString Validator, int twostate); private slots: void on_selected( Q_ULLONG uid ); @@ -118,6 +119,7 @@ protected: wCatButton *objButton; wCheckBox *checkBox; QValidator *v; + int two_state; tEditorType vEditorType; QString vFieldType; QString vValue;