[kde-doc-english] [calligra/kexi-features-tanis] kexi/plugins/forms/widgets: Enforce field length constraint in Forms for LineEdit and TextEdit

Dimitrios T. Tanis dimitrios.tanis at kdemail.net
Mon Mar 12 23:43:38 UTC 2012


Git commit 35d45f6539057d1338e70292b884d0ccbf4c798f by Dimitrios T. Tanis.
Committed on 13/03/2012 at 00:35.
Pushed by tanis into branch 'kexi-features-tanis'.

Enforce field length constraint in Forms for LineEdit and TextEdit

Field length constraint is enforced in forms when using either a
lineEdit or textEdit. Since SQLite has dynamic types and does not
enforce it, it is handled internally in Kexi.

BUG: 278295
FIXED-IN: 2.5 ALPHA 2
GUI: Field Length constraint is now enforced.
DIGEST: Field Length constraint is now enforced in Kexi.

M  +5    -0    kexi/plugins/forms/widgets/kexidblineedit.cpp
M  +18   -1    kexi/plugins/forms/widgets/kexidbtextedit.cpp
M  +3    -0    kexi/plugins/forms/widgets/kexidbtextedit.h

http://commits.kde.org/calligra/35d45f6539057d1338e70292b884d0ccbf4c798f

diff --git a/kexi/plugins/forms/widgets/kexidblineedit.cpp b/kexi/plugins/forms/widgets/kexidblineedit.cpp
index 639c454..a669cbb 100644
--- a/kexi/plugins/forms/widgets/kexidblineedit.cpp
+++ b/kexi/plugins/forms/widgets/kexidblineedit.cpp
@@ -254,6 +254,11 @@ void KexiDBLineEdit::setColumnInfo(KexiDB::QueryColumnInfo* cinfo)
         setInputMask(inputMask);
 
     KexiDBTextWidgetInterface::setColumnInfo(cinfo, this);
+
+    if (cinfo->field->isTextType()) {
+        if (!designMode())
+            setMaxLength(cinfo->field->length());
+    }
 }
 
 /*todo
diff --git a/kexi/plugins/forms/widgets/kexidbtextedit.cpp b/kexi/plugins/forms/widgets/kexidbtextedit.cpp
index 0c52e43..0de5989 100644
--- a/kexi/plugins/forms/widgets/kexidbtextedit.cpp
+++ b/kexi/plugins/forms/widgets/kexidbtextedit.cpp
@@ -74,6 +74,7 @@ KexiDBTextEdit::KexiDBTextEdit(QWidget *parent)
         , m_menuExtender(this, this)
         , m_slotTextChanged_enabled(true)
         , m_dataSourceLabel(0)
+        , m_Length(0)
 {
     QFont tmpFont;
     tmpFont.setPointSize(KGlobalSettings::smallestReadableFont().pointSize());
@@ -121,6 +122,14 @@ void KexiDBTextEdit::slotTextChanged()
 {
     if (!m_slotTextChanged_enabled)
         return;
+
+    if (m_Length > 0) {
+        if (toPlainText().length() > m_Length) {
+            setPlainText(toPlainText().left(m_Length));
+            moveCursorToEnd();
+        }
+    }
+
     signalValueChanged();
 }
 
@@ -187,8 +196,16 @@ void KexiDBTextEdit::clear()
 void KexiDBTextEdit::setColumnInfo(KexiDB::QueryColumnInfo* cinfo)
 {
     KexiFormDataItemInterface::setColumnInfo(cinfo);
-    if (!cinfo)
+    if (!cinfo) {
+        m_Length = 0;
         return;
+    }
+
+    if (cinfo->field->isTextType()) {
+        if (!designMode())
+            m_Length = cinfo->field->length();
+    }
+
     KexiDBTextWidgetInterface::setColumnInfo(m_columnInfo, this);
 }
 
diff --git a/kexi/plugins/forms/widgets/kexidbtextedit.h b/kexi/plugins/forms/widgets/kexidbtextedit.h
index 0e1c7e3..b6320d9 100644
--- a/kexi/plugins/forms/widgets/kexidbtextedit.h
+++ b/kexi/plugins/forms/widgets/kexidbtextedit.h
@@ -129,6 +129,9 @@ private:
     bool m_slotTextChanged_enabled : 1;
 
     DataSourceLabel *m_dataSourceLabel;
+
+    //! Text length allowed
+    uint m_Length;
 };
 
 #endif


More information about the kde-doc-english mailing list