[QGIS Commit] r8603 - in trunk/qgis/src: app gui plugins/grass

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Jun 6 09:29:03 EDT 2008


Author: timlinux
Date: 2008-06-06 09:29:03 -0400 (Fri, 06 Jun 2008)
New Revision: 8603

Modified:
   trunk/qgis/src/app/qgspluginmanager.cpp
   trunk/qgis/src/gui/qgsdetaileditemdata.cpp
   trunk/qgis/src/gui/qgsdetaileditemdata.h
   trunk/qgis/src/gui/qgsdetaileditemdelegate.cpp
   trunk/qgis/src/plugins/grass/qgsgrasstools.cpp
Log:
Refactored grass tools and plugin manager to always use qgsdetaileditemdata to represent the info to be display in items. This will let us switch between widget based and manually drawn implementations easily.


Modified: trunk/qgis/src/app/qgspluginmanager.cpp
===================================================================
--- trunk/qgis/src/app/qgspluginmanager.cpp	2008-06-06 11:33:19 UTC (rev 8602)
+++ trunk/qgis/src/app/qgspluginmanager.cpp	2008-06-06 13:29:03 UTC (rev 8603)
@@ -50,6 +50,13 @@
 #include <dlfcn.h>
 #endif
 #endif
+
+
+const int PLUGIN_DATA_ROLE=Qt::UserRole;
+const int PLUGIN_LIBRARY_ROLE=Qt::UserRole + 1;
+const int PLUGIN_LIBRARY_NAME_ROLE=Qt::UserRole + 2;
+const int PLUGIN_FILTER_ROLE=Qt::UserRole + 3;
+
 QgsPluginManager::QgsPluginManager(QgsPythonUtils* pythonUtils, QWidget * parent, Qt::WFlags fl)
 : QDialog(parent, fl)
 {
@@ -98,7 +105,6 @@
   mModelPlugins= new QStandardItemModel(0,1);
   mModelProxy = new QSortFilterProxyModel(this);
   mModelProxy->setSourceModel(mModelPlugins);
-  //mModelProxy->setFilterKeyColumn(0);
   vwPlugins->setModel(mModelProxy);
   vwPlugins->setFocus();
   vwPlugins->setItemDelegateForColumn(0,new QgsDetailedItemDelegate());
@@ -138,31 +144,28 @@
     QString description = mPythonUtils->getPluginMetadata(packageName, "description");
     QString version     = mPythonUtils->getPluginMetadata(packageName, "version");
     
-    if (pluginName == "???" || description == "???" || version == "???")
-      continue;
+    if (pluginName == "???" || description == "???" || version == "???") continue;
 
-    // We will create two items for each row:
-    // The first has the following roles :
-    // - DisplayRole : the name and version of the version of the plugin e.g. Plugin Foo (version 1.0)
-    // - UserRole : the description of the plugin.
-    // And the second has these roles :
-    // - DisplayRole : the library name (without path) for the plugin e.g. libfoo.so
-    // - UserRole : the name of the plugin without version e.g. plugin foor
-    // The plugin name without version is used elsewhere in this class to match
-    // aganst plugins loaded in the plugin registry
-    QStandardItem * mypDetailItem = new QStandardItem(
-        pluginName + " (" + version + ")");
-    mypDetailItem->setData(description,Qt::UserRole);
+    QStandardItem * mypDetailItem = new QStandardItem( pluginName );
     QString myLibraryName = "python:" + packageName;;
-    QStandardItem * mypLibraryNameItem = new QStandardItem(myLibraryName);
-    mypLibraryNameItem->setData(pluginName,Qt::UserRole);
-    // myName have a checkbox
-    mypDetailItem->setCheckable(true);
+    mypDetailItem->setData(myLibraryName, PLUGIN_LIBRARY_ROLE); //for loading libs later
+    mypDetailItem->setData(pluginName, PLUGIN_LIBRARY_NAME_ROLE); //for matching in registry later
+    QString mySearchText = pluginName + " - " + description;
+    mypDetailItem->setData(mySearchText , PLUGIN_FILTER_ROLE); //for filtering later
+    mypDetailItem->setCheckable(false);
     mypDetailItem->setEditable(false);
+    // setData in the delegate with a variantised QgsDetailedItemData
+    QgsDetailedItemData myData;
+    myData.setTitle(pluginName + " (" + version + ")");
+    myData.setDetail(description);
+    //myData.setIcon(pixmap); //todo use a python logo here
+    myData.setCheckable(true);
+    myData.setRenderAsWidget(false);
+    QVariant myVariant = qVariantFromValue(myData);
+    mypDetailItem->setData(myVariant,PLUGIN_DATA_ROLE);
 
     // check to see if the plugin is loaded and set the checkbox accordingly
     QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
-
     QString libName = pRegistry->library(pluginName);
     if (libName.length() == 0 || !pRegistry->isPythonPlugin(pluginName))
     {
@@ -177,10 +180,8 @@
         mypDetailItem->setCheckState(Qt::Checked);
       }
     }
-    // Add items to model
-    QList<QStandardItem *> myItems;
-    myItems << mypDetailItem << mypLibraryNameItem;
-    mModelPlugins->appendRow(myItems);
+    // Add item to model
+    mModelPlugins->appendRow(mypDetailItem);
   }
 }
 
@@ -262,19 +263,28 @@
     version_t *pVersion = (version_t *) myLib->resolve("version");
 
     // show the values (or lack of) for each function
-    if(pName){
+    if(pName)
+    {
       QgsDebugMsg("Plugin name: " + pName());
-    }else{
+    }
+    else
+    {
       QgsDebugMsg("Plugin name not returned when queried\n");
     }
-    if(pDesc){
+    if(pDesc)
+    {
       QgsDebugMsg("Plugin description: " + pDesc());
-    }else{
+    }
+    else
+    {
       QgsDebugMsg("Plugin description not returned when queried\n");
     }
-    if(pVersion){
+    if(pVersion)
+    {
       QgsDebugMsg("Plugin version: " + pVersion());
-    }else{
+    }
+    else
+    {
       QgsDebugMsg("Plugin version not returned when queried\n");
     }
 
@@ -285,39 +295,20 @@
       continue;
     }
 
-    // We will create two items for each row:
-    // The first has the following roles :
-    // - DisplayRole : the name and version of the version of the plugin e.g. Plugin Foo (version 1.0)
-    // - UserRole : the description of the plugin.
-    // And the second has these roles :
-    // - DisplayRole : the library name (without path) for the plugin e.g. libfoo.so
-    // - UserRole : the name of the plugin without version e.g. plugin foor
-    // The plugin name without version is used elsewhere in this class to match
-    // aganst plugins loaded in the plugin registry
-        
-    QStandardItem * mypDetailItem = new QStandardItem(
-        pName() + " (" + pVersion() + ")");
-    //
-    // Uncomment this block to render item using simple painter technique
-    // 
-    mypDetailItem->setData(pDesc(),Qt::UserRole);
-    //
-    //Uncomment this block to used widget based detail items (experimental)
-    //
-    /*
+    QString myLibraryName = pluginDir[i];
+    QStandardItem * mypDetailItem = new QStandardItem(myLibraryName);
+    mypDetailItem->setData(myLibraryName,PLUGIN_LIBRARY_ROLE);
+    mypDetailItem->setData(pName(), PLUGIN_LIBRARY_NAME_ROLE); //for matching in registry later
     QgsDetailedItemData myData;
     myData.setTitle(pName());
     myData.setDetail(pDesc());
+    myData.setRenderAsWidget(false);
     QVariant myVariant = qVariantFromValue(myData);
     //round trip test - delete this...no need to uncomment
     //QgsDetailedItemData myData2 = qVariantValue<QgsDetailedItemData>(myVariant);
     //Q_ASSERT(myData.title() == myData2.title());
     //round trip test ends
-    mypDetailItem->setData(myVariant,Qt::UserRole);
-    */
-    QString myLibraryName = pluginDir[i];
-    QStandardItem * mypLibraryNameItem = new QStandardItem(myLibraryName);
-    mypLibraryNameItem->setData(pName(),Qt::UserRole);
+    mypDetailItem->setData(myVariant,PLUGIN_DATA_ROLE);
     // Let the first col  have a checkbox
     mypDetailItem->setCheckable(true);
     mypDetailItem->setEditable(false);
@@ -326,9 +317,9 @@
 
     // check to see if the plugin is loaded and set the checkbox accordingly
     QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
+    QString libName = pRegistry->library(pName());
 
     // get the library using the plugin description
-    QString libName = pRegistry->library(pName());
     if (libName.length() == 0)
     {
       QgsDebugMsg("Couldn't find library name in the registry");
@@ -343,9 +334,7 @@
       }
     }
     // Add items to model
-    QList<QStandardItem *> myItems;
-    myItems << mypDetailItem << mypLibraryNameItem;
-    mModelPlugins->appendRow(myItems);
+    mModelPlugins->appendRow(mypDetailItem);
 
     delete myLib;
   }
@@ -369,15 +358,16 @@
     QModelIndex myIndex=mModelPlugins->index(row,0);
     if (mModelPlugins->data(myIndex,Qt::CheckStateRole).toInt() == 0)
     {
-      // Get the second col index now since it stores the 
-      // plugin name without version string in its data UserRole [ts]
-      myIndex=mModelPlugins->index(row,1);
+      // iThe plugin name without version string in its data PLUGIN_LIB [ts]
+      myIndex=mModelPlugins->index(row,0);
       // its off -- see if it is loaded and if so, unload it
       QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
 #ifdef QGISDEBUG
-      std::cout << "Checking to see if " << mModelPlugins->data(myIndex, Qt::UserRole).toString().toLocal8Bit().data() << " is loaded" << std::endl;
+      std::cout << "Checking to see if " << 
+        mModelPlugins->data(myIndex, PLUGIN_LIBRARY_NAME_ROLE).toString().toLocal8Bit().data() << 
+        " is loaded" << std::endl;
 #endif
-      QString pluginName = mModelPlugins->data(myIndex,Qt::UserRole).toString();
+      QString pluginName = mModelPlugins->data(myIndex,PLUGIN_LIBRARY_NAME_ROLE).toString();
       if (pRegistry->isPythonPlugin(pluginName))
       {
         if (mPythonUtils && mPythonUtils->isEnabled())
@@ -412,10 +402,10 @@
   {
     if (mModelPlugins->item(row,0)->checkState() == Qt::Checked)
     {
-      QString pluginName = mModelPlugins->item(row,1)->data(Qt::UserRole).toString();
+      QString pluginName = mModelPlugins->item(row,0)->data(PLUGIN_LIBRARY_NAME_ROLE).toString();
       bool pythonic = false;
 
-      QString library = mModelPlugins->item(row,1)->text();
+      QString library = mModelPlugins->item(row,0)->data(PLUGIN_LIBRARY_ROLE).toString();
       if (library.left(7) == "python:")
       {
         library = library.mid(7);
@@ -425,7 +415,15 @@
       {
         library = lblPluginDir->text() + QDir::separator() + library;
       }
-      pis.push_back(QgsPluginItem(pluginName, mModelPlugins->item(row,0)->text(), library, 0, pythonic));
+      // Ctor params for plugin item:
+      //QgsPluginItem(QString name=0, 
+      //              QString description=0, 
+      //              QString fullPath=0, 
+      //              QString type=0, 
+      //              bool python=false);
+      pis.push_back(QgsPluginItem(pluginName, 
+            mModelPlugins->item(row,0)->data(PLUGIN_FILTER_ROLE).toString(), 
+            library, 0, pythonic));
     }
 
   }
@@ -462,7 +460,7 @@
     // little hoop to get the correct item
     //
     QStandardItem * mypItem = 
-      mModelPlugins->findItems(theIndex.data(Qt::DisplayRole).toString()).first();
+      mModelPlugins->findItems(theIndex.data(Qt ::DisplayRole).toString()).first();
     if ( mypItem->checkState() == Qt::Checked )
     {
       mypItem->setCheckState(Qt::Unchecked);

Modified: trunk/qgis/src/gui/qgsdetaileditemdata.cpp
===================================================================
--- trunk/qgis/src/gui/qgsdetaileditemdata.cpp	2008-06-06 11:33:19 UTC (rev 8602)
+++ trunk/qgis/src/gui/qgsdetaileditemdata.cpp	2008-06-06 13:29:03 UTC (rev 8603)
@@ -19,6 +19,7 @@
 #include "qgsdetaileditemdata.h"
 QgsDetailedItemData::QgsDetailedItemData() 
 {
+  mRenderAsWidgetFlag=false;
 }
 
 QgsDetailedItemData::~QgsDetailedItemData()
@@ -47,6 +48,10 @@
 {
   mCheckedFlag = theFlag;
 }
+void QgsDetailedItemData::setRenderAsWidget(bool theFlag)
+{
+  mRenderAsWidgetFlag = theFlag;
+}
 
 QString QgsDetailedItemData::title()
 {
@@ -72,3 +77,9 @@
 {
   return mCheckedFlag;
 }
+
+bool QgsDetailedItemData::isRenderedAsWidget()
+{
+  return mRenderAsWidgetFlag;
+}
+

Modified: trunk/qgis/src/gui/qgsdetaileditemdata.h
===================================================================
--- trunk/qgis/src/gui/qgsdetaileditemdata.h	2008-06-06 11:33:19 UTC (rev 8602)
+++ trunk/qgis/src/gui/qgsdetaileditemdata.h	2008-06-06 13:29:03 UTC (rev 8603)
@@ -36,12 +36,20 @@
     void setIcon(QPixmap theIcon);
     void setCheckable(bool theFlag);
     void setChecked(bool theFlag);
+    /** This is a hint to the delegate to render using 
+     * a widget rather than manually painting every 
+     * part of the list item.
+     * @note the delegate may completely ignore this 
+     * depending on the delegate implementation.
+     */
+    void setRenderAsWidget(bool theFlag);
 
     QString title();
     QString detail();
     QPixmap icon();
     bool isCheckable();
     bool isChecked();
+    bool isRenderedAsWidget();
 
   private:
     QString mTitle;
@@ -50,6 +58,7 @@
     QPixmap mPixmap;
     bool mCheckableFlag;
     bool mCheckedFlag;
+    bool mRenderAsWidgetFlag;
 };
 
 // Make QVariant aware of this data type (see qtdocs star 

Modified: trunk/qgis/src/gui/qgsdetaileditemdelegate.cpp
===================================================================
--- trunk/qgis/src/gui/qgsdetaileditemdelegate.cpp	2008-06-06 11:33:19 UTC (rev 8602)
+++ trunk/qgis/src/gui/qgsdetaileditemdelegate.cpp	2008-06-06 13:29:03 UTC (rev 8603)
@@ -46,145 +46,145 @@
       const QStyleOptionViewItem & theOption,
       const QModelIndex & theIndex) const
 {
+  // After painting we need to restore the painter to its original state
+  thepPainter->save();
   if (qVariantCanConvert<QgsDetailedItemData>(theIndex.data(Qt::UserRole))) 
   {
     QgsDetailedItemData myData = 
       qVariantValue<QgsDetailedItemData>(theIndex.data(Qt::UserRole));
     bool myCheckState = theIndex.model()->data(theIndex, Qt::CheckStateRole).toBool();
-    mpWidget->setChecked(myCheckState);
-    mpWidget->setData(myData);
-    mpWidget->resize(theOption.rect.width(),mpWidget->height());
-    mpWidget->setAutoFillBackground(false);
-    mpWidget->repaint();
+    if (myData.isRenderedAsWidget())
+    {
+      mpWidget->setChecked(myCheckState);
+      mpWidget->setData(myData);
+      mpWidget->resize(theOption.rect.width(),mpWidget->height());
+      mpWidget->setAutoFillBackground(false);
+      mpWidget->repaint();
 
-    if (theOption.state & QStyle::State_Selected)
+      if (theOption.state & QStyle::State_Selected)
+      {
+        QColor myColor1 = theOption.palette.highlight();
+        QColor myColor2 = myColor1;
+        myColor2 = myColor2.lighter(110); //10% lighter
+        QLinearGradient myGradient(QPointF(0,theOption.rect.y()),
+            QPointF(0,theOption.rect.y() + mpWidget->height()));
+        myGradient.setColorAt(0, myColor1);
+        myGradient.setColorAt(0.1, myColor2);
+        myGradient.setColorAt(0.5, myColor1);
+        myGradient.setColorAt(0.9, myColor2);
+        myGradient.setColorAt(1, myColor1);
+        thepPainter->fillRect(theOption.rect, QBrush(myGradient));
+      }
+      QPixmap myPixmap = QPixmap::grabWidget(mpWidget);
+      thepPainter->drawPixmap(theOption.rect.x(),
+          theOption.rect.y(), 
+          myPixmap);
+    } //render as widget 
+    else //render by manually painting
     {
-      QColor myColor1 = theOption.palette.highlight();
-      QColor myColor2 = myColor1;
-      myColor2 = myColor2.lighter(110); //10% lighter
-      QLinearGradient myGradient(QPointF(0,theOption.rect.y()),
-          QPointF(0,theOption.rect.y() + mpWidget->height()));
-      myGradient.setColorAt(0, myColor1);
-      myGradient.setColorAt(0.1, myColor2);
-      myGradient.setColorAt(0.5, myColor1);
-      myGradient.setColorAt(0.9, myColor2);
-      myGradient.setColorAt(1, myColor1);
-      thepPainter->fillRect(theOption.rect, QBrush(myGradient));
-    }
-    QPixmap myPixmap = QPixmap::grabWidget(mpWidget);
-    thepPainter->drawPixmap(theOption.rect.x(),
-        theOption.rect.y(), 
-        myPixmap);
-  } 
-  else 
-  {
-    // After painting we need to restore the painter to its original state
-    thepPainter->save();
-    //
-    // Get the strings and check box properties
-    //
-    QString myString = theIndex.model()->data(theIndex, Qt::DisplayRole).toString();
-    QString myDetailString = theIndex.model()->data(theIndex, Qt::UserRole).toString();
-    bool myCheckState = theIndex.model()->data(theIndex, Qt::CheckStateRole).toBool();
-    mpCheckBox->setChecked(myCheckState);
-    QPixmap myCbxPixmap(mpCheckBox->size());
-    mpCheckBox->render(&myCbxPixmap); //we will draw this onto the widget further down
-    QPixmap myDecoPixmap;
+      //
+      // Get the strings and check box properties
+      //
+      bool myCheckState = theIndex.model()->data(theIndex, Qt::CheckStateRole).toBool();
+      mpCheckBox->setChecked(myCheckState);
+      QPixmap myCbxPixmap(mpCheckBox->size());
+      mpCheckBox->render(&myCbxPixmap); //we will draw this onto the widget further down
 
-    //
-    // Calculate the widget height and other metrics
-    //
-    QFont myFont = theOption.font;
-    QFont myTitleFont = myFont;
-    myTitleFont.setBold(true);
-    myTitleFont.setPointSize(myFont.pointSize() + 3);
-    QFontMetrics myTitleMetrics(myTitleFont);
-    QFontMetrics myDetailMetrics(myFont);
-    int myVerticalSpacer = 3; //spacing between title and description
-    int myHorizontalSpacer = 5; //spacing between checkbox / icon and description
-    int myTextStartX = theOption.rect.x() + myHorizontalSpacer;
-    int myTextStartY= theOption.rect.y() + myVerticalSpacer;
-    int myHeight = myTitleMetrics.height() + myVerticalSpacer;
-
-    //
-    // Draw the item background with a gradient if its highlighted
-    //
-    if (theOption.state & QStyle::State_Selected)
-    {
-      QColor myColor1 = theOption.palette.highlight();
-      QColor myColor2 = myColor1;
-      myColor2 = myColor2.lighter(110); //10% lighter
+      //
+      // Calculate the widget height and other metrics
+      //
+      QFont myFont = theOption.font;
+      QFont myTitleFont = myFont;
+      myTitleFont.setBold(true);
+      myTitleFont.setPointSize(myFont.pointSize() + 3);
+      QFontMetrics myTitleMetrics(myTitleFont);
+      QFontMetrics myDetailMetrics(myFont);
+      int myVerticalSpacer = 3; //spacing between title and description
+      int myHorizontalSpacer = 5; //spacing between checkbox / icon and description
+      int myTextStartX = theOption.rect.x() + myHorizontalSpacer;
+      int myTextStartY= theOption.rect.y() + myVerticalSpacer;
       int myHeight = myTitleMetrics.height() + myVerticalSpacer;
-      QLinearGradient myGradient(QPointF(0,theOption.rect.y()),
-          QPointF(0,theOption.rect.y() + myHeight*2));
-      myGradient.setColorAt(0, myColor1);
-      myGradient.setColorAt(0.1, myColor2);
-      myGradient.setColorAt(0.5, myColor1);
-      myGradient.setColorAt(0.9, myColor2);
-      myGradient.setColorAt(1, myColor2);
-      thepPainter->fillRect(theOption.rect, QBrush(myGradient));
-    }
 
-    //
-    // Draw the checkbox
-    //
-    bool myCheckableFlag = true;
-    if (theIndex.flags() == Qt::ItemIsUserCheckable)
-    {
-      myCheckableFlag = false;
-    }
-    if (myCheckableFlag)
-    {
-      thepPainter->drawPixmap(theOption.rect.x(),
-          theOption.rect.y() + mpCheckBox->height(), 
-          myCbxPixmap);
-      myTextStartX = theOption.rect.x() + myCbxPixmap.width() + myHorizontalSpacer;
-    }
-    //
-    // Draw the decoration (pixmap)
-    //
-    bool myIconFlag = false;
-    if (!theIndex.model()->data(theIndex, Qt::DecorationRole).isNull())
-    {
-      myDecoPixmap = theIndex.model()->data(theIndex, Qt::DecorationRole).value<QPixmap>();
-      thepPainter->drawPixmap(myTextStartX,
-          myTextStartY + (myDecoPixmap.height() / 2), 
-          myDecoPixmap);
-      myTextStartX += myDecoPixmap.width() + myHorizontalSpacer;
-    }
-    //
-    // Draw the title 
-    //
-    myTextStartY += myHeight/2;
-    thepPainter->setFont(myTitleFont);
-    thepPainter->drawText( myTextStartX ,
-        myTextStartY , 
-        myString);
-    //
-    // Draw the description with word wrapping if needed
-    //
-    thepPainter->setFont(myFont); //return to original font set by client
-    if (myIconFlag)
-    {
-          myTextStartY += myVerticalSpacer;
-    }
-    else
-    {
-          myTextStartY +=  myDetailMetrics.height() + myVerticalSpacer;
-    }
-    QStringList myList = 
-      wordWrap( myDetailString, myDetailMetrics, theOption.rect.width() - myTextStartX );
-    QStringListIterator myLineWrapIterator(myList);
-    while (myLineWrapIterator.hasNext())
-    {
-      QString myLine = myLineWrapIterator.next();
-      thepPainter->drawText( myTextStartX, 
-          myTextStartY,
-          myLine);
-      myTextStartY += myDetailMetrics.height() - myVerticalSpacer;
-    }
-    thepPainter->restore();
-  }
+      //
+      // Draw the item background with a gradient if its highlighted
+      //
+      if (theOption.state & QStyle::State_Selected)
+      {
+        QColor myColor1 = theOption.palette.highlight();
+        QColor myColor2 = myColor1;
+        myColor2 = myColor2.lighter(110); //10% lighter
+        int myHeight = myTitleMetrics.height() + myVerticalSpacer;
+        QLinearGradient myGradient(QPointF(0,theOption.rect.y()),
+            QPointF(0,theOption.rect.y() + myHeight*2));
+        myGradient.setColorAt(0, myColor1);
+        myGradient.setColorAt(0.1, myColor2);
+        myGradient.setColorAt(0.5, myColor1);
+        myGradient.setColorAt(0.9, myColor2);
+        myGradient.setColorAt(1, myColor2);
+        thepPainter->fillRect(theOption.rect, QBrush(myGradient));
+      }
+
+      //
+      // Draw the checkbox
+      //
+      bool myCheckableFlag = true;
+      if (theIndex.flags() == Qt::ItemIsUserCheckable)
+      {
+        myCheckableFlag = false;
+      }
+      if (myCheckableFlag)
+      {
+        thepPainter->drawPixmap(theOption.rect.x(),
+            theOption.rect.y() + mpCheckBox->height(), 
+            myCbxPixmap);
+        myTextStartX = theOption.rect.x() + myCbxPixmap.width() + myHorizontalSpacer;
+      }
+      //
+      // Draw the decoration (pixmap)
+      //
+      bool myIconFlag = false;
+      QPixmap myDecoPixmap = myData.icon();
+      if (!myDecoPixmap.isNull())
+      {
+        thepPainter->drawPixmap(myTextStartX,
+            myTextStartY + (myDecoPixmap.height() / 2), 
+            myDecoPixmap);
+        myTextStartX += myDecoPixmap.width() + myHorizontalSpacer;
+      }
+      //
+      // Draw the title 
+      //
+      myTextStartY += myHeight/2;
+      thepPainter->setFont(myTitleFont);
+      thepPainter->drawText( myTextStartX ,
+          myTextStartY , 
+          myData.title());
+      //
+      // Draw the description with word wrapping if needed
+      //
+      thepPainter->setFont(myFont); //return to original font set by client
+      if (myIconFlag)
+      {
+        myTextStartY += myVerticalSpacer;
+      }
+      else
+      {
+        myTextStartY +=  myDetailMetrics.height() + myVerticalSpacer;
+      }
+      QStringList myList = 
+        wordWrap( myData.detail(), myDetailMetrics, theOption.rect.width() - myTextStartX );
+      QStringListIterator myLineWrapIterator(myList);
+      while (myLineWrapIterator.hasNext())
+      {
+        QString myLine = myLineWrapIterator.next();
+        thepPainter->drawText( myTextStartX, 
+            myTextStartY,
+            myLine);
+        myTextStartY += myDetailMetrics.height() - myVerticalSpacer;
+      }
+    } //render by manual painting
+  } //can convert item data
+  thepPainter->restore();
 }
 
 QSize QgsDetailedItemDelegate::sizeHint( 

Modified: trunk/qgis/src/plugins/grass/qgsgrasstools.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrasstools.cpp	2008-06-06 11:33:19 UTC (rev 8602)
+++ trunk/qgis/src/plugins/grass/qgsgrasstools.cpp	2008-06-06 13:29:03 UTC (rev 8603)
@@ -442,21 +442,15 @@
         mypDetailItem->setData(pixmap,Qt::DecorationRole);
         mypDetailItem->setCheckable(false);
         mypDetailItem->setEditable(false);
-
-      
-        // Render items using widget based detail items (experimental)
-        // Calling setData in the delegate with a variantised QgsDetailedItemData
-        // will cause the widget based mode to be enabled
-        //QgsDetailedItemData myData;
-        //myData.setTitle(name);
-        //myData.setDetail(label);
-        //myData.setIcon(pixmap);
-        //myData.setCheckable(false);
-        //QVariant myVariant = qVariantFromValue(myData);
-        //mypDetailItem->setData(myVariant,Qt::UserRole);
-        
-        //alternate invocation method using simple drawing code
-        mypDetailItem->setData(label,Qt::UserRole);
+        // setData in the delegate with a variantised QgsDetailedItemData
+        QgsDetailedItemData myData;
+        myData.setTitle(name);
+        myData.setDetail(label);
+        myData.setIcon(pixmap);
+        myData.setCheckable(false);
+        myData.setRenderAsWidget(true);
+        QVariant myVariant = qVariantFromValue(myData);
+        mypDetailItem->setData(myVariant,Qt::UserRole);
         mModelTools->appendRow(mypDetailItem);
         //
         // End of experimental work by Tim 



More information about the QGIS-commit mailing list