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

List:       kde-core-devel
Subject:    RFC: KInputDialog + completion
From:       Joseph Wenninger <jowenn () kde ! org>
Date:       2007-03-04 14:09:45
Message-ID: 200703041509.45464.jowenn () kde ! org
[Download RAW message or body]

Hi !

I'd like to propose an API change of the static getText member function of the 
KInputDialog class.

I propose to add an additional string list parameter at the end, which allows 
to specify items for input completion of the line edit.

Attached is a patch which contains the needed changes and modifications for 
the test applications

Kind regards
Joseph Wenninger

-- 
"People's characters are strengthened through struggle against
difficulties; they are weakened by comfort." (Old Chinese adage)
KATE developer - Joseph Wenninger <jowenn@kde.org>


["proposal_kinputdialog+completion.patch" (text/x-diff)]

Index: dialogs/kinputdialog.h
===================================================================
--- dialogs/kinputdialog.h	(Revision 638840)
+++ dialogs/kinputdialog.h	(Arbeitskopie)
@@ -106,13 +106,15 @@
      * @param mask      Mask associated with the line edit. See the
      *                  documentation for @ref QLineEdit about masks
      * @param whatsThis a QWhatsThis text for the input widget.
+     * @param completionList a list of items which should be used for input \
                completion
      * @return String user entered if Ok was pressed, else a null string
      */
     static QString getText( const QString &caption, const QString &label,
         const QString &value=QString(), bool *ok=0, QWidget *parent=0,
         QValidator *validator=0,
         const QString &mask=QString(),
-	const QString& whatsThis=QString()  );
+	const QString& whatsThis=QString(),
+        const QStringList &completionList=QStringList()  );
 
     /**
      * Static convenience function to get a multiline string from the user.
Index: dialogs/kinputdialog.cpp
===================================================================
--- dialogs/kinputdialog.cpp	(Revision 638840)
+++ dialogs/kinputdialog.cpp	(Arbeitskopie)
@@ -28,6 +28,7 @@
 #include <klistwidget.h>
 #include <kstandardguiitem.h>
 #include <ktextedit.h>
+#include <kcompletion.h>
 
 #include "kinputdialog.h"
 
@@ -299,13 +300,20 @@
 QString KInputDialog::getText( const QString &caption,
     const QString &label, const QString &value, bool *ok, QWidget *parent,
     QValidator *validator, const QString &mask,
-    const QString &whatsThis )
+    const QString &whatsThis,const QStringList &completionList )
 {
   KInputDialog dlg( caption, label, value, parent, validator, mask );
 
   if( !whatsThis.isEmpty() )
     dlg.lineEdit()->setWhatsThis(whatsThis );
 
+  if (!completionList.isEmpty())
+  {
+    KCompletion *comp=dlg.lineEdit()->completionObject();
+    for(QStringList::const_iterator \
it=completionList.constBegin();it!=completionList.constEnd();++it) +      \
comp->addItem(*it); +  }
+
   bool _ok = ( dlg.exec() == Accepted );
 
   if ( ok )
Index: tests/kinputdialogtest.cpp
===================================================================
--- tests/kinputdialogtest.cpp	(Revision 638840)
+++ tests/kinputdialogtest.cpp	(Arbeitskopie)
@@ -29,6 +29,12 @@
   svalue = KInputDialog::getText( "_caption", "_label:", "_value", &ok );
   kDebug() << "value1: " << svalue << ", ok: " << ok << endl;
 
+  QStringList completionList;
+  completionList<<"test1"<<"test2"<<"test3"<<"abcdef";
+  svalue = KInputDialog::getText( "_caption", "_label:", "_value", \
&ok,0,0,QString(),QString(),completionList); +  kDebug() << "value1: " << svalue << \
", ok: " << ok << endl; +
+
   QRegExpValidator validator( QRegExp( "[0-9]{3}\\-[0-9]{3}\\-[0-9]{4}" ), 0 );
   svalue = KInputDialog::getText( "_caption", "_label:", "_value", &ok, 0L,
     &validator );



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

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