[Qgis-developer] how to know if QPainter comes from a print job ?

A Huarte ahuarte47 at yahoo.es
Mon Nov 4 07:48:46 PST 2013


Hi Marco, in "QgsMapRenderer::render" method there is....

...
  //calculate scale factor
  //use the specified dpi and not those from the paint device
  //because sometimes QPainter units are in a local coord sys (e.g. in case of QGraphicsScene)
  double sceneDpi = mScaleCalculator->dpi();
  double scaleFactor = 1.0;
  if ( mOutputUnits == QgsMapRenderer::Millimeters )
  {
    if ( forceWidthScale )
    {
      scaleFactor = *forceWidthScale; <------------------------ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    }
    else
    {
      scaleFactor = sceneDpi / 25.4;
    }
  }
...
  if ( mRenderContext.scaleFactor() != scaleFactor )

  {
    mRenderContext.setScaleFactor( scaleFactor );
    mySameAsLastFlag = false;
  }
...

I have debugged the code and I have verified.
:-)




>________________________________
> De: Marco Hugentobler <marco.hugentobler at sourcepole.ch>
>Para: qgis-developer at lists.osgeo.org 
>Enviado: Lunes 4 de noviembre de 2013 16:40
>Asunto: Re: [Qgis-developer] how to know if QPainter comes from a print job ?
> 
>
>
>>The ScaleFactor is distinct of 1 when the composition engine must paint the map to one specific map scale.
>
>I think you are mixing up QgsRenderContext::scaleFactor() and
      QgsRenderContext::rendererScale().
>
>Regards,
>Marco
>
>On 04.11.2013 16:29, A Huarte wrote:
>
>Hi, Marco, finally I added a flag in 'QgsRenderContext' class indicating that it works in a 'print composition' task.
>>The ScaleFactor is distinct of 1 when the composition engine must paint the map to one specific map scale.
>>
>>
>>At any rate, thank you very much!
>>
>>
>>
>>
>>
>>
>>
>>
>>>________________________________
>>> De: Marco Hugentobler <marco.hugentobler at sourcepole.ch>
>>>Para: qgis-developer at lists.osgeo.org 
>>>Enviado: Lunes 4 de noviembre de 2013 11:37
>>>Asunto: Re: [Qgis-developer] how to know if QPainter comes from a print job ?
>>> 
>>>
>>>
>>>Hi 
>>>
>>>You cannot get that information from the painter
                      itself (a print composition can be printed into
                      QImage, pdf, QPrinter, etc...). The safest guess
                      is probably to look at the QgsRenderContext. If
                      the parameter 'scaleFactor' is very close to 1.0,
                      it is most likely the rendering comes from a print
                      composition.
>>>
>>>Regards,
>>>Marco
>>>
>>>On 04.11.2013 11:28, A Huarte wrote:
>>>
>>>Hi!
>>>>
>>>>
>>>>Within of qgis_core I need know if a QgsRenderContext comes from a print job (from composer) in order to disable one functionality.
>>>>
>>>>
>>>>I get that information from QPainter, QPaintDevice, QPaintEngine::Type ?
>>>>
>>>>
>>>>
>>>>Thank your very much!
>>>>
>>>>
>>>>
>>>>
>>>>_______________________________________________
Qgis-developer mailing list Qgis-developer at lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>
>>>
>>>-- 
Dr. Marco Hugentobler
Sourcepole -  Linux & Open Source Solutions
Weberstrasse 5, CH-8004 Zürich, Switzerland marco.hugentobler at sourcepole.ch http://www.sourcepole.ch Technical Advisor QGIS Project Steering Committee 
>>>
>>>_______________________________________________
>>>Qgis-developer mailing list
>>>Qgis-developer at lists.osgeo.org
>>>http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>
>>>
>>
>>
>>_______________________________________________
Qgis-developer mailing list Qgis-developer at lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
>-- 
Dr. Marco Hugentobler
Sourcepole -  Linux & Open Source Solutions
Weberstrasse 5, CH-8004 Zürich, Switzerland marco.hugentobler at sourcepole.ch http://www.sourcepole.ch Technical Advisor QGIS Project Steering Committee 
>
>_______________________________________________
>Qgis-developer mailing list
>Qgis-developer at lists.osgeo.org
>http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20131104/81913c52/attachment-0001.html>


More information about the Qgis-developer mailing list