[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    PATCH:KLineEdit
From:       "Dawit A." <adawit () kde ! org>
Date:       2002-08-23 21:25:46
[Download RAW message or body]

Since we are in a freeze, would anyone object to the following patch that 
makes an insignificant change in terms of KLineEdit's functionality and adds
one new member function ?

The patch makes it possible for applications to set a flag, smartTextUpdate,
which determines whether or not the current text in the lineedit needs to be 
updated by comparing it with the new text.  If the text has not changed, it 
will simply return without called QLineEdit::setText.  The current default 
behavior is not changed and stays the way it is.

Regards,
Dawit A.

["klineedit.diff" (text/x-diff)]

Index: klineedit.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/klineedit.cpp,v
retrieving revision 1.147
diff -u -p -b -B -w -r1.147 klineedit.cpp
--- klineedit.cpp	2002/08/11 01:14:51	1.147
+++ klineedit.cpp	2002/08/24 21:19:10
@@ -47,21 +47,24 @@ class KLineEdit::KLineEditPrivate
 public:
     KLineEditPrivate()
     {
-        grabReturnKeyEvents = false;
-        handleURLDrops = true;
         completionBox = 0L;
+        handleURLDrops = true;
+        smartTextUpdate = false;
+        grabReturnKeyEvents = false;        
     }
     ~KLineEditPrivate()
     {
         delete completionBox;
     }
 
-    bool grabReturnKeyEvents;
+    int squeezedEnd;    
+    int squeezedStart;
     bool handleURLDrops;
-    KCompletionBox *completionBox;
+    bool smartTextUpdate;    
+    bool grabReturnKeyEvents;    
+    
     QString squeezedText;
-    int squeezedStart;
-    int squeezedEnd;
+    KCompletionBox *completionBox;
 };
 
 
@@ -86,6 +89,7 @@ void KLineEdit::init()
 {
     d = new KLineEditPrivate;
     possibleTripleClick = false;
+    
     // Enable the context menu by default.
     setContextMenuEnabled( true );
     KCursor::setAutoHideCursor( this, true, true );
@@ -592,18 +596,25 @@ void KLineEdit::completionMenuActivated(
     switch ( id )
     {
         case Default:
-           setCompletionMode( KGlobalSettings::completionMode() ); break;
+           setCompletionMode( KGlobalSettings::completionMode() );
+           break;
         case NoCompletion:
-           setCompletionMode( KGlobalSettings::CompletionNone ); break;
+           setCompletionMode( KGlobalSettings::CompletionNone );
+           break;
         case AutoCompletion:
-            setCompletionMode( KGlobalSettings::CompletionAuto ); break;
+            setCompletionMode( KGlobalSettings::CompletionAuto );
+            break;
         case SemiAutoCompletion:
-            setCompletionMode( KGlobalSettings::CompletionMan ); break;
+            setCompletionMode( KGlobalSettings::CompletionMan );
+            break;
         case ShellCompletion:
-            setCompletionMode( KGlobalSettings::CompletionShell ); break;
+            setCompletionMode( KGlobalSettings::CompletionShell );
+            break;
         case PopupCompletion:
-            setCompletionMode( KGlobalSettings::CompletionPopup ); break;
-        default: return;
+            setCompletionMode( KGlobalSettings::CompletionPopup );
+            break;
+        default:
+            return;
     }
 
     if ( oldMode != completionMode() )
@@ -700,7 +711,7 @@ bool KLineEdit::trapReturnKey() const
 
 void KLineEdit::setURL( const KURL& url )
 {
-    QLineEdit::setText( url.prettyURL() );
+    setText( url.prettyURL() );
 }
 
 void KLineEdit::makeCompletionBox()
@@ -829,6 +840,21 @@ void KLineEdit::clear()
     setText( QString::null );
 }
 
-void KLineEdit::virtual_hook( int id, void* data )
-{ KCompletionBase::virtual_hook( id, data ); }
+void KLineEdit::setText (const QString & newText)
+{
+    if ( !d->smartTextUpdate || text().length() == 0 || newText != text() )
+    {
+        QLineEdit::setText (newText);
+        return;
+    }
+}
 
+void KLineEdit::setEnableSmartTextUpdate (bool enable)
+{
+    d->smartTextUpdate = enable;
+}
+
+void KLineEdit::virtual_hook( int id, void* data )
+{
+    KCompletionBase::virtual_hook( id, data );
+}
Index: klineedit.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/klineedit.h,v
retrieving revision 1.94
diff -u -p -b -B -w -r1.94 klineedit.h
--- klineedit.h	2002/08/11 01:14:51	1.94
+++ klineedit.h	2002/08/24 21:19:10
@@ -250,6 +250,14 @@ public:
     bool trapReturnKey() const;
 
     /**
+     * Enables text update if and only if the new text is different
+     * from the current one.  Otherwise, the call to setText is ignored.
+     *
+     * @param true enable smart text update, false otherwise.
+     */
+    void setEnableSmartTextUpdate (bool);
+    
+    /**
      * Re-implemented for internal reasons.  API not affected.
      *
      * @reimplemented
@@ -380,6 +388,11 @@ public slots:
      * This can only be used with read-only line-edits.
      */
     void setSqueezedText( const QString &text);
+    
+    /**
+     * Re-implemented for internal reasons.  API is unaffected.
+     */
+    virtual void setText (const QString &text);
 
 protected slots:
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic