[QGIS Commit] r8784 - in branches/advanced_printing_branch/src: app/composer ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Jul 15 09:20:49 EDT 2008


Author: mhugent
Date: 2008-07-15 09:20:48 -0400 (Tue, 15 Jul 2008)
New Revision: 8784

Modified:
   branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposerlegendwidget.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposerlegendwidget.h
   branches/advanced_printing_branch/src/app/composer/qgslegendmodel.cpp
   branches/advanced_printing_branch/src/ui/qgscomposerlegendwidgetbase.ui
Log:
Possibility to move classification items of one layer up and down

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.cpp	2008-07-15 08:36:10 UTC (rev 8783)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.cpp	2008-07-15 13:20:48 UTC (rev 8784)
@@ -154,8 +154,7 @@
   QFontMetricsF itemFontMetrics(mItemFont);
   double itemHeight = std::max(mSymbolHeight, itemFontMetrics.height());
 
-  QStandardItem* firstItem;
-  QStandardItem* secondItem;
+  QStandardItem* currentItem;
 
   int numChildren = layerItem->rowCount();
 
@@ -169,46 +168,46 @@
       currentYCoord += mSymbolSpace;
       double currentXCoord = mBoxSpace;
      
-      firstItem = layerItem->child(i, 0);
-      secondItem = layerItem->child(i, 1);
-
-      if(secondItem) //an item with an icon
+      currentItem = layerItem->child(i, 0);
+      
+      if(!currentItem)
 	{
-	  QIcon symbolIcon = firstItem->icon();
-
-	  //take QgsSymbol* from user data
-	  QVariant symbolVariant = firstItem->data();
-	  if(!symbolVariant.canConvert<void*>())
-	    {
-	      continue;
-	    }
+	  continue;
+	}
+	
+      //take QgsSymbol* from user data
+      QVariant symbolVariant = currentItem->data();
+      QgsSymbol* symbol = 0;
+      if(symbolVariant.canConvert<void*>())
+	{
 	  void* symbolData = symbolVariant.value<void*>();
-	  QgsSymbol* symbol = (QgsSymbol*)(symbolData);
-	  if(!symbol)
-	    {
-	      continue;
-	    }
-
-	  //draw symbol considering output device resolution
+	  symbol = (QgsSymbol*)(symbolData);
+	}
+      
+      if(symbol)  //item with symbol?
+	{
+	  //draw symbol
 	  drawSymbol(p, symbol, currentYCoord + (itemHeight - mSymbolHeight) /2, currentXCoord);
 	  currentXCoord += mIconLabelSpace;
-	  
-	  if(p)
-	    {
-	      p->drawText(QPointF(currentXCoord, currentYCoord + itemFontMetrics.height()), secondItem->text());
-	    }
-
-	  maxXCoord = std::max(maxXCoord, currentXCoord + itemFontMetrics.width(secondItem->text()) + mBoxSpace);
 	}
-      else //an item witout icon (e.g. name of classification field)
+      else //item with icon?
 	{
-	  if(p)
+	  QIcon symbolIcon = currentItem->icon();
+	  if(!symbolIcon.isNull() && p)
 	    {
-	      p->drawText(QPointF(currentXCoord, currentYCoord + itemFontMetrics.height()), firstItem->text());
+	      symbolIcon.paint(p, currentXCoord, currentYCoord, mSymbolWidth, mSymbolHeight);
 	    }
-	  maxXCoord = std::max(maxXCoord, currentXCoord + itemFontMetrics.width(firstItem->text()) + mBoxSpace);
+	  currentXCoord += mIconLabelSpace;
 	}
- 
+      
+      //finally draw text
+      if(p)
+	{
+	  p->drawText(QPointF(currentXCoord, currentYCoord + itemFontMetrics.height()), currentItem->text());
+	}
+      
+      maxXCoord = std::max(maxXCoord, currentXCoord + itemFontMetrics.width(currentItem->text()) + mBoxSpace);
+      
       currentYCoord += itemHeight;
     }
 }

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerlegendwidget.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerlegendwidget.cpp	2008-07-15 08:36:10 UTC (rev 8783)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerlegendwidget.cpp	2008-07-15 13:20:48 UTC (rev 8784)
@@ -200,3 +200,91 @@
       mLegend->update();
     }
 }
+
+void QgsComposerLegendWidget::on_mMoveDownPushButton_clicked()
+{
+  QStandardItemModel* itemModel = dynamic_cast<QStandardItemModel*>(mItemTreeView->model());
+  if(!itemModel)
+    {
+      return;
+    }
+
+  QModelIndex currentIndex = mItemTreeView->currentIndex();
+  if(!currentIndex.isValid())
+    {
+      return;
+    }
+  
+  //is there an older sibling?
+  int row = currentIndex.row();
+  QModelIndex youngerSibling = currentIndex.sibling(row + 1, 0);
+
+  if(!youngerSibling.isValid())
+    {
+      return;
+    }
+
+  QModelIndex parentIndex = currentIndex.parent();
+  if(!parentIndex.isValid())
+    {
+      return;
+    }
+
+  //exchange the items
+  QStandardItem* parentItem = itemModel->itemFromIndex(parentIndex);
+  QList<QStandardItem*> youngerSiblingItem = parentItem->takeRow(row + 1);
+  QList<QStandardItem*> itemToMove = parentItem->takeRow(row);
+  
+  parentItem->insertRow(row, youngerSiblingItem);
+  parentItem->insertRow(row + 1, itemToMove); 
+  mItemTreeView->setCurrentIndex(itemModel->indexFromItem(itemToMove.at(0)));
+
+  if(mLegend)
+    {
+      mLegend->update();
+    }
+}
+
+void QgsComposerLegendWidget::on_mMoveUpPushButton_clicked()
+{
+  QStandardItemModel* itemModel = dynamic_cast<QStandardItemModel*>(mItemTreeView->model());
+  if(!itemModel)
+    {
+      return;
+    }
+
+  QModelIndex currentIndex = mItemTreeView->currentIndex();
+  if(!currentIndex.isValid())
+    {
+      return;
+    }
+
+  //is there an older sibling?
+  int row = currentIndex.row();
+  QModelIndex olderSibling = currentIndex.sibling(row - 1, 0);
+
+  if(!olderSibling.isValid())
+    {
+      return;
+    }
+
+  QModelIndex parentIndex = currentIndex.parent();
+  if(!parentIndex.isValid())
+    {
+      return;
+    }
+  
+  //exchange the items
+  QStandardItem* parentItem = itemModel->itemFromIndex(parentIndex);
+  QList<QStandardItem*> itemToMove = parentItem->takeRow(row);
+  QList<QStandardItem*> olderSiblingItem = parentItem->takeRow(row - 1);
+  
+  parentItem->insertRow(row - 1, itemToMove);
+  parentItem->insertRow(row, olderSiblingItem);
+  mItemTreeView->setCurrentIndex(itemModel->indexFromItem(itemToMove.at(0)));
+
+  if(mLegend)
+    {
+      mLegend->update();
+    }
+}

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerlegendwidget.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerlegendwidget.h	2008-07-15 08:36:10 UTC (rev 8783)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerlegendwidget.h	2008-07-15 13:20:48 UTC (rev 8784)
@@ -45,6 +45,10 @@
   void on_mBoxCheckBox_stateChanged(int state);
   void on_mBoxSpaceSpinBox_valueChanged(double d);
 
+  //item manipulation
+  void on_mMoveDownPushButton_clicked();
+  void on_mMoveUpPushButton_clicked();
+
  private:
   QgsComposerLegendWidget();
   /**Sets GUI according to state of mLegend*/

Modified: branches/advanced_printing_branch/src/app/composer/qgslegendmodel.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgslegendmodel.cpp	2008-07-15 08:36:10 UTC (rev 8783)
+++ branches/advanced_printing_branch/src/app/composer/qgslegendmodel.cpp	2008-07-15 13:20:48 UTC (rev 8784)
@@ -25,10 +25,6 @@
 
 QgsLegendModel::QgsLegendModel(): QStandardItemModel()
 {
-  QStringList headerLabels;
-  headerLabels << tr("Symbol");
-  headerLabels << tr("Value");
-  setHorizontalHeaderLabels(headerLabels);
 }
 
 QgsLegendModel::~QgsLegendModel()
@@ -108,17 +104,31 @@
 	  continue;
 	}
 
+       //label
+      QString label;
+      QString lowerValue = (*symbolIt)->lowerValue();
+      QString upperValue = (*symbolIt)->upperValue();
+
+      if(lowerValue == upperValue)
+	{
+	  label = lowerValue;
+	}
+      else
+	{
+	  label = lowerValue + " - " + upperValue;
+	}
+
       //icon item
       switch((*symbolIt)->type())
 	{
 	case QGis::Point:
-	  currentSymbolItem = new QStandardItem(QIcon(QPixmap::fromImage((*symbolIt)->getPointSymbolAsImage())), "PointSymbol");
+	  currentSymbolItem = new QStandardItem(QIcon(QPixmap::fromImage((*symbolIt)->getPointSymbolAsImage())), label);
 	  break;
 	case QGis::Line:
-	  currentSymbolItem = new QStandardItem(QIcon(QPixmap::fromImage((*symbolIt)->getLineSymbolAsImage())), "PointSymbol");
+	  currentSymbolItem = new QStandardItem(QIcon(QPixmap::fromImage((*symbolIt)->getLineSymbolAsImage())), label);
 	  break;
 	case QGis::Polygon:
-	  currentSymbolItem = new QStandardItem(QIcon(QPixmap::fromImage((*symbolIt)->getPolygonSymbolAsImage())), "PointSymbol");
+	  currentSymbolItem = new QStandardItem(QIcon(QPixmap::fromImage((*symbolIt)->getPolygonSymbolAsImage())), label);
 	  break;
 	default:
 	  currentSymbolItem = 0;
@@ -138,27 +148,7 @@
       int currentRowCount = layerItem->rowCount();
       currentSymbolItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
 
-      //label
-      QString label;
-      QString lowerValue = (*symbolIt)->lowerValue();
-      QString upperValue = (*symbolIt)->upperValue();
-
-      if(lowerValue == upperValue)
-	{
-	  label = lowerValue;
-	}
-      else
-	{
-	  label = lowerValue + " - " + upperValue;
-	}
-
-      currentLabelItem = new QStandardItem(label);
-      currentLabelItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
-      QList<QStandardItem*> childItemList;
-      childItemList.push_back(currentSymbolItem);
-      childItemList.push_back(currentLabelItem);
-      layerItem->appendRow(childItemList);
+      layerItem->setChild(layerItem->rowCount(), 0, currentSymbolItem);
       
     }
   
@@ -178,12 +168,10 @@
       return 2;
     }
 
-  QStandardItem* currentSymbolItem = new QStandardItem(QIcon(rasterLayer->getLegendQPixmap(true)), "Raster");
-  QStandardItem* currentLabelItem = new QStandardItem("");
+  QStandardItem* currentSymbolItem = new QStandardItem(QIcon(rasterLayer->getLegendQPixmap(true)), "");
 
   int currentRowCount = layerItem->rowCount();
   layerItem->setChild(currentRowCount, 0, currentSymbolItem);
-  layerItem->setChild(currentRowCount, 1, currentLabelItem);
 
   return 0;
 }

Modified: branches/advanced_printing_branch/src/ui/qgscomposerlegendwidgetbase.ui
===================================================================
--- branches/advanced_printing_branch/src/ui/qgscomposerlegendwidgetbase.ui	2008-07-15 08:36:10 UTC (rev 8783)
+++ branches/advanced_printing_branch/src/ui/qgscomposerlegendwidgetbase.ui	2008-07-15 13:20:48 UTC (rev 8784)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>495</width>
-    <height>513</height>
+    <width>496</width>
+    <height>575</height>
    </rect>
   </property>
   <property name="sizePolicy" >
@@ -192,8 +192,60 @@
      </property>
      <layout class="QGridLayout" name="gridLayout" >
       <item row="0" column="0" >
-       <widget class="QTreeView" name="mItemTreeView" />
+       <widget class="QPushButton" name="mMoveDownPushButton" >
+        <property name="text" >
+         <string>down</string>
+        </property>
+       </widget>
       </item>
+      <item row="0" column="1" >
+       <widget class="QPushButton" name="mMoveUpPushButton" >
+        <property name="text" >
+         <string>up</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2" >
+       <widget class="QPushButton" name="mAddPushButton" >
+        <property name="text" >
+         <string>add...</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="3" >
+       <widget class="QPushButton" name="mRemovePushButton" >
+        <property name="text" >
+         <string>remove</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="4" >
+       <widget class="QPushButton" name="mEditPushButton" >
+        <property name="text" >
+         <string>edit...</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="5" >
+       <spacer name="horizontalSpacer" >
+        <property name="orientation" >
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0" >
+         <size>
+          <width>28</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="1" column="0" colspan="6" >
+       <widget class="QTreeView" name="mItemTreeView" >
+        <property name="headerHidden" >
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>



More information about the QGIS-commit mailing list