[QGIS Commit] r9532 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Oct 24 10:33:50 EDT 2008


Author: jef
Date: 2008-10-24 10:33:50 -0400 (Fri, 24 Oct 2008)
New Revision: 9532

Modified:
   trunk/qgis/src/app/qgspythondialog.cpp
   trunk/qgis/src/app/qgspythondialog.h
Log:
fix #1376

Modified: trunk/qgis/src/app/qgspythondialog.cpp
===================================================================
--- trunk/qgis/src/app/qgspythondialog.cpp	2008-10-24 11:49:51 UTC (rev 9531)
+++ trunk/qgis/src/app/qgspythondialog.cpp	2008-10-24 14:33:50 UTC (rev 9532)
@@ -30,6 +30,8 @@
 #endif
   mIface = pIface;
   mPythonUtils = pythonUtils;
+
+  pos = 0;
 }
 
 QgsPythonDialog::~QgsPythonDialog()
@@ -41,12 +43,51 @@
   return text.replace( "<", "&lt;" ).replace( ">", "&gt;" );
 }
 
+void QgsPythonDialog::keyPressEvent( QKeyEvent *ev )
+{
+  switch( ev->key() )
+  {
+  case Qt::Key_Up:
+    {
+      if(pos>0)
+      {
+        if( pos==history.size() )
+          history << edtCmdLine->text();
+        else
+          history[pos] = edtCmdLine->text();
+        pos--;
+        edtCmdLine->setText(history[pos]);
+      }
+    }
+    break;
+  case Qt::Key_Down:
+    {
+      if( pos<history.size()-1 )
+      {
+        history[pos] = edtCmdLine->text();
+        pos++;
+        edtCmdLine->setText(history[pos]);
+      }
+    }
+    break;
+  default:
+    QWidget::keyPressEvent(ev);
+    break;
+  }
+}
+
 void QgsPythonDialog::on_edtCmdLine_returnPressed()
 {
   QString command = edtCmdLine->text();
+
+  if( !command.isEmpty() )
+  {
+    history << command;
+    pos = history.size();
+  }
+
   QString output;
 
-
   // when using Py_single_input the return value will be always null
   // we're using custom hooks for output and exceptions to show output in console
   if ( mPythonUtils->runStringUnsafe( command ) )

Modified: trunk/qgis/src/app/qgspythondialog.h
===================================================================
--- trunk/qgis/src/app/qgspythondialog.h	2008-10-24 11:49:51 UTC (rev 9531)
+++ trunk/qgis/src/app/qgspythondialog.h	2008-10-24 14:33:50 UTC (rev 9532)
@@ -41,13 +41,17 @@
 
   protected:
 
-    void closeEvent( QCloseEvent* event );
-    void showEvent( QShowEvent* event );
+    void keyPressEvent( QKeyEvent *event );
+    void closeEvent( QCloseEvent *event );
+    void showEvent( QShowEvent *event );
 
   private:
 
     QgisInterface* mIface;
     QgsPythonUtils* mPythonUtils;
+
+    QStringList history;
+    int pos;
 };
 
 #endif



More information about the QGIS-commit mailing list