Vous êtes sur la page 1sur 31

/****************************************************************************

**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact http//!!!."t-pro#ect.org/legal
**
** $his %ile is part o% the e&a'ples o% the (t $ool)it.
**
** *($+,-./0+1/C-02-,2D*
** 3ou 'ay use this %ile under the ter's o% the ,2D license as %ollo!s
**
** 45edistribution and use in source and binary %or's6 !ith or !ithout
** 'odi%ication6 are per'itted pro7ided that the %ollo!ing conditions are
** 'et
** * 5edistributions o% source code 'ust retain the abo7e copyright
** notice6 this list o% conditions and the %ollo!ing disclai'er.
** * 5edistributions in binary %or' 'ust reproduce the abo7e copyright
** notice6 this list o% conditions and the %ollo!ing disclai'er in
** the docu'entation and/or other 'aterials pro7ided !ith the
** distribution.
** * 0either the na'e o% Digia Plc and its 2ubsidiary(-ies) nor the na'es
** o% its contributors 'ay be used to endorse or pro'ote products deri7ed
** %ro' this so%t!are !ithout speci%ic prior !ritten per'ission.
**
**
** $8/2 29:$;<5- /2 P59=/D-D ,3 $8- C9P35/.8$ 891D-52 <0D
C90$5/,>$952
** 4<2 /24 <0D <03 -?P5-22 95 /@P1/-D ;<55<0$/-26 /0C1>D/0.6 ,>$ 09$
** 1/@/$-D $96 $8- /@P1/-D ;<55<0$/-2 9: @-5C8<0$<,/1/$3 <0D :/$0-22
:95
** < P<5$/C>1<5 P>5P92- <5- D/2C1</@-D. /0 09 -=-0$ 28<11 $8-
C9P35/.8$
** 9;0-5 95 C90$5/,>$952 ,- 1/<,1- :95 <03 D/5-C$6 /0D/5-C$6
/0C/D-0$<16
** 2P-C/<16 -?-@P1<536 95 C902-(>-0$/<1 D<@<.-2 (/0C1>D/0.6 ,>$ 09$
** 1/@/$-D $96 P59C>5-@-0$ 9: 2>,2$/$>$- .99D2 95 2-5=/C-2A 1922
9: >2-6
** D<$<6 95 P59:/$2A 95 ,>2/0-22 /0$-55>P$/90) 89;-=-5 C<>2-D <0D
90 <03
** $8-953 9: 1/<,/1/$36 ;8-$8-5 /0 C90$5<C$6 2$5/C$ 1/<,/1/$36 95 $95$
** (/0C1>D/0. 0-.1/.-0C- 95 9$8-5;/2-) <5/2/0. /0 <03 ;<3 9>$ 9: $8-
>2-
** 9: $8/2 29:$;<5-6 -=-0 /: <D=/2-D 9: $8- P922/,/1/$3 9: 2>C8
D<@<.-.4
**
** *($+-0D+1/C-02-*
**
****************************************************************************/
Bi%nde% 5-0D-5<5-<+8
Bde%ine 5-0D-5<5-<+8
Binclude C(,rushD
Binclude C(PenD
Binclude C(Pi&'apD
Binclude C(;idgetD
class 5ender<rea public (;idget
E
(+9,F-C$
public
enu' 2hape E 1ine6 Points6 Polyline6 Polygon6 5ect6 5ounded5ect6 -llipse6 <rc6
Chord6 Pie6 Path6 $e&t6 Pi&'ap GA
5ender<rea((;idget *parent H 0)A
(2iIe 'ini'u'2iIe8int() constA
(2iIe siIe8int() constA
public slots
7oid set2hape(2hape shape)A
7oid setPen(const (Pen Jpen)A
7oid set,rush(const (,rush Jbrush)A
7oid set<ntialiased(bool antialiased)A
7oid set$rans%or'ed(bool trans%or'ed)A
protected
7oid paint-7ent((Paint-7ent *e7ent)A
pri7ate
2hape shapeA
(Pen penA
(,rush brushA
bool antialiasedA
bool trans%or'edA
(Pi&'ap pi&'apA
GA
Bendi%
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact http//!!!."t-pro#ect.org/legal
**
** $his %ile is part o% the e&a'ples o% the (t $ool)it.
**
** *($+,-./0+1/C-02-,2D*
** 3ou 'ay use this %ile under the ter's o% the ,2D license as %ollo!s
**
** 45edistribution and use in source and binary %or's6 !ith or !ithout
** 'odi%ication6 are per'itted pro7ided that the %ollo!ing conditions are
** 'et
** * 5edistributions o% source code 'ust retain the abo7e copyright
** notice6 this list o% conditions and the %ollo!ing disclai'er.
** * 5edistributions in binary %or' 'ust reproduce the abo7e copyright
** notice6 this list o% conditions and the %ollo!ing disclai'er in
** the docu'entation and/or other 'aterials pro7ided !ith the
** distribution.
** * 0either the na'e o% Digia Plc and its 2ubsidiary(-ies) nor the na'es
** o% its contributors 'ay be used to endorse or pro'ote products deri7ed
** %ro' this so%t!are !ithout speci%ic prior !ritten per'ission.
**
**
** $8/2 29:$;<5- /2 P59=/D-D ,3 $8- C9P35/.8$ 891D-52 <0D
C90$5/,>$952
** 4<2 /24 <0D <03 -?P5-22 95 /@P1/-D ;<55<0$/-26 /0C1>D/0.6 ,>$ 09$
** 1/@/$-D $96 $8- /@P1/-D ;<55<0$/-2 9: @-5C8<0$<,/1/$3 <0D :/$0-22
:95
** < P<5$/C>1<5 P>5P92- <5- D/2C1</@-D. /0 09 -=-0$ 28<11 $8-
C9P35/.8$
** 9;0-5 95 C90$5/,>$952 ,- 1/<,1- :95 <03 D/5-C$6 /0D/5-C$6
/0C/D-0$<16
** 2P-C/<16 -?-@P1<536 95 C902-(>-0$/<1 D<@<.-2 (/0C1>D/0.6 ,>$ 09$
** 1/@/$-D $96 P59C>5-@-0$ 9: 2>,2$/$>$- .99D2 95 2-5=/C-2A 1922
9: >2-6
** D<$<6 95 P59:/$2A 95 ,>2/0-22 /0$-55>P$/90) 89;-=-5 C<>2-D <0D
90 <03
** $8-953 9: 1/<,/1/$36 ;8-$8-5 /0 C90$5<C$6 2$5/C$ 1/<,/1/$36 95 $95$
** (/0C1>D/0. 0-.1/.-0C- 95 9$8-5;/2-) <5/2/0. /0 <03 ;<3 9>$ 9: $8-
>2-
** 9: $8/2 29:$;<5-6 -=-0 /: <D=/2-D 9: $8- P922/,/1/$3 9: 2>C8
D<@<.-.4
**
** *($+-0D+1/C-02-*
**
****************************************************************************/
Binclude C(t.uiD
Binclude 4renderarea.h4
5ender<rea5ender<rea((;idget *parent)
(;idget(parent)
E
shape H PolygonA
antialiased H %alseA
trans%or'ed H %alseA
pi&'ap.load(4/i'ages/"t-logo.png4)A
set,ac)ground5ole((Palette,ase)A
set<uto:ill,ac)ground(true)A
G
(2iIe 5ender<rea'ini'u'2iIe8int() const
E
return (2iIe(1006 100)A
G
(2iIe 5ender<reasiIe8int() const
E
return (2iIe(K006 200)A
G
7oid 5ender<reaset2hape(2hape shape)
E
this-Dshape H shapeA
update()A
G
7oid 5ender<reasetPen(const (Pen Jpen)
E
this-Dpen H penA
update()A
G
7oid 5ender<reaset,rush(const (,rush Jbrush)
E
this-Dbrush H brushA
update()A
G
7oid 5ender<reaset<ntialiased(bool antialiased)
E
this-Dantialiased H antialiasedA
update()A
G
7oid 5ender<reaset$rans%or'ed(bool trans%or'ed)
E
this-Dtrans%or'ed H trans%or'edA
update()A
G
7oid 5ender<reapaint-7ent((Paint-7ent * /* e7ent */)
E
static const (Point pointsLKM H E
(Point(106 N0)6
(Point(206 10)6
(Point(N06 30)6
(Point(O06 P0)
GA
(5ect rect(106 206 N06 Q0)A
(PainterPath pathA
path.'o7e$o(206 N0)A
path.line$o(206 30)A
path.cubic$o(N06 06 R06 R06 N06 N0)A
int start<ngle H 20 * 1QA
int arc1ength H 120 * 1QA
(Painter painter(this)A
painter.setPen(pen)A
painter.set,rush(brush)A
i% (antialiased)
painter.set5ender8int((Painter<ntialiasing6 true)A
%or (int & H 0A & C !idth()A & SH 100) E
%or (int y H 0A y C height()A y SH 100) E
painter.sa7e()A
painter.translate(&6 y)A
i% (trans%or'ed) E
painter.translate(R06 R0)A
painter.rotate(Q0.0)A
painter.scale(0.Q6 0.O)A
painter.translate(-R06 -R0)A
G
s!itch (shape) E
case 1ine
painter.dra!1ine(rect.botto'1e%t()6 rect.top5ight())A
brea)A
case Points
painter.dra!Points(points6 K)A
brea)A
case Polyline
painter.dra!Polyline(points6 K)A
brea)A
case Polygon
painter.dra!Polygon(points6 K)A
brea)A
case 5ect
painter.dra!5ect(rect)A
brea)A
case 5ounded5ect
painter.dra!5ounded5ect(rect6 2R6 2R6 (t5elati7e2iIe)A
brea)A
case -llipse
painter.dra!-llipse(rect)A
brea)A
case <rc
painter.dra!<rc(rect6 start<ngle6 arc1ength)A
brea)A
case Chord
painter.dra!Chord(rect6 start<ngle6 arc1ength)A
brea)A
case Pie
painter.dra!Pie(rect6 start<ngle6 arc1ength)A
brea)A
case Path
painter.dra!Path(path)A
brea)A
case $e&t
painter.dra!$e&t(rect6 (t<lignCenter6 tr(4(t byTn0o)ia4))A
brea)A
case Pi&'ap
painter.dra!Pi&'ap(106 106 pi&'ap)A
G
painter.restore()A
G
G
painter.set5ender8int((Painter<ntialiasing6 %alse)A
painter.setPen(palette().dar)().color())A
painter.set,rush((t0o,rush)A
painter.dra!5ect((5ect(06 06 !idth() - 16 height() - 1))A
G
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact http//!!!."t-pro#ect.org/legal
**
** $his %ile is part o% the e&a'ples o% the (t $ool)it.
**
** *($+,-./0+1/C-02-,2D*
** 3ou 'ay use this %ile under the ter's o% the ,2D license as %ollo!s
**
** 45edistribution and use in source and binary %or's6 !ith or !ithout
** 'odi%ication6 are per'itted pro7ided that the %ollo!ing conditions are
** 'et
** * 5edistributions o% source code 'ust retain the abo7e copyright
** notice6 this list o% conditions and the %ollo!ing disclai'er.
** * 5edistributions in binary %or' 'ust reproduce the abo7e copyright
** notice6 this list o% conditions and the %ollo!ing disclai'er in
** the docu'entation and/or other 'aterials pro7ided !ith the
** distribution.
** * 0either the na'e o% Digia Plc and its 2ubsidiary(-ies) nor the na'es
** o% its contributors 'ay be used to endorse or pro'ote products deri7ed
** %ro' this so%t!are !ithout speci%ic prior !ritten per'ission.
**
**
** $8/2 29:$;<5- /2 P59=/D-D ,3 $8- C9P35/.8$ 891D-52 <0D
C90$5/,>$952
** 4<2 /24 <0D <03 -?P5-22 95 /@P1/-D ;<55<0$/-26 /0C1>D/0.6 ,>$ 09$
** 1/@/$-D $96 $8- /@P1/-D ;<55<0$/-2 9: @-5C8<0$<,/1/$3 <0D :/$0-22
:95
** < P<5$/C>1<5 P>5P92- <5- D/2C1</@-D. /0 09 -=-0$ 28<11 $8-
C9P35/.8$
** 9;0-5 95 C90$5/,>$952 ,- 1/<,1- :95 <03 D/5-C$6 /0D/5-C$6
/0C/D-0$<16
** 2P-C/<16 -?-@P1<536 95 C902-(>-0$/<1 D<@<.-2 (/0C1>D/0.6 ,>$ 09$
** 1/@/$-D $96 P59C>5-@-0$ 9: 2>,2$/$>$- .99D2 95 2-5=/C-2A 1922
9: >2-6
** D<$<6 95 P59:/$2A 95 ,>2/0-22 /0$-55>P$/90) 89;-=-5 C<>2-D <0D
90 <03
** $8-953 9: 1/<,/1/$36 ;8-$8-5 /0 C90$5<C$6 2$5/C$ 1/<,/1/$36 95 $95$
** (/0C1>D/0. 0-.1/.-0C- 95 9$8-5;/2-) <5/2/0. /0 <03 ;<3 9>$ 9: $8-
>2-
** 9: $8/2 29:$;<5-6 -=-0 /: <D=/2-D 9: $8- P922/,/1/$3 9: 2>C8
D<@<.-.4
**
** *($+-0D+1/C-02-*
**
****************************************************************************/
Bi%nde% ;/0D9;+8
Bde%ine ;/0D9;+8
Binclude C(;idgetD
class (Chec),o&A
class (Co'bo,o&A
class (1abelA
class (2pin,o&A
class 5ender<reaA
class ;indo! public (;idget
E
(+9,F-C$
public
;indo!()A
pri7ate slots
7oid shapeChanged()A
7oid penChanged()A
7oid brushChanged()A
pri7ate
5ender<rea *render<reaA
(1abel *shape1abelA
(1abel *pen;idth1abelA
(1abel *pen2tyle1abelA
(1abel *penCap1abelA
(1abel *penFoin1abelA
(1abel *brush2tyle1abelA
(1abel *other9ptions1abelA
(Co'bo,o& *shapeCo'bo,o&A
(2pin,o& *pen;idth2pin,o&A
(Co'bo,o& *pen2tyleCo'bo,o&A
(Co'bo,o& *penCapCo'bo,o&A
(Co'bo,o& *penFoinCo'bo,o&A
(Co'bo,o& *brush2tyleCo'bo,o&A
(Chec),o& *antialiasingChec),o&A
(Chec),o& *trans%or'ationsChec),o&A
GA
Bendi%
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact http//!!!."t-pro#ect.org/legal
**
** $his %ile is part o% the e&a'ples o% the (t $ool)it.
**
** *($+,-./0+1/C-02-,2D*
** 3ou 'ay use this %ile under the ter's o% the ,2D license as %ollo!s
**
** 45edistribution and use in source and binary %or's6 !ith or !ithout
** 'odi%ication6 are per'itted pro7ided that the %ollo!ing conditions are
** 'et
** * 5edistributions o% source code 'ust retain the abo7e copyright
** notice6 this list o% conditions and the %ollo!ing disclai'er.
** * 5edistributions in binary %or' 'ust reproduce the abo7e copyright
** notice6 this list o% conditions and the %ollo!ing disclai'er in
** the docu'entation and/or other 'aterials pro7ided !ith the
** distribution.
** * 0either the na'e o% Digia Plc and its 2ubsidiary(-ies) nor the na'es
** o% its contributors 'ay be used to endorse or pro'ote products deri7ed
** %ro' this so%t!are !ithout speci%ic prior !ritten per'ission.
**
**
** $8/2 29:$;<5- /2 P59=/D-D ,3 $8- C9P35/.8$ 891D-52 <0D
C90$5/,>$952
** 4<2 /24 <0D <03 -?P5-22 95 /@P1/-D ;<55<0$/-26 /0C1>D/0.6 ,>$ 09$
** 1/@/$-D $96 $8- /@P1/-D ;<55<0$/-2 9: @-5C8<0$<,/1/$3 <0D :/$0-22
:95
** < P<5$/C>1<5 P>5P92- <5- D/2C1</@-D. /0 09 -=-0$ 28<11 $8-
C9P35/.8$
** 9;0-5 95 C90$5/,>$952 ,- 1/<,1- :95 <03 D/5-C$6 /0D/5-C$6
/0C/D-0$<16
** 2P-C/<16 -?-@P1<536 95 C902-(>-0$/<1 D<@<.-2 (/0C1>D/0.6 ,>$ 09$
** 1/@/$-D $96 P59C>5-@-0$ 9: 2>,2$/$>$- .99D2 95 2-5=/C-2A 1922
9: >2-6
** D<$<6 95 P59:/$2A 95 ,>2/0-22 /0$-55>P$/90) 89;-=-5 C<>2-D <0D
90 <03
** $8-953 9: 1/<,/1/$36 ;8-$8-5 /0 C90$5<C$6 2$5/C$ 1/<,/1/$36 95 $95$
** (/0C1>D/0. 0-.1/.-0C- 95 9$8-5;/2-) <5/2/0. /0 <03 ;<3 9>$ 9: $8-
>2-
** 9: $8/2 29:$;<5-6 -=-0 /: <D=/2-D 9: $8- P922/,/1/$3 9: 2>C8
D<@<.-.4
**
** *($+-0D+1/C-02-*
**
****************************************************************************/
Binclude C(t.uiD
Binclude 4renderarea.h4
Binclude 4!indo!.h4
const int /d5ole H (t>ser5oleA
;indo!;indo!()
E
render<rea H ne! 5ender<reaA
shapeCo'bo,o& H ne! (Co'bo,o&A
shapeCo'bo,o&-Dadd/te'(tr(4Polygon4)6 5ender<reaPolygon)A
shapeCo'bo,o&-Dadd/te'(tr(45ectangle4)6 5ender<rea5ect)A
shapeCo'bo,o&-Dadd/te'(tr(45ounded 5ectangle4)6 5ender<rea5ounded5ect)A
shapeCo'bo,o&-Dadd/te'(tr(4-llipse4)6 5ender<rea-llipse)A
shapeCo'bo,o&-Dadd/te'(tr(4Pie4)6 5ender<reaPie)A
shapeCo'bo,o&-Dadd/te'(tr(4Chord4)6 5ender<reaChord)A
shapeCo'bo,o&-Dadd/te'(tr(4Path4)6 5ender<reaPath)A
shapeCo'bo,o&-Dadd/te'(tr(41ine4)6 5ender<rea1ine)A
shapeCo'bo,o&-Dadd/te'(tr(4Polyline4)6 5ender<reaPolyline)A
shapeCo'bo,o&-Dadd/te'(tr(4<rc4)6 5ender<rea<rc)A
shapeCo'bo,o&-Dadd/te'(tr(4Points4)6 5ender<reaPoints)A
shapeCo'bo,o&-Dadd/te'(tr(4$e&t4)6 5ender<rea$e&t)A
shapeCo'bo,o&-Dadd/te'(tr(4Pi&'ap4)6 5ender<reaPi&'ap)A
shape1abel H ne! (1abel(tr(4J2hape4))A
shape1abel-Dset,uddy(shapeCo'bo,o&)A
pen;idth2pin,o& H ne! (2pin,o&A
pen;idth2pin,o&-Dset5ange(06 20)A
Bi% de%ined((+92+23@,/<0) UU de%ined((+;2+@<-@9+R) UU
de%ined((+;2+2/@>1<$95)
pen;idth2pin,o&-Dset2pecial=alue$e&t(tr(404))A
Belse
pen;idth2pin,o&-Dset2pecial=alue$e&t(tr(40 (cos'etic pen)4))A
Bendi%
pen;idth1abel H ne! (1abel(tr(4Pen J;idth4))A
pen;idth1abel-Dset,uddy(pen;idth2pin,o&)A
pen2tyleCo'bo,o& H ne! (Co'bo,o&A
pen2tyleCo'bo,o&-Dadd/te'(tr(42olid4)6 (t2olid1ine)A
pen2tyleCo'bo,o&-Dadd/te'(tr(4Dash4)6 (tDash1ine)A
pen2tyleCo'bo,o&-Dadd/te'(tr(4Dot4)6 (tDot1ine)A
pen2tyleCo'bo,o&-Dadd/te'(tr(4Dash Dot4)6 (tDashDot1ine)A
pen2tyleCo'bo,o&-Dadd/te'(tr(4Dash Dot Dot4)6 (tDashDotDot1ine)A
pen2tyleCo'bo,o&-Dadd/te'(tr(40one4)6 (t0oPen)A
pen2tyle1abel H ne! (1abel(tr(4JPen 2tyle4))A
pen2tyle1abel-Dset,uddy(pen2tyleCo'bo,o&)A
penCapCo'bo,o& H ne! (Co'bo,o&A
penCapCo'bo,o&-Dadd/te'(tr(4:lat4)6 (t:latCap)A
penCapCo'bo,o&-Dadd/te'(tr(42"uare4)6 (t2"uareCap)A
penCapCo'bo,o&-Dadd/te'(tr(45ound4)6 (t5oundCap)A
penCap1abel H ne! (1abel(tr(4Pen JCap4))A
penCap1abel-Dset,uddy(penCapCo'bo,o&)A
penFoinCo'bo,o& H ne! (Co'bo,o&A
penFoinCo'bo,o&-Dadd/te'(tr(4@iter4)6 (t@iterFoin)A
penFoinCo'bo,o&-Dadd/te'(tr(4,e7el4)6 (t,e7elFoin)A
penFoinCo'bo,o&-Dadd/te'(tr(45ound4)6 (t5oundFoin)A
penFoin1abel H ne! (1abel(tr(4Pen JFoin4))A
penFoin1abel-Dset,uddy(penFoinCo'bo,o&)A
brush2tyleCo'bo,o& H ne! (Co'bo,o&A
brush2tyleCo'bo,o&-Dadd/te'(tr(41inear .radient4)6
(t1inear.radientPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(45adial .radient4)6
(t5adial.radientPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4Conical .radient4)6
(tConical.radientPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4$e&ture4)6 (t$e&turePattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(42olid4)6 (t2olidPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(48oriIontal4)6 (t8orPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4=ertical4)6 (t=erPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4Cross4)6 (tCrossPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4,ac)!ard Diagonal4)6 (t,DiagPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4:or!ard Diagonal4)6 (t:DiagPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4Diagonal Cross4)6 (tDiagCrossPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4Dense 14)6 (tDense1Pattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4Dense 24)6 (tDense2Pattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4Dense 34)6 (tDense3Pattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4Dense K4)6 (tDenseKPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4Dense R4)6 (tDenseRPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4Dense Q4)6 (tDenseQPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(4Dense P4)6 (tDensePPattern)A
brush2tyleCo'bo,o&-Dadd/te'(tr(40one4)6 (t0o,rush)A
brush2tyle1abel H ne! (1abel(tr(4J,rush4))A
brush2tyle1abel-Dset,uddy(brush2tyleCo'bo,o&)A
other9ptions1abel H ne! (1abel(tr(49ptions4))A
antialiasingChec),o& H ne! (Chec),o&(tr(4J<ntialiasing4))A
trans%or'ationsChec),o& H ne! (Chec),o&(tr(4J$rans%or'ations4))A
connect(shapeCo'bo,o&6 2/.0<1(acti7ated(int))6
this6 219$(shapeChanged()))A
connect(pen;idth2pin,o&6 2/.0<1(7alueChanged(int))6
this6 219$(penChanged()))A
connect(pen2tyleCo'bo,o&6 2/.0<1(acti7ated(int))6
this6 219$(penChanged()))A
connect(penCapCo'bo,o&6 2/.0<1(acti7ated(int))6
this6 219$(penChanged()))A
connect(penFoinCo'bo,o&6 2/.0<1(acti7ated(int))6
this6 219$(penChanged()))A
connect(brush2tyleCo'bo,o&6 2/.0<1(acti7ated(int))6
this6 219$(brushChanged()))A
connect(antialiasingChec),o&6 2/.0<1(toggled(bool))6
render<rea6 219$(set<ntialiased(bool)))A
connect(trans%or'ationsChec),o&6 2/.0<1(toggled(bool))6
render<rea6 219$(set$rans%or'ed(bool)))A
(.rid1ayout *'ain1ayout H ne! (.rid1ayoutA
Bi% de%ined((+92+23@,/<0) UU de%ined((+;2+@<-@9+R) UU
de%ined((+;2+2/@>1<$95)
'ain1ayout-Dset2iIeConstraint((1ayout2et0oConstraint)A
Bendi%
'ain1ayout-DsetColu'n2tretch(06 1)A
'ain1ayout-DsetColu'n2tretch(36 1)A
'ain1ayout-Dadd;idget(render<rea6 06 06 16 K)A
'ain1ayout-Dadd;idget(shape1abel6 26 06 (t<lign5ight)A
'ain1ayout-Dadd;idget(shapeCo'bo,o&6 26 1)A
'ain1ayout-Dadd;idget(pen;idth1abel6 36 06 (t<lign5ight)A
'ain1ayout-Dadd;idget(pen;idth2pin,o&6 36 1)A
'ain1ayout-Dadd;idget(pen2tyle1abel6 K6 06 (t<lign5ight)A
'ain1ayout-Dadd;idget(pen2tyleCo'bo,o&6 K6 1)A
'ain1ayout-Dadd;idget(penCap1abel6 36 26 (t<lign5ight)A
'ain1ayout-Dadd;idget(penCapCo'bo,o&6 36 3)A
'ain1ayout-Dadd;idget(penFoin1abel6 26 26 (t<lign5ight)A
'ain1ayout-Dadd;idget(penFoinCo'bo,o&6 26 3)A
'ain1ayout-Dadd;idget(brush2tyle1abel6 K6 26 (t<lign5ight)A
'ain1ayout-Dadd;idget(brush2tyleCo'bo,o&6 K6 3)A
'ain1ayout-Dadd;idget(other9ptions1abel6 R6 06 (t<lign5ight)A
'ain1ayout-Dadd;idget(antialiasingChec),o&6 R6 16 16 16 (t<lign5ight)A
'ain1ayout-Dadd;idget(trans%or'ationsChec),o&6 R6 26 16 26 (t<lign5ight)A
set1ayout('ain1ayout)A
shapeChanged()A
penChanged()A
brushChanged()A
antialiasingChec),o&-DsetChec)ed(true)A
set;indo!$itle(tr(4,asic Dra!ing4))A
G
7oid ;indo!shapeChanged()
E
5ender<rea2hape shape H 5ender<rea2hape(shapeCo'bo,o&-Dite'Data(
shapeCo'bo,o&-Dcurrent/nde&()6 /d5ole).to/nt())A
render<rea-Dset2hape(shape)A
G
7oid ;indo!penChanged()
E
int !idth H pen;idth2pin,o&-D7alue()A
(tPen2tyle style H (tPen2tyle(pen2tyleCo'bo,o&-Dite'Data(
pen2tyleCo'bo,o&-Dcurrent/nde&()6 /d5ole).to/nt())A
(tPenCap2tyle cap H (tPenCap2tyle(penCapCo'bo,o&-Dite'Data(
penCapCo'bo,o&-Dcurrent/nde&()6 /d5ole).to/nt())A
(tPenFoin2tyle #oin H (tPenFoin2tyle(penFoinCo'bo,o&-Dite'Data(
penFoinCo'bo,o&-Dcurrent/nde&()6 /d5ole).to/nt())A
render<rea-DsetPen((Pen((tblue6 !idth6 style6 cap6 #oin))A
G
7oid ;indo!brushChanged()
E
(t,rush2tyle style H (t,rush2tyle(brush2tyleCo'bo,o&-Dite'Data(
brush2tyleCo'bo,o&-Dcurrent/nde&()6 /d5ole).to/nt())A
i% (style HH (t1inear.radientPattern) E
(1inear.radient linear.radient(06 06 1006 100)A
linear.radient.setColor<t(0.06 (t!hite)A
linear.radient.setColor<t(0.26 (tgreen)A
linear.radient.setColor<t(1.06 (tblac))A
render<rea-Dset,rush(linear.radient)A
G else i% (style HH (t5adial.radientPattern) E
(5adial.radient radial.radient(R06 R06 R06 P06 P0)A
radial.radient.setColor<t(0.06 (t!hite)A
radial.radient.setColor<t(0.26 (tgreen)A
radial.radient.setColor<t(1.06 (tblac))A
render<rea-Dset,rush(radial.radient)A
G else i% (style HH (tConical.radientPattern) E
(Conical.radient conical.radient(R06 R06 1R0)A
conical.radient.setColor<t(0.06 (t!hite)A
conical.radient.setColor<t(0.26 (tgreen)A
conical.radient.setColor<t(1.06 (tblac))A
render<rea-Dset,rush(conical.radient)A
G else i% (style HH (t$e&turePattern) E
render<rea-Dset,rush((,rush((Pi&'ap(4/i'ages/bric).png4)))A
G else E
render<rea-Dset,rush((,rush((tgreen6 style))A
G
G
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact http//!!!."t-pro#ect.org/legal
**
** $his %ile is part o% the e&a'ples o% the (t $ool)it.
**
** *($+,-./0+1/C-02-,2D*
** 3ou 'ay use this %ile under the ter's o% the ,2D license as %ollo!s
**
** 45edistribution and use in source and binary %or's6 !ith or !ithout
** 'odi%ication6 are per'itted pro7ided that the %ollo!ing conditions are
** 'et
** * 5edistributions o% source code 'ust retain the abo7e copyright
** notice6 this list o% conditions and the %ollo!ing disclai'er.
** * 5edistributions in binary %or' 'ust reproduce the abo7e copyright
** notice6 this list o% conditions and the %ollo!ing disclai'er in
** the docu'entation and/or other 'aterials pro7ided !ith the
** distribution.
** * 0either the na'e o% Digia Plc and its 2ubsidiary(-ies) nor the na'es
** o% its contributors 'ay be used to endorse or pro'ote products deri7ed
** %ro' this so%t!are !ithout speci%ic prior !ritten per'ission.
**
**
** $8/2 29:$;<5- /2 P59=/D-D ,3 $8- C9P35/.8$ 891D-52 <0D
C90$5/,>$952
** 4<2 /24 <0D <03 -?P5-22 95 /@P1/-D ;<55<0$/-26 /0C1>D/0.6 ,>$ 09$
** 1/@/$-D $96 $8- /@P1/-D ;<55<0$/-2 9: @-5C8<0$<,/1/$3 <0D :/$0-22
:95
** < P<5$/C>1<5 P>5P92- <5- D/2C1</@-D. /0 09 -=-0$ 28<11 $8-
C9P35/.8$
** 9;0-5 95 C90$5/,>$952 ,- 1/<,1- :95 <03 D/5-C$6 /0D/5-C$6
/0C/D-0$<16
** 2P-C/<16 -?-@P1<536 95 C902-(>-0$/<1 D<@<.-2 (/0C1>D/0.6 ,>$ 09$
** 1/@/$-D $96 P59C>5-@-0$ 9: 2>,2$/$>$- .99D2 95 2-5=/C-2A 1922
9: >2-6
** D<$<6 95 P59:/$2A 95 ,>2/0-22 /0$-55>P$/90) 89;-=-5 C<>2-D <0D
90 <03
** $8-953 9: 1/<,/1/$36 ;8-$8-5 /0 C90$5<C$6 2$5/C$ 1/<,/1/$36 95 $95$
** (/0C1>D/0. 0-.1/.-0C- 95 9$8-5;/2-) <5/2/0. /0 <03 ;<3 9>$ 9: $8-
>2-
** 9: $8/2 29:$;<5-6 -=-0 /: <D=/2-D 9: $8- P922/,/1/$3 9: 2>C8
D<@<.-.4
**
** *($+-0D+1/C-02-*
**
****************************************************************************/
Binclude C(<pplicationD
Binclude 4!indo!.h4
int 'ain(int argc6 char *arg7LM)
E
(+/0/$+5-29>5C-(basicdra!ing)A
(<pplication app(argc6 arg7)A
;indo! !indo!A
Bi% de%ined((+92+23@,/<0)
!indo!.sho!@a&i'iIed()A
Belse
!indo!.sho!()A
Bendi%
return app.e&ec()A
G
si'ple dra!ing ....
Bi%nde% @3;/D.-$+8
Bde%ine @3;/D.-$+8

Binclude C(t.uiD
Binclude C(;idgetD

class @y;idget public (;idget
E
(+9,F-C$
public
// @y;idget()A

protected
7oid paint-7ent((Paint-7ent *e7ent)A
signals

public slots

GA

Bendi% // @3;/D.-$+8
'y!idget.cpp
Binclude 4'y!idget.h4

7oid @y;idgetpaint-7ent((Paint-7ent *e7ent)
E
//create a (Painter and pass a pointer to the de7ice.
//< paint de7ice can be a (;idget6 a (Pi&'ap or a (/'age
(Painter painter(this)A

//a si'ple line
painter.dra!1ine(16161006100)A

//create a blac) pen that has solid line
//and the !idth is 2.
(Pen 'yPen((tblac)6 26 (t2olid1ine)A
painter.setPen('yPen)A
painter.dra!1ine(1006100610061)A

//dra! a point
'yPen.setColor((tred)A
painter.dra!Point(1106110)A

//dra! a polygon
(Polygon polygonA
polygon CC (Point(1306 1K0) CC (Point(1N06 1P0)
CC (Point(1N06 1K0) CC (Point(2206 110)
CC (Point(1K06 100)A
painter.dra!Polygon(polygon)A

//dra! an ellipse
//$he set5ender8int() call enables antialiasing6 telling (Painter to use di%%erent
//color intensities on the edges to reduce the 7isual distortion that nor'ally
//occurs !hen the edges o% a shape are con7erted into pi&els
painter.set5ender8int((Painter<ntialiasing6 true)A
painter.setPen((Pen((tblac)6 36 (tDashDot1ine6 (t5oundCap))A
painter.set,rush((,rush((tgreen6 (t2olidPattern))A
painter.dra!-llipse(2006 N06 K006 2K0)A

G
'ain.cpp
Binclude C(t.uiD
Binclude 4'y!idget.h4

int 'ain( int argc6 char **arg7 )
E
(<pplication app( argc6 arg7 )A

@y;idget 'y;idgetA
'y;idget.sho!()A

return app.e&ec()A
G
trans%or'ations.........
Coordinate 2yste'
$he coordinate syste' is controlled by the (Painter class. $ogether !ith the
(PaintDe7ice and (Paint-ngine classes6 (Painter %or' the basis o% (tVs painting
syste'6 <rthur. (Painter is used to per%or' dra!ing operations6 (PaintDe7ice is an
abstraction o% a t!o-di'ensional space that can be painted on using a (Painter6 and
(Paint-ngine pro7ides the inter%ace that the painter uses to dra! onto di%%erent types o%
de7ices.
$he (PaintDe7ice class is the base class o% ob#ects that can be painted /ts dra!ing
capabilities are inherited by the (;idget6 (Pi&'ap6 (Picture6 (/'age6 and (Printer
classes. $he de%ault coordinate syste' o% a paint de7ice has its origin at the top-le%t
corner. $he & 7alues increase to the right and the y 7alues increase do!n!ards. $he
de%ault unit is one pi&el on pi&el-based de7ices and one point (1/P2 o% an inch) on
printers.
$he 'apping o% the logical (Painter coordinates to the physical (PaintDe7ice
coordinates are handled by (PainterVs trans%or'ation 'atri&6 7ie!port and 4!indo!4.
$he logical and physical coordinate syste's coincide by de%ault. (Painter also supports
coordinate trans%or'ations (e.g. rotation and scaling).
5endering
1ogical 5epresentation
$he siIe (!idth and height) o% a graphics pri'iti7e al!ays correspond to its 'athe'atical
'odel6 ignoring the !idth o% the pen it is rendered !ith
(5ect(16 26 Q6 K) (1ine(26 P6 Q6 1)
<liased Painting
;hen dra!ing6 the pi&el rendering is controlled by the (Painter<ntialiasing render hint.
$he 5ender8int enu' is used to speci%y %lags to (Painter that 'ay or 'ay not be
respected by any gi7en engine. $he (Painter<ntialiasing 7alue indicates that the
engine should antialias edges o% pri'iti7es i% possible6 i.e. s'oothing the edges by using
di%%erent color intensities.
,ut by de%ault the painter is aliased and other rules apply ;hen rendering !ith a one
pi&el !ide pen the pi&els !ill be rendered to the right and belo! the 'athe'atically
de%ined points. :or e&a'ple
(Painter painter(this)A
painter.setPen((tdar).reen)A
painter.dra!5ect(16 26 Q6 K)A
(Painter painter(this)A
painter.setPen((tdar).reen)A
painter.dra!1ine(26 P6 Q6 1)A
;hen rendering !ith a pen !ith an e7en nu'ber o% pi&els6 the pi&els !ill be rendered
sy'etrically around the 'athe'atical de%ined points6 !hile rendering !ith a pen !ith an
odd nu'ber o% pi&els6 the spare pi&el !ill be rendered to the right and belo! the
'athe'atical point as in the one pi&el case. 2ee the (5ect: diagra's belo! %or
concrete e&a'ples.
(5ect:
1ogical representation 9ne pi&el !ide pen
$!o pi&el !ide pen $hree pi&el !ide pen
0ote that %or historical reasons the return 7alue o% the (5ectright() and (5ectbotto'()
%unctions de7iate %ro' the true botto'-right corner o% the rectangle.
(5ectVs right() %unction returns le%t() S !idth() - 1 and the botto'() %unction returns top()
S height() - 1. $he botto'-right green point in the diagra's sho!s the return coordinates
o% these %unctions.
;e reco''end that you si'ply use (5ect: instead $he (5ect: class de%ines a
rectangle in the plane using %loating point coordinates %or accuracy ((5ect uses integer
coordinates)6 and the (5ect:right() and (5ect:botto'() %unctions do return the true
botto'-right corner.
<lternati7ely6 using (5ect6 apply &() S !idth() and y() S height() to %ind the botto'-right
corner6 and a7oid the right() and botto'() %unctions.
<nti-aliased Painting
/% you set (PainterVs anti-aliasing render hint6 the pi&els !ill be rendered sy'etrically on
both sides o% the 'athe'atically de%ined points
(Painter painter(this)A
painter.set5ender8int(
(Painter<ntialiasing)A
painter.setPen((tdar).reen)A
painter.dra!5ect(16 26 Q6 K)A
(Painter painter(this)A
painter.set5ender8int(
(Painter<ntialiasing)A
painter.setPen((tdar).reen)A
painter.dra!1ine(26 P6 Q6 1)A
$rans%or'ations
,y de%ault6 the (Painter operates on the associated de7iceVs o!n coordinate syste'6 but
it also has co'plete support %or a%%ine coordinate trans%or'ations.
3ou can scale the coordinate syste' by a gi7en o%%set using the (Painterscale()
%unction6 you can rotate it cloc)!ise using the (Painterrotate() %unction and you can
translate it (i.e. adding a gi7en o%%set to the points) using the (Paintertranslate()
%unction.
nop rotate()scale() translate()
3ou can also t!ist the coordinate syste' around the origin using the (Paintershear()
%unction. 2ee the <%%ine $rans%or'ations de'o %or a 7isualiIation o% a sheared
coordinate syste'. <ll the trans%or'ation operations operate on (PainterVs
trans%or'ation 'atri& that you can retrie7e using the (Painter!orld$rans%or'()
%unction. < 'atri& trans%or's a point in the plane to another point.
/% you need the sa'e trans%or'ations o7er and o7er6 you can also use ($rans%or'
ob#ects and the (Painter!orld$rans%or'() and (Painterset;orld$rans%or'()
%unctions. 3ou can at any ti'e sa7e the (PainterVs trans%or'ation 'atri& by calling the
(Paintersa7e() %unction !hich sa7es the 'atri& on an internal stac). $he
(Painterrestore() %unction pops it bac).
9ne %re"uent need %or the trans%or'ation 'atri& is !hen reusing the sa'e dra!ing code
on a 7ariety o% paint de7ices. ;ithout trans%or'ations6 the results are tightly bound to the
resolution o% the paint de7ice. Printers ha7e high resolution6 e.g. Q00 dots per inch6
!hereas screens o%ten ha7e bet!een P2 and 100 dots per inch.
<nalog Cloc) -&a'ple
$he <nalog Cloc) e&a'ple sho!s ho! to dra! the contents o% a custo' !idget
using (PainterVs trans%or'ation 'atri&.
(tVs e&a'ple directory pro7ides a co'plete !al)-through o% the e&a'ple. 8ere6 !e !ill
only re7ie! the e&a'pleVs paint-7ent() %unction to see ho! !e can use the
trans%or'ation 'atri& (i.e. (PainterVs 'atri& %unctions) to dra! the cloc)Vs %ace.
;e reco''end co'piling and running this e&a'ple be%ore you read any %urther. /n
particular6 try resiIing the !indo! to di%%erent siIes.
7oid <nalogCloc)paint-7ent((Paint-7ent *)
E
static const (Point hour8andL3M H E
(Point(P6 N)6
(Point(-P6 N)6
(Point(06 -K0)
GA
static const (Point 'inute8andL3M H E
(Point(P6 N)6
(Point(-P6 N)6
(Point(06 -P0)
GA
(Color hourColor(12P6 06 12P)A
(Color 'inuteColor(06 12P6 12P6 1O1)A
int side H "@in(!idth()6 height())A
($i'e ti'e H ($i'ecurrent$i'e()A
(Painter painter(this)A
painter.set5ender8int((Painter<ntialiasing)A
painter.translate(!idth() / 26 height() / 2)A
painter.scale(side / 200.06 side / 200.0)A
:irst6 !e set up the painter. ;e translate the coordinate syste' so that point (06 0) is in
the !idgetVs center6 instead o% being at the top-le%t corner. ;e also scale the syste' by
side / 1006 !here side is either the !idgetVs !idth or the height6 !hiche7er is shortest.
;e !ant the cloc) to be s"uare6 e7en i% the de7ice isnVt.
$his !ill gi7e us a 200 & 200 s"uare area6 !ith the origin (06 0) in the center6 that !e can
dra! on. ;hat !e dra! !ill sho! up in the largest possible s"uare that !ill %it in the
!idget.
2ee also the ;indo!-=ie!port Con7ersion section.
painter.sa7e()A
painter.rotate(30.0 * ((ti'e.hour() S ti'e.'inute() / Q0.0)))A
painter.dra!Con7e&Polygon(hour8and6 3)A
painter.restore()A
;e dra! the cloc)Vs hour hand by rotating the coordinate syste' and calling
(Painterdra!Con7e&Polygon(). $han)Vs to the rotation6 itVs dra!n pointed in the right
direction.
$he polygon is speci%ied as an array o% alternating &6 y 7alues6 stored in the hour8and
static 7ariable (de%ined at the beginning o% the %unction)6 !hich corresponds to the %our
points (26 0)6 (06 2)6 (-26 0)6 and (06 -2R).
$he calls to (Paintersa7e() and (Painterrestore() surrounding the code guarantees
that the code that %ollo!s !onVt be disturbed by the trans%or'ations !eV7e used.
painter.sa7e()A
painter.rotate(Q.0 * (ti'e.'inute() S ti'e.second() / Q0.0))A
painter.dra!Con7e&Polygon('inute8and6 3)A
painter.restore()A
;e do the sa'e %or the cloc)Vs 'inute hand6 !hich is de%ined by the %our points (16 0)6
(06 1)6 (-16 0)6 and (06 -K0). $hese coordinates speci%y a hand that is thinner and longer
than the 'inute hand.
%or (int # H 0A # C Q0A SS#) E
i% ((# W R) XH 0)
painter.dra!1ine(O26 06 OQ6 0)A
painter.rotate(Q.0)A
G
:inally6 !e dra! the cloc) %ace6 !hich consists o% t!el7e short lines at 30-degree
inter7als. <t the end o% that6 the painter is rotated in a !ay !hich isnVt 7ery use%ul6 but
!eVre done !ith painting so that doesnVt 'atter.
:or a de'onstation o% (tVs ability to per%or' a%%ine trans%or'ations on painting
operations6 see the <%%ine $rans%or'ations de'o !hich allo!s the user to e&peri'ent
!ith the trans%or'ation operations. 2ee also the $rans%or'ations e&a'ple !hich sho!s
ho! trans%or'ations in%luence the !ay that (Painter renders graphics pri'iti7es. /n
particular6 it sho!s ho! the order o% trans%or'ations a%%ects the result.
:or 'ore in%or'ation about the trans%or'ation 'atri&6 see the ($rans%or'
docu'entation.
;indo!-=ie!port Con7ersion
;hen dra!ing !ith (Painter6 !e speci%y points using logical coordinates !hich then are
con7erted into the physical coordinates o% the paint de7ice.
$he 'apping o% the logical coordinates to the physical coordinates are handled by
(PainterVs !orld trans%or'ation !orld$rans%or'() (described in the $rans%or'ations
section)6 and (PainterVs 7ie!port() and !indo!(). $he 7ie!port represents the physical
coordinates speci%ying an arbitrary rectangle. $he 4!indo!4 describes the sa'e
rectangle in logical coordinates. ,y de%ault the logical and physical coordinate syste's
coincide6 and are e"ui7alent to the paint de7iceVs rectangle.
>sing !indo!-7ie!port con7ersion you can 'a)e the logical coordinate syste' %it your
pre%erences. $he 'echanis' can also be used to 'a)e the dra!ing code independent
o% the paint de7ice. 3ou can6 %or e&a'ple6 'a)e the logical coordinates e&tend %ro' (-R06
-R0) to (R06 R0) !ith (06 0) in the center by calling the (Painterset;indo!() %unction
(Painter painter(this)A
painter.set;indo!((5ect(-R06 -R06 1006 100))A
0o!6 the logical coordinates (-R06-R0) correspond to the paint de7iceVs physical
coordinates (06 0). /ndependent o% the paint de7ice6 your painting code !ill al!ays
operate on the speci%ied logical coordinates.
,y setting the 4!indo!4 or 7ie!port rectangle6 you per%or' a linear trans%or'ation o% the
coordinates. 0ote that each corner o% the 4!indo!4 'aps to the corresponding corner o%
the 7ie!port6 and 7ice 7ersa. :or that reason it nor'ally is a good idea to let the 7ie!port
and 4!indo!4 'aintain the sa'e aspect ratio to pre7ent de%or'ation
int side H "@in(!idth()6 height())
int & H (!idth() - side / 2)A
int y H (height() - side / 2)A
painter.set=ie!port(&6 y6 side6 side)A
/% !e 'a)e the logical coordinate syste' a s"uare6 !e should also 'a)e the 7ie!port a
s"uare using the (Painterset=ie!port() %unction. /n the e&a'ple abo7e !e 'a)e it
e"ui7alent to the largest s"uare that %it into the paint de7iceVs rectangle. ,y ta)ing the
paint de7iceVs siIe into consideration !hen setting the !indo! or 7ie!port6 it is possible
to )eep the dra!ing code independent o% the paint de7ice.
0ote that the !indo!-7ie!port con7ersion is only a linear trans%or'ation6 i.e. it does not
per%or' clipping. $his 'eans that i% you paint outside the currently set 4!indo!46 your
painting is still trans%or'ed to the 7ie!port using the sa'e linear algebraic approach.
$he 7ie!port6 4!indo!4 and trans%or'ation 'atri& deter'ine ho! logical (Painter
coordinates 'ap to the paint de7iceVs physical coordinates. ,y de%ault the !orld
trans%or'ation 'atri& is the identity 'atri&6 and the 4!indo!4 and 7ie!port settings are
e"ui7alent to the paint de7iceVs settings6 i.e. the !orld6 4!indo!4 and de7ice coordinate
syste's are e"ui7alent6 but as !e ha7e seen6 the syste's can be 'anipulated using
trans%or'ation operations and !indo!-7ie!port con7ersion. $he illustration abo7e
describes the process.
$he $rans%or'ations e&a'ple sho!s ho! trans%or'ations in%luence the !ay that
(Painter renders graphics pri'iti7es. /n particular it sho!s ho! the order o%
trans%or'ations a%%ect the result.
$he application allo!s the user to 'anipulate the rendering o% a shape by changing the
translation6 rotation and scale o% (PainterVs coordinate syste'.
$he e&a'ple consists o% t!o classes and a global enu'
$he 5ender<rea class controls the rendering o% a gi7en shape.
$he ;indo! class is the applicationVs 'ain !indo!.
$he 9peration enu' describes the 7arious trans%or'ation operations a7ailable in the
application.
:irst !e !ill ta)e a "uic) loo) at the 9peration enu'6 then !e !ill re7ie! the
5ender<rea class to see ho! a shape is rendered. :inally6 !e !ill ta)e a loo) at the
$rans%or'ations applicationVs %eatures i'ple'ented in the ;indo! class.
$rans%or'ation 9perations
0or'ally6 the (Painter operates on the associated de7iceVs o!n coordinate syste'6 but
it also has good support %or coordinate trans%or'ations.
$he de%ault coordinate syste' o% a paint de7ice has its origin at the top-le%t corner. $he &
7alues increase to the right and the y 7alues increase do!n!ards. 3ou can scale the
coordinate syste' by a gi7en o%%set using the (Painterscale() %unction6 you can rotate it
cloc)!ise using the (Painterrotate() %unction and you can translate it (i.e. adding a
gi7en o%%set to the points) using the (Paintertranslate() %unction. 3ou can also t!ist the
coordinate syste' around the origin (called shearing) using the (Paintershear()
%unction.
<ll the tran%or'ation operations operate on (PainterVs tran%or'ation 'atri& that you can
retrie7e using the (Painter!orld$rans%or'() %unction. < 'atri& trans%or's a point in the
plane to another point. :or 'ore in%or'ation about the trans%or'ation 'atri&6 see the
Coordinate 2yste' and ($rans%or' docu'entation.
enu' 9peration E 0o$rans%or'ation6 $ranslate6 5otate6 2cale GA
$he global 9peration enu' is declared in the renderarea.h %ile and describes the 7arious
trans%or'ation operations a7ailable in the $rans%or'ations application.
5ender<rea Class De%inition
$he 5ender<rea class inherits (;idget6 and controls the rendering o% a gi7en shape.
class 5ender<rea public (;idget
E
(+9,F-C$
public
5ender<rea((;idget *parent H 0)A
7oid set9perations(const (1istC9perationD Joperations)A
7oid set2hape(const (PainterPath Jshape)A
(2iIe 'ini'u'2iIe8int() constA
(2iIe siIe8int() constA
protected
7oid paint-7ent((Paint-7ent *e7ent)A
;e declare t!o public %unctions6 set9perations() and set2hape()6 to be able to speci%y
the 5ender<rea !idgetVs shape and to trans%or' the coordinate syste' the shape is
rendered !ithin.
;e rei'ple'ent the (;idgetVs 'ini'u'2iIe8int() and siIe8int() %unctions to gi7e the
5ender<rea !idget a reasonable siIe !ithin our application6 and !e rei'ple'ent the
(;idgetpaint-7ent() e7ent handler to dra! the render areaVs shape applying the userVs
trans%or'ation choices.
pri7ate
7oid dra!Coordinates((Painter Jpainter)A
7oid dra!9utline((Painter Jpainter)A
7oid dra!2hape((Painter Jpainter)A
7oid trans%or'Painter((Painter Jpainter)A
(1istC9perationD operationsA
(PainterPath shapeA
(5ect &,ounding5ectA
(5ect y,ounding5ectA
GA
;e also declare se7eral con7enience %unctions to dra! the shape6 the coordinate
syste'Vs outline and the coordinates6 and to trans%or' the painter according to the
chosen trans%or'ations.
/n addition6 the 5ender<rea !idget )eeps a list o% the currently applied trans%or'ation
operations6 a re%erence to its shape6 and a couple o% con7enience 7ariables that !e !ill
use !hen rendering the coordinates.
5ender<rea Class /'ple'entation
$he 5ender<rea !idget controls the rendering o% a gi7en shape6 including the
trans%or'ations o% the coordinate syste'6 by rei'ple'enting the (;idgetpaint-7ent()
e7ent handler. ,ut %irst !e !ill ta)e a "uic) loo) at the constructor and at the %unctions
that pro7ides access to the 5ender<rea !idget
5ender<rea5ender<rea((;idget *parent)
(;idget(parent)
E
(:ont ne!:ont H %ont()A
ne!:ont.setPi&el2iIe(12)A
set:ont(ne!:ont)A
(:ont@etrics %ont@etrics(ne!:ont)A
&,ounding5ect H %ont@etrics.bounding5ect(tr(4&4))A
y,ounding5ect H %ont@etrics.bounding5ect(tr(4y4))A
G
/n the constructor !e pass the parent para'eter on to the base class6 and custo'iIe the
%ont that !e !ill use to render the coordinates. $he (;idget%ont() %untion returns the
%ont currently set %or the !idget. <s long as no special %ont has been set6 or a%ter
(;idgetset:ont() is called6 this is either a special %ont %or the !idget class6 the parentVs
%ont or (i% this !idget is a top le7el !idget) the de%ault application %ont.
<%ter ensuring that the %ontVs siIe is 12 points6 !e e&tract the rectangles enclosing the
coordinate letters6 V&V and VyV6 using the (:ont@etrics class.
(:ont@etrics pro7ides %unctions to access the indi7idual 'etrics o% the %ont6 its
characters6 and %or strings rendered in the %ont. $he (:ont@etricsbounding5ect()
%unction returns the bounding rectangle o% the gi7en character relati7e to the le%t-'ost
point on the base line.
7oid 5ender<reaset9perations(const (1istC9perationD Joperations)
E
this-Doperations H operationsA
update()A
G
7oid 5ender<reaset2hape(const (PainterPath Jshape)
E
this-Dshape H shapeA
update()A
G
/n the set2hape() and set9perations() %unctions !e update the 5ender<rea !idget by
storing the ne! 7alue or 7alues %ollo!ed by a call to the (;idgetupdate() slot !hich
schedules a paint e7ent %or processing !hen (t returns to the 'ain e7ent loop.
(2iIe 5ender<rea'ini'u'2iIe8int() const
E
return (2iIe(1N26 1N2)A
G
(2iIe 5ender<reasiIe8int() const
E
return (2iIe(2326 232)A
G
;e rei'ple'ent the (;idgetVs 'ini'u'2iIe8int() and siIe8int() %unctions to gi7e the
5ender<rea !idget a reasonable siIe !ithin our application. $he de%ault
i'ple'entations o% these %unctions returns an in7alid siIe i% there is no layout %or this
!idget6 and returns the layoutVs 'ini'u' siIe or pre%erred siIe6 respecti7ely6 other!ise.
7oid 5ender<reapaint-7ent((Paint-7ent *e7ent)
E
(Painter painter(this)A
painter.set5ender8int((Painter<ntialiasing)A
painter.%ill5ect(e7ent-Drect()6 (,rush((t!hite))A
painter.translate(QQ6 QQ)A
$he paint-7ent() e7ent handler recie7es the 5ender<rea !idgetVs paint e7ents. < paint
e7ent is a re"uest to repaint all or part o% the !idget. /t can happen as a result o%
(;idgetrepaint() or (;idgetupdate()6 or because the !idget !as obscured and has
no! been unco7ered6 or %or 'any other reasons.
:irst !e create a (Painter %or the 5ender<rea !idget. $he (Painter<ntialiasing render
hint indicates that the engine should antialias edges o% pri'iti7es i% possible. $hen !e
erase the area that needs to be repainted using the (Painter%ill5ect() %unction.
;e also translate the coordinate syste' !ith an constant o%%set to ensure that the
original shape is renderend !ith a suitable 'argin.
painter.sa7e()A
trans%or'Painter(painter)A
dra!2hape(painter)A
painter.restore()A
,e%ore !e start to render the shape6 !e call the (Paintersa7e() %unction.
(Paintersa7e() sa7es the current painter state (i.e. pushes the state onto a stac))
including the current coordinate syste'. $he rationale %or sa7ing the painter state is that
the %ollo!ing call to the trans%or'Painter() %unction !ill trans%or' the coordinate syste'
depending on the currently chosen trans%or'ation operations6 and !e need a !ay to get
bac) to the original state to dra! the outline.
<%ter trans%or'ing the coordinate syste'6 !e dra! the 5ender<reaVs shape6 and then
!e restore the painter state using the (Painterrestore() %unction (i.e. popping the sa7ed
state o%% the stac)).
dra!9utline(painter)A
$hen !e dra! the s"uare outline.
trans%or'Painter(painter)A
dra!Coordinates(painter)A
G
2ince !e !ant the coordinates to correspond !ith the coordinate syste' the shape is
rendered !ithin6 !e 'ust 'a)e another call to the trans%or'Painter() %unction.
$he order o% the painting operations is essential !ith respect to the shared pi&els. $he
reason !hy !e donVt render the coordinates !hen the coordinate syste' already is
trans%or'ed to render the shape6 but instead de%er their rendering to the end6 is that !e
!ant the coordinates to appear on top o% the shape and its outline.
$here is no need to sa7e the (Painter state this ti'e since dra!ing the coordinates is
the last painting operation.
7oid 5ender<readra!Coordinates((Painter Jpainter)
E
painter.setPen((tred)A
painter.dra!1ine(06 06 R06 0)A
painter.dra!1ine(KN6 -26 R06 0)A
painter.dra!1ine(KN6 26 R06 0)A
painter.dra!$e&t(Q0 - &,ounding5ect.!idth() / 26
0 S &,ounding5ect.height() / 26 tr(4&4))A
painter.dra!1ine(06 06 06 R0)A
painter.dra!1ine(-26 KN6 06 R0)A
painter.dra!1ine(26 KN6 06 R0)A
painter.dra!$e&t(0 - y,ounding5ect.!idth() / 26
Q0 S y,ounding5ect.height() / 26 tr(4y4))A
G
7oid 5ender<readra!9utline((Painter Jpainter)
E
painter.setPen((tdar).reen)A
painter.setPen((tDash1ine)A
painter.set,rush((t0o,rush)A
painter.dra!5ect(06 06 1006 100)A
G
7oid 5ender<readra!2hape((Painter Jpainter)
E
painter.%illPath(shape6 (tblue)A
G
$he dra!Coordinates()6 dra!9utline() and dra!2hape() are con7enience %unctions
called %ro' the paint-7ent() e7ent handler. :or 'ore in%or'ation about (PainterVs basic
dra!ing operations and ho! to display basic graphics pri'iti7es6 see the ,asic Dra!ing
e&a'ple.
7oid 5ender<reatrans%or'Painter((Painter Jpainter)
E
%or (int i H 0A i C operations.siIe()A SSi) E
s!itch (operationsLiM) E
case $ranslate
painter.translate(R06 R0)A
brea)A
case 2cale
painter.scale(0.PR6 0.PR)A
brea)A
case 5otate
painter.rotate(Q0)A
brea)A
case 0o$rans%or'ation
de%ault
A
G
G
G
$he trans%or'Painter() con7enience %unction is also called %ro' the paint-7ent() e7ent
handler6 and trans%or's the gi7en (PainterVs coordinate syste' according to the userVs
trans%or'ation choices.
;indo! Class De%inition
$he ;indo! class is the $rans%or'ations applicationVs 'ain !indo!.
$he application displays %our 5ender<rea !idgets. $he le%t-'ost !idget renders the
shape in (PainterVs de%ault coordinate syste'6 the others render the shape !ith the
chosen trans%or'ation in addition to all the trans%or'ations applied to the 5ender<rea
!idgets to their le%t.
class ;indo! public (;idget
E
(+9,F-C$
public
;indo!()A
public slots
7oid operationChanged()A
7oid shape2elected(int inde&)A
;e declare t!o public slots to 'a)e the application able to respond to user interaction6
updating the displayed 5ender<rea !idgets according to the userVs trans%or'ation
choices.
$he operationChanged() slot updates each o% the 5ender<rea !idgets applying the
currently chosen trans%or'ation operations6 and is called !hene7er the user changes
the selected operations. $he shape2elected() slot updates the 5ender<rea !idgetsV
shapes !hene7er the user changes the pre%erred shape.
pri7ate
7oid setup2hapes()A
enu' E 0u'$rans%or'ed<reas H 3 GA
5ender<rea *original5ender<reaA
5ender<rea *trans%or'ed5ender<reasL0u'$rans%or'ed<reasMA
(Co'bo,o& *shapeCo'bo,o&A
(Co'bo,o& *operationCo'bo,o&esL0u'$rans%or'ed<reasMA
(1istC(PainterPathD shapesA
GA
;e also declare a pri7ate con7enience %unction6 setup2hapes()6 that is used !hen
constructing the ;indo! !idget6 and !e declare pointers to the 7arious co'ponents o%
the !idget. ;e choose to )eep the a7ailable shapes in a (1ist o% (PainterPaths. /n
addition !e declare a pri7ate enu' counting the nu'ber o% displayed 5ender<rea
!idgets e&cept the !idget that renders the shape in (PainterVs de%ault coordinate
syste'.
;indo! Class /'ple'entation
/n the constructor !e create and initialiIe the applicationVs co'ponents
;indo!;indo!()
E
original5ender<rea H ne! 5ender<reaA
shapeCo'bo,o& H ne! (Co'bo,o&A
shapeCo'bo,o&-Dadd/te'(tr(4Cloc)4))A
shapeCo'bo,o&-Dadd/te'(tr(48ouse4))A
shapeCo'bo,o&-Dadd/te'(tr(4$e&t4))A
shapeCo'bo,o&-Dadd/te'(tr(4$ruc)4))A
(.rid1ayout *layout H ne! (.rid1ayoutA
layout-Dadd;idget(original5ender<rea6 06 0)A
layout-Dadd;idget(shapeCo'bo,o&6 16 0)A
:irst !e create the 5ender<rea !idget that !ill render the shape in the de%ault
coordinate syste'. ;e also create the associated (Co'bo,o& that allo!s the user to
choose a'ong %our di%%erent shapes < cloc)6 a house6 a te&t and a truc). $he shapes
the'sel7es are created at the end o% the constructor6 using the setup2hapes()
con7enience %unction.
%or (int i H 0A i C 0u'$rans%or'ed<reasA SSi) E
trans%or'ed5ender<reasLiM H ne! 5ender<reaA
operationCo'bo,o&esLiM H ne! (Co'bo,o&A
operationCo'bo,o&esLiM-Dadd/te'(tr(40o trans%or'ation4))A
operationCo'bo,o&esLiM-Dadd/te'(tr(45otate by Q0T&,04))A
operationCo'bo,o&esLiM-Dadd/te'(tr(42cale to PRW4))A
operationCo'bo,o&esLiM-Dadd/te'(tr(4$ranslate by (R06 R0)4))A
connect(operationCo'bo,o&esLiM6 2/.0<1(acti7ated(int))6
this6 219$(operationChanged()))A
layout-Dadd;idget(trans%or'ed5ender<reasLiM6 06 i S 1)A
layout-Dadd;idget(operationCo'bo,o&esLiM6 16 i S 1)A
G
$hen !e create the 5ender<rea !idgets that !ill render their shapes !ith coordinate
tran%or'ations. ,y de%ault the applied operation is 0o $rans%or'ation6 i.e. the shapes
are rendered !ithin the de%ault coordinate syste'. ;e create and initialiIe the
associated (Co'bo,o&es !ith ite's corresponding to the 7arious trans%or'ation
operations decribed by the global 9peration enu'.
;e also connect the (Co'bo,o&esV acti7ated() signal to the operationChanged() slot to
update the application !hene7er the user changes the selected trans%or'ation
operations.
set1ayout(layout)A
setup2hapes()A
shape2elected(0)A
set;indo!$itle(tr(4$rans%or'ations4))A
G
:inally6 !e set the layout %or the application !indo! using the (;idgetset1ayout()
%unction6 construct the a7ailable shapes using the pri7ate setup2hapes() con7enience
%unction6 and 'a)e the application sho! the cloc) shape on startup using the public
shape2elected() slot be%ore !e set the !indo! title.
7oid ;indo!setup2hapes()
E
(PainterPath truc)A
(PainterPath cloc)A
(PainterPath houseA
(PainterPath te&tA
...
shapes.append(cloc))A
shapes.append(house)A
shapes.append(te&t)A
shapes.append(truc))A
connect(shapeCo'bo,o&6 2/.0<1(acti7ated(int))6
this6 219$(shape2elected(int)))A
G
$he setup2hapes() %unction is called %ro' the constructor and create the (PainterPath
ob#ects representing the shapes that are used in the application. :or construction details6
see the !indo!.cpp e&a'ple %ile. $he shapes are stored in a (1ist. $he (1istappend()
%unction inserts the gi7en shape at the end o% the list.
;e also connect the associated (Co'bo,o&Vs acti7ated() signal to the shape2elected()
slot to update the application !hen the user changes the pre%erred shape.
7oid ;indo!operationChanged()
E
static const 9peration operation$ableLM H E
0o$rans%or'ation6 5otate6 2cale6 $ranslate
GA
(1istC9perationD operationsA
%or (int i H 0A i C 0u'$rans%or'ed<reasA SSi) E
int inde& H operationCo'bo,o&esLiM-Dcurrent/nde&()A
operations.append(operation$ableLinde&M)A
trans%or'ed5ender<reasLiM-Dset9perations(operations)A
G
G
$he public operationChanged() slot is called !hene7er the user changes the selected
operations.
;e retrie7e the chosen trans%or'ation operation %or each o% the trans%or'ed
5ender<rea !idgets by "uerying the associated (Co'bo,o&es. $he trans%or'ed
5ender<rea !idgets are supposed to render the shape !ith the trans%or'ation speci%ied
by its associated co'bobo& in addition to all the trans%or'ations applied to the
5ender<rea !idgets to its le%t. :or that reason6 %or each !idget !e "uery6 !e append the
associated operation to a (1ist o% trans%or'ations !hich !e apply to the !idget be%ore
proceeding to the ne&t.
7oid ;indo!shape2elected(int inde&)
E
(PainterPath shape H shapesLinde&MA
original5ender<rea-Dset2hape(shape)A
%or (int i H 0A i C 0u'$rans%or'ed<reasA SSi)
trans%or'ed5ender<reasLiM-Dset2hape(shape)A
G
$he shape2elected() slot is called !hene7er the user changes the pre%erred shape6
updating the 5ender<rea !idgets using their public set2hape() %unction.
2u''ary
$he $rans%or'ations e&a'ple sho!s ho! trans%or'ations in%luence the !ay that
(Painter renders graphics pri'iti7es. 0or'ally6 the (Painter operates on the de7iceVs
o!n coordinate syste'6 but it also has good support %or coordinate trans%or'ations. ;ith
the $rans%or'ations application you can scale6 rotate and translate (PainterVs
coordinate syste'. $he order in !hich these tran%or'ations are applied is essential %or
the result.
<ll the tran%or'ation operations operate on (PainterVs tran%or'ation 'atri&. :or 'ore
in%or'ation about the trans%or'ation 'atri&6 see the oordinate 2yste' and ($rans%or'
docu'entation.
$he (t re%erence docu'entation pro7ides se7eral painting de'os. <'ong these is the
<%%ine $rans%or'ations de'o that sho!s (tVs ability to per%or' trans%or'ations on
painting operations. $he de'o also allo!s the user to e&peri'ent !ith the 7arious
trans%or'ation operations.
"gis ---
e&a'ples---
/***************************************************************************
* Copyright (C) 200Q by $i' 2utton *
* ti'Ylin%initi.co' *
* *
* $his progra' is %ree so%t!areA you can redistribute it and/or 'odi%y *
* it under the ter's o% the .0> .eneral Public 1icense as published by *
* the :ree 2o%t!are :oundationA either 7ersion 2 o% the 1icense6 or *
* (at your option) any later 7ersion. *
* *
* $his progra' is distributed in the hope that it !ill be use%ul6 *
* but ;/$89>$ <03 ;<55<0$3A !ithout e7en the i'plied !arranty o% *
* @-5C8<0$<,/1/$3 or :/$0-22 :95 < P<5$/C>1<5 P>5P92-. 2ee the *
* .0> .eneral Public 1icense %or 'ore details. *
* *
* 3ou should ha7e recei7ed a copy o% the .0> .eneral Public 1icense *
* along !ith this progra'A i% not6 !rite to the *
* :ree 2o%t!are :oundation6 /nc.6 *
* RO $e'ple Place - 2uite 3306 ,oston6 @< 02111-130P6 >2<. *
***************************************************************************/
Binclude 4'ain!indo!.h4
//
// (./2 /ncludes
//
Binclude C"gsapplication.hD
Binclude C"gspro7iderregistry.hD
Binclude C"gssinglesy'bolrenderer.hD
Binclude C"gs'aplayerregistry.hD
Binclude C"gs7ectorlayer.hD
Binclude C"gs'apcan7as.hD
//
// (./2 @ap tools
//
Binclude 4"gs'aptoolpan.h4
Binclude 4"gs'aptoolIoo'.h4
//
// $hese are the other headers %or a7ailable 'ap tools (not used in this e&a'ple)
//
//Binclude 4"gs'aptoolcapture.h4
//Binclude 4"gs'aptoolidenti%y.h4
//Binclude 4"gs'aptoolselect.h4
//Binclude 4"gs'aptool7erte&edit.h4
//Binclude 4"gs'easure.h4
//
@ain;indo!@ain;indo!((;idget* parent6 (t;:lags %l)
(@ain;indo!(parent6%l)
E
//re"uired by (tK to initialise the ui
setup>i(this)A
// /nstantiate Pro7ider 5egistry
Bi% de%ined((+;2+@<C)
//
// ,e sure to set this to an appropriate place i% you are on 92?
//
(2tring 'yPluginsDir H 4/>sers/ti'sutton/apps/"gis.app/Contents/@ac92/lib/"gis4A
Belse
//
// ,e sure to set this to an appropriate place i% you are on 1inu& or !indo!s
//
(2tring 'yPluginsDir H 4/ho'e/ti'linu&/apps/"gis+trun)/lib/"gis4A
Bendi%
(gsPro7ider5egistryinstance('yPluginsDir)A
// Create the @ap Can7as
'p@apCan7asH ne! (gs@apCan7as(06 0)A
'p@apCan7as-Denable<nti<liasing(true)A
'p@apCan7as-Duse/'age$o5ender(%alse)A
'p@apCan7as-DsetCan7asColor((Color(2RR6 2RR6 2RR))A
'p@apCan7as-D%reeIe(%alse)A
'p@apCan7as-Dset=isible(true)A
'p@apCan7as-Dre%resh()A
'p@apCan7as-Dsho!()A

// 1ay our !idgets out in the 'ain !indo!
'p1ayout H ne! (=,o&1ayout(%ra'e@ap)A
'p1ayout-Dadd;idget('p@apCan7as)A
//create the action beha7iours
connect('p<ctionPan6 2/.0<1(triggered())6 this6 219$(pan@ode()))A
connect('p<ctionZoo'/n6 2/.0<1(triggered())6 this6 219$(Ioo'/n@ode()))A
connect('p<ctionZoo'9ut6 2/.0<1(triggered())6 this6 219$(Ioo'9ut@ode()))A
connect('p<ction<dd1ayer6 2/.0<1(triggered())6 this6 219$(add1ayer()))A
//create a little toolbar
'p@ap$ool,ar H add$ool,ar(tr(4:ile4))A
'p@ap$ool,ar-Dadd<ction('p<ction<dd1ayer)A
'p@ap$ool,ar-Dadd<ction('p<ctionZoo'/n)A
'p@ap$ool,ar-Dadd<ction('p<ctionZoo'9ut)A
'p@ap$ool,ar-Dadd<ction('p<ctionPan)A
//create the 'aptools
'pPan$ool H ne! (gs@ap$oolPan('p@apCan7as)A
'pPan$ool-Dset<ction('p<ctionPan)A
'pZoo'/n$ool H ne! (gs@ap$oolZoo'('p@apCan7as6 :<12-)A // %alse H in
'pZoo'/n$ool-Dset<ction('p<ctionZoo'/n)A
'pZoo'9ut$ool H ne! (gs@ap$oolZoo'('p@apCan7as6 $5>- )A //true H out
'pZoo'9ut$ool-Dset<ction('p<ctionZoo'9ut)A
G
@ain;indo![@ain;indo!()
E
delete 'pZoo'/n$oolA
delete 'pZoo'9ut$oolA
delete 'pPan$oolA
delete 'p@ap$ool,arA
delete 'p@apCan7asA
delete 'p1ayoutA
G
7oid @ain;indo!pan@ode()
E
'p@apCan7as-Dset@ap$ool('pPan$ool)A
G
7oid @ain;indo!Ioo'/n@ode()
E
'p@apCan7as-Dset@ap$ool('pZoo'/n$ool)A
G
7oid @ain;indo!Ioo'9ut@ode()
E
'p@apCan7as-Dset@ap$ool('pZoo'9ut$ool)A
G
7oid @ain;indo!add1ayer()
E
(2tring 'y1ayerPath H 4../data4A
(2tring 'y1ayer,ase0a'e H 4test4A
(2tring 'yPro7ider0a'e H 4ogr4A

(gs=ector1ayer * 'yp1ayer H ne! (gs=ector1ayer('y1ayerPath6
'y1ayer,ase0a'e6 'yPro7ider0a'e)A
(gs2ingle2y'bol5enderer *'yp5enderer H ne!
(gs2ingle2y'bol5enderer('yp1ayer-Dgeo'etry$ype())A
(1istC(gs@apCan7as1ayerD 'y1ayer2etA
'yp1ayer-Dset5enderer('yp5enderer)A
i% ('yp1ayer-Dis=alid())
E
"Debug(41ayer is 7alid4)A
G
else
E
"Debug(41ayer is 09$ 7alid4)A
returnA
G
// <dd the =ector 1ayer to the 1ayer 5egistry
(gs@ap1ayer5egistryinstance()-Dadd@ap1ayer('yp1ayer6 $5>-)A
// <dd the 1ayer to the 1ayer 2et
'y1ayer2et.append((gs@apCan7as1ayer('yp1ayer))A
// set the can7as to the e&tent o% our layer
'p@apCan7as-Dset-&tent('yp1ayer-De&tent())A
// 2et the @ap Can7as 1ayer 2et
'p@apCan7as-Dset1ayer2et('y1ayer2et)A
G
sudo rp' ->7h http//elgis.argeo.org/repos/R/elgis-release-R-R+0.noarch.rp'
$he release 5P@ can be directly do!nloaded here http//elgis.argeo.org/repos/R/elgis-
release-R-R+0.noarch.rp'

Vous aimerez peut-être aussi