Qwt User's Guide: qwt_painter_command.cpp Source File

Qwt User's Guide 6.3.0

Loading...
Searching...
No Matches
qwt_painter_command.cpp
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#include "qwt_painter_command.h"
11
13QwtPainterCommand::QwtPainterCommand()
14 : m_type( Invalid )
15{
16}
17
19 QwtPainterCommand::QwtPainterCommand( const QPainterPath& path )
20 : m_type( Path )
21{
22 m_path = new QPainterPath( path );
23}
24
34 QwtPainterCommand::QwtPainterCommand( const QRectF& rect,
35 const QPixmap& pixmap, const QRectF& subRect )
36 : m_type( Pixmap )
37{
38 m_pixmapData = new PixmapData();
39 m_pixmapData->rect = rect;
40 m_pixmapData->pixmap = pixmap;
41 m_pixmapData->subRect = subRect;
42}
43
54 QwtPainterCommand::QwtPainterCommand( const QRectF& rect,
55 const QImage& image, const QRectF& subRect,
56 Qt::ImageConversionFlags flags )
57 : m_type( Image )
58{
59 m_imageData = new ImageData();
60 m_imageData->rect = rect;
61 m_imageData->image = image;
62 m_imageData->subRect = subRect;
63 m_imageData->flags = flags;
64}
65
70 QwtPainterCommand::QwtPainterCommand( const QPaintEngineState& state )
71 : m_type( State )
72{
73 m_stateData = new StateData();
74
75 m_stateData->flags = state.state();
76
77 if ( m_stateData->flags & QPaintEngine::DirtyPen )
78 m_stateData->pen = state.pen();
79
80 if ( m_stateData->flags & QPaintEngine::DirtyBrush )
81 m_stateData->brush = state.brush();
82
83 if ( m_stateData->flags & QPaintEngine::DirtyBrushOrigin )
84 m_stateData->brushOrigin = state.brushOrigin();
85
86 if ( m_stateData->flags & QPaintEngine::DirtyFont )
87 m_stateData->font = state.font();
88
89 if ( m_stateData->flags & QPaintEngine::DirtyBackground )
90 {
91 m_stateData->backgroundMode = state.backgroundMode();
92 m_stateData->backgroundBrush = state.backgroundBrush();
93 }
94
95 if ( m_stateData->flags & QPaintEngine::DirtyTransform )
96 m_stateData->transform = state.transform();
97
98 if ( m_stateData->flags & QPaintEngine::DirtyClipEnabled )
99 m_stateData->isClipEnabled = state.isClipEnabled();
100
101 if ( m_stateData->flags & QPaintEngine::DirtyClipRegion )
102 {
103 m_stateData->clipRegion = state.clipRegion();
104 m_stateData->clipOperation = state.clipOperation();
105 }
106
107 if ( m_stateData->flags & QPaintEngine::DirtyClipPath )
108 {
109 m_stateData->clipPath = state.clipPath();
110 m_stateData->clipOperation = state.clipOperation();
111 }
112
113 if ( m_stateData->flags & QPaintEngine::DirtyHints )
114 m_stateData->renderHints = state.renderHints();
115
116 if ( m_stateData->flags & QPaintEngine::DirtyCompositionMode )
117 m_stateData->compositionMode = state.compositionMode();
118
119 if ( m_stateData->flags & QPaintEngine::DirtyOpacity )
120 m_stateData->opacity = state.opacity();
121}
122
128 QwtPainterCommand::QwtPainterCommand( const QwtPainterCommand& other )
129{
130 copy( other );
131}
132
134QwtPainterCommand::~QwtPainterCommand()
135{
136 reset();
137}
138
145 QwtPainterCommand& QwtPainterCommand::operator=( const QwtPainterCommand& other )
146{
147 reset();
148 copy( other );
149
150 return *this;
151}
152
153void QwtPainterCommand::copy( const QwtPainterCommand& other )
154{
155 m_type = other.m_type;
156
157 switch( other.m_type )
158 {
159 case Path:
160 {
161 m_path = new QPainterPath( *other.m_path );
162 break;
163 }
164 case Pixmap:
165 {
166 m_pixmapData = new PixmapData( *other.m_pixmapData );
167 break;
168 }
169 case Image:
170 {
171 m_imageData = new ImageData( *other.m_imageData );
172 break;
173 }
174 case State:
175 {
176 m_stateData = new StateData( *other.m_stateData );
177 break;
178 }
179 default:
180 break;
181 }
182}
183
184void QwtPainterCommand::reset()
185{
186 switch( m_type )
187 {
188 case Path:
189 {
190 delete m_path;
191 break;
192 }
193 case Pixmap:
194 {
195 delete m_pixmapData;
196 break;
197 }
198 case Image:
199 {
200 delete m_imageData;
201 break;
202 }
203 case State:
204 {
205 delete m_stateData;
206 break;
207 }
208 default:
209 break;
210 }
211
212 m_type = Invalid;
213}
214
216QPainterPath* QwtPainterCommand::path()
217{
218 return m_path;
219}
220
222QwtPainterCommand::PixmapData* QwtPainterCommand::pixmapData()
223{
224 return m_pixmapData;
225}
226
228QwtPainterCommand::ImageData* QwtPainterCommand::imageData()
229{
230 return m_imageData;
231}
232
234QwtPainterCommand::StateData* QwtPainterCommand::stateData()
235{
236 return m_stateData;
237}
QwtPainterCommand
Definition qwt_painter_command.h:33
QwtPainterCommand::operator=
QwtPainterCommand & operator=(const QwtPainterCommand &)
Definition qwt_painter_command.cpp:145
QwtPainterCommand::QwtPainterCommand
QwtPainterCommand()
Construct an invalid command.
Definition qwt_painter_command.cpp:13
QwtPainterCommand::path
QPainterPath * path()
Definition qwt_painter_command.cpp:216
QwtPainterCommand::Pixmap
@ Pixmap
Draw a QPixmap.
Definition qwt_painter_command.h:45
QwtPainterCommand::Invalid
@ Invalid
Invalid command.
Definition qwt_painter_command.h:39
QwtPainterCommand::Path
@ Path
Draw a QPainterPath.
Definition qwt_painter_command.h:42
QwtPainterCommand::Image
@ Image
Draw a QImage.
Definition qwt_painter_command.h:48
QwtPainterCommand::State
@ State
QPainter state change.
Definition qwt_painter_command.h:51
QwtPainterCommand::pixmapData
PixmapData * pixmapData()
Definition qwt_painter_command.cpp:222
QwtPainterCommand::imageData
ImageData * imageData()
Definition qwt_painter_command.cpp:228
QwtPainterCommand::stateData
StateData * stateData()
Definition qwt_painter_command.cpp:234
QwtPainterCommand::~QwtPainterCommand
~QwtPainterCommand()
Destructor.
Definition qwt_painter_command.cpp:134