[QGIS Commit] r8778 - trunk/qgis/src/plugins/grass

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Jul 14 18:08:48 EDT 2008


Author: timlinux
Date: 2008-07-14 18:08:48 -0400 (Mon, 14 Jul 2008)
New Revision: 8778

Added:
   trunk/qgis/src/plugins/grass/qgsgrasstoolsbase.ui
Modified:
   trunk/qgis/src/plugins/grass/CMakeLists.txt
   trunk/qgis/src/plugins/grass/qgsgrasstools.cpp
   trunk/qgis/src/plugins/grass/qgsgrasstools.h
Log:
Implement grass toolbox as a designer ui and make toolbox subclass it - reduces the amount of manually (programmatically) constructed gui code required.

Modified: trunk/qgis/src/plugins/grass/CMakeLists.txt
===================================================================
--- trunk/qgis/src/plugins/grass/CMakeLists.txt	2008-07-14 20:23:43 UTC (rev 8777)
+++ trunk/qgis/src/plugins/grass/CMakeLists.txt	2008-07-14 22:08:48 UTC (rev 8778)
@@ -42,6 +42,7 @@
 )
 
 SET (GRASS_PLUGIN_UIS
+     qgsgrasstoolsbase.ui
      qgsgrassselectbase.ui
      qgsgrasseditbase.ui
      qgsgrassmapcalcbase.ui

Modified: trunk/qgis/src/plugins/grass/qgsgrasstools.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrasstools.cpp	2008-07-14 20:23:43 UTC (rev 8777)
+++ trunk/qgis/src/plugins/grass/qgsgrasstools.cpp	2008-07-14 22:08:48 UTC (rev 8778)
@@ -95,27 +95,14 @@
 }
 #endif
 
-QgsGrassToolsTabWidget::QgsGrassToolsTabWidget( QWidget * parent ): 
-  QTabWidget(parent)
-{
-  // Default height seems to be too small for our purpose
-  int height = (int)(1.5 * tabBar()->iconSize().height());
-  // Max width (see QgsGrassModule::pixmap for hardcoded sizes)
-  int width = 3*height + 28 + 29;
-  tabBar()->setIconSize( QSize(width,height) );
-}
 
-QSize QgsGrassToolsTabWidget::iconSize()
-{
-  return tabBar()->iconSize();
-}
 
-QgsGrassToolsTabWidget::~QgsGrassToolsTabWidget() {}
-
 QgsGrassTools::QgsGrassTools ( QgisInterface *iface, 
 	                     QWidget * parent, const char * name, Qt::WFlags f )
- : QDialog ( parent )
+  : QDialog(parent, f ), QgsGrassToolsBase ()
 {
+  
+  setupUi(this);
 #ifdef QGISDEBUG
   std::cerr << "QgsGrassTools()" << std::endl;
 #endif
@@ -129,35 +116,14 @@
   connect( qApp, SIGNAL(aboutToQuit()), 
     this, SLOT(closeTools()) );
 
-  mTabWidget = new QgsGrassToolsTabWidget (this);
-  QVBoxLayout *layout1 = new QVBoxLayout(this);
-  layout1->addWidget(mTabWidget);
-
   //
   // Radims original tree view code.
   //
-  // Warning: if the tree is not the first page modules are 
-  // displayed over the other pages on first load
+  mModulesTree->header()->hide();
+ connect( mModulesTree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), 
+   this, SLOT(moduleClicked( QTreeWidgetItem *, int)) );
 
-  mModulesListView = new QTreeWidget();
-  mTabWidget->addTab( mModulesListView, tr("Modules Tree") );
-  mModulesListView->setColumnCount(1);
-  QStringList headers;
-  headers << tr("Modules");
-  mModulesListView->setHeaderLabels(headers);    
-  // Set list view
-  mModulesListView->clear();
-  mModulesListView->setSortingEnabled(false);
-  mModulesListView->setRootIsDecorated(true);
-  //    mModulesListView->setResizeMode(QTreeWidget::AllColumns);
-  mModulesListView->header()->hide();
 
-  connect( mModulesListView, SIGNAL(itemClicked(QTreeWidgetItem *, int)), 
-    this, SLOT(moduleClicked( QTreeWidgetItem *, int)) );
-
-  
-
-
   //
   // Tims experimental list view with filter
   //
@@ -165,20 +131,16 @@
   mModelProxy = new QSortFilterProxyModel(this);
   mModelProxy->setSourceModel(mModelTools);
   mModelProxy->setFilterRole(Qt::UserRole + 2);
-  mListView = new QListView();
+
   mListView->setModel(mModelProxy);
-  mListView->setFocus();
   mListView->setItemDelegateForColumn(0,new QgsDetailedItemDelegate());
   mListView->setUniformItemSizes(false);
-
-  QWidget * mypBase = new QWidget(this);
-  QVBoxLayout * mypListTabLayout = new QVBoxLayout(mypBase);
-  mypListTabLayout->addWidget(mListView);
-  mFilterInput = new QLineEdit(this);
-  mypListTabLayout->addWidget(mFilterInput);
-  mTabWidget->addTab( mypBase, tr("Modules List") );
-  connect( mFilterInput, SIGNAL(textChanged(QString)), 
-    this, SLOT(filterChanged(QString)) );
+  //mListView2 = new QListView(this);
+  //mDockWidget = new QDockWidget(tr("Grass Tools"), 0);
+  //mDockWidget->setWidget(mListView2);
+  //mDockWidget->setObjectName("GrassTools");
+  //mDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+  //mIface->addDockWidget(Qt::LeftDockWidgetArea, mDockWidget);
   connect( mListView, SIGNAL(clicked(const QModelIndex)), 
     this, SLOT(listItemClicked(const QModelIndex)));
   //
@@ -201,8 +163,7 @@
   QString title = tr("GRASS Tools: ") + QgsGrass::getDefaultLocation()
       + "/" + QgsGrass::getDefaultMapset();
   setCaption(title);
-  mModulesListView->show(); 
-  mListView->show();
+
   
     // Add map browser 
   mBrowser = new QgsGrassBrowser ( mIface, this );
@@ -322,7 +283,6 @@
   is.addPixmap ( pixmap2 );
   mTabWidget->addTab ( m, is, "" );
 
-  QgsGrassToolsTabWidget tw;
 
   mTabWidget->setCurrentPage ( mTabWidget->count()-1 );
 
@@ -338,8 +298,8 @@
 #ifdef QGISDEBUG
   std::cerr << "QgsGrassTools::loadConfig(): " << filePath.toLocal8Bit().data() << std::endl;
 #endif
-  mModulesListView->clear();
-  mModulesListView->setIconSize(QSize(80,22));
+  mModulesTree->clear();
+  mModulesTree->setIconSize(QSize(80,22));
 
   QFile file ( filePath );
 
@@ -407,7 +367,7 @@
       } 
       else 
       {
-        item = new QTreeWidgetItem( mModulesListView, lastItem );
+        item = new QTreeWidgetItem( mModulesTree, lastItem );
       }
 
       if ( e.tagName() == "section" ) 
@@ -415,7 +375,7 @@
         QString label = e.attribute("label");
         QgsDebugMsg( QString("label = %1").arg(label) );
         item->setText( 0, label );
-        item->setExpanded(true); // for debuging to spare one click
+        item->setExpanded(true); 
 
         addModules ( item, e );
 
@@ -548,7 +508,7 @@
 // Helper function for Tim's experimental model list
 //
 
-void QgsGrassTools::filterChanged(QString theText)
+void QgsGrassTools::on_mFilterInput_textChanged(QString theText)
 {
   QgsDebugMsg("PluginManager filter changed to :" + theText);
   QRegExp::PatternSyntax mySyntax = QRegExp::PatternSyntax(QRegExp::RegExp);

Modified: trunk/qgis/src/plugins/grass/qgsgrasstools.h
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrasstools.h	2008-07-14 20:23:43 UTC (rev 8777)
+++ trunk/qgis/src/plugins/grass/qgsgrasstools.h	2008-07-14 22:08:48 UTC (rev 8778)
@@ -31,8 +31,11 @@
 class QgsGrassBrowser;
 class QgsMapCanvas;
 
+#include "ui_qgsgrasstoolsbase.h"
+
 #include <QDialog>
 #include <QTabWidget>
+#include <QDockWidget>
 
 //
 // For experimental filterable list model by Tim
@@ -42,25 +45,13 @@
 #include <QStandardItemModel>
 #include <QSortFilterProxyModel>
 
-class QgsGrassToolsTabWidget: public QTabWidget
-{
-    Q_OBJECT;
 
-public:
-    //! Constructor
-    QgsGrassToolsTabWidget ( QWidget * parent = 0 );
 
-    //! Destructor
-    ~QgsGrassToolsTabWidget();
-
-    QSize iconSize();
-};
-
 /*! \class QgsGrassTools
  *  \brief Interface to GRASS modules.
  *
  */
-class QgsGrassTools: public QDialog
+class QgsGrassTools: public QDialog, private Ui::QgsGrassToolsBase
 {
     Q_OBJECT;
 
@@ -107,8 +98,8 @@
     //! Close open tabs with tools
     void closeTools();
 
-    //! Update the regex used to filter the modules list 
-    void filterChanged(QString theText);
+    //! Update the regex used to filter the modules list (autoconnect to ui)
+    void on_mFilterInput_textChanged(QString theText);
     //! Run a module when its entry is clicked in the list view
     void listItemClicked(const QModelIndex &theIndex );
     //! Run a module given its module name e.g. r.in.gdal
@@ -126,17 +117,14 @@
     //! Browser
     QgsGrassBrowser *mBrowser;
 
-    QgsGrassToolsTabWidget *mTabWidget;
-    QTreeWidget *mModulesListView;
 
-
     //
     // For experimental model & filtered model by Tim
     //
-    QListView * mListView;
     QStandardItemModel * mModelTools;
     QSortFilterProxyModel * mModelProxy;
-    QLineEdit * mFilterInput;
+    QListView * mListView2;
+    QDockWidget * mDockWidget;
 
 };
 

Added: trunk/qgis/src/plugins/grass/qgsgrasstoolsbase.ui
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrasstoolsbase.ui	                        (rev 0)
+++ trunk/qgis/src/plugins/grass/qgsgrasstoolsbase.ui	2008-07-14 22:08:48 UTC (rev 8778)
@@ -0,0 +1,118 @@
+<ui version="4.0" >
+ <class>QgsGrassToolsBase</class>
+ <widget class="QDialog" name="QgsGrassToolsBase" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Grass Tools</string>
+  </property>
+  <layout class="QGridLayout" >
+   <item row="0" column="0" >
+    <widget class="QTabWidget" name="mTabWidget" >
+     <property name="currentIndex" >
+      <number>0</number>
+     </property>
+     <widget class="QWidget" name="modulesTree" >
+      <attribute name="title" >
+       <string>Modules Tree</string>
+      </attribute>
+      <layout class="QGridLayout" >
+       <item row="0" column="0" >
+        <widget class="QTreeWidget" name="mModulesTree" >
+         <property name="indentation" >
+          <number>8</number>
+         </property>
+         <property name="rootIsDecorated" >
+          <bool>false</bool>
+         </property>
+         <property name="wordWrap" >
+          <bool>true</bool>
+         </property>
+         <property name="headerHidden" stdset="0" >
+          <bool>true</bool>
+         </property>
+         <column>
+          <property name="text" >
+           <string>1</string>
+          </property>
+         </column>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="modulesList" >
+      <attribute name="title" >
+       <string>Modules List</string>
+      </attribute>
+      <layout class="QGridLayout" >
+       <item row="0" column="0" >
+        <widget class="QListView" name="mListView" >
+         <property name="alternatingRowColors" >
+          <bool>true</bool>
+         </property>
+         <property name="wordWrap" >
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="0" >
+        <widget class="QLineEdit" name="mFilterInput" />
+       </item>
+      </layout>
+     </widget>
+    </widget>
+   </item>
+   <item row="1" column="0" >
+    <widget class="QDialogButtonBox" name="buttonBox" >
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons" >
+      <set>QDialogButtonBox::Close|QDialogButtonBox::Help|QDialogButtonBox::NoButton</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>QgsGrassToolsBase</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>252</x>
+     <y>295</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>QgsGrassToolsBase</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>320</x>
+     <y>295</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>



More information about the QGIS-commit mailing list