Validator for String fields. Red:Yellow:Green color coding.
authorDmintriy L. Kruglikov <master@shadow.breg.pl.ua>
Mon, 30 Jun 2008 16:09:04 +0000 (19:09 +0300)
committerDmintriy L. Kruglikov <master@shadow.breg.pl.ua>
Mon, 30 Jun 2008 16:09:04 +0000 (19:09 +0300)
src/designer/deditfield.ui
src/designer/deditfield.ui.h
src/lib/acfg.h
src/plugins/wdbfield.cpp
src/plugins/wfield.cpp
src/plugins/wfield.h

index 5fe96fe..9ec82d0 100644 (file)
@@ -8,8 +8,8 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>478</width>
-            <height>475</height>
+            <width>488</width>
+            <height>490</height>
         </rect>
     </property>
     <property name="caption">
                             </widget>
                             <widget class="QCheckBox">
                                 <property name="name">
-                                    <cstring>VdcheckBox</cstring>
+                                    <cstring>efVd</cstring>
                                 </property>
                                 <property name="text">
                                     <string>Vd</string>
                                     <cstring>textLabel3</cstring>
                                 </property>
                                 <property name="text">
-                                    <string>&lt;font size="-1"&gt;&lt;u&gt;Example:&lt;/u&gt; RegEx &lt;b&gt;&lt;i&gt;[A-C]\d{5}[W-Z]&lt;/b&gt;&lt;/i&gt; for string &lt;i&gt;&lt;b&gt;A12345Z&lt;/b&gt;&lt;/i&gt;&lt;/font&gt;</string>
+                                    <string>&lt;u&gt;Example:&lt;/u&gt; RegExp &lt;b&gt;&lt;i&gt;[A-C]\d{5}[W-Z]&lt;/b&gt;&lt;/i&gt; for string &lt;i&gt;&lt;b&gt;A12345Z&lt;/b&gt;&lt;/i&gt;</string>
                                 </property>
-                                <property name="alignment">
-                                    <set>WordBreak|AlignCenter</set>
+                                <property name="textFormat">
+                                    <enum>AutoText</enum>
                                 </property>
                             </widget>
                         </grid>
         <slot>tNotBound_stateChanged(int)</slot>
     </connection>
     <connection>
-        <sender>VdcheckBox</sender>
+        <sender>efVd</sender>
         <signal>stateChanged(int)</signal>
         <receiver>dEditField</receiver>
-        <slot>VdcheckBox_stateChanged(int)</slot>
+        <slot>efVd_stateChanged(int)</slot>
     </connection>
     <connection>
         <sender>VdRegEx</sender>
     <slot>tNotBound_stateChanged( int )</slot>
     <slot>aUsersList_clicked( QListViewItem * )</slot>
     <slot>setExample()</slot>
-    <slot>VdcheckBox_stateChanged( int )</slot>
+    <slot>efVd_stateChanged( int )</slot>
     <slot>VdRegEx_textChanged( const QString &amp; )</slot>
     <slot>Testline_textChanged( const QString &amp; )</slot>
 </slots>
index 134edac..75f104a 100644 (file)
@@ -38,7 +38,7 @@
 #include <qdatetime.h>
 #include <qvaluelist.h>
 #include <qlistview.h>
-#include <qvalidator.h> 
+#include <qvalidator.h>
 #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);
     }
 }
index f3ae1c1..67e51b9 100644 (file)
@@ -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
index a2812a1..24a7929 100644 (file)
@@ -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");
index 89642d8..4c4a19d 100644 (file)
@@ -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
index edf6b96..c0dffa3 100644 (file)
@@ -42,6 +42,7 @@
 #include "adatabase.h"
 #include "ananas.h"
 #include "acalendar.h"
+#include <qvalidator.h>
 
 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;