⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwt__plot__print_8cpp-source.html

📁 QWT5.01用于Qt开发的二维图形库程序
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Qwt User&apos;s Guide: qwt_plot_print.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.6 --><div class="tabs">  <ul>    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>    <li><a href="classes.html"><span>Classes</span></a></li>    <li id="current"><a href="files.html"><span>Files</span></a></li>    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>  </ul></div><h1>qwt_plot_print.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************</span><a name="l00002"></a>00002 <span class="comment"> * Qwt Widget Library</span><a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 1997   Josef Wilgen</span><a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002   Uwe Rathmann</span><a name="l00005"></a>00005 <span class="comment"> *</span><a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span><a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the Qwt License, Version 1.0</span><a name="l00008"></a>00008 <span class="comment"> *****************************************************************************/</span><a name="l00009"></a>00009 <a name="l00010"></a>00010 <span class="comment">// vim: expandtab</span><a name="l00011"></a>00011 <a name="l00012"></a>00012 <span class="preprocessor">#include &lt;qpainter.h&gt;</span><a name="l00013"></a>00013 <span class="preprocessor">#if QT_VERSION &lt; 0x040000</span><a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#include &lt;qpaintdevicemetrics.h&gt;</span><a name="l00015"></a>00015 <span class="preprocessor">#else</span><a name="l00016"></a>00016 <span class="preprocessor"></span><span class="preprocessor">#include &lt;qpaintengine.h&gt;</span><a name="l00017"></a>00017 <span class="preprocessor">#endif</span><a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#include "qwt_painter.h"</span><a name="l00019"></a>00019 <span class="preprocessor">#include "qwt_legend_item.h"</span><a name="l00020"></a>00020 <span class="preprocessor">#include "qwt_plot.h"</span><a name="l00021"></a>00021 <span class="preprocessor">#include "qwt_plot_canvas.h"</span><a name="l00022"></a>00022 <span class="preprocessor">#include "qwt_plot_layout.h"</span><a name="l00023"></a>00023 <span class="preprocessor">#include "qwt_legend.h"</span><a name="l00024"></a>00024 <span class="preprocessor">#include "qwt_rect.h"</span><a name="l00025"></a>00025 <span class="preprocessor">#include "qwt_dyngrid_layout.h"</span><a name="l00026"></a>00026 <span class="preprocessor">#include "qwt_scale_widget.h"</span><a name="l00027"></a>00027 <span class="preprocessor">#include "qwt_scale_engine.h"</span><a name="l00028"></a>00028 <span class="preprocessor">#include "qwt_text.h"</span><a name="l00029"></a>00029 <span class="preprocessor">#include "qwt_text_label.h"</span><a name="l00030"></a>00030 <span class="preprocessor">#include "qwt_math.h"</span><a name="l00031"></a>00031 <a name="l00044"></a><a class="code" href="class_qwt_plot.html#db2f14174770601e55d6822437c3fe26">00044</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot.html#db2f14174770601e55d6822437c3fe26">QwtPlot::print</a>(QPaintDevice &amp;paintDev,<a name="l00045"></a>00045    <span class="keyword">const</span> <a class="code" href="class_qwt_plot_print_filter.html">QwtPlotPrintFilter</a> &amp;pfilter)<span class="keyword"> const</span><a name="l00046"></a>00046 <span class="keyword"></span>{<a name="l00047"></a>00047 <span class="preprocessor">#if QT_VERSION &lt; 0x040000</span><a name="l00048"></a>00048 <span class="preprocessor"></span>    QPaintDeviceMetrics mpr(&amp;paintDev);<a name="l00049"></a>00049     <span class="keywordtype">int</span> w = mpr.width();<a name="l00050"></a>00050     <span class="keywordtype">int</span> h = mpr.height();<a name="l00051"></a>00051 <span class="preprocessor">#else</span><a name="l00052"></a>00052 <span class="preprocessor"></span>    <span class="keywordtype">int</span> w = paintDev.width();<a name="l00053"></a>00053     <span class="keywordtype">int</span> h = paintDev.height();<a name="l00054"></a>00054 <span class="preprocessor">#endif</span><a name="l00055"></a>00055 <span class="preprocessor"></span><a name="l00056"></a>00056     QRect rect(0, 0, w, h);<a name="l00057"></a>00057     <span class="keywordtype">double</span> aspect = double(rect.width())/<span class="keywordtype">double</span>(rect.height());<a name="l00058"></a>00058     <span class="keywordflow">if</span> ((aspect &lt; 1.0))<a name="l00059"></a>00059         rect.setHeight(<span class="keywordtype">int</span>(aspect*rect.width()));<a name="l00060"></a>00060 <a name="l00061"></a>00061     QPainter p(&amp;paintDev);<a name="l00062"></a>00062     <a class="code" href="class_qwt_plot.html#db2f14174770601e55d6822437c3fe26">print</a>(&amp;p, rect, pfilter);<a name="l00063"></a>00063 }<a name="l00064"></a>00064 <a name="l00074"></a><a class="code" href="class_qwt_plot.html#2170b35727d35c9b9f4031f490789adc">00074</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot.html#db2f14174770601e55d6822437c3fe26">QwtPlot::print</a>(QPainter *painter, <span class="keyword">const</span> QRect &amp;plotRect,<a name="l00075"></a>00075         <span class="keyword">const</span> <a class="code" href="class_qwt_plot_print_filter.html">QwtPlotPrintFilter</a> &amp;pfilter)<span class="keyword"> const</span><a name="l00076"></a>00076 <span class="keyword"></span>{<a name="l00077"></a>00077     <span class="keywordtype">int</span> axisId;<a name="l00078"></a>00078 <a name="l00079"></a>00079     <span class="keywordflow">if</span> ( painter == 0 || !painter-&gt;isActive() ||<a name="l00080"></a>00080             !plotRect.isValid() || size().isNull() )<a name="l00081"></a>00081        <span class="keywordflow">return</span>;<a name="l00082"></a>00082 <a name="l00083"></a>00083     painter-&gt;save();<a name="l00084"></a>00084 <a name="l00085"></a>00085     <span class="comment">// All paint operations need to be scaled according to</span><a name="l00086"></a>00086     <span class="comment">// the paint device metrics. </span><a name="l00087"></a>00087 <a name="l00088"></a>00088     <a class="code" href="class_qwt_painter.html#952553514abb7ab83c4a43602c899777">QwtPainter::setMetricsMap</a>(<span class="keyword">this</span>, painter-&gt;device());<a name="l00089"></a>00089     <span class="keyword">const</span> <a class="code" href="class_qwt_metrics_map.html">QwtMetricsMap</a> &amp;metricsMap = <a class="code" href="class_qwt_painter.html#3de95bfc83c9beee537404b41749bad5">QwtPainter::metricsMap</a>();<a name="l00090"></a>00090 <a name="l00091"></a>00091     <span class="comment">// It is almost impossible to integrate into the Qt layout</span><a name="l00092"></a>00092     <span class="comment">// framework, when using different fonts for printing</span><a name="l00093"></a>00093     <span class="comment">// and screen. To avoid writing different and Qt unconform</span><a name="l00094"></a>00094     <span class="comment">// layout engines we change the widget attributes, print and </span><a name="l00095"></a>00095     <span class="comment">// reset the widget attributes again. This way we produce a lot of</span><a name="l00096"></a>00096     <span class="comment">// useless layout events ...</span><a name="l00097"></a>00097 <a name="l00098"></a>00098     pfilter.<a class="code" href="class_qwt_plot_print_filter.html#b6ce402443e59a6f4fc68dc24cc6b2ad">apply</a>((<a class="code" href="class_qwt_plot.html">QwtPlot</a> *)<span class="keyword">this</span>);<a name="l00099"></a>00099 <a name="l00100"></a>00100     <span class="keywordtype">int</span> baseLineDists[QwtPlot::axisCnt];<a name="l00101"></a>00101     <span class="keywordflow">if</span> ( !(pfilter.<a class="code" href="class_qwt_plot_print_filter.html#0f47c339382f3292d3e71e0585a008e4">options</a>() &amp; QwtPlotPrintFilter::PrintCanvasBackground) )<a name="l00102"></a>00102     {<a name="l00103"></a>00103         <span class="comment">// In case of no background we set the backbone of</span><a name="l00104"></a>00104         <span class="comment">// the scale on the frame of the canvas.</span><a name="l00105"></a>00105 <a name="l00106"></a>00106         <span class="keywordflow">for</span> (axisId = 0; axisId &lt; QwtPlot::axisCnt; axisId++ )<a name="l00107"></a>00107         {<a name="l00108"></a>00108             <a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *scaleWidget = (<a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *)<a class="code" href="class_qwt_plot.html#6b495d9b17962be6e098026441a1f7b8">axisWidget</a>(axisId);<a name="l00109"></a>00109             <span class="keywordflow">if</span> ( scaleWidget )<a name="l00110"></a>00110             {<a name="l00111"></a>00111                 baseLineDists[axisId] = scaleWidget-&gt;margin();<a name="l00112"></a>00112                 scaleWidget-&gt;setMargin(0);<a name="l00113"></a>00113             }<a name="l00114"></a>00114         }<a name="l00115"></a>00115     }<a name="l00116"></a>00116     <span class="comment">// Calculate the layout for the print.</span><a name="l00117"></a>00117 <a name="l00118"></a>00118     <span class="keywordtype">int</span> layoutOptions = QwtPlotLayout::IgnoreScrollbars <a name="l00119"></a>00119         | QwtPlotLayout::IgnoreFrames;<a name="l00120"></a>00120     <span class="keywordflow">if</span> ( !(pfilter.options() &amp; QwtPlotPrintFilter::PrintMargin) )<a name="l00121"></a>00121         layoutOptions |= QwtPlotLayout::IgnoreMargin;<a name="l00122"></a>00122     <span class="keywordflow">if</span> ( !(pfilter.options() &amp; QwtPlotPrintFilter::PrintLegend) )<a name="l00123"></a>00123         layoutOptions |= QwtPlotLayout::IgnoreLegend;<a name="l00124"></a>00124 <a name="l00125"></a>00125     ((<a class="code" href="class_qwt_plot.html">QwtPlot</a> *)<span class="keyword">this</span>)-&gt;plotLayout()-&gt;activate(<span class="keyword">this</span>, <a name="l00126"></a>00126         <a class="code" href="class_qwt_painter.html#3de95bfc83c9beee537404b41749bad5">QwtPainter::metricsMap</a>().deviceToLayout(plotRect), <a name="l00127"></a>00127         layoutOptions);<a name="l00128"></a>00128 <a name="l00129"></a>00129     <span class="keywordflow">if</span> ((pfilter.options() &amp; QwtPlotPrintFilter::PrintTitle)<a name="l00130"></a>00130         &amp;&amp; (!titleLabel()-&gt;text().isEmpty()))<a name="l00131"></a>00131     {<a name="l00132"></a>00132         printTitle(painter, plotLayout()-&gt;titleRect());<a name="l00133"></a>00133     }<a name="l00134"></a>00134 <a name="l00135"></a>00135     <span class="keywordflow">if</span> ( (pfilter.options() &amp; QwtPlotPrintFilter::PrintLegend)<a name="l00136"></a>00136         &amp;&amp; legend() &amp;&amp; !legend()-&gt;isEmpty() )<a name="l00137"></a>00137     {<a name="l00138"></a>00138         printLegend(painter, plotLayout()-&gt;legendRect());<a name="l00139"></a>00139     }<a name="l00140"></a>00140 <a name="l00141"></a>00141     <span class="keywordflow">for</span> ( axisId = 0; axisId &lt; QwtPlot::axisCnt; axisId++ )<a name="l00142"></a>00142     {<a name="l00143"></a>00143         <a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *scaleWidget = (<a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *)axisWidget(axisId);<a name="l00144"></a>00144         <span class="keywordflow">if</span> (scaleWidget)<a name="l00145"></a>00145         {<a name="l00146"></a>00146             <span class="keywordtype">int</span> baseDist = scaleWidget-&gt;margin();<a name="l00147"></a>00147 <a name="l00148"></a>00148             <span class="keywordtype">int</span> startDist, endDist;<a name="l00149"></a>00149             scaleWidget-&gt;getBorderDistHint(startDist, endDist);<a name="l00150"></a>00150 <a name="l00151"></a>00151             printScale(painter, axisId, startDist, endDist,<a name="l00152"></a>00152                 baseDist, plotLayout()-&gt;scaleRect(axisId));<a name="l00153"></a>00153         }<a name="l00154"></a>00154     }<a name="l00155"></a>00155 <a name="l00156"></a>00156     <span class="keyword">const</span> QRect canvasRect = metricsMap.layoutToDevice(plotLayout()-&gt;canvasRect());<a name="l00157"></a>00157 <a name="l00158"></a>00158     <span class="comment">// When using QwtPainter all sizes where computed in pixel</span><a name="l00159"></a>00159     <span class="comment">// coordinates and scaled by QwtPainter later. This limits</span><a name="l00160"></a>00160     <span class="comment">// the precision to screen resolution. A much better solution</span><a name="l00161"></a>00161     <span class="comment">// is to scale the maps and print in unlimited resolution.</span>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -