Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_plot_renderer.h"
#include "qwt_plot.h"
#include "qwt_painter.h"
#include "qwt_plot_layout.h"
#include "qwt_abstract_legend.h"
#include "qwt_scale_widget.h"
#include "qwt_scale_engine.h"
#include "qwt_text.h"
#include "qwt_text_label.h"
#include "qwt_math.h"
#include <qpainter.h>
#include <qpaintengine.h>
#include <qtransform.h>
#include <qprinter.h>
#include <qprintdialog.h>
#include <qfiledialog.h>
#include <qfileinfo.h>
#include <qstyle.h>
#include <qstyleoption.h>
#include <qimagewriter.h>
#ifndef QWT_NO_SVG
#ifdef QT_SVG_LIB
#include <qsvggenerator.h>
#endif
#endif
static QPainterPath qwtCanvasClip(
const QWidget* canvas, const QRectF &canvasRect )
{
// The clip region is calculated in integers
// To avoid too much rounding errors better
// calculate it in target device resolution
int x1 = qCeil( canvasRect.left() );
int x2 = qFloor( canvasRect.right() );
int y1 = qCeil( canvasRect.top() );
int y2 = qFloor( canvasRect.bottom() );
const QRect r( x1, y1, x2 - x1 - 1, y2 - y1 - 1 );
QPainterPath clipPath;
( void ) QMetaObject::invokeMethod(
const_cast< QWidget *>( canvas ), "borderPath",
Qt::DirectConnection,
Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, r ) );
return clipPath;
}
class QwtPlotRenderer::PrivateData
{
public:
PrivateData():
discardFlags( QwtPlotRenderer::DiscardNone ),
layoutFlags( QwtPlotRenderer::DefaultLayout )
{
}
QwtPlotRenderer::DiscardFlags discardFlags;
QwtPlotRenderer::LayoutFlags layoutFlags;
};
/*!
Constructor
\param parent Parent object
*/
QwtPlotRenderer::QwtPlotRenderer( QObject *parent ):
QObject( parent )
{
d_data = new PrivateData;
}
//! Destructor
QwtPlotRenderer::~QwtPlotRenderer()
{
delete d_data;
}
/*!
Change a flag, indicating what to discard from rendering
\param flag Flag to change
\param on On/Off
\sa DiscardFlag, testDiscardFlag(), setDiscardFlags(), discardFlags()
*/
void QwtPlotRenderer::setDiscardFlag( DiscardFlag flag, bool on )
{
if ( on )
d_data->discardFlags |= flag;
else
d_data->discardFlags &= ~flag;
}
/*!
\return True, if flag is enabled.
\param flag Flag to be tested
\sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags()
*/
bool QwtPlotRenderer::testDiscardFlag( DiscardFlag flag ) const
{
return d_data->discardFlags & flag;
}
/*!
Set the flags, indicating what to discard from rendering
\param flags Flags
\sa DiscardFlag, setDiscardFlag(), testDiscardFlag(), discardFlags()
*/
void QwtPlotRenderer::setDiscardFlags( DiscardFlags flags )
{
d_data->discardFlags = flags;
}
/*!
\return Flags, indicating what to discard from rendering
\sa DiscardFlag, setDiscardFlags(), setDiscardFlag(), testDiscardFlag()
*/
QwtPlotRenderer::DiscardFlags QwtPlotRenderer::discardFlags() const
{
return d_data->discardFlags;
}
/*!
Change a layout flag
\param flag Flag to change
\param on On/Off
\sa LayoutFlag, testLayoutFlag(), setLayoutFlags(), layoutFlags()
*/
void QwtPlotRenderer::setLayoutFlag( LayoutFlag flag, bool on )
{
if ( on )
d_data->layoutFlags |= flag;
else
d_data->layoutFlags &= ~flag;
}
/*!
\return True, if flag is enabled.
\param flag Flag to be tested
\sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags()
*/
bool QwtPlotRenderer::testLayoutFlag( LayoutFlag flag ) const
{
return d_data->layoutFlags & flag;
}
/*!
Set the layout flags
\param flags Flags
\sa LayoutFlag, setLayoutFlag(), testLayoutFlag(), layoutFlags()
*/
void QwtPlotRenderer::setLayoutFlags( LayoutFlags flags )
{
d_data->layoutFlags = flags;
}
/*!
\return Layout flags
\sa LayoutFlag, setLayoutFlags(), setLayoutFlag(), testLayoutFlag()
*/
QwtPlotRenderer::LayoutFlags QwtPlotRenderer::layoutFlags() const
{
return d_data->layoutFlags;
}
/*!
Render a plot to a file
The format of the document will be auto-detected from the
suffix of the file name.
\param plot Plot widget
\param fileName Path of the file, where the document will be stored
\param sizeMM Size for the document in millimeters.
\param resolution Resolution in dots per Inch (dpi)
*/
void QwtPlotRenderer::renderDocument( QwtPlot *plot,
const QString &fileName, const QSizeF &sizeMM, int resolution )
{
renderDocument( plot, fileName,
QFileInfo( fileName ).suffix(), sizeMM, resolution );
}
/*!
Render a plot to a file
Loading
Loading full blame...