[QGIS Commit] r8894 - in branches/grass-tidyup-branch/src: app plugins/grass plugins/grass/images

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Jul 24 18:10:20 EDT 2008


Author: timlinux
Date: 2008-07-24 18:10:20 -0400 (Thu, 24 Jul 2008)
New Revision: 8894

Added:
   branches/grass-tidyup-branch/src/plugins/grass/images/error.png
   branches/grass-tidyup-branch/src/plugins/grass/images/error.svg
   branches/grass-tidyup-branch/src/plugins/grass/images/warning.png
   branches/grass-tidyup-branch/src/plugins/grass/images/warning.svg
Removed:
   branches/grass-tidyup-branch/src/plugins/grass/images/grass_module_error.png
   branches/grass-tidyup-branch/src/plugins/grass/images/grass_module_warning.png
Modified:
   branches/grass-tidyup-branch/src/app/qgisapp.cpp
   branches/grass-tidyup-branch/src/plugins/grass/CMakeLists.txt
   branches/grass-tidyup-branch/src/plugins/grass/images/qgsgrass_plugin.qrc
   branches/grass-tidyup-branch/src/plugins/grass/qgsgrassplugin.cpp
   branches/grass-tidyup-branch/src/plugins/grass/qgsgrassplugin.h
   branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshell.cpp
   branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshell.h
   branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshellbase.ui
Log:
In progress work of porting grass shell to Qt4 and related cleanups to the grass plugin. Note the shell does not 
behave correctly in many situations yet, but it no longer requires qt3support.


Modified: branches/grass-tidyup-branch/src/app/qgisapp.cpp
===================================================================
--- branches/grass-tidyup-branch/src/app/qgisapp.cpp	2008-07-24 16:28:57 UTC (rev 8893)
+++ branches/grass-tidyup-branch/src/app/qgisapp.cpp	2008-07-24 22:10:20 UTC (rev 8894)
@@ -1589,12 +1589,15 @@
 void QgisApp::restoreWindowState()
 {
   // restore the toolbar and dock widgets postions using Qt4 settings API
+  QByteArray myDefaultState("\0\0\0\xff\0\0\0\0\xfd\0\0\0\x1\0\0\0\0\0\0\x1\0\0\0\x2\0\xfc\x2\0\0\0\x2\xfb\0\0\0\f\0L\0\x65\0g\0\x65\0n\0\x64\x1\0\0\0\x66\0\0\x1\xc4\0\0\0\x62\0\xff\xff\xff\xfb\0\0\0\x10\0O\0v\0\x65\0r\0v\0i\0\x65\0w\x1\0\0\x2\x30\0\0\0\x36\0\0\0\x17\0\xff\xff\xff\0\0\x3/\0\0\x2\0\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\x5\0\0\0\0\0\0\0\x1\0\0\0\n\0G\0R\0\x41\0S\0S\x1\0\0\0\0\0\0\x2\0\0\0\0\0\0\0\0\0\0\0\0\x1\0\0\0\0\0\0\0\x1\0\0\0\x1\0\0\0\xe\0P\0l\0u\0g\0i\0n\0s\x1\0\0\0\0\0\0\x2\0\0\0\0\0\0\0\0\0\0\0\0\x2\0\0\0\x4\0\0\0\x16\0\x46\0i\0l\0\x65\0T\0o\0o\0l\0\x42\0\x61\0r\x1\0\0\0\0\0\0\x1\xa2\0\0\0\0\0\0\0\0\0\0\0\x18\0L\0\x61\0y\0\x65\0r\0T\0o\0o\0l\0\x42\0\x61\0r\x1\0\0\x1\xa2\0\0\0\xc8\0\0\0\0\0\0\0\0\0\0\0\x14\0\x41\0t\0t\0r\0i\0\x62\0u\0t\0\x65\0s\x1\0\0\x2j\0\0\x2\x15\0\0\0\0\0\0\0\0\0\0\0\b\0H\0\x65\0l\0p\0\0\0\x3\xd8\0\0\0\xa7\0\0\0\0\0\0\0\0\0\0\0\x2\0\0\0\x2\0\0\0\x14\0\x44\0i\0g\0i\0t\0i\0z\0i\0n\0g\x1\0\0\0\0\0\0\x2\x36\0\0\0\0\0\0\0\0\0\0\0\x1c\0M\0\x61\0p\0 \0N\0\x61\0v\0i\0g\0\x61\0t\0i\0o\0n\x1\0\0\x2\x36\0\0\x2I\0\0\0\0\0\0\0\0");
+  QByteArray myDefaultGeometry ("\x1\xd9\xd0\xcb\0\x1\0\0\0\0\0\0\0\0\0\0\0\0\x4\x7f\0\0\x2\x9d\0\0\0\0\0\0\0-\0\0\x4~\0\0\x1\x8d\0\0\0\0\x2\0");
   QSettings settings;
-  QVariant vstate = settings.value("/UI/state");
+  QVariant vstate = settings.value("/UI/state",myDefaultState);
+  qDebug("vstate : " + vstate.toString().toLocal8Bit());
   this->restoreState(vstate.toByteArray());
 
   // restore window geometry
-  restoreGeometry(settings.value("/UI/geometry").toByteArray());
+  restoreGeometry(settings.value("/UI/geometry",myDefaultGeometry).toByteArray());
 //  canvasLegendSplit->restoreState(settings.value("/UI/canvasSplitterState").toByteArray());
 //  legendOverviewSplit->restoreState(settings.value("/UI/legendSplitterState").toByteArray());
 }
@@ -5406,10 +5409,7 @@
 
 void QgisApp::keyPressEvent ( QKeyEvent * e )
 {
-  // The following statment causes a crash on WIN32 and should be 
-  // enclosed in an #ifdef QGISDEBUG if its really necessary. Its
-  // commented out for now. [gsherman]
-  //    std::cout << e->text().toLocal8Bit().data() << " (keypress recevied)" << std::endl;
+
   emit keyPressed (e);
 
   //cancel rendering progress with esc key

Modified: branches/grass-tidyup-branch/src/plugins/grass/CMakeLists.txt
===================================================================
--- branches/grass-tidyup-branch/src/plugins/grass/CMakeLists.txt	2008-07-24 16:28:57 UTC (rev 8893)
+++ branches/grass-tidyup-branch/src/plugins/grass/CMakeLists.txt	2008-07-24 22:10:20 UTC (rev 8894)
@@ -48,7 +48,6 @@
      qgsgrassmapcalcbase.ui
      qgsgrassmodulebase.ui
      qgsgrassnewmapsetbase.ui
-     qgsgrassshellbase.ui
      qgsgrassattributesbase.ui
      qgsgrassregionbase.ui
      ../../ui/qgsprojectionselectorbase.ui

Copied: branches/grass-tidyup-branch/src/plugins/grass/images/error.png (from rev 8893, branches/grass-tidyup-branch/src/plugins/grass/images/grass_module_error.png)
===================================================================
(Binary files differ)

Added: branches/grass-tidyup-branch/src/plugins/grass/images/error.svg
===================================================================
--- branches/grass-tidyup-branch/src/plugins/grass/images/error.svg	                        (rev 0)
+++ branches/grass-tidyup-branch/src/plugins/grass/images/error.svg	2008-07-24 22:10:20 UTC (rev 8894)
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="32px"
+   height="32px"
+   id="svg3167"
+   sodipodi:version="0.32"
+   inkscape:version="0.46"
+   sodipodi:docname="error.svg"
+   inkscape:output_extension="org.inkscape.output.svg.inkscape"
+   inkscape:export-filename="/home/timlinux/dev/cpp/grass_tidyup_branch/src/plugins/grass/images/error.png"
+   inkscape:export-xdpi="28.125"
+   inkscape:export-ydpi="28.125">
+  <defs
+     id="defs3169">
+    <inkscape:perspective
+       sodipodi:type="inkscape:persp3d"
+       inkscape:vp_x="0 : 16 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_z="32 : 16 : 1"
+       inkscape:persp3d-origin="16 : 10.666667 : 1"
+       id="perspective3175" />
+    <filter
+       inkscape:collect="always"
+       id="filter4412"
+       x="-1.1218204"
+       width="3.2436407"
+       y="-0.1525315"
+       height="1.305063">
+      <feGaussianBlur
+         inkscape:collect="always"
+         stdDeviation="1.6291407"
+         id="feGaussianBlur4414" />
+    </filter>
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="24.1875"
+     inkscape:cx="7.4211886"
+     inkscape:cy="16.198532"
+     inkscape:current-layer="layer1"
+     showgrid="true"
+     inkscape:grid-bbox="true"
+     inkscape:document-units="px"
+     inkscape:window-width="1680"
+     inkscape:window-height="975"
+     inkscape:window-x="0"
+     inkscape:window-y="49" />
+  <metadata
+     id="metadata3172">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     id="layer1"
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer">
+    <path
+       sodipodi:type="star"
+       style="opacity:1;fill:#c8260a;fill-opacity:1;fill-rule:nonzero;stroke:#525252;stroke-width:2.09500003000000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       id="path3180"
+       sodipodi:sides="5"
+       sodipodi:cx="7.9379845"
+       sodipodi:cy="5.9534883"
+       sodipodi:r1="14.800107"
+       sodipodi:r2="12.181088"
+       sodipodi:arg1="2.1659679"
+       sodipodi:arg2="2.7523517"
+       inkscape:flatsided="false"
+       inkscape:rounded="0"
+       inkscape:randomized="0"
+       d="M -0.35970787,18.208751 L -3.3319266,10.576044 L -6.2815911,1.8489985 L 0.059078748,-3.3363857 L 7.4474958,-8.8384888 L 14.338464,-4.4105252 L 21.854421,0.91603357 L 19.772604,8.8380498 L 17.029304,17.632147 L 8.8517021,18.100259 L -0.35970787,18.208751 z"
+       transform="matrix(1.019397,3.3899291e-2,-3.3710496e-2,1.0419927,8.0592551,10.697328)" />
+    <path
+       sodipodi:type="star"
+       style="opacity:1;fill:#c8260a;fill-opacity:1;fill-rule:nonzero;stroke:#fdfdfd;stroke-width:0.87278043999999999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       id="path3691"
+       sodipodi:sides="5"
+       sodipodi:cx="7.9379845"
+       sodipodi:cy="5.9534883"
+       sodipodi:r1="14.800107"
+       sodipodi:r2="12.181088"
+       sodipodi:arg1="2.1659679"
+       sodipodi:arg2="2.7523517"
+       inkscape:flatsided="false"
+       inkscape:rounded="0"
+       inkscape:randomized="0"
+       d="M -0.35970787,18.208751 L -3.3319266,10.576044 L -6.2815911,1.8489985 L 0.059078748,-3.3363857 L 7.4474958,-8.8384888 L 14.338464,-4.4105252 L 21.854421,0.91603357 L 19.772604,8.8380498 L 17.029304,17.632147 L 8.8517021,18.100259 L -0.35970787,18.208751 z"
+       transform="matrix(1.019397,3.3899291e-2,-3.3710496e-2,1.0419927,8.0264697,10.650324)" />
+    <text
+       xml:space="preserve"
+       style="font-size:29.52629662000000010px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
+       x="9.1972065"
+       y="27.479221"
+       id="text6182"
+       transform="scale(1.042109,0.9595925)"><tspan
+         sodipodi:role="line"
+         id="tspan6184"
+         x="9.1972065"
+         y="27.479221">!</tspan></text>
+  </g>
+</svg>

Deleted: branches/grass-tidyup-branch/src/plugins/grass/images/grass_module_error.png
===================================================================
(Binary files differ)

Deleted: branches/grass-tidyup-branch/src/plugins/grass/images/grass_module_warning.png
===================================================================
(Binary files differ)

Modified: branches/grass-tidyup-branch/src/plugins/grass/images/qgsgrass_plugin.qrc
===================================================================
--- branches/grass-tidyup-branch/src/plugins/grass/images/qgsgrass_plugin.qrc	2008-07-24 16:28:57 UTC (rev 8893)
+++ branches/grass-tidyup-branch/src/plugins/grass/images/qgsgrass_plugin.qrc	2008-07-24 22:10:20 UTC (rev 8894)
@@ -17,8 +17,8 @@
     <file>grass_delete_vertex.png</file>
     <file>grass_edit_attributes.png</file>
     <file>grass_edit.png</file>
-    <file>grass_module_error.png</file>
-    <file>grass_module_warning.png</file>
+    <file>error.png</file>
+    <file>warning.png</file>
     <file>grass_move_line.png</file>
     <file>grass_move_vertex.png</file>
     <file>grass_new_boundary.png</file>

Copied: branches/grass-tidyup-branch/src/plugins/grass/images/warning.png (from rev 8893, branches/grass-tidyup-branch/src/plugins/grass/images/grass_module_warning.png)
===================================================================
(Binary files differ)

Added: branches/grass-tidyup-branch/src/plugins/grass/images/warning.svg
===================================================================
--- branches/grass-tidyup-branch/src/plugins/grass/images/warning.svg	                        (rev 0)
+++ branches/grass-tidyup-branch/src/plugins/grass/images/warning.svg	2008-07-24 22:10:20 UTC (rev 8894)
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="32"
+   height="32"
+   id="svg5639"
+   sodipodi:version="0.32"
+   inkscape:version="0.46"
+   version="1.0"
+   sodipodi:docname="warning.svg"
+   inkscape:output_extension="org.inkscape.output.svg.inkscape"
+   inkscape:export-filename="/home/timlinux/dev/cpp/grass_tidyup_branch/src/plugins/grass/images/warning.png"
+   inkscape:export-xdpi="28.125"
+   inkscape:export-ydpi="28.125">
+  <defs
+     id="defs5641">
+    <inkscape:perspective
+       sodipodi:type="inkscape:persp3d"
+       inkscape:vp_x="0 : 526.18109 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_z="744.09448 : 526.18109 : 1"
+       inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+       id="perspective5647" />
+    <filter
+       inkscape:collect="always"
+       id="filter4312"
+       x="-0.59512582"
+       width="2.1902516"
+       y="-0.080917978"
+       height="1.161836">
+      <feGaussianBlur
+         inkscape:collect="always"
+         stdDeviation="0.80560101"
+         id="feGaussianBlur4314" />
+    </filter>
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="24.1875"
+     inkscape:cx="16"
+     inkscape:cy="16"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     showguides="true"
+     inkscape:guide-bbox="true"
+     inkscape:window-width="1680"
+     inkscape:window-height="975"
+     inkscape:window-x="0"
+     inkscape:window-y="49">
+    <sodipodi:guide
+       orientation="1,0"
+       position="1.1989664,23.069767"
+       id="guide5653" />
+    <sodipodi:guide
+       orientation="1,0"
+       position="30.718346,25.219638"
+       id="guide5655" />
+    <sodipodi:guide
+       orientation="0,1"
+       position="12.155039,31.007752"
+       id="guide5657" />
+    <sodipodi:guide
+       orientation="0,1"
+       position="11.617571,1.4470284"
+       id="guide5659" />
+    <sodipodi:guide
+       orientation="1,0"
+       position="15.917313,26.749354"
+       id="guide5661" />
+  </sodipodi:namedview>
+  <metadata
+     id="metadata5644">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Camada 1"
+     inkscape:groupmode="layer"
+     id="layer1">
+    <path
+       style="fill:#e7f315;fill-rule:evenodd;stroke:#525252;stroke-width:2.095;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1;fill-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
+       d="M 1.1962567,30.515246 L 15.875943,1.3202877 L 30.845087,30.597025 L 1.1962567,30.515246 z"
+       id="path5663"
+       inkscape:export-filename="/home/timlinux/dev/cpp/grass_tidyup_branch/src/plugins/grass/images/grass_module_warning.png"
+       inkscape:export-xdpi="94.824997"
+       inkscape:export-ydpi="94.824997" />
+    <text
+       xml:space="preserve"
+       style="font-size:29.52629662px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
+       x="9.3034344"
+       y="30.116138"
+       id="text6182"
+       transform="scale(1.042109,0.9595925)"><tspan
+         sodipodi:role="line"
+         id="tspan6184"
+         x="9.3034344"
+         y="30.116138">!</tspan></text>
+    <text
+       xml:space="preserve"
+       style="font-size:32.77603149px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;filter:url(#filter4312);font-family:Bitstream Vera Sans"
+       x="7.5023003"
+       y="32.777256"
+       id="text4240"
+       transform="matrix(1.1296718,0,0,0.8852128,0.537468,0.6201552)"><tspan
+         sodipodi:role="line"
+         id="tspan4242"
+         x="7.5023003"
+         y="32.777256">!</tspan></text>
+    <path
+       style="fill:#e7f315;fill-opacity:0;fill-rule:evenodd;stroke:#d2d2d2;stroke-width:0.6507076;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+       d="M 2.1870304,29.92231 L 15.906338,2.5384517 L 29.896166,29.999016 L 2.1870304,29.92231 z"
+       id="path3729"
+       inkscape:export-filename="/home/timlinux/dev/cpp/grass_tidyup_branch/src/plugins/grass/images/grass_module_warning.png"
+       inkscape:export-xdpi="94.824997"
+       inkscape:export-ydpi="94.824997" />
+  </g>
+</svg>

Modified: branches/grass-tidyup-branch/src/plugins/grass/qgsgrassplugin.cpp
===================================================================
--- branches/grass-tidyup-branch/src/plugins/grass/qgsgrassplugin.cpp	2008-07-24 16:28:57 UTC (rev 8893)
+++ branches/grass-tidyup-branch/src/plugins/grass/qgsgrassplugin.cpp	2008-07-24 22:10:20 UTC (rev 8894)
@@ -63,6 +63,7 @@
 #include "qgsgrassattributes.h"
 #include "qgsgrassselect.h"
 #include "qgsgrassedit.h"
+#include "qgsgrassshell.h"
 #include "qgsgrasstools.h"
 #include "qgsgrassregion.h"
 #include "qgsgrassnewmapset.h"
@@ -82,19 +83,16 @@
   pluginNameQString = tr("GrassVector");
   pluginVersionQString = tr("0.2");
   pluginDescriptionQString = tr("GRASS data access and tools");
-  mTools = 0;
-  mpDockWidget =0;
 }
 
 QgsGrassPlugin::~QgsGrassPlugin()
 {
   QString err = QgsGrass::closeMapset();
-  if (mTools) delete mTools;
-  if (mpDockWidget)
+  if (mpToolsDockWidget)
   {
     QSettings settings;
-    settings.setValue("/GRASS/windows/tools/geometry", mpDockWidget->saveGeometry());
-    delete mpDockWidget;
+    settings.setValue("/GRASS/windows/tools/geometry", mpToolsDockWidget->saveGeometry());
+    delete mpToolsDockWidget;
   }
 }
 
@@ -130,7 +128,6 @@
 void QgsGrassPlugin::initGui()
 {
   toolBarPointer = 0;
-  mTools = 0;
   mNewMapset = 0;
   mRegion = 0; 
 
@@ -247,13 +244,10 @@
     mCloseMapsetAction->setEnabled(false);
     mNewVectorAction->setEnabled(false);
 
-    if ( mTools ) 
-    {      
-      delete mTools;
-      delete mpDockWidget;
-      mpDockWidget = 0;
-      mTools = 0;
-    }    
+    if ( mpToolsDockWidget ) 
+    {
+      delete mpToolsDockWidget;
+    }
   } 
   else 
   {
@@ -414,20 +408,28 @@
 }
 void QgsGrassPlugin::openShell()
 {
-  QMessageBox::warning( 0, tr("Info"), tr("If I was a shell you would sea me...ssssshweessshh.") );
+  QgsGrassShell * mypShell = new QgsGrassShell ( qGisInterface->getMainWindow() );
+  QDockWidget * mypShellDockWidget = new QDockWidget(tr("Grass Shell"),qGisInterface->getMainWindow() );
+  mypShellDockWidget->setWidget(mypShell);
+  mypShellDockWidget->setObjectName("GrassShell");
+  mypShellDockWidget->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
+  qGisInterface->addDockWidget(Qt::BottomDockWidgetArea, mypShellDockWidget);
+  mypShellDockWidget->show();
 }
 // Open tools
 void QgsGrassPlugin::openTools()
 {
-  if ( !mTools ) { 
-    mTools = new QgsGrassTools ( qGisInterface, qGisInterface->getMainWindow() );
-    mpDockWidget = new QDockWidget(tr("Grass Tools"), 0);
-    mpDockWidget->setWidget(mTools);
-    mpDockWidget->setObjectName("GrassTools");
-    mpDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
-    qGisInterface->addDockWidget(Qt::LeftDockWidgetArea, mpDockWidget);
+  if ( !mpToolsDockWidget ) 
+  {
+    //toolbox will be deleted when its parent is deleted 
+    QgsGrassTools * mypTools = new QgsGrassTools ( qGisInterface, qGisInterface->getMainWindow() );
+    mpToolsDockWidget = new QDockWidget(tr("Grass Tools"), qGisInterface->getMainWindow());
+    mpToolsDockWidget->setWidget(mypTools);
+    mpToolsDockWidget->setObjectName("GrassTools");
+    mpToolsDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+    qGisInterface->addDockWidget(Qt::LeftDockWidgetArea, mpToolsDockWidget);
     QSettings settings;
-    mpDockWidget->restoreGeometry(settings.value("/GRASS/windows/tools/geometry").toByteArray());
+    mpToolsDockWidget->restoreGeometry(settings.value("/GRASS/windows/tools/geometry").toByteArray());
 
     
     // @TODO this needs to be wired to the new mapbrowser rather!!!

Modified: branches/grass-tidyup-branch/src/plugins/grass/qgsgrassplugin.h
===================================================================
--- branches/grass-tidyup-branch/src/plugins/grass/qgsgrassplugin.h	2008-07-24 16:28:57 UTC (rev 8893)
+++ branches/grass-tidyup-branch/src/plugins/grass/qgsgrassplugin.h	2008-07-24 22:10:20 UTC (rev 8894)
@@ -17,8 +17,7 @@
 #ifndef QGSGRASSPLUGIN_H
 #define QGSGRASSPLUGIN_H
 #include "../qgisplugin.h"
-#include <qwidget.h>
-#include <qpen.h>
+#include <QPen>
 
 
 #include <vector>
@@ -27,12 +26,13 @@
 class QgsMapCanvas;
 class QgsRubberBand;
 
-class QgsGrassTools;
+
 class QgsGrassNewMapset;
 class QgsGrassRegion;
 class QToolBar;
 
 #include <QDockWidget>
+#include <QPointer>
              
 /**
 * \class QgsGrassPlugin
@@ -144,10 +144,9 @@
   QgsGrassRegion *mRegion;
   // Region rubber band
   QgsRubberBand *mRegionBand;
-  //! GRASS tools
-  QgsGrassTools *mTools;
+
   //! Dock widget the tools will be placed into
-  QDockWidget * mpDockWidget;
+  QPointer <QDockWidget> mpToolsDockWidget;
   //! Pointer to QgsGrassNewMapset
   QgsGrassNewMapset *mNewMapset;
 

Modified: branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshell.cpp
===================================================================
--- branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshell.cpp	2008-07-24 16:28:57 UTC (rev 8893)
+++ branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshell.cpp	2008-07-24 22:10:20 UTC (rev 8894)
@@ -2,8 +2,9 @@
      qgsgrassshell.cpp
      --------------------------------------
     Date                 : Sun Sep 16 12:06:10 AKDT 2007
-    Copyright            : (C) 2007 by Gary E. Sherman
-    Email                : sherman at mrcc dot com
+    Copyright            : (C) 2007 by Radim Blazek 
+    Revised and ported to Qt4: Tim Sutton 2008
+    Email                : blazek at itc.it
  ***************************************************************************
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -15,37 +16,30 @@
 #include <iostream>
 #include <vector>
 
-#include <qstring.h>
-#include <qapplication.h>
-#include <qpushbutton.h>
-#include <qwidget.h>
-#include <q3textedit.h>
-#include <q3process.h>
-#include <qmessagebox.h>
-#include <q3cstring.h>
-#include <qfile.h>
-#include <qdatastream.h>
-#include <qstringlist.h>
-#include <qsocketnotifier.h>
-#include <q3socket.h>
-#include <q3socketdevice.h>
-#include <qevent.h>
-#include <q3textbrowser.h>
-#include <qregexp.h>
-#include <qcursor.h>
-#include <qlayout.h>
-#include <qclipboard.h>
-#include <qfontmetrics.h>
-#include <q3progressbar.h>
+#include <QString>
+#include <QApplication>
+#include <QProcess>
+#include <QMessageBox>
+#include <QFile>
+#include <QDataStream>
+#include <QStringList>
+#include <QSocketNotifier>
+#include <QTcpSocket>
+#include <QEvent>
+#include <QTextBrowser>
+#include <QTextBlock>
+#include <QTextDocument>
+#include <QRegExp>
+#include <QCursor>
+#include <QLayout>
+#include <QClipboard>
+#include <QFontMetrics>
+#include <QFileInfo>
+#include <QProgressBar>
 
 #include "qgsapplication.h"
-
 #include "qgsgrassshell.h"
-//Added by qt3to4:
-#include <QGridLayout>
-#include <QKeyEvent>
-#include <QResizeEvent>
-#include <QMouseEvent>
+#include "qgsgrassshelltext.h"
 
 extern "C" {
 #include <stdio.h>
@@ -80,10 +74,10 @@
 #endif //!WIN32
 }
 
-QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools, 
-    QWidget * parent, const char * name  ):
-QDialog(parent), QgsGrassShellBase()
+QgsGrassShell::QgsGrassShell ( QWidget * parent, const char * name  ):
+  QTextEdit(parent)
 {
+  setName("GrassShell");
   mValid = false;
   mSkipLines = 2;
 
@@ -93,34 +87,35 @@
   return;
 #else 
 
-  setupUi(this);
+  //get focus from both mouse and keyboard
+  setFocusPolicy(Qt::StrongFocus);
+  setTabChangesFocus ( false );
+  setReadOnly ( false );
+  setWordWrapMode ( QTextOption::WrapAnywhere );
 
-  QGridLayout *layout = new QGridLayout( mTextFrame, 1, 1 );
-  mText = new QgsGrassShellText( this, mTextFrame);
-  layout->addWidget ( mText, 0 , 0 );
-  mText->show();
+    // Set tab stops ???
+  mTabStop.resize(200);
+  for ( int i = 0 ; i * 8 < (int)mTabStop.size(); i++ )
+  {
+    mTabStop[i*8] = true;
+  }
+  
+  mpProgressBar = new QProgressBar(this);
+  mpProgressBar->hide();
+  setFont(QFont ( "Courier", 10 ));
 
+ 
 
-  mFont = QFont ( "Courier", 10 );
-
-
-#ifndef Q_WS_MAC
-  // Qt4.3.2/Mac Q3TextEdit readOnly property causes keys to be processed as keyboard actions
-  mText->setReadOnly(TRUE);
-#endif
-  //mText->setFocusPolicy ( QWidget::NoFocus ); // To get key press directly
-
+  //setFocusPolicy ( QWidget::NoFocus ); // To get key press directly
+  append (tr( "GRASS shell ready...") ); 
 #ifndef HAVE_OPENPTY
-  mText->append ( "GRASS shell is not supported" ); 
+  append (tr( "GRASS shell is not supported") ); 
   return;
 #endif
 
-  // TODO set cursor IbeamCursor
-  // This does not work - the cursor is used for scrollbars -> disabled
-  //mText->setCursor ( QCursor(Qt::IbeamCursor) );
-  mParagraph = -1; // first will be 0
-  mIndex = -1;
 
+  mBlockNo = -1; // first will be 0
+
   mNewLine = true;
 
   for ( int i = 0; i < ModeCount; i++ )
@@ -168,7 +163,7 @@
 #endif
   if ( pid == -1 )
   {
-    QMessageBox::warning( 0, "Warning", "Cannot fork shell" );
+    QMessageBox::warning( 0, tr("Warning"), tr("Cannot fork shell") );
     return;
   }
 
@@ -193,8 +188,8 @@
     int fd = open ( (char*) slaveName.ascii(), O_RDWR);
     if ( fd < 0 ) 
     {
-      QMessageBox::warning( 0, "Warning", "Cannot open slave file "
-        "in child process" );
+      QMessageBox::warning( 0, tr("Warning"), tr("Cannot open slave file "
+        "in child process") );
       return;
     }
 
@@ -265,18 +260,12 @@
   QObject::connect ( mOutNotifier, SIGNAL(activated(int)),
     this, SLOT(readStdout(int)));
 
-  // Set tab stops ???
-  mTabStop.resize(200);
-  for ( int i = 0 ; i * 8 < (int)mTabStop.size(); i++ )
-  {
-    mTabStop[i*8] = true;
-  }
 
+
   // Set trap to write history on SIGUSR1
   //QString trap = "trap 'history -w' SIGUSR1\015\012";
   QString trap = "trap 'history -w' SIGUSR1\015";
   write( mFdMaster, trap.ascii(), trap.length());
-  mText->clear();
 
   resizeTerminal();
   mValid = true;
@@ -320,6 +309,39 @@
   }
 #endif
 }
+  
+void QgsGrassShell::focusInEvent ( QFocusEvent * event )
+{
+  //install an event filter to prevent other parts of the app
+  //receiving keystrokes and e.g. invoking menu shortcuts
+  qApp->installEventFilter(this);
+  QTextEdit::focusInEvent(event);
+}
+  void QgsGrassShell::focusOutEvent ( QFocusEvent * event )
+{
+  qApp->removeEventFilter(this);
+  QTextEdit::focusOutEvent(event);
+}
+bool QgsGrassShell::eventFilter(QObject *object, QEvent *event)
+{
+  //note object name must be wrapped in a QString because you can directly compare char[] with char[]
+  if (QString(object->name()) == "GrassShell" && event->type() == QEvent::KeyPress)
+  {
+    if (event->type() != QEvent::KeyPress)
+    {
+      qDebug("Keypress event NOT accepted: ");
+      return false;
+    }
+    qDebug("Keypress event accepted: ");
+    QKeyEvent * mypKeyEvent = static_cast<QKeyEvent *>(event);
+    keyPressEvent(mypKeyEvent);
+    return true; //stop further processing by other widgets
+  }
+  else
+  {
+    return false;
+  }
+}
 
 void QgsGrassShell::keyPressEvent( QKeyEvent * e  )
 {
@@ -333,7 +355,7 @@
 
   if ( !mValid ) return;
 
-  mProgressBar->setValue ( 0 );
+  mpProgressBar->setValue ( 0 );
 
   char c = (char) e->ascii();
 #ifdef QGISDEBUG
@@ -375,10 +397,13 @@
     }
   }
 
+  //pass the key press on to the text edit parent (results in double chars echoed to textedit
+  //QTextEdit::keyPressEvent(  e  );
   ret = write( mFdMaster, s, length);
 #ifdef QGISDEBUG
   std::cerr << "write ret = " << ret << std::endl;
 #endif
+
 }
 
 void QgsGrassShell::keyReleaseEvent( QKeyEvent * e  )
@@ -392,6 +417,7 @@
   else if ( e->key() == Qt::Key_Shift ) mKeyDown[DownShift] = false;
   else if ( e->key() == Qt::Key_Alt ) mKeyDown[DownAlt] = false;
   else if ( e->key() == Qt::Key_Meta ) mKeyDown[DownMeta] = false;
+
 }
 
 void QgsGrassShell::readStdout( int socket )
@@ -421,58 +447,58 @@
   std::cerr << "-->";
   for ( int i = 0; i < (int)mStdoutBuffer.length(); i++ )
   {
-    int c = mStdoutBuffer[i];
-    QString s = "";
-    if ( c > '\037' && c != '\177' ) // control characters
+    int myCharInt = mStdoutBuffer[i];
+    QString myString = "";
+    if ( myCharInt > '\037' && myCharInt != '\177' ) // myControlChar characters
     {
-      s = (char) c;
-      std::cerr << s.local8Bit().data();
+      myString = (char) myCharInt;
+      std::cerr << myString.local8Bit().data();
     }
     else
     {
-      std::cerr << "(c=" << QString::number(c,8).local8Bit().data() << ")";
+      std::cerr << "(myCharInt=" << QString::number(myCharInt,8).local8Bit().data() << ")";
     }
   }
   std::cerr << "<--" << std::endl;
 #endif
 
   eraseCursor();
-  // To make it faster we want to print maximum lenght blocks from buffer
+  // To make it faster we want to print maximum length blocks from buffer
   while ( mStdoutBuffer.length() > 0 ) 
   {
 #ifdef QGISDEBUG
     std::cerr << "------ cycle ------" << std::endl;
 #endif
 
-    // Search control character
-    int control = -1; 
+    // Search myControlChar character
+    int myControlChar = -1; 
     for ( int i = 0; i < (int)mStdoutBuffer.length(); i++ )
     {
-      int c = mStdoutBuffer[i];
-      if ( c < '\037' || c == '\177' )
+      int myCharInt = mStdoutBuffer[i];
+      if ( myCharInt < '\037' || myCharInt == '\177' )
       {
-        control = i;
+        myControlChar = i;
         break;
       }
     }
 #ifdef QGISDEBUG
-    std::cerr << "control = " << control << std::endl;
+    std::cerr << "myControlChar = " << myControlChar << std::endl;
 #endif
 
-    // Process control character if found at index 0
-    if ( control == 0 ) 
+    // Process myControlChar character if myFoundFlag at index 0
+    if ( myControlChar == 0 ) 
     {
-      int c = mStdoutBuffer[0];
+      int myCharInt = mStdoutBuffer[0];
 #ifdef QGISDEBUG
-      std::cerr << "c = " << QString::number(c,8).local8Bit().data() << std::endl;
+      std::cerr << "myCharInt = " << QString::number(myCharInt,8).local8Bit().data() << std::endl;
 #endif
 
-      // control sequence
-      if ( c == '\033' )
+      // myControlChar sequence
+      if ( myCharInt == '\033' )
       {
-        //std::cerr << "control sequence" << std::endl;
+        //std::cerr << "myControlChar sequence" << std::endl;
 
-        bool found = false;
+        bool myFoundFlag = false;
 
         // It is sequence, so it should be at least one more character
         // wait for more data 
@@ -480,32 +506,32 @@
         if ( mStdoutBuffer[1] == ']' && mStdoutBuffer.length() < 3 ) break;
 
         // ESC ] Ps ; Pt BEL    (xterm title hack)
-        QRegExp rx ( "\\](\\d+);([^\\a]+)\\a" ); 
-        if ( rx.search ( mStdoutBuffer, 1 ) == 1 ) 
+        QRegExp myRegExp ( "\\](\\d+);([^\\a]+)\\a" ); 
+        if ( myRegExp.search ( mStdoutBuffer, 1 ) == 1 ) 
         {
-          int mlen = rx.matchedLength();
+          int mlen = myRegExp.matchedLength();
 #ifdef QGISDEBUG
-          std::cerr << "ESC(set title): " << rx.cap(2).local8Bit().data() << std::endl;
+          std::cerr << "ESC(set title): " << myRegExp.cap(2).local8Bit().data() << std::endl;
 #endif
           mStdoutBuffer.remove ( 0, mlen+1 );
-          found = true;
+          myFoundFlag = true;
         }
 
-        if ( !found ) 
+        if ( !myFoundFlag ) 
         {
           //    ESC [ Pn ; Pn FINAL
           // or ESC [ = Pn ; Pn FINAL
           // or ESC [ = Pn ; Pn FINAL
           // TODO: QRegExp captures only last of repeated patterns 
           //       ( ; separated nums - (;\\d+)* )
-          rx.setPattern ( "\\[([?=])*(\\d+)*(;\\d+)*([A-z])" ); 
-          if ( rx.search ( mStdoutBuffer, 1 ) == 1 ) 
+          myRegExp.setPattern ( "\\[([?=])*(\\d+)*(;\\d+)*([A-z])" ); 
+          if ( myRegExp.search ( mStdoutBuffer, 1 ) == 1 ) 
           {
-            int mlen = rx.matchedLength();
-            char final = rx.cap(4).at(0).latin1();
+            int mlen = myRegExp.matchedLength();
+            char final = myRegExp.cap(4).at(0).latin1();
 
             std::cerr << "final = " << final << std::endl;
-            //std::cerr << "ESC: " << rx.cap(0) << std::endl;
+            //std::cerr << "ESC: " << myRegExp.cap(0) << std::endl;
 
             switch ( final )
             {
@@ -513,14 +539,14 @@
             case 'h' : // SM - Set Mode
               {
                 int mode = -1;
-                switch ( rx.cap(2).toInt() )
+                switch ( myRegExp.cap(2).toInt() )
                 {
                 case 4 :
                   mode = Insert;
                   break;
 
                 default:
-                  std::cerr << "ESC ignored: " << rx.cap(0).local8Bit().data() << std::endl;
+                  std::cerr << "ESC ignored: " << myRegExp.cap(0).local8Bit().data() << std::endl;
                   break;
                 }
                 if ( mode >= 0 )
@@ -534,41 +560,40 @@
               }
 
             case 'm' : // SGR - Select Graphic Rendition
-              if ( rx.cap(2).isEmpty() || rx.cap(2).toInt() == 0 )
+              if ( myRegExp.cap(2).isEmpty() || myRegExp.cap(2).toInt() == 0 )
               {
-                for ( int i = 0; i < RendetionCount; i++ )
+                for ( int i = 0; i < RenditionCount; i++ )
                 {
-                  mRendetion[i] = false;
+                  mRendition[i] = false;
                 }
               }
               else
               {
-                std::cerr << "ESC SGR ignored: " << rx.cap(0).local8Bit().data() << std::endl;
+                std::cerr << "ESC SGR ignored: " << myRegExp.cap(0).local8Bit().data() << std::endl;
               }
               break;
 
             case 'P' : // DCH - Delete Character
               {
-                int n = rx.cap(2).toInt();
-                mText->setSelection ( mParagraph, mIndex, mParagraph, mIndex+n, 0 );
-                mText->removeSelectedText ( 0 );
+                int n = myRegExp.cap(2).toInt();
+                textCursor().deleteChar();
                 break;
               }
 
             case 'K' : // EL - Erase In Line
-              if ( rx.cap(2).isEmpty() || rx.cap(2).toInt() == 0 )
+              if ( myRegExp.cap(2).isEmpty() || myRegExp.cap(2).toInt() == 0 )
               {
-                //mText->setSelectionAttributes ( 1, QColor(255,255,255), true );  
-                mText->setSelection ( mParagraph, mIndex, mParagraph, 
-                  mText->paragraphLength(mParagraph), 0 );
-                mText->removeSelectedText ( 0 );
+                //setSelectionAttributes ( 1, QColor(255,255,255), true );  
+                textCursor().select( QTextCursor::LineUnderCursor );
+                textCursor().removeSelectedText();    
               }
               break;
 
               // TODO: multiple tab stops
             case 'H' : // Horizontal Tabulation Set (HTS)
-              mTabStop[mIndex] = true;
-              std::cerr << "TAB set on " << mIndex << std::endl;
+              //@TODO this should be using position in the line rather than the document I think [TS]
+              mTabStop[ textCursor().position()] = true;
+              std::cerr << "TAB set on " << textCursor().position() << std::endl;
               break;
 
             case 'g' : // Tabulation Clear (TBC)
@@ -576,55 +601,57 @@
               // ESC [ 2 g 	Clears all tab stops in the line
               // ESC [ 3 g 	Clears all tab stops in the Page
               std::cerr << "TAB reset" << std::endl;
-              if ( rx.cap(2).isEmpty() || rx.cap(2).toInt() == 0 )
+              if ( myRegExp.cap(2).isEmpty() || myRegExp.cap(2).toInt() == 0 )
               {
-                mTabStop[mIndex] = false;
+                //@TODO this should be using position in the line rather than the document I think [TS]
+                mTabStop[textCursor().position()] = false;
               } 
               else
               {
                 for (int i = 0; i < (int)mTabStop.size(); i++ ) 
-                  mTabStop[mIndex] = false;
+                  //@TODO this should be using position in the line rather than the document I think [TS]
+                  mTabStop[textCursor().position()] = false;
               }
               break;
 
             default:
-              std::cerr << "ESC ignored: " << rx.cap(0).local8Bit().data() << std::endl;
+              std::cerr << "ESC ignored: " << myRegExp.cap(0).local8Bit().data() << std::endl;
               break;
             }
 
             mStdoutBuffer.remove ( 0, mlen+1 );
-            found = true;
+            myFoundFlag = true;
           }
         }
 
-        if ( !found ) 
+        if ( !myFoundFlag ) 
         {
           // ESC # DIGIT
-          rx.setPattern ( "#(\\d)" ); 
-          if ( rx.search ( mStdoutBuffer, 1 ) == 1 )
+          myRegExp.setPattern ( "#(\\d)" ); 
+          if ( myRegExp.search ( mStdoutBuffer, 1 ) == 1 )
           {
-            std::cerr << "ESC ignored: " << rx.cap(0).local8Bit().data() << std::endl;
+            std::cerr << "ESC ignored: " << myRegExp.cap(0).local8Bit().data() << std::endl;
             mStdoutBuffer.remove ( 0, 3 );
-            found = true;
+            myFoundFlag = true;
           }
         }
 
-        if ( !found ) 
+        if ( !myFoundFlag ) 
         {
           // ESC CHARACTER
-          rx.setPattern ( "[A-z<>=]" ); 
-          if ( rx.search ( mStdoutBuffer, 1 ) == 1 )
+          myRegExp.setPattern ( "[A-z<>=]" ); 
+          if ( myRegExp.search ( mStdoutBuffer, 1 ) == 1 )
           {
-            std::cerr << "ESC ignored: " << rx.cap(0).local8Bit().data() << std::endl;
+            std::cerr << "ESC ignored: " << myRegExp.cap(0).local8Bit().data() << std::endl;
             mStdoutBuffer.remove ( 0, 2 );
-            found = true;
+            myFoundFlag = true;
           }
         }
 
         // TODO: it can happen that the sequence is not complete ->
         //       no match -> how to distinguish unknown sequence from
         //       missing characters
-        if ( !found ) 
+        if ( !myFoundFlag ) 
         {
           // For now move forward
           std::cerr << "UNKNOWN ESC ignored: " << mStdoutBuffer.mid(1,5).data() << std::endl;
@@ -633,14 +660,13 @@
       }
       else
       {
-        // control character
-        switch ( c ) 
+        // myControlChar character
+        switch ( myCharInt ) 
         {
         case '\015' : // CR
           //std::cerr << "CR" << std::endl;
           mStdoutBuffer.remove ( 0, 1 );
           // TODO : back tab stops?
-          mIndex = 0;
           break;
 
         case '\012' : // NL
@@ -651,7 +677,10 @@
 
         case '\010' : // BS 
           //std::cerr << "BS" << std::endl;
-          mIndex--;
+          //we must remove the selection first because in a shell backspace can only delete a 
+          //single char
+          textCursor().clearSelection ();
+          textCursor().deletePreviousChar ();
           mStdoutBuffer.remove ( 0, 1 );
           break;
 
@@ -659,7 +688,8 @@
           {
             //std::cerr << "HT" << std::endl;
             QString space;
-            for ( int i = mIndex; i < (int)mTabStop.size(); i++ )
+            //@TODO this should be using position in the line rather than the document I think [TS]
+            for ( int i = textCursor().position(); i < (int)mTabStop.size(); i++ )
             {
               space.append ( " " );
               if ( mTabStop[i] ) break;
@@ -671,12 +701,12 @@
 
         case '>' : // Keypad Numeric Mode 
           std::cerr << "Keypad Numeric Mode ignored: " 
-            << QString::number(c,8).local8Bit().data() << std::endl;
+              << QString::number(myCharInt,8).local8Bit().data() << std::endl;
           mStdoutBuffer.remove ( 0, 2 );
           break;
 
-        default : // unknown control, do nothing
-          std::cerr << "UNKNOWN control char ignored: " << QString::number(c,8).local8Bit().data() << std::endl;
+        default : // unknown myControlChar, do nothing
+          std::cerr << "UNKNOWN myControlChar char ignored: " << QString::number(myCharInt,8).local8Bit().data() << std::endl;
           mStdoutBuffer.remove ( 0, 1 );
           break;
         }
@@ -688,42 +718,42 @@
     // and stop with \015\012 (\n)
 
     // first info
-    QRegExp rxinfo ( "GRASS_INFO_" );
-    int message = rxinfo.search(mStdoutBuffer);
+    QRegExp myRegExpinfo ( "GRASS_INFO_" );
+    int message = myRegExpinfo.search(mStdoutBuffer);
 
-    if ( message == 0 ) // Info found at index 0
+    if ( message == 0 ) // Info myFoundFlag at index 0
     { 
       // First try percent
-      QRegExp rxpercent ( "GRASS_INFO_PERCENT: (\\d+)\\015\\012" );
-      if ( rxpercent.search(mStdoutBuffer) == 0 ) {
-        int mlen = rxpercent.matchedLength();
-        int progress = rxpercent.cap(1).toInt();
-        mProgressBar->setValue ( progress  );
+      QRegExp myRegExpPercent ( "GRASS_INFO_PERCENT: (\\d+)\\015\\012" );
+      if ( myRegExpPercent.search(mStdoutBuffer) == 0 ) {
+        int mlen = myRegExpPercent.matchedLength();
+        int progress = myRegExpPercent.cap(1).toInt();
+        mpProgressBar->setValue ( progress  );
         mStdoutBuffer.remove ( 0, mlen );
         continue;
       }
 
-      QRegExp rxwarning ( "GRASS_INFO_WARNING\\(\\d+,\\d+\\): ([^\\015]*)\\015\\012" );
-      QRegExp rxerror ( "GRASS_INFO_ERROR\\(\\d+,\\d+\\): ([^\\015]*)\\015\\012" );
-      QRegExp rxend ( "GRASS_INFO_END\\(\\d+,\\d+\\)\\015\\012" );
+      QRegExp myRegExpwarning ( "GRASS_INFO_WARNING\\(\\d+,\\d+\\): ([^\\015]*)\\015\\012" );
+      QRegExp myRegExperror ( "GRASS_INFO_ERROR\\(\\d+,\\d+\\): ([^\\015]*)\\015\\012" );
+      QRegExp myRegExpend ( "GRASS_INFO_END\\(\\d+,\\d+\\)\\015\\012" );
 
       int mlen = 0; 
       QString msg;
       QString img;
-      if ( rxwarning.search(mStdoutBuffer) == 0 ) 
+      if ( myRegExpwarning.search(mStdoutBuffer) == 0 ) 
       {
-        mlen = rxwarning.matchedLength();
-        msg = rxwarning.cap(1);
-        img = QgsApplication::pkgDataPath() + "/themes/default/grass/grass_module_warning.png";
+        mlen = myRegExpwarning.matchedLength();
+        msg = myRegExpwarning.cap(1);
+        img = ":/grass/warning.png";
       }
-      else if ( rxerror.search(mStdoutBuffer) == 0 ) 
+      else if ( myRegExperror.search(mStdoutBuffer) == 0 ) 
       {
-        mlen = rxerror.matchedLength();
-        msg = rxerror.cap(1);
-        img = QgsApplication::pkgDataPath() + "/themes/default/grass/grass_module_error.png";
+        mlen = myRegExperror.matchedLength();
+        msg = myRegExperror.cap(1);
+        img =  ":/grass/error.png";
       }
 
-      if ( mlen > 0 ) // found error or warning
+      if ( mlen > 0 ) // myFoundFlag error or warning
       {
 #ifdef QGISDEBUG
         std::cerr << "MSG: " << msg.local8Bit().data() << std::endl;
@@ -736,27 +766,23 @@
         // but it does not look nice to have empty rows before 
         removeEmptyParagraphs();
 
-        msg.replace ( "&", "&amp;" );
-        msg.replace ( "<", "&lt;" );
-        msg.replace ( ">", "&gt;" );
-        msg.replace ( " ", "&nbsp;" );
-
-        mText->setTextFormat(Qt::RichText);
-        mText->append ( "<img src=\"" + img + "\">" + msg );
-        mParagraph++;
+        textCursor().insertImage(img);
+        insertPlainText ( msg );
+        
+        mBlockNo++;
         mNewLine = true;
         mStdoutBuffer.remove ( 0, mlen );
         continue;
       } 
 
-      if ( rxend.search(mStdoutBuffer) == 0 ) 
+      if ( myRegExpend.search(mStdoutBuffer) == 0 ) 
       {
-        mlen = rxend.matchedLength();
+        mlen = myRegExpend.matchedLength();
         mStdoutBuffer.remove ( 0, mlen );
         continue;
       }
 
-      // No complete message found => wait for input 
+      // No complete message myFoundFlag => wait for input 
       // TODO: 1) Sleep for a moment because GRASS writes 
       //          1 character in loop
       //       2) Fix GRASS to write longer strings
@@ -765,8 +791,8 @@
 
     // Print plain text
     int length = mStdoutBuffer.length();
-    if ( control >= 0 ) length = control;
-    if ( message >= 0 && (control == -1 || control > message ) )
+    if ( myControlChar >= 0 ) length = myControlChar;
+    if ( message >= 0 && (myControlChar == -1 || myControlChar > message ) )
     {
       length = message;
     }
@@ -784,72 +810,72 @@
     }
   }
 
-  showCursor();
-  mText->ensureCursorVisible();
+
+  ensureCursorVisible();
 }
 
 void QgsGrassShell::removeEmptyParagraphs()
 {
-  while ( mParagraph >= 0 
-       && mText->text(mParagraph).stripWhiteSpace().length() <= 0 )
+  QTextDocument * mypDocument = document();
+  QTextCursor myEndCursor(mypDocument);
+  textCursor().setPosition(QTextCursor::Start); //start of document
+  myEndCursor.setPosition(QTextCursor::End);//end of document
+  while (textCursor().position() != myEndCursor.position())
   {
-    mText->removeParagraph ( mParagraph );
-    mParagraph--;
+     textCursor().select(QTextCursor::BlockUnderCursor);
+     textCursor().removeSelectedText();
+     textCursor().setPosition(QTextCursor::NextBlock);//start of next block
+     myEndCursor.setPosition(QTextCursor::End);//end of document
   }
-  mIndex = mText->paragraphLength(mParagraph);
+  textCursor().setPosition(QTextCursor::End);
 }
 
-void QgsGrassShell::insert ( QString s )
+void QgsGrassShell::insert ( QString theString )
 {
 #ifdef QGISDEBUG
   std::cerr << "insert()" << std::endl;
 #endif
 
-  if ( s.isEmpty() ) return; 
+  if ( theString.isEmpty() ) return; 
 
-  // In theory mParagraph == mText->paragrephs()-1
+  // In theory mBlockNo == paragraphs()-1
   // but if something goes wrong (more paragraphs) we want to write 
   // at the end
-  if ( mParagraph > -1 && mParagraph != mText->paragraphs()-1 )
+  if ( mBlockNo > -1 && mBlockNo != document()->blockCount()-1 )
   {
-    std::cerr << "WRONG mParagraph!" << std::endl;
+    std::cerr << "WRONG mBlockNo!" << std::endl;
     mNewLine = true;
   }
 
   // Bug?: QTextEdit::setOverwriteMode does not work, always 'insert'
   //       -> if Insert mode is not set, delete first the string 
   //          to the right
-  // mText->setOverwriteMode ( !mMode[Insert] ); // does not work
-  if ( !mMode[Insert] && !mNewLine && mParagraph >= 0 &&
-    mText->paragraphLength(mParagraph) > mIndex ) 
+  // setOverwriteMode ( !mMode[Insert] ); // does not work
+  if ( !mMode[Insert] && !mNewLine && mBlockNo >= 0  ) 
   {
 #ifdef QGISDEBUG
-    std::cerr << "erase old " << mIndex+s.length() << " chars "  << std::endl;
+    std::cerr << "erase old " << textCursor().position() + theString.length() << " chars "  << std::endl;
 #endif
-    mText->setSelection ( mParagraph, mIndex, mParagraph, mIndex+s.length(), 0 );
-    mText->removeSelectedText ( 0 );
+    
+    textCursor().clearSelection();
+    textCursor().setPosition ( textCursor().position(), QTextCursor::MoveAnchor );
+    //If the anchor() is kept where it is and the position() is moved, the text in between will be selected.
+    textCursor().setPosition (  textCursor().position() + theString.length(), QTextCursor::KeepAnchor );
+    textCursor().removeSelectedText ( );
   }
 
   if ( mNewLine )
   {
     // Start new paragraph
-    mText->setTextFormat(Qt::PlainText);
-    mText->setCurrentFont ( mFont ); 
-    mText->append ( s );
-    mIndex = s.length();
-    //mParagraph++;
-    mParagraph = mText->paragraphs()-1;
+    append ( theString );
+    //mBlockNo++;
+    mBlockNo = document()->blockCount()-1;
     mNewLine = false;
   }
   else
   {
-    // Append to existing paragraph
-    mText->setCursorPosition ( mParagraph, mIndex );
-    mText->setTextFormat(Qt::PlainText);
-    mText->setCurrentFont ( mFont ); 
-    mText->insert ( s );
-
-    mIndex += s.length(); 
+    insertPlainText ( theString );
+    textCursor().setPosition(textCursor().position() + theString.length()); 
   }
 }
 
@@ -857,18 +883,14 @@
 {
   if ( mSkipLines > 0 )
   {
-    mText->clear();
     mSkipLines--;
   }
   if ( mNewLine ) 
   {
-    mText->setTextFormat(Qt::PlainText);
-    mText->setCurrentFont ( mFont ); 
-    mText->append ( " " );
-    //mParagraph++; 
+    append ( " " );
+    //mBlockNo++; 
     // To be sure that we are at the end
-    mParagraph = mText->paragraphs()-1;
-    mIndex = 0;
+    mBlockNo = document()->blockCount()-1;
   }
   mNewLine = true;
 }
@@ -876,34 +898,39 @@
 void QgsGrassShell::eraseCursor()
 {
   // Remove space representing cursor from the end of current paragraph
-  if ( !mNewLine && mCursorSpace && mParagraph >= 0 ) 
+  if ( !mNewLine && mCursorSpace && mBlockNo >= 0 ) 
   {
-    mText->setSelection ( mParagraph, mIndex, mParagraph, mIndex+1, 0 );
-    mText->removeSelectedText ( 0 );
+    textCursor().setPosition (  textCursor().position(), QTextCursor::MoveAnchor );
+    //If the anchor() is kept where it is and the position() is moved, the text in between will be selected.
+    textCursor().setPosition (  textCursor().position() + 1, QTextCursor::KeepAnchor );
+    textCursor().removeSelectedText ( );
+    
   }
   mCursorSpace = false;
 }
 
+/* Chuck this - we use the inbuilt QTextEdit cursor rather
 void QgsGrassShell::showCursor()
 {
   // Do not highlite cursor if last printed paragraph was GRASS message
   if ( mNewLine ) return;
-
   // If cursor is at the end of paragraph add space  
-  if ( mParagraph >= 0 && mIndex > mText->paragraphLength(mParagraph)-1 )
+  if ( mBlockNo >= 0 && textCursor().atBlockEnd() )
   {
-    mText->setCursorPosition(mParagraph,mIndex);
-    mText->setCursorPosition ( mParagraph, mIndex );
-    mText->insert ( " " );
-    // Warning: do not increase mIndex, 
+    textCursor().setPosition (  textCursor().position(), QTextCursor::MoveAnchor  );
+    insert ( " " );
     // the space if after current position
     mCursorSpace = true;
   }
 
-  // Selection 1 is used as cursor highlite
-  mText->setSelection ( mParagraph, mIndex, mParagraph, mIndex+1, 1 );
-  mText->setSelectionAttributes ( 1, QColor(0,0,0), true );  
+  // Highlight the cursor
+  textCursor().setPosition (  textCursor().position(), QTextCursor::MoveAnchor );
+    //If the anchor() is kept where it is and the position() is moved, the text in between will be selected.
+  textCursor().setPosition (  textCursor().position() + 1, QTextCursor::KeepAnchor );
+  //@todo work out how to do this in Qt4
+  //setSelectionAttributes ( 1, QColor(0,0,0), true );  
 }
+*/
 
 void QgsGrassShell::mousePressEvent(QMouseEvent* e)
 {
@@ -913,6 +940,7 @@
 
   if ( !mValid ) return;
 
+  //@TODO Add some logic to check click was in textedit
   // paste clipboard
   if ( e->button() == Qt::MidButton )
   {
@@ -920,24 +948,35 @@
     QString text = cb->text(QClipboard::Selection);
     write( mFdMaster, (char*) text.ascii(), text.length() );
   }
+  else
+  {
+    QTextEdit::mousePressEvent(e);
+  }
 }
-
+void QgsGrassShell::resizeEvent(QResizeEvent *e)
+{
+#ifdef QGISDEBUG
+  std::cerr << "resizeEvent()" << std::endl;
+#endif
+  resizeTerminal();
+}
 void QgsGrassShell::resizeTerminal()
 {
 #ifndef WIN32
-  int width = mText->visibleWidth(); 
-  int height = mText->visibleHeight(); 
 
-  QFontMetrics fm ( mFont );
-  int col = (int) (width / fm.width("x")); 
-  int row = (int) (height / fm.height()); 
 
+  QFontMetrics fm ( font() );
+  int col = (int) (width() / fm.width("x")); 
+  int row = (int) (height() / fm.height()); 
+
   struct winsize winSize;
   memset(&winSize, 0, sizeof(winSize));
   winSize.ws_row = row;
   winSize.ws_col = col;
 
   ioctl( mFdMaster, TIOCSWINSZ, (char *)&winSize );
+  setLineWrapMode(QTextEdit::FixedColumnWidth);
+  setLineWrapColumnOrWidth(col);
 #endif
 }
 
@@ -948,45 +987,4 @@
 
 
 
-QgsGrassShellText::QgsGrassShellText ( QgsGrassShell *gs, 
-    QWidget * parent, const char *name )
-: Q3TextEdit (parent,name),
-mShell(gs)
-{
-}
 
-QgsGrassShellText::~QgsGrassShellText() {} 
-
-void QgsGrassShellText::contentsMousePressEvent(QMouseEvent* e)
-{
-#ifdef QGISDEBUG
-  std::cerr << "contentsMousePressEvent()" << std::endl;
-#endif
-  mShell->mousePressEvent(e);
-  Q3TextEdit::contentsMousePressEvent(e);
-}
-
-void QgsGrassShellText::keyPressEvent ( QKeyEvent * e )
-{
-#ifdef QGISDEBUG
-  std::cerr << "QgsGrassShellText::keyPressEvent()" << std::endl;
-#endif
-  mShell->keyPressEvent(e);
-}
-
-void QgsGrassShellText::keyReleaseEvent ( QKeyEvent * e )
-{
-#ifdef QGISDEBUG
-  std::cerr << "QgsGrassShellText::keyReleaseEvent()" << std::endl;
-#endif
-  mShell->keyReleaseEvent(e);
-}
-
-void QgsGrassShellText::resizeEvent(QResizeEvent *e)
-{
-#ifdef QGISDEBUG
-  std::cerr << "resizeEvent()" << std::endl;
-#endif
-  mShell->resizeTerminal();
-  Q3TextEdit::resizeEvent(e);
-}

Modified: branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshell.h
===================================================================
--- branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshell.h	2008-07-24 16:28:57 UTC (rev 8893)
+++ branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshell.h	2008-07-24 22:10:20 UTC (rev 8894)
@@ -1,9 +1,9 @@
 /***************************************************************************
      qgsgrassshell.h
-     --------------------------------------
-    Date                 : Sun Sep 16 12:06:16 AKDT 2007
-    Copyright            : (C) 2007 by Gary E. Sherman
-    Email                : sherman at mrcc dot com
+
+    Date                 : Sun Sep 16 12:06:10 AKDT 2007
+    Copyright            : (C) 2007 by Radim Blazek 
+    Email                : blazek at itc.it
  ***************************************************************************
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -14,22 +14,15 @@
  ***************************************************************************/
 
 #include <QByteArray>
-#include <Q3Process>
-#include <Q3TextEdit>
-#include <QDialog>
-#include <QKeyEvent>
+#include <QProcess>
 #include <QMessageBox>
-#include <QMouseEvent>
-#include <QResizeEvent>
 #include <QSocketNotifier>
-#include <QString>
+#include <QPointer>
+#include <QTextEdit>
 
-#include "qgsgrasstools.h"
-#include "ui_qgsgrassshellbase.h"
+class QProgressBar;
 
-class QTabWidget;
 
-class QgsGrassShellText;
 
 extern "C" {
 #include <stdio.h>
@@ -70,13 +63,12 @@
  * are transformed to appropriate output written to QTextEdit.
  */
 
-class QgsGrassShell: public QDialog, private Ui::QgsGrassShellBase
+class QgsGrassShell: public QTextEdit
 {
     Q_OBJECT;
 
 public:
-    QgsGrassShell ( QgsGrassTools *tools, 
-                    QWidget * parent = 0, const char * name = 0 );
+    QgsGrassShell (QWidget * parent = 0, const char * name = 0 );
     ~QgsGrassShell();
 
     // Modes 
@@ -98,7 +90,7 @@
         Underline,
         Blink,
         Reverse,
-        RendetionCount
+        RenditionCount
     };
 
     // Pressed key 
@@ -130,8 +122,8 @@
     // Erase cursor highlight (space)
     void eraseCursor(void);
 
-    // Highlite cursor
-    void showCursor(void);
+    // Highlite cursor - delete this? [TS]
+   //void showCursor(void);
 
     // Reset pseudoterminal size
     void resizeTerminal ();
@@ -141,14 +133,20 @@
 
     // Reset cursor to current position
     //void setCursorPosition();
-
+    
 public slots:
-    void readStdout(int socket);
-    void readStderr();
-    void keyPressEvent ( QKeyEvent * e );
-    void keyReleaseEvent ( QKeyEvent * e );
-    void mousePressEvent(QMouseEvent* e);
 
+  void focusInEvent ( QFocusEvent * event );
+  void focusOutEvent ( QFocusEvent * event );
+  // filter keypresses from going to main app
+  bool eventFilter( QObject *object, QEvent *event );
+  void keyPressEvent ( QKeyEvent * e );
+  void keyReleaseEvent ( QKeyEvent * e );
+  void mousePressEvent(QMouseEvent* e);
+  void resizeEvent ( QResizeEvent * );
+
+  void readStdout(int socket);
+  void readStderr();
 signals:
 
 private:
@@ -180,23 +178,21 @@
     bool mCursorSpace; 
 
     // Current cursor position
-    int mParagraph;
-    int mIndex;
+    int mBlockNo;
+    int mPosition;
 
-    // Text widget
-    QgsGrassShellText *mText;
+    // Progress bar
+    QPointer <QProgressBar> mpProgressBar;
 
-    // Default text font
-    QFont mFont;
 
-    // Rendetion
-    bool mRendetion[RendetionCount];
+    // Rendition
+    bool mRendition[RenditionCount];
 
     // Pressed keys
     bool mKeyDown[KeyDownCount];
 
 
-    // Create new line in nex insert
+    // Create new line in next insert
     // This must be used because QTextEdit will remove all empty
     // paragraphs
     bool mNewLine;
@@ -212,19 +208,5 @@
     
 };
 
-class QgsGrassShellText : public Q3TextEdit
-{
-    Q_OBJECT;
-public:
-    QgsGrassShellText ( QgsGrassShell *, 
-	                QWidget * parent = 0, const char * name = 0 );
-    ~QgsGrassShellText();
-public slots:
-    void contentsMousePressEvent(QMouseEvent *);
-    void resizeEvent ( QResizeEvent *);
-    void keyPressEvent ( QKeyEvent * e );
-    void keyReleaseEvent ( QKeyEvent * e );
-private:
-    QgsGrassShell *mShell;
-};
 
+

Modified: branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshellbase.ui
===================================================================
--- branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshellbase.ui	2008-07-24 16:28:57 UTC (rev 8893)
+++ branches/grass-tidyup-branch/src/plugins/grass/qgsgrassshellbase.ui	2008-07-24 22:10:20 UTC (rev 8894)
@@ -1,69 +0,0 @@
-<ui version="4.0" >
- <class>QgsGrassShellBase</class>
- <widget class="QWidget" name="QgsGrassShellBase" >
-  <property name="geometry" >
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>600</width>
-    <height>434</height>
-   </rect>
-  </property>
-  <property name="minimumSize" >
-   <size>
-    <width>600</width>
-    <height>400</height>
-   </size>
-  </property>
-  <property name="windowTitle" >
-   <string>GRASS Shell</string>
-  </property>
-  <layout class="QGridLayout" >
-   <item row="0" column="0" colspan="2" >
-    <widget class="QFrame" name="mTextFrame" >
-     <property name="frameShape" >
-      <enum>QFrame::StyledPanel</enum>
-     </property>
-     <property name="frameShadow" >
-      <enum>QFrame::Raised</enum>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="0" >
-    <widget class="QProgressBar" name="mProgressBar" >
-     <property name="value" >
-      <number>0</number>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="1" >
-    <widget class="QDialogButtonBox" name="buttonBox" >
-     <property name="standardButtons" >
-      <set>QDialogButtonBox::Close</set>
-     </property>
-    </widget>
-   </item>
-  </layout>
- </widget>
- <layoutdefault spacing="6" margin="11" />
- <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
- <resources/>
- <connections>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>accepted()</signal>
-   <receiver>QgsGrassShellBase</receiver>
-   <slot>close()</slot>
-   <hints>
-    <hint type="sourcelabel" >
-     <x>561</x>
-     <y>417</y>
-    </hint>
-    <hint type="destinationlabel" >
-     <x>565</x>
-     <y>432</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
-</ui>



More information about the QGIS-commit mailing list