[QGIS Commit] r15064 - in trunk/qgis: python/core src/app/composer src/core/composer src/mapserver src/ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Jan 21 09:34:26 EST 2011


Author: mhugent
Date: 2011-01-21 06:34:26 -0800 (Fri, 21 Jan 2011)
New Revision: 15064

Modified:
   trunk/qgis/python/core/qgscomposerlabel.sip
   trunk/qgis/src/app/composer/qgscomposerlabelwidget.cpp
   trunk/qgis/src/app/composer/qgscomposerlabelwidget.h
   trunk/qgis/src/core/composer/qgscomposeritemcommand.h
   trunk/qgis/src/core/composer/qgscomposerlabel.cpp
   trunk/qgis/src/core/composer/qgscomposerlabel.h
   trunk/qgis/src/mapserver/qgsconfigparser.cpp
   trunk/qgis/src/mapserver/qgsprojectparser.cpp
   trunk/qgis/src/ui/qgscomposerlabelwidgetbase.ui
Log:
WMS print: manual setting for exported label ids, display paper width and height in capabilities

Modified: trunk/qgis/python/core/qgscomposerlabel.sip
===================================================================
--- trunk/qgis/python/core/qgscomposerlabel.sip	2011-01-21 10:51:17 UTC (rev 15063)
+++ trunk/qgis/python/core/qgscomposerlabel.sip	2011-01-21 14:34:26 UTC (rev 15064)
@@ -49,6 +49,11 @@
        */
     bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
 
-    /**Get label identification number*/
-    int id() const;
+    /**Get label identification number
+      @note this method was added in version 1.7*/
+    QString id() const;
+
+    /**Set label identification number
+      @note this method was added in version 1.7*/
+    void setId( const QString& id );
 };

Modified: trunk/qgis/src/app/composer/qgscomposerlabelwidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerlabelwidget.cpp	2011-01-21 10:51:17 UTC (rev 15063)
+++ trunk/qgis/src/app/composer/qgscomposerlabelwidget.cpp	2011-01-21 14:34:26 UTC (rev 15064)
@@ -162,6 +162,16 @@
   }
 }
 
+void QgsComposerLabelWidget::on_mLabelIdLineEdit_textChanged( const QString& text )
+{
+  if ( mComposerLabel )
+  {
+    mComposerLabel->beginCommand( tr( "Label id changed" ), QgsComposerMergeCommand::ComposerLabelSetId );
+    mComposerLabel->setId( text );
+    mComposerLabel->endCommand();
+  }
+}
+
 void QgsComposerLabelWidget::setGuiElementValues()
 {
   blockAllSignals( true );
@@ -173,6 +183,7 @@
   mLeftRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignLeft );
   mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter );
   mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight );
+  mLabelIdLineEdit->setText( mComposerLabel->id() );
   blockAllSignals( false );
 }
 
@@ -186,4 +197,5 @@
   mLeftRadioButton->blockSignals( block );
   mCenterRadioButton->blockSignals( block );
   mRightRadioButton->blockSignals( block );
+  mLabelIdLineEdit->blockSignals( block );
 }

Modified: trunk/qgis/src/app/composer/qgscomposerlabelwidget.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerlabelwidget.h	2011-01-21 10:51:17 UTC (rev 15063)
+++ trunk/qgis/src/app/composer/qgscomposerlabelwidget.h	2011-01-21 14:34:26 UTC (rev 15064)
@@ -42,6 +42,7 @@
     void on_mTopRadioButton_clicked();
     void on_mBottomRadioButton_clicked();
     void on_mMiddleRadioButton_clicked();
+    void on_mLabelIdLineEdit_textChanged( const QString& text );
 
   private slots:
     void setGuiElementValues();

Modified: trunk/qgis/src/core/composer/qgscomposeritemcommand.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritemcommand.h	2011-01-21 10:51:17 UTC (rev 15063)
+++ trunk/qgis/src/core/composer/qgscomposeritemcommand.h	2011-01-21 14:34:26 UTC (rev 15064)
@@ -71,6 +71,7 @@
       Unknown = 0,
       //composer label
       ComposerLabelSetText,
+      ComposerLabelSetId,
       //composer map
       ComposerMapRotation,
       ComposerMapAnnotationDistance,

Modified: trunk/qgis/src/core/composer/qgscomposerlabel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlabel.cpp	2011-01-21 10:51:17 UTC (rev 15063)
+++ trunk/qgis/src/core/composer/qgscomposerlabel.cpp	2011-01-21 14:34:26 UTC (rev 15064)
@@ -25,9 +25,6 @@
 {
   //default font size is 10 point
   mFont.setPointSizeF( 10 );
-
-  //get new id
-  mId = maximumLabelId( composition ) + 1;
 }
 
 QgsComposerLabel::~QgsComposerLabel()
@@ -173,7 +170,7 @@
   mVAlignment = ( Qt::AlignmentFlag )( itemElem.attribute( "valign" ).toInt() );
 
   //id
-  mId = itemElem.attribute( "id", "0" ).toInt();
+  mId = itemElem.attribute( "id", "" );
 
   //font
   QDomNodeList labelFontList = itemElem.elementsByTagName( "LabelFont" );
@@ -208,27 +205,3 @@
   emit itemChanged();
   return true;
 }
-
-int QgsComposerLabel::maximumLabelId( const QgsComposition* c ) const
-{
-  int id = -1;
-  if ( !c )
-  {
-    return id;
-  }
-
-  QList<QGraphicsItem *> itemList = c->items();
-  QList<QGraphicsItem *>::const_iterator itemIt = itemList.constBegin();
-  for ( ; itemIt != itemList.constEnd(); ++itemIt )
-  {
-    const QgsComposerLabel* label = dynamic_cast<const QgsComposerLabel *>( *itemIt );
-    if ( label )
-    {
-      if ( label->id() > id )
-      {
-        id = label->id();
-      }
-    }
-  }
-  return id;
-}

Modified: trunk/qgis/src/core/composer/qgscomposerlabel.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlabel.h	2011-01-21 10:51:17 UTC (rev 15063)
+++ trunk/qgis/src/core/composer/qgscomposerlabel.h	2011-01-21 14:34:26 UTC (rev 15064)
@@ -72,9 +72,14 @@
        */
     bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
 
-    /**Get label identification number*/
-    int id() const { return mId; }
+    /**Get label identification number
+      @note this method was added in version 1.7*/
+    QString id() const { return mId; }
 
+    /**Set label identification number
+      @note this method was added in version 1.7*/
+    void setId( const QString& id ) { mId = id; }
+
   private:
     // Text
     QString mText;
@@ -95,13 +100,10 @@
     Qt::AlignmentFlag mVAlignment;
 
     // Label id (unique within the same composition)
-    int mId;
+    QString mId;
 
     /**Replaces replace '$CURRENT_DATE<(FORMAT)>' with the current date (e.g. $CURRENT_DATE(d 'June' yyyy)*/
     void replaceDateText( QString& text ) const;
-
-    /**Returns maximum id of all label items or -1 if no item is in the scene. Used to generate new ids in the constructor*/
-    int maximumLabelId( const QgsComposition* c ) const;
 };
 
 #endif

Modified: trunk/qgis/src/mapserver/qgsconfigparser.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgsconfigparser.cpp	2011-01-21 10:51:17 UTC (rev 15063)
+++ trunk/qgis/src/mapserver/qgsconfigparser.cpp	2011-01-21 14:34:26 UTC (rev 15064)
@@ -383,10 +383,15 @@
   for ( ; labelIt != composerLabels.constEnd(); ++labelIt )
   {
     currentLabel = *labelIt;
-    QMap< QString, QString >::const_iterator titleIt = parameterMap.find( "LABEL" + QString::number( currentLabel->id() ) );
+    QMap< QString, QString >::const_iterator titleIt = parameterMap.find( currentLabel->id().toUpper() );
     if ( titleIt == parameterMap.constEnd() )
     {
-      //keep label with default text and size
+      //remove exported labels not referenced in the request
+      if ( !currentLabel->id().isEmpty() )
+      {
+        c->removeItem( currentLabel );
+        delete( currentLabel );
+      }
       continue;
     }
 

Modified: trunk/qgis/src/mapserver/qgsprojectparser.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgsprojectparser.cpp	2011-01-21 10:51:17 UTC (rev 15063)
+++ trunk/qgis/src/mapserver/qgsprojectparser.cpp	2011-01-21 14:34:26 UTC (rev 15064)
@@ -941,6 +941,16 @@
     composerTemplateElem.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
     composerTemplateElem.setAttribute( "xsi:type", "wms:_ExtendedCapabilities" );
 
+    //get paper width and hight in mm from composition
+    QDomElement compositionElem = currentComposerElem.firstChildElement( "Composition" );
+    if ( compositionElem.isNull() )
+    {
+      continue;
+    }
+    composerTemplateElem.setAttribute( "width", compositionElem.attribute( "paperWidth" ) );
+    composerTemplateElem.setAttribute( "height", compositionElem.attribute( "paperHeight" ) );
+
+
     //add available composer maps and their size in mm
     QDomNodeList composerMapList = currentComposerElem.elementsByTagName( "ComposerMap" );
     for ( int j = 0; j < composerMapList.size(); ++j )
@@ -964,8 +974,13 @@
     for ( int j = 0; j < composerLabelList.size(); ++j )
     {
       QDomElement clabel = composerLabelList.at( j ).toElement();
+      QString id = clabel.attribute( "id" );
+      if ( id.isEmpty() ) //only export labels with ids for text replacement
+      {
+        continue;
+      }
       QDomElement composerLabelElem = doc.createElement( "ComposerLabel" );
-      composerLabelElem.setAttribute( "name", "label" + clabel.attribute( "id" ) );
+      composerLabelElem.setAttribute( "name", id );
       composerTemplateElem.appendChild( composerLabelElem );
     }
 

Modified: trunk/qgis/src/ui/qgscomposerlabelwidgetbase.ui
===================================================================
--- trunk/qgis/src/ui/qgscomposerlabelwidgetbase.ui	2011-01-21 10:51:17 UTC (rev 15063)
+++ trunk/qgis/src/ui/qgscomposerlabelwidgetbase.ui	2011-01-21 14:34:26 UTC (rev 15064)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>519</width>
-    <height>362</height>
+    <width>547</width>
+    <height>425</height>
    </rect>
   </property>
   <property name="sizePolicy">
@@ -30,8 +30,8 @@
        <rect>
         <x>0</x>
         <y>0</y>
-        <width>486</width>
-        <height>320</height>
+        <width>513</width>
+        <height>402</height>
        </rect>
       </property>
       <attribute name="label">
@@ -65,7 +65,7 @@
          </property>
         </widget>
        </item>
-       <item row="5" column="0">
+       <item row="6" column="0">
         <widget class="QLabel" name="mMarginTextLabel">
          <property name="text">
           <string>Margin (mm)</string>
@@ -75,7 +75,7 @@
          </property>
         </widget>
        </item>
-       <item row="6" column="0">
+       <item row="7" column="0">
         <widget class="QDoubleSpinBox" name="mMarginDoubleSpinBox"/>
        </item>
        <item row="3" column="0">
@@ -141,6 +141,16 @@
          </layout>
         </widget>
        </item>
+       <item row="9" column="0">
+        <widget class="QLineEdit" name="mLabelIdLineEdit"/>
+       </item>
+       <item row="8" column="0">
+        <widget class="QLabel" name="mIdLabel">
+         <property name="text">
+          <string>Label id</string>
+         </property>
+        </widget>
+       </item>
       </layout>
      </widget>
     </widget>



More information about the QGIS-commit mailing list